-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSysMLUnits.java
More file actions
83 lines (79 loc) · 3.26 KB
/
Copy pathSysMLUnits.java
File metadata and controls
83 lines (79 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package sysmlinjava.units;
import java.util.ArrayList;
import java.util.List;
import sysmlinjava.common.SysMLClass;
/**
* SysMLinJava's representation of a collection (library) of {@code SysMLUnit}s
* which are SysMLinJava's representations of the SysML unit. Whereas units in
* SysMLinJava are instances of the {@code SysMLUnit}, this {@code SysMLUnits}
* class provides a base library of {@code SysMLUnit} instances.
* <p>
* Each {@code SysMLUnit} instance must be declared as a static final instance,
* i.e. each unit is declared as a unique object within the scope of the
* containing class. This {@code SysMLUnits} class provides the base for classes
* that contain {@code SysMLUnit} instances. Extensions of the
* {@code SysMLUnits} class should exclusively contain unit declarations, i.e.
* {@code SysMLUnit} instances, and not other objects or operations. An example
* of a use of this class to declare units is as follows.
*
* <pre>
public class SysMLinJavaUnits extends SysMLUnits
{
@Unit
public static final SysMLUnit FeetCubic = new SysMLUnit("feet-cubic", "ft3", "", "", Optional.of(SysMLinJavaQuantityKinds.Volume));
@Unit
public static final SysMLUnit MilesCubic = new SysMLUnit("miles-cubic", "mi3", "", "", Optional.of(SysMLinJavaQuantityKinds.Volume));
@Unit
public static final SysMLUnit Liters = new SysMLUnit("liters", "ltr", "", "", Optional.of(SysMLinJavaQuantityKinds.Volume));
@Unit
public static final SysMLUnit Gallons = new SysMLUnit("gallons", "gal", "", "", Optional.of(SysMLinJavaQuantityKinds.Volume));
@Unit
public static final SysMLUnit Nanoseconds = new SysMLUnit("nanoseconds", "ns", "", "", Optional.of(SysMLinJavaQuantityKinds.Time));
static {instances.addAll(List.of(FeetCubic, MilesCubic, Liters, Gallons, Nanoseconds));}
}
* </pre>
*
* The units can be referenced in the SysMLinJava model code by simply
* referencing the containing class scope with the unit name. An example from a
* units declaration for a {@code SysMLValueType} is as follows:
*
* <pre>
@Override
protected void createUnits()
{
units = SysMLinJavaUnits.FeetCubic;
}
* </pre>
*
* @author ModelerOne
*
*/
public abstract class SysMLUnits extends SysMLClass
{
/**
* List (library) of all SysMLUnit instances. This list can be used to
* programmatically search for units or otherwise use the library of units.
* SysMLinJava tools use this list for generating model reports, requirements
* generation, etc. so it should be created for these purposes.
* <p>
* Extensions to this class that create/instantiate SysMLUnit instances should
* invoke a static statement to add the instances to this list. An example of
* adding the {@code SysMLUnit}s to this "library" of units in an extension to
* the {@code SysMLUnits} class is as follows:
*
* <pre>
static
{
instances.addAll(List.of(FeetCubic, MilesCubic, Liters, Gallons, Nanoseconds));
}
* </pre>
*/
public static List<SysMLUnit> instances = new ArrayList<>();
/**
* Constructor - default, no initializations
*/
public SysMLUnits()
{
super();
}
}