forked from ikmdev/tinkar-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation of ConceptEnumerationFacade, and related changes.
- Loading branch information
Showing
12 changed files
with
159 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
common/src/main/java/dev/ikm/tinkar/common/id/PublicIdWithString.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright © 2015 Integrated Knowledge Management ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package dev.ikm.tinkar.common.id; | ||
|
||
import dev.ikm.tinkar.common.binary.Encodable; | ||
|
||
/** | ||
* An interface that can be implemented by an enum, and can also be made compatible | ||
* with a future concept binding that may exist in a starter set or elsewhere. | ||
* @param <T> | ||
*/ | ||
public interface PublicIdWithString<T> extends Comparable<PublicIdStringKey>, Encodable { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
terms/src/main/java/dev/ikm/tinkar/terms/ConceptEnumerationFacade.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright © 2015 Integrated Knowledge Management ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package dev.ikm.tinkar.terms; | ||
|
||
import dev.ikm.tinkar.common.binary.DecoderInput; | ||
import dev.ikm.tinkar.common.binary.Encodable; | ||
import dev.ikm.tinkar.common.binary.EncoderOutput; | ||
import dev.ikm.tinkar.common.id.PublicId; | ||
import dev.ikm.tinkar.common.id.PublicIds; | ||
import dev.ikm.tinkar.common.service.PrimitiveData; | ||
import dev.ikm.tinkar.common.util.uuid.UuidUtil; | ||
|
||
public interface ConceptEnumerationFacade<E extends Enum<E>> | ||
extends ConceptFacade, Encodable { | ||
ConceptFacade conceptForEnum(); | ||
|
||
String name(); | ||
|
||
default PublicId publicId() { | ||
return this.conceptForEnum().publicId(); | ||
} | ||
|
||
default int nid() { | ||
return PrimitiveData.nid(this.conceptForEnum().publicId()); | ||
} | ||
|
||
default E enumValue() { | ||
return (E) this; | ||
} | ||
|
||
static <E extends Enum<E>> E decode(DecoderInput in, Class<E> enumClass) { | ||
switch (Encodable.checkVersion(in)) { | ||
default: | ||
String encodedName = in.readString(); | ||
PublicId encodedId = PublicIds.of(UuidUtil.fromString(in.readString())); | ||
ConceptEnumerationFacade<E> enumElement = (ConceptEnumerationFacade<E>) Enum.valueOf(enumClass, encodedName); | ||
if (enumElement.conceptForEnum().publicId().equals(encodedId)) { | ||
return enumElement.enumValue(); | ||
} | ||
throw new IllegalStateException("Unknown enum concept " + encodedName + "with id " + encodedId); | ||
} | ||
} | ||
|
||
@Override | ||
default void encode(EncoderOutput out) { | ||
out.writeString(this.name()); | ||
out.writeString(UuidUtil.toString(this.conceptForEnum().publicId())); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters