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

    Fields
    Modifier and Type
    Field
    Description
    private 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 Function<String,Object>
     
    private static final Function<String,Object>
     
    private static final Function<String,Object>
     
    private static final Function<String,Object>
     
    private static final Function<String,Object>
     
    private static final Function<Object,String>
     
    private static final Function<Object,String>
     
    private static final Function<Object,String>
     
    private static final Function<Object,String>
     
    private static final Function<Object,String>
     
    private static final Map<Class<?>,org.eclipse.digitaltwin.aas4j.v3.model.KeyTypes>
     
    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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) static <T> List<T>
    addElement(List<T> list, T element)
    Adds element to list and returns list.
    static String
    checkId(String idShort)
    Checks a given short id for not being empty.
    static String
    Checks a given URN for not being empty.
    private static Calendar
    Converts an object to a calendar.
    static org.eclipse.digitaltwin.aas4j.v3.model.Reference
    createModelReference(org.eclipse.digitaltwin.aas4j.v3.model.Identifiable target)
    Returns a model reference to target.
    static org.eclipse.digitaltwin.aas4j.v3.model.Reference
    createModelReference(org.eclipse.digitaltwin.aas4j.v3.model.Referable target)
    Returns a model reference to target.
    (package private) static <T extends org.eclipse.digitaltwin.aas4j.v3.model.Referable>
    T
    getElement(List<T> list, String idShort)
    Returns an element based on its idShort.
    (package private) static List<org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement>
    Returns the elements of the container cont.
    static <E extends Enum<E>>
    E
    getOption(String[] options, E dflt, Class<E> cls)
    Tests the values in pptions against the constants in cls and returns a matching constant or dflt.
    (package private) static String
    Turns an id into a URL path.
    static boolean
    isAlias(org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd type)
    Returns whether type is mapped through mapBaSyxType(Type, ValueType) as alias/one-way fashion to an implementation type.
    private static String
    Turns a LangString given as object to a String.
    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.
    (package private) static void
    mapKeyType(Class<?> cls, org.eclipse.digitaltwin.aas4j.v3.model.KeyTypes type)
    Maps a key type.
    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.
    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.
    (package private) static <T> List<T>
    removeElement(List<T> list, T element)
    Removes element from list and returns list.
    (package private) static <T> List<T>
    removeElements(List<T> list, Predicate<T> pred)
    Removes elements complying with pred from list and returns list.
    static <T> T
    setSemanticId(T caller, String semanticId, org.eclipse.digitaltwin.aas4j.v3.model.HasSemantics target)
    Sets the semanticId on target.
    private static org.eclipse.digitaltwin.aas4j.v3.model.Reference
    toReferenceIf(org.eclipse.digitaltwin.aas4j.v3.model.Reference ref, String prefix, String id)
    Turns a semantic id conditionally into a reference.
    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.
    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.
    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.
    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.DataTypeDefXsd
    translate(de.iip_ecosphere.platform.support.aas.Type type)
    Translates a implementation-independent type to an implementation-specific type.
    static Map<String,de.iip_ecosphere.platform.support.aas.LangString>
    translate(List<org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType> ls)
    Translates BaSyx LangStrings back.
    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.
    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.
    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.
    static String
    Translates an identifier back into its string notation.
    static String
    Translates an identifier.
    static org.eclipse.digitaltwin.aas4j.v3.model.Reference
    Translates a reference, supports IRDI, IRI, see SemanticIdRecognizer.
    static String
    translateReference(org.eclipse.digitaltwin.aas4j.v3.model.Reference ref, boolean stripPrefix)
    Translates a reference back to its string format.
    static Object
    translateValueFromBaSyx(String val, org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd type)
    Translates a BaSyx (property) value back.
    static Object
    translateValueFromBaSyx(org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement val, org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd type)
    Translates a BaSyx value back.
    static String
    translateValueToBaSyx(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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      private static final Map<org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd,Function<Object,String>> OBJECT2BASYX
    • BASYX2OBJECT

      private static final Map<org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd,Function<String,Object>> BASYX2OBJECT
    • BASYX2TYPES_ALIAS

      private static final Set<org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd> BASYX2TYPES_ALIAS
    • KEYTYPES

      private static final Map<Class<?>,org.eclipse.digitaltwin.aas4j.v3.model.KeyTypes> 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

      private static final Function<Object,String> DFLT_OBJECT2BASXY
    • DFLT_BASYX2OBJECT

      private static final Function<String,Object> DFLT_BASYX2OBJECT
    • DFLT_INT2BASXY

      private static final Function<Object,String> DFLT_INT2BASXY
    • DFLT_LONG2BASXY

      private static final Function<Object,String> DFLT_LONG2BASXY
    • DFLT_BASYX2INT

      private static final Function<String,Object> DFLT_BASYX2INT
    • DFLT_BASYX2LONG

      private static final Function<String,Object> DFLT_BASYX2LONG
    • DFLT_INTEGER2BASXY

      private static final Function<Object,String> DFLT_INTEGER2BASXY
    • DFLT_BASYX2INTEGER

      private static final Function<String,Object> DFLT_BASYX2INTEGER
    • DFLT_STRING2BASXY

      private static final Function<Object,String> DFLT_STRING2BASXY
    • DFLT_BASYX2STRING

      private static final Function<String,Object> DFLT_BASYX2STRING
  • Constructor Details

    • Tools

      public Tools()
  • Method Details

    • convertToCalendar

      private static Calendar convertToCalendar(Object obj)
      Converts an object to a calendar.
      Parameters:
      obj - the object
      Returns:
      the calendar or null
    • mapKeyType

      static void mapKeyType(Class<?> cls, org.eclipse.digitaltwin.aas4j.v3.model.KeyTypes type)
      Maps a key type.
      Parameters:
      cls - the class to be used as key
      type - 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 type
      basyxType - 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 type
      basyxType - 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 kind
      basyxKind - the corresponding BaSyx asset kind
    • checkUrn

      public static String checkUrn(String urn)
      Checks a given URN for not being empty.
      Parameters:
      urn - the URN
      Returns:
      urn
      Throws:
      IllegalArgumentException - if the urn is empty or null
    • checkId

      public static String checkId(String idShort)
      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 whether type is mapped through mapBaSyxType(Type, ValueType) as alias/one-way fashion to an implementation type.
      Parameters:
      type - the type to check
      Returns:
      true for one-way, false else
    • 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

      static String idToUrlPath(String id)
      Turns an id into a URL path.
      Parameters:
      id - the id
      Returns:
      the URL path
    • addElement

      static <T> List<T> addElement(List<T> list, T element)
      Adds element to list and returns list.
      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 element added
    • removeElement

      static <T> List<T> removeElement(List<T> list, T element)
      Removes element from list and returns list.
      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

      static <T> List<T> removeElements(List<T> list, Predicate<T> pred)
      Removes elements complying with pred from list and returns list.
      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 its idShort.
      Type Parameters:
      T - the element type
      Parameters:
      list - the list to look into
      idShort - the id short to return the element for
      Returns:
      the element or null for not found
    • getElements

      static List<org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement> getElements(Object cont)
      Returns the elements of the container cont.
      Parameters:
      cont - the container
      Returns:
      the elements or null for not available
    • translateIdentifierToBaSyx

      public static String translateIdentifierToBaSyx(String id, String dfltCustom)
      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 on dfltCustom
      dfltCustom - the default value if id cannot be used
      Returns:
      the identifier
    • translateIdentifierFromBaSyx

      public static String translateIdentifierFromBaSyx(String identifier)
      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

      public static org.eclipse.digitaltwin.aas4j.v3.model.Reference translateReference(String id)
      Translates a reference, supports IRDI, IRI, see SemanticIdRecognizer.
      Parameters:
      id - the for declaring the reference showing some form of type, e.g., prefix "irdi:", may be empty or null leading to null, see IdentifierType
      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 semantic id conditionally into a reference.
      Parameters:
      ref - optional reference, already detected, null for none
      prefix - optional id prefix to match, null matches everything
      id - the semantic id, potentially prefixed, ignored if null or empty
      Returns:
      ref if 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 to target.
      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 to target.
      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 the semanticId on target.
      Parameters:
      caller - the caller to return
      semanticId - the semantic id
      target - 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, see SemanticIdRecognizer.
      Parameters:
      ref - the reference to translate back
      stripPrefix - whether the prefix shall be included
      Returns:
      the translated reference or null if ref was null or it cannot be translated
    • getOption

      public static <E extends Enum<E>> E getOption(String[] options, E dflt, Class<E> cls)
      Tests the values in pptions against the constants in cls and returns a matching constant or dflt.
      Type Parameters:
      E - the enum type
      Parameters:
      options - the options to check
      dflt - the default value
      cls - 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

      private static String langStringToString(Object obj)
      Turns a LangString given 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 type
      value - 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 translated
      type - 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 translated
      type - the expected target type to support the translation, may be null
      Returns:
      the translated value