Class Tools
java.lang.Object
de.iip_ecosphere.platform.support.aas.basyx2.common.Tools
de.iip_ecosphere.platform.support.aas.basyx2.Tools
public class Tools
extends de.iip_ecosphere.platform.support.aas.basyx2.common.Tools
Some utilities, such as for parameter checking. Public for testing.
- Author:
- Holger Eichelberger, SSE
-
Nested Class Summary
Nested classes/interfaces inherited from class de.iip_ecosphere.platform.support.aas.basyx2.common.Tools
de.iip_ecosphere.platform.support.aas.basyx2.common.Tools.ApiProvider<A,C>, de.iip_ecosphere.platform.support.aas.basyx2.common.Tools.ClientSupplier<C>, de.iip_ecosphere.platform.support.aas.basyx2.common.Tools.HttpClientBuilderConsumer<C>, de.iip_ecosphere.platform.support.aas.basyx2.common.Tools.UriConsumer<C> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Map<de.iip_ecosphere.platform.support.aas.AssetKind, org.eclipse.digitaltwin.aas4j.v3.model.AssetKind> private static final Map<org.eclipse.digitaltwin.aas4j.v3.model.AssetKind, de.iip_ecosphere.platform.support.aas.AssetKind> private static final Map<org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd, Function<String, Object>> private static final Map<org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd, de.iip_ecosphere.platform.support.aas.Type> private static final Set<org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd> private static final Map<org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd, Function<Object, String>> private static final Map<de.iip_ecosphere.platform.support.aas.Type, org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static <T> List<T> addElement(List<T> list, T element) Addselementtolistand returnslist.static StringChecks a given short id for not being empty.static StringChecks a given URN for not being empty.private static CalendarconvertToCalendar(Object obj) Converts an object to a calendar.static org.eclipse.digitaltwin.aas4j.v3.model.ReferencecreateModelReference(org.eclipse.digitaltwin.aas4j.v3.model.Identifiable target) Returns a model reference totarget.static org.eclipse.digitaltwin.aas4j.v3.model.ReferencecreateModelReference(org.eclipse.digitaltwin.aas4j.v3.model.Referable target) Returns a model reference totarget.(package private) static <T extends org.eclipse.digitaltwin.aas4j.v3.model.Referable>
TgetElement(List<T> list, String idShort) Returns an element based on itsidShort.(package private) static List<org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement> getElements(Object cont) Returns the elements of the containercont.static <E extends Enum<E>>
ETests the values inpptionsagainst the constants inclsand returns a matching constant ordflt.(package private) static StringidToUrlPath(String id) Turns an id into a URL path.static booleanisAlias(org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd type) Returns whethertypeis mapped throughmapBaSyxType(Type, ValueType)as alias/one-way fashion to an implementation type.private static StringlangStringToString(Object obj) Turns aLangStringgiven as object to a String.static voidmapBaSyxType(de.iip_ecosphere.platform.support.aas.Type type, org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd basyxType) Maps a BaSyx property-value type into an implementation-independent type.(package private) static voidmapKeyType(Class<?> cls, org.eclipse.digitaltwin.aas4j.v3.model.KeyTypes type) Maps a key type.static voidmapKind(de.iip_ecosphere.platform.support.aas.AssetKind kind, org.eclipse.digitaltwin.aas4j.v3.model.AssetKind basyxKind) Maps an implementation-independent asset kind into a BaSyx asset kind.static voidmapType(de.iip_ecosphere.platform.support.aas.Type type, org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd basyxType, Function<Object, String> toBaSyx, Function<String, Object> fromBaSyx) Maps an implementation-independent type into a BaSyx property-value type.(package private) static <T> List<T> removeElement(List<T> list, T element) Removeselementfromlistand returnslist.(package private) static <T> List<T> removeElements(List<T> list, Predicate<T> pred) Removes elements complying withpredfromlistand returnslist.static <T> TsetSemanticId(T caller, String semanticId, org.eclipse.digitaltwin.aas4j.v3.model.HasSemantics target) Sets thesemanticIdontarget.private static org.eclipse.digitaltwin.aas4j.v3.model.ReferencetoReferenceIf(org.eclipse.digitaltwin.aas4j.v3.model.Reference ref, String prefix, String id) Turns a semanticidconditionally into a reference.static org.eclipse.digitaltwin.aas4j.v3.model.AssetKindtranslate(de.iip_ecosphere.platform.support.aas.AssetKind kind) Translates a implementation-independent asset kind to an implementation-specific asset kind.static org.eclipse.digitaltwin.aas4j.v3.model.EntityTypetranslate(de.iip_ecosphere.platform.support.aas.Entity.EntityType type) Translates a implementation-independent entity type to an implementation-specific type.static org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextTypetranslate(de.iip_ecosphere.platform.support.aas.LangString ls) Translates an AAS to a BaSyx lang string.static List<org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType> translate(de.iip_ecosphere.platform.support.aas.LangString... description) Transforms the given descriptions.static org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsdtranslate(de.iip_ecosphere.platform.support.aas.Type type) Translates a implementation-independent type to an implementation-specific type.Translates BaSyx LangStrings back.static de.iip_ecosphere.platform.support.aas.AssetKindtranslate(org.eclipse.digitaltwin.aas4j.v3.model.AssetKind kind) Translates a implementation-specific asset kind to an implementation-independent asset kind.static de.iip_ecosphere.platform.support.aas.Typetranslate(org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd type) Translates a implementation-specific type to an implementation-independent type.static de.iip_ecosphere.platform.support.aas.Entity.EntityTypetranslate(org.eclipse.digitaltwin.aas4j.v3.model.EntityType type) Translates a implementation-specific entity type to an implementation-independent type.static StringtranslateIdentifierFromBaSyx(String identifier) Translates an identifier back into its string notation.static StringtranslateIdentifierToBaSyx(String id, String dfltCustom) Translates an identifier.static org.eclipse.digitaltwin.aas4j.v3.model.ReferenceTranslates a reference, supports IRDI, IRI, seeSemanticIdRecognizer.static StringtranslateReference(org.eclipse.digitaltwin.aas4j.v3.model.Reference ref, boolean stripPrefix) Translates a reference back to its string format.static ObjecttranslateValueFromBaSyx(String val, org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd type) Translates a BaSyx (property) value back.static ObjecttranslateValueFromBaSyx(org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement val, org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd type) Translates a BaSyx value back.static StringtranslateValueToBaSyx(org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd type, Object value) Translates a value for a given target type.Methods inherited from class de.iip_ecosphere.platform.support.aas.basyx2.common.Tools
clearCache, createApi, fromCache, getApi
-
Field Details
-
TYPES2BASYX
private static final Map<de.iip_ecosphere.platform.support.aas.Type,org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd> TYPES2BASYX -
BASYX2TYPES
private static final Map<org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd,de.iip_ecosphere.platform.support.aas.Type> BASYX2TYPES -
OBJECT2BASYX
-
BASYX2OBJECT
-
BASYX2TYPES_ALIAS
-
KEYTYPES
-
ASSETKINDS2BASYX
private static final Map<de.iip_ecosphere.platform.support.aas.AssetKind,org.eclipse.digitaltwin.aas4j.v3.model.AssetKind> ASSETKINDS2BASYX -
BASYX2ASSETKINDS
private static final Map<org.eclipse.digitaltwin.aas4j.v3.model.AssetKind,de.iip_ecosphere.platform.support.aas.AssetKind> BASYX2ASSETKINDS -
DFLT_OBJECT2BASXY
-
DFLT_BASYX2OBJECT
-
DFLT_INT2BASXY
-
DFLT_LONG2BASXY
-
DFLT_BASYX2INT
-
DFLT_BASYX2LONG
-
DFLT_INTEGER2BASXY
-
DFLT_BASYX2INTEGER
-
DFLT_STRING2BASXY
-
DFLT_BASYX2STRING
-
-
Constructor Details
-
Tools
public Tools()
-
-
Method Details
-
convertToCalendar
Converts an object to a calendar.- Parameters:
obj- the object- Returns:
- the calendar or null
-
mapKeyType
Maps a key type.- Parameters:
cls- the class to be used as keytype- the key type
-
mapBaSyxType
public static void mapBaSyxType(de.iip_ecosphere.platform.support.aas.Type type, org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd basyxType) Maps a BaSyx property-value type into an implementation-independent type.- Parameters:
type- the implementation-independent typebasyxType- the corresponding BaSyx property-value type
-
mapType
public static void mapType(de.iip_ecosphere.platform.support.aas.Type type, org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd basyxType, Function<Object, String> toBaSyx, Function<String, Object> fromBaSyx) Maps an implementation-independent type into a BaSyx property-value type.- Parameters:
type- the implementation-independent typebasyxType- the corresponding BaSyx property-value type
-
mapKind
public static void mapKind(de.iip_ecosphere.platform.support.aas.AssetKind kind, org.eclipse.digitaltwin.aas4j.v3.model.AssetKind basyxKind) Maps an implementation-independent asset kind into a BaSyx asset kind.- Parameters:
kind- the implementation-independent asset kindbasyxKind- the corresponding BaSyx asset kind
-
checkUrn
Checks a given URN for not being empty.- Parameters:
urn- the URN- Returns:
urn- Throws:
IllegalArgumentException- if the urn is empty or null
-
checkId
Checks a given short id for not being empty.- Parameters:
idShort- the short id- Returns:
idShort- Throws:
IllegalArgumentException- if the id is empty or null
-
translate
public static de.iip_ecosphere.platform.support.aas.Entity.EntityType translate(org.eclipse.digitaltwin.aas4j.v3.model.EntityType type) Translates a implementation-specific entity type to an implementation-independent type.- Parameters:
type- the implementation-independent type- Returns:
- the implementation-specific type
-
translate
public static org.eclipse.digitaltwin.aas4j.v3.model.EntityType translate(de.iip_ecosphere.platform.support.aas.Entity.EntityType type) Translates a implementation-independent entity type to an implementation-specific type.- Parameters:
type- the implementation-independent type- Returns:
- the implementation-specific type
-
translate
public static org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd translate(de.iip_ecosphere.platform.support.aas.Type type) Translates a implementation-independent type to an implementation-specific type.- Parameters:
type- the implementation-independent type- Returns:
- the implementation-specific type
-
translate
public static de.iip_ecosphere.platform.support.aas.Type translate(org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd type) Translates a implementation-specific type to an implementation-independent type.- Parameters:
type- the implementation-specific type- Returns:
- the implementation-independent type
-
isAlias
public static boolean isAlias(org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd type) Returns whethertypeis mapped throughmapBaSyxType(Type, ValueType)as alias/one-way fashion to an implementation type.- Parameters:
type- the type to check- Returns:
truefor one-way,falseelse
-
translate
public static org.eclipse.digitaltwin.aas4j.v3.model.AssetKind translate(de.iip_ecosphere.platform.support.aas.AssetKind kind) Translates a implementation-independent asset kind to an implementation-specific asset kind.- Parameters:
kind- the implementation-independent asset kind- Returns:
- the implementation-specific asset kind
-
translate
public static de.iip_ecosphere.platform.support.aas.AssetKind translate(org.eclipse.digitaltwin.aas4j.v3.model.AssetKind kind) Translates a implementation-specific asset kind to an implementation-independent asset kind.- Parameters:
kind- the implementation-specific asset kind- Returns:
- the implementation-independent asset kind
-
idToUrlPath
Turns an id into a URL path.- Parameters:
id- the id- Returns:
- the URL path
-
addElement
Addselementtolistand returnslist.- Type Parameters:
T- the element type- Parameters:
list- the list to add to (may be null)element- the element to add- Returns:
- a list with
elementadded
-
removeElement
Removeselementfromlistand returnslist.- Type Parameters:
T- the element type- Parameters:
list- the list to remove the element from (may be null)element- the element to remove- Returns:
list
-
removeElements
Removes elements complying withpredfromlistand returnslist.- Type Parameters:
T- the element type- Parameters:
list- the list to remove the element from (may be null)pred- a predicate to select the elements to be removed- Returns:
list
-
getElement
static <T extends org.eclipse.digitaltwin.aas4j.v3.model.Referable> T getElement(List<T> list, String idShort) Returns an element based on itsidShort.- Type Parameters:
T- the element type- Parameters:
list- the list to look intoidShort- the id short to return the element for- Returns:
- the element or null for not found
-
getElements
Returns the elements of the containercont.- Parameters:
cont- the container- Returns:
- the elements or null for not available
-
translateIdentifierToBaSyx
Translates an identifier. (supports URN and custom ids)- Parameters:
id- the id showing some form of type, e.g., prefix "urn:", may be empty or null leading to a custom identifier based ondfltCustomdfltCustom- the default value if id cannot be used- Returns:
- the identifier
-
translateIdentifierFromBaSyx
Translates an identifier back into its string notation.- Parameters:
identifier- the identifier (may be null, result is also null then)- Returns:
- the string notation
-
translateReference
Translates a reference, supports IRDI, IRI, seeSemanticIdRecognizer.- Parameters:
id- the for declaring the reference showing some form of type, e.g., prefix "irdi:", may be empty or null leading to null, seeIdentifierType- Returns:
- the reference or null
-
toReferenceIf
private static org.eclipse.digitaltwin.aas4j.v3.model.Reference toReferenceIf(org.eclipse.digitaltwin.aas4j.v3.model.Reference ref, String prefix, String id) Turns a semanticidconditionally into a reference.- Parameters:
ref- optional reference, already detected, null for noneprefix- optional id prefix to match, null matches everythingid- the semantic id, potentially prefixed, ignored if null or empty- Returns:
refif not null, the created reference if the prefix matches, null else
-
createModelReference
public static org.eclipse.digitaltwin.aas4j.v3.model.Reference createModelReference(org.eclipse.digitaltwin.aas4j.v3.model.Identifiable target) Returns a model reference totarget.- Parameters:
target- the element to return the references to- Returns:
- the reference
-
createModelReference
public static org.eclipse.digitaltwin.aas4j.v3.model.Reference createModelReference(org.eclipse.digitaltwin.aas4j.v3.model.Referable target) Returns a model reference totarget.- Parameters:
target- the element to return the references to- Returns:
- the reference
-
setSemanticId
public static <T> T setSemanticId(T caller, String semanticId, org.eclipse.digitaltwin.aas4j.v3.model.HasSemantics target) Sets thesemanticIdontarget.- Parameters:
caller- the caller to returnsemanticId- the semantic idtarget- the target element to set the id on- Returns:
- caller
-
translateReference
public static String translateReference(org.eclipse.digitaltwin.aas4j.v3.model.Reference ref, boolean stripPrefix) Translates a reference back to its string format. Supports IRDI, IRI, seeSemanticIdRecognizer.- Parameters:
ref- the reference to translate backstripPrefix- whether the prefix shall be included- Returns:
- the translated reference or null if
refwas null or it cannot be translated
-
getOption
Tests the values inpptionsagainst the constants inclsand returns a matching constant ordflt.- Type Parameters:
E- the enum type- Parameters:
options- the options to checkdflt- the default valuecls- the enum class providing the constants- Returns:
- the matching option or
dflt
-
translate
public static List<org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType> translate(de.iip_ecosphere.platform.support.aas.LangString... description) Transforms the given descriptions.- Parameters:
description- the description(s) as language string(s)- Returns:
- the translated BaSyx instance
-
langStringToString
Turns aLangStringgiven as object to a String.- Parameters:
obj- the object- Returns:
- the string value
-
translate
public static org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType translate(de.iip_ecosphere.platform.support.aas.LangString ls) Translates an AAS to a BaSyx lang string.- Parameters:
ls- the AAS lang string- Returns:
- the BaSyx lang string
-
translate
public static Map<String,de.iip_ecosphere.platform.support.aas.LangString> translate(List<org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType> ls) Translates BaSyx LangStrings back.- Parameters:
ls- the LangStrings- Returns:
- the translation into a map
-
translateValueToBaSyx
public static String translateValueToBaSyx(org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd type, Object value) Translates a value for a given target type.- Parameters:
type- the BaSyx typevalue- the value to translate- Returns:
- the translated value
-
translateValueFromBaSyx
public static Object translateValueFromBaSyx(String val, org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd type) Translates a BaSyx (property) value back.- Parameters:
val- the value to be translatedtype- the expected target type to support the translation, may be null- Returns:
- the translated value
-
translateValueFromBaSyx
public static Object translateValueFromBaSyx(org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement val, org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd type) Translates a BaSyx value back.- Parameters:
val- the value to be translatedtype- the expected target type to support the translation, may be null- Returns:
- the translated value
-