Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions use-core/src/main/java/org/tzi/use/uml/mm/MAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

import com.google.common.base.Optional;

import java.util.Objects;

/**
* An Attribute is a model element that is part of a classifier.
*
Expand Down Expand Up @@ -73,7 +75,7 @@ public Type type() {
/**
* <code>true</code> if a derive expression is specified for
* this attribute.
* @return
* @return <code>true</code> if a derive expression is specified for this attribute.
*/
public boolean isDerived() {
return deriveExpression != null;
Expand Down Expand Up @@ -141,14 +143,18 @@ public String toString() {
public boolean equals(Object obj) {
if (obj == this )
return true;
if (obj instanceof MAttribute ) {
MAttribute other = (MAttribute)obj;
if (obj instanceof MAttribute other) {
return fOwner.equals(other.fOwner) && name().equals(other.name());
}

return false;
}


@Override
public int hashCode() {
return Objects.hash(super.hashCode(), fOwner);
}
Comment thread
h-man2 marked this conversation as resolved.

/**
* Process this element with visitor.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public MDataTypeValueState(MDataTypeValue instance) {

List<MAttribute> atts = instance.cls().allAttributes();
// initialize attribute slots with instance values
fAttrSlots = new IdentityHashMap<MAttribute, Value>(atts.size());
fAttrSlots = new HashMap<>(atts.size());

for (MAttribute attr : atts) {
fAttrSlots.put(attr, instance.value().getValues().get(attr.name()));
Expand All @@ -58,7 +58,7 @@ public MDataTypeValueState(MDataTypeValue instance) {
* Copy constructor.
*/
public MDataTypeValueState(MDataTypeValueState x) {
this.fAttrSlots = new IdentityHashMap<MAttribute, Value>(x.fAttrSlots);
this.fAttrSlots = new HashMap<>(x.fAttrSlots);
this.fInstance = x.fInstance;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ dataType Time
pre: hour >= 0 and hour < 24
pre: minute >= 0 and minute < 60
pre: second >= 0 and second < 60

before(other: Time) : Boolean =
self.hour < other.hour or
(self.hour = other.hour and self.minute < other.minute) or
(self.hour = other.hour and self.minute = other.minute and
self.second < other.second)
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
model Date

dataType Date
operations
Date(day: Integer, month : Integer, year : Integer)
pre: day >= 1 and day <= 31
pre: month >= 1 and month <= 12

getMonths() : Sequence(Tuple(days : Integer, name : String)) = Sequence{
Tuple{name='January', days=31},
Tuple{name='February', days=if self.isLeapYear() then 29 else 28 endif},
Tuple{name='March', days=31},
Tuple{name='April', days=30},
Tuple{name='May', days=31},
Tuple{name='June', days=30},
Tuple{name='July', days=31},
Tuple{name='August', days=31},
Tuple{name='September', days=30},
Tuple{name='October', days=31},
Tuple{name='November', days=30},
Tuple{name='December', days=31}
}

before(other:Date):Boolean =
self.year < other.year or
(self.year = other.year and self.month < other.month) or
(self.year = other.year and self.month = other.month and self.day < other.day)

equals(other:Date):Boolean =
self.day = other.day and
self.month = other.month and
self.year = other.year

isLeapYear() : Boolean =
self.year.mod(400) = 0 or (self.year.mod(4) = 0 and self.year.mod(100) <> 0)

add(days : Integer) : Date =
Sequence{1..days}->iterate(d; result : Date =
Date(self.day, self.month, self.year) |
if result.day + 1 > self.getMonths()->at(result.month).days then
if (result.month = 12) then
Date(1, 1, result.year + 1)
else
Date(1, result.month + 1, result.year)
endif
else
Date(result.day + 1, result.month, result.year)
endif
)

getEasterSunday() : Date =
// Following Gauss algorithm to calculate eastern
// See: https://de.wikipedia.org/wiki/Gau%C3%9Fsche_Osterformel

let k:Integer = (self.year / 100).floor() in
let m:Integer = 15 + ((3 * k) / 4).floor() - ((8 * k + 13) / 25).floor() in
let s:Integer = 2 - ((3 * k + 3) / 4).floor() in
let a:Integer = self.year.mod(19) in
let d:Integer = (19 * a + m).mod(30) in
let r:Integer = ((d + (a / 11).floor()) / 29).floor() in
let og:Integer = 21 + d - r in
let sz:Integer = 7 - (self.year + (self.year / 4).floor() + s).mod(7) in
let oe:Integer = 7 - (og - sz).mod(7) in
let os:Integer = og + oe in
Date(1, 3, self.year).add(os - 1)
end

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Date from "t133_import_date.use"
import Time from "t133_import_time.use"

model DateTime

dataType DateTime
operations
DateTime(date:Date, time:Time)

before(other:DateTime):Boolean =
self.date.before(other.date) or
(self.date.equals(other.date) and self.time.before(other.time))
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
model Time

dataType Time
operations
Time(hour: Integer, minute: Integer, second: Integer)
pre: hour >= 0 and hour < 24
pre: minute >= 0 and minute < 60
pre: second >= 0 and second < 60

before(other: Time) : Boolean =
self.hour < other.hour or
(self.hour = other.hour and self.minute < other.minute) or
(self.hour = other.hour and self.minute = other.minute and self.second < other.second)
end
43 changes: 43 additions & 0 deletions use-gui/src/it/resources/testfiles/shell/t133_imports.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
-- Script generated by USE 7.5.0

!new Bootstyp('btTretboot')
!new Bootstyp('btSegelboot')
!new Bootstyp('btMotorboot')
!new Boot('bSchwalbe')
!new Boot('bMoewe')
!new Person('pAda')
!new Person('pBob')
!new Person('pCyd')
!new Person('pDan')
!new Person('pEve')
!btTretboot.bezeichnung := 'Tretboot'
!btSegelboot.bezeichnung := 'Segelboot'
!btMotorboot.bezeichnung := 'Motorboot'
!pAda.name := 'Ada'
!pBob.name := 'Bob'
!pCyd.name := 'Cyd'
!pDan.name := 'Dan'
!pEve.name := 'Eve'
!bSchwalbe.bezeichnung := 'Schwalbe'
!bSchwalbe.kapazitaet := 2
!bMoewe.bezeichnung := 'Möwe'
!bMoewe.kapazitaet := 4
!insert (bSchwalbe,btTretboot) into A_BootBootstyp
!insert (bMoewe,btMotorboot) into A_BootBootstyp
!new Vermietung('v1')
!v1.start := DateTime(Date(17, 4, 2026), Time(11, 0, 0))
!v1.ende := DateTime(Date(17, 4, 2026), Time(13, 0, 0))
!insert (v1,bSchwalbe) into A_Vermietung_Boot
!insert (v1,pAda) into A_Vermietung_Hauptmieter
!insert (v1,pBob) into A_Vermietung_Mitfahrer
!insert (v1,pAda) into A_Vermietung_Mitfahrer
?v1.start.before(v1.ende)
*-> true : Boolean
check
*checking structure...
*checking invariants...
*checking invariant (1) `Vermietung::businessHours': OK.
*checking invariant (2) `Vermietung::kapazitaetNichtUeberschritten': OK.
*checking invariant (3) `Vermietung::validDuration': OK.
*checked 3 invariants, 0 failures.
exit
60 changes: 60 additions & 0 deletions use-gui/src/it/resources/testfiles/shell/t133_imports.use
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
-- Test indirect imports

import { Date } from "imports/t133_import_date.use"
import { Time } from "imports/t133_import_time.use"
import { DateTime } from "imports/t133_import_datetime.use"

model Bootsverleih

class Boot
attributes
bezeichnung : String
kapazitaet : Integer
end

class Bootstyp
attributes
bezeichnung : String
end

class Vermietung
attributes
start : DateTime
ende : DateTime
constraints
inv validDuration:
self.start.before(self.ende)
inv businessHours:
self.start.time.hour >= 9 and
self.start.time.hour < 19 and
self.ende.time.hour < 19 and
self.ende.time.hour >= 9
inv kapazitaetNichtUeberschritten:
self.mitfaherer->size() <= self.boot.kapazitaet
end

class Person
attributes
name : String
telefonNr : String
end

association A_BootBootstyp between
Boot[*]
Bootstyp[1]
end

association A_Vermietung_Boot between
Vermietung[*]
Boot[1]
end

association A_Vermietung_Hauptmieter between
Vermietung[*] role bootsmieten
Person[1] role hauptmieter
end

association A_Vermietung_Mitfahrer between
Vermietung[*] role mitfahrten
Person[0..*] role mitfaherer
end
Loading