📄 testmodelutil.java
字号:
MClass company = mf.createClass( "Company", false ); model.addClass( person ); model.addClass( company ); MAttribute companyName = mf.createAttribute( "name", TypeFactory.mkString() ); company.addAttribute( companyName ); MAssociationClass job = mf.createAssociationClass( "Job", false ); MMultiplicity m1 = mf.createMultiplicity(); m1.addRange( 0, 1 ); MMultiplicity m2 = mf.createMultiplicity(); m2.addRange( 0, 1 ); MAssociationEnd endPerson = mf.createAssociationEnd( person, "person", m1, MAggregationKind.NONE, false ); MAssociationEnd endCompany = mf.createAssociationEnd( company, "company", m2, MAggregationKind.NONE, false ); job.addAssociationEnd( endPerson ); job.addAssociationEnd( endCompany ); model.addClass( job ); model.addAssociation( job ); MAttribute salary = mf.createAttribute( "salary", TypeFactory.mkInteger() ); job.addAttribute( salary ); return model; } catch ( MInvalidModelException e ) { //e.printStackTrace(); throw new Error( e ); } } /** * This method creates a model with one class (Person) * and one associationclass (Job). */ public MModel createModelWithOneClassAndOneAssocClass() { try { ModelFactory mf = new ModelFactory(); MModel model = mf.createModel( "PersonCompany" ); MClass person = mf.createClass( "Person", false ); model.addClass( person ); MAssociationClass job = mf.createAssociationClass( "Job", false ); MMultiplicity m1 = mf.createMultiplicity(); m1.addRange( 0, 1 ); MMultiplicity m2 = mf.createMultiplicity(); m2.addRange( 0, 1 ); MAssociationEnd endPerson1 = mf.createAssociationEnd( person, "boss", m1, MAggregationKind.NONE, false ); MAssociationEnd endPerson2 = mf.createAssociationEnd( person, "worker", m2, MAggregationKind.NONE, false ); job.addAssociationEnd( endPerson1 ); job.addAssociationEnd( endPerson2 ); model.addClass( job ); model.addAssociation( job ); return model; } catch ( MInvalidModelException e ) { //e.printStackTrace(); throw new Error( e ); } } /** * This method creates a model with three classes (Person, Salary and Company) * and an associationclass (Job). */ public MModel createModelWithClassAndTenaryAssocClass() { try { ModelFactory mf = new ModelFactory(); MModel model = mf.createModel( "PersonCompany" ); MClass person = mf.createClass( "Person", false ); MClass company = mf.createClass( "Company", false ); MClass salary = mf.createClass( "Salary", false ); model.addClass( person ); model.addClass( company ); model.addClass( salary ); MAttribute companyName = mf.createAttribute( "name", TypeFactory.mkString() ); company.addAttribute( companyName ); MAssociationClass job = mf.createAssociationClass( "Job", false ); MMultiplicity m1 = mf.createMultiplicity(); m1.addRange( 0, 1 ); MMultiplicity m2 = mf.createMultiplicity(); m2.addRange( 0, 1 ); MMultiplicity m3 = mf.createMultiplicity(); m3.addRange( 0, 1 ); MAssociationEnd endPerson = mf.createAssociationEnd( person, "person", m1, MAggregationKind.NONE, false ); MAssociationEnd endCompany = mf.createAssociationEnd( company, "company", m2, MAggregationKind.NONE, false ); MAssociationEnd endSalary = mf.createAssociationEnd( salary, "salary", m3, MAggregationKind.NONE, false ); job.addAssociationEnd( endPerson ); job.addAssociationEnd( endCompany ); job.addAssociationEnd( endSalary ); model.addClass( job ); model.addAssociation( job ); return model; } catch ( MInvalidModelException e ) { //e.printStackTrace(); throw new Error( e ); } } /** * This method creates a model with two classes (Person and Company), * an associationclass (Job) and an association (isBoss). */ public MModel createComplexModel() { try { ModelFactory mf = new ModelFactory(); MModel model = mf.createModel( "PersonCompany" ); // adds two classes named Person and Company MClass person = mf.createClass( "Person", false ); MClass company = mf.createClass( "Company", false ); model.addClass( person ); model.addClass( company ); MAttribute companyName = mf.createAttribute( "name", TypeFactory.mkString() ); company.addAttribute( companyName ); // adds an associationclass between Person and Company named Job MAssociationClass job = mf.createAssociationClass( "Job", false ); MMultiplicity m1 = mf.createMultiplicity(); m1.addRange( 0, 1 ); MMultiplicity m2 = mf.createMultiplicity(); m2.addRange( 0, 1 ); MAssociationEnd endPerson = mf.createAssociationEnd( person, "employee", m1, MAggregationKind.NONE, false ); MAssociationEnd endCompany = mf.createAssociationEnd( company, "company", m2, MAggregationKind.NONE, false ); job.addAssociationEnd( endPerson ); job.addAssociationEnd( endCompany ); model.addClass( job ); model.addAssociation( job ); // adds an association between Person itself named isBoss MAssociation isBoss = mf.createAssociation( "isBoss" ); MMultiplicity m3 = mf.createMultiplicity(); m1.addRange( 0, 1 ); MMultiplicity m4 = mf.createMultiplicity(); m2.addRange( 0, 1 ); MAssociationEnd endWorker = mf.createAssociationEnd( person, "worker", m1, MAggregationKind.NONE, false ); MAssociationEnd endBoss = mf.createAssociationEnd( person, "boss", m2, MAggregationKind.NONE, false ); isBoss.addAssociationEnd( endWorker ); isBoss.addAssociationEnd( endBoss ); model.addAssociation( isBoss ); return model; } catch ( MInvalidModelException e ) { //e.printStackTrace(); throw new Error( e ); } } /** * This method creates a model with two classes (Person * and Employee) and a generalization structure between them. */ public MModel createModelWithGen() { try { ModelFactory mf = new ModelFactory(); MModel model = mf.createModel( "PersonEmployee" ); MClass person = mf.createClass( "Person", false ); MClass employee = mf.createClass( "Employee", false ); model.addClass( person ); model.addClass( employee ); MGeneralization gen = mf.createGeneralization( employee, person ); model.addGeneralization( gen ); return model; } catch ( MInvalidModelException e ) { throw new Error( e ); } } public MModel createModelWithOperation() { try{ ModelFactory mf = new ModelFactory(); MModel model = mf.createModel( "Person" ); MClass person = mf.createClass( "Person", false ); model.addClass (person); // adds an attribute MAttribute name = mf.createAttribute("fName", TypeFactory.mkString() ); person.addAttribute (name); // adds an operation MOperation op = mf.createOperation( "equalsName", new VarDeclList( new VarDecl( "name", TypeFactory.mkString() )), TypeFactory.mkBoolean() ); person.addOperation( op ); return model; } catch ( MInvalidModelException e ) { throw new Error( e ) ; } } public MModel createModelWithInvariant() { try{ ModelFactory mf = new ModelFactory(); MModel model = mf.createModel( "Person" ); MClass person = mf.createClass( "Person", false ); model.addClass (person); // adds an attribute MAttribute name = mf.createAttribute("fName", TypeFactory.mkString() ); person.addAttribute (name); Expression expr = new ExpVariable( "p1", TypeFactory.mkBoolean() ); MClassInvariant inv = new MClassInvariant( null, null, person, expr ); model.addClassInvariant( inv ); return model; } catch ( MInvalidModelException e ) { throw new Error( e ); } catch ( ExpInvalidException e ) { throw new Error( e ); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -