-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from kit-sdq/families-utils
Add utilities for families, persons and insurance metamodel
- Loading branch information
Showing
17 changed files
with
177 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,9 @@ tmp/ | |
# EMF | ||
src-gen/ | ||
|
||
#Xtend | ||
xtend-gen/ | ||
|
||
# Maven | ||
target/ | ||
.polyglot.build.properties | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...it.ipd.sdq.metamodels.families/src/edu/kit/ipd/sdq/metamodels/families/FamiliesUtil.xtend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package edu.kit.ipd.sdq.metamodels.families | ||
|
||
import edu.kit.ipd.sdq.activextendannotations.Utility | ||
import java.util.ArrayList | ||
|
||
@Utility | ||
class FamiliesUtil { | ||
/** | ||
* Returns whether the member is a child in its family. | ||
* | ||
* @param member the family member, must not be <code>null</code> | ||
*/ | ||
def static boolean isChild(Member member) { | ||
return (member.familySon ?: member.familyDaughter) !== null | ||
} | ||
|
||
/** | ||
* Returns the family of a members. Returns <code>null</code> if it has no family. | ||
* | ||
* @param member the member to return the family for, must not be <code>null</code> | ||
*/ | ||
def static Family getFamily(Member member) { | ||
return member.familyFather ?: member.familyMother ?: member.familySon ?: member.familyDaughter | ||
} | ||
|
||
/** | ||
* Returns the members of a family, consisting of father, mother, sons and daughters. | ||
* | ||
* @param family the family to return the members for, must not be <code>null</code> | ||
*/ | ||
def static Iterable<Member> getMembers(Family family) { | ||
val members = new ArrayList<Member> | ||
if (family.father !== null) { | ||
members += family.father | ||
} | ||
if (family.mother !== null) { | ||
members += family.mother | ||
} | ||
members += family.sons | ||
members += family.daughters | ||
return members | ||
} | ||
|
||
/** | ||
* Returns the register of the family of a member. | ||
* | ||
* @param member the member to return the containing register for, must not be <code>null</code> and must | ||
* have a containing family | ||
* @see #getFamily(Member) | ||
* @see #getRegister(Family) | ||
*/ | ||
def static FamilyRegister getRegister(Member member) { | ||
return member.family.register | ||
} | ||
|
||
/** Returns the {@linkplain FamilyRegister} in which the family is contained. | ||
* | ||
* @param family the family to obtain the FamilyRegister from, must not be <code>null</code> | ||
* @return <code>family.eContainer</code> as {@linkplain FamilyRegister}, if it actually is one | ||
* @throws UnsupportedOperationException if the container is not a {@linkplain FamilyRegister} | ||
*/ | ||
def static FamilyRegister getRegister(Family family) { | ||
val container = family.eContainer | ||
if (container instanceof FamilyRegister) { | ||
return container | ||
} else { | ||
throw new UnsupportedOperationException( | ||
"Cannot retrieve register of a family if it is not its direct container") | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...ipd.sdq.metamodels.insurance/src/edu/kit/ipd/sdq/metamodels/insurance/InsuranceUtil.xtend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package edu.kit.ipd.sdq.metamodels.insurance | ||
|
||
import edu.kit.ipd.sdq.activextendannotations.Utility | ||
|
||
@Utility | ||
class InsuranceUtil { | ||
/** Returns the {@linkplain InsuranceDatabase} in which the client is contained. | ||
* | ||
* @param client the client to obtain the {@linkplain InsuranceDatabase} from, must not be <code>null</code> | ||
* @return <code>client.eContainer</code> as InsuranceDatabase, if it actually is one | ||
* @throws UnsupportedOperationException if the container is not a {@linkplain InsuranceDatabase} | ||
*/ | ||
def static InsuranceDatabase getInsuranceDatabase(InsuranceClient client) { | ||
val container = client.eContainer | ||
|
||
if (container instanceof InsuranceDatabase) { | ||
return container | ||
} | ||
throw new UnsupportedOperationException( | ||
"Cannot retrieve database of an insurance client if it is not its direct container") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...u.kit.ipd.sdq.metamodels.persons/src/edu/kit/ipd/sdq/metamodels/persons/PersonsUtil.xtend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package edu.kit.ipd.sdq.metamodels.persons | ||
|
||
import edu.kit.ipd.sdq.activextendannotations.Utility | ||
|
||
@Utility | ||
class PersonsUtil { | ||
/** Returns the {@linkplain PersonRegister} in which the person is contained. | ||
* | ||
* @param person the person to obtain the {@linkplain PersonRegister} from, must not be <code>null</code> | ||
* @return <code>person.eContainer</code> as PersonRegister, if it actually is one | ||
* @throws UnsupportedOperationException if the container is not a {@linkplain PersonRegister} | ||
*/ | ||
def static PersonRegister getPersonRegister(Person person) { | ||
val container = person.eContainer | ||
|
||
if (container instanceof PersonRegister) { | ||
return container | ||
} | ||
throw new UnsupportedOperationException( | ||
"Cannot retrieve register of a person if it is not its direct container") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters