Skip to content

Commit 211f0e0

Browse files
committed
Merge branch 'main' into 2.9.x
2 parents b015b7d + 8ce592a commit 211f0e0

File tree

119 files changed

+7468
-923
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+7468
-923
lines changed

core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/metamodel/Aspect.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
package org.eclipse.esmf.metamodel;
1515

1616
import java.util.List;
17+
import java.util.Optional;
18+
19+
import org.eclipse.esmf.metamodel.characteristic.Collection;
1720

1821
/**
1922
* An Aspect encapsulates a number of properties and operations that define one functional facet of a Digital Twin.
@@ -31,4 +34,11 @@ public interface Aspect extends StructureElement {
3134
* @since SAMM 2.0.0
3235
*/
3336
List<Event> getEvents();
37+
38+
default boolean isCollectionAspect() {
39+
return getProperties().stream()
40+
.map( Property::getCharacteristic )
41+
.flatMap( Optional::stream )
42+
.filter( Collection.class::isInstance ).count() == 1;
43+
}
3444
}

core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/metamodel/ComplexType.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717
import java.util.Collections;
1818
import java.util.List;
1919
import java.util.Optional;
20-
import java.util.stream.Collectors;
20+
import java.util.function.Function;
2121
import java.util.stream.Stream;
2222

2323
/**
2424
* Defines the data type of a {@link Characteristic} as being a complex value.
2525
*/
2626
public interface ComplexType extends Type, StructureElement {
27-
2827
/**
2928
* @return a {@link java.util.List} of {@link ComplexType}s which extend this Entity
3029
*/
@@ -41,12 +40,18 @@ default boolean isAbstractEntity() {
4140
*/
4241
default List<Property> getAllProperties() {
4342
if ( getExtends().isPresent() ) {
44-
return Stream.of( getProperties(), getExtends().get().getAllProperties() ).flatMap( Collection::stream )
45-
.collect( Collectors.toList() );
43+
return Stream.of( getProperties(), getExtends().get().getAllProperties() ).flatMap( Collection::stream ).toList();
4644
}
4745
return List.copyOf( getProperties() );
4846
}
4947

48+
default List<ComplexType> getAllSuperTypes() {
49+
if ( getExtends().isPresent() ) {
50+
return Stream.of( getExtends().stream(), getExtends().get().getAllSuperTypes().stream() ).flatMap( Function.identity() ).toList();
51+
}
52+
return List.of();
53+
}
54+
5055
@Override
5156
default String getUrn() {
5257
return urn().toString();
@@ -63,4 +68,15 @@ default Optional<ComplexType> getExtends() {
6368
default boolean isComplexType() {
6469
return true;
6570
}
71+
72+
@Override
73+
default boolean isTypeOrSubtypeOf( final Type other ) {
74+
if ( equals( other ) ) {
75+
return true;
76+
}
77+
if ( !other.isComplexType() ) {
78+
return false;
79+
}
80+
return ( (ComplexType) other ).getAllSuperTypes().contains( this );
81+
}
6682
}

core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/metamodel/Scalar.java

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313

1414
package org.eclipse.esmf.metamodel;
1515

16+
import java.util.Map;
17+
18+
import org.eclipse.esmf.metamodel.vocabulary.SammNs;
19+
20+
import com.google.common.collect.ImmutableList;
21+
import com.google.common.collect.ImmutableMap;
22+
import org.apache.jena.vocabulary.RDF;
23+
import org.apache.jena.vocabulary.XSD;
24+
1625
/**
1726
* Defines the data type of a {@link Characteristic} as being a scalar value.
1827
*/
@@ -21,4 +30,65 @@ public interface Scalar extends Type {
2130
default boolean isScalar() {
2231
return true;
2332
}
33+
34+
private boolean transitivelyCastable( final String from, final String to ) {
35+
if ( from.equals( to ) ) {
36+
return true;
37+
}
38+
final Map<String, String> castable = ImmutableMap.<String, String> builder()
39+
.put( XSD.xbyte.getURI(), XSD.xshort.getURI() )
40+
.put( XSD.xshort.getURI(), XSD.xint.getURI() )
41+
.put( XSD.xint.getURI(), XSD.xlong.getURI() )
42+
.put( XSD.xlong.getURI(), XSD.integer.getURI() )
43+
.put( XSD.integer.getURI(), XSD.decimal.getURI() )
44+
.put( XSD.unsignedByte.getURI(), XSD.unsignedShort.getURI() )
45+
.put( XSD.unsignedShort.getURI(), XSD.unsignedInt.getURI() )
46+
.put( XSD.unsignedInt.getURI(), XSD.unsignedLong.getURI() )
47+
.put( XSD.unsignedLong.getURI(), XSD.nonNegativeInteger.getURI() )
48+
.put( XSD.positiveInteger.getURI(), XSD.nonNegativeInteger.getURI() )
49+
.put( XSD.nonNegativeInteger.getURI(), XSD.integer.getURI() )
50+
.put( XSD.negativeInteger.getURI(), XSD.nonPositiveInteger.getURI() )
51+
.put( XSD.nonPositiveInteger.getURI(), XSD.integer.getURI() )
52+
.put( XSD.dateTimeStamp.getURI(), XSD.dateTime.getURI() )
53+
.put( XSD.yearMonthDuration.getURI(), XSD.duration.getURI() )
54+
.put( XSD.dayTimeDuration.getURI(), XSD.duration.getURI() )
55+
.build();
56+
57+
final String entry = castable.get( from );
58+
if ( entry == null ) {
59+
return false;
60+
} else if ( entry.equals( to ) ) {
61+
return true;
62+
}
63+
return transitivelyCastable( entry, to );
64+
}
65+
66+
@Override
67+
default boolean isTypeOrSubtypeOf( final Type other ) {
68+
return transitivelyCastable( getUrn(), other.getUrn() );
69+
}
70+
71+
default boolean hasStringLikeValueSpace() {
72+
return ImmutableList.<String> builder()
73+
.add( XSD.xstring.getURI() )
74+
.add( XSD.date.getURI() )
75+
.add( XSD.time.getURI() )
76+
.add( XSD.dateTime.getURI() )
77+
.add( XSD.dateTimeStamp.getURI() )
78+
.add( XSD.gYear.getURI() )
79+
.add( XSD.gMonth.getURI() )
80+
.add( XSD.gDay.getURI() )
81+
.add( XSD.gYearMonth.getURI() )
82+
.add( XSD.gMonthDay.getURI() )
83+
.add( XSD.duration.getURI() )
84+
.add( XSD.yearMonthDuration.getURI() )
85+
.add( XSD.dayTimeDuration.getURI() )
86+
.add( XSD.hexBinary.getURI() )
87+
.add( XSD.base64Binary.getURI() )
88+
.add( XSD.anyURI.getURI() )
89+
.add( SammNs.SAMM.curie().getURI() )
90+
.add( RDF.langString.getURI() )
91+
.build()
92+
.contains( getUrn() );
93+
}
2494
}

core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/metamodel/Type.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ default boolean isScalar() {
2929
default boolean isComplexType() {
3030
return false;
3131
}
32+
33+
boolean isTypeOrSubtypeOf( Type other );
3234
}
3335

3436

core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/metamodel/characteristic/Collection.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,26 @@
2424
* @since SAMM 1.0.0
2525
*/
2626
public interface Collection extends Characteristic {
27-
2827
/**
2928
* @return a {@link boolean} which determines whether the elements in the collection are ordered.
3029
*/
3130
boolean isOrdered();
3231

32+
/**
33+
* @deprecated Use {@link #allowsDuplicates()} instead
34+
*/
35+
@Deprecated( forRemoval = true )
36+
default boolean isAllowDuplicates() {
37+
return allowsDuplicates();
38+
}
39+
3340
/**
3441
* @return a {@link boolean} which determines whether the collection may contain duplicate values.
3542
*/
36-
boolean isAllowDuplicates();
43+
boolean allowsDuplicates();
3744

3845
/**
3946
* @return {@link Optional} containing the {@link Characteristic} describing the elements of the Collection
40-
*
4147
* @since SAMM 1.0.0
4248
*/
4349
default Optional<Characteristic> getElementCharacteristic() {

core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/metamodel/characteristic/StructuredValue.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.List;
1717

1818
import org.eclipse.esmf.metamodel.Characteristic;
19+
import org.eclipse.esmf.metamodel.Property;
1920

2021
/**
2122
* @since SAMM 1.0.0

core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/metamodel/constraint/RangeConstraint.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,27 @@
2828
public interface RangeConstraint extends Constraint {
2929

3030
/**
31-
* @return the lower bound of the range. The type of the values is determined by the {@link Type} returned by
32-
* {@link RangeConstraint#getDataType()}.
31+
* @return the lower bound of the range. The type of the values is determined by the {@link Type} of the Trait that the Constraint
32+
* is used with.
3333
*/
3434
Optional<ScalarValue> getMinValue();
3535

3636
/**
37-
* @return the upper bound of the range. The type of the values is determined by the {@link Type} returned by
38-
* {@link RangeConstraint#getDataType()}.
37+
* @return the upper bound of the range. The type of the values is determined by the {@link Type} of the Trait that the Constraint
38+
* is used with.
3939
*/
4040
Optional<ScalarValue> getMaxValue();
4141

4242
/**
4343
* @return the definition of how the lower bound of the range is to be interpreted. Possible values are
44-
* 'OPEN', 'AT_LEAST' and 'GREATER_THAN'
45-
*
44+
* 'OPEN', 'AT_LEAST' and 'GREATER_THAN'
4645
* @since SAMM 1.0.0
4746
*/
4847
BoundDefinition getLowerBoundDefinition();
4948

5049
/**
5150
* @return the definition of how the upper bound of the range is to be interpreted. Possible values are
52-
* 'OPEN', 'AT_MOST' and 'LESS_THAN'
53-
*
51+
* 'OPEN', 'AT_MOST' and 'LESS_THAN'
5452
* @since SAMM 1.0.0
5553
*/
5654
BoundDefinition getUpperBoundDefinition();

0 commit comments

Comments
 (0)