📄 msystemstate.java
字号:
if ( objClass.isSubClassOf( aend.cls() ) ) { Set removedLinks = linkSet.removeAll( aend, obj ); Iterator it = removedLinks.iterator(); while ( it.hasNext() ) { Object o = it.next(); if ( o instanceof MLinkObject ) { Set[] resLinkObject = auxDeleteObject( ( MLinkObject ) o ); res[REMOVED_LINKS].addAll( resLinkObject[REMOVED_LINKS] ); res[REMOVED_OBJECTS].addAll( resLinkObject[REMOVED_OBJECTS] ); res[REMOVED_OBJECTSTATES].addAll( resLinkObject[REMOVED_OBJECTSTATES] ); } } res[REMOVED_LINKS].addAll( removedLinks ); } } } res[REMOVED_OBJECTS].add( obj ); res[REMOVED_OBJECTSTATES].add( fObjectStates.get( obj ) ); fObjectStates.remove( obj ); fClassObjects.remove( objClass, obj ); fSystem.deleteObject( obj ); return res; } private void auxDeleteLink( MLink link ) { MLinkSet linkSet = ( MLinkSet ) fLinkSets.get( link.association() ); linkSet.remove( link ); } /** * Creates and adds a new link to the state. * * @exception MSystemException link invalid or already existing * @return the newly created link. */ public MLink createLink( MAssociation assoc, List objects ) throws MSystemException { MLink link; // checks if assoc is an associationclass if ( assoc instanceof MAssociationClass ) { // specifies if there is already an existing linkobject of this // association class between the objects HashSet objectsAsSet = new HashSet( objects ); if ( hasLinkBetweenObjects( assoc, objectsAsSet ) ) { throw new MSystemException( "Cannot insert two linkobjects of the same type" + " between one set of objects!" ); } String name = fSystem.uniqueObjectNameForClass( assoc.name() );// Log.println( "Information: The name '" + name + "' was automatically generated for the "// + "linkobject." ); // creates a linkobject with a generated name link = createLinkObject( ( MAssociationClass ) assoc, name, objects ); } else { // create a normal link link = new MLinkImpl( assoc, objects ); // get link set for association MLinkSet linkSet = ( MLinkSet ) fLinkSets.get( assoc ); if ( linkSet.contains( link ) ) throw new MSystemException( "Link `" + assoc.name() + "' between (" + StringUtil.fmtSeq( objects.iterator(), "," ) + ") already exist." ); linkSet.add( link ); } return link; } /** * Inserts a link into the state. */ public void insertLink(MLink link) { // get link set for association MLinkSet linkSet = (MLinkSet) fLinkSets.get(link.association()); linkSet.add(link); } /** * Deletes a link from the state. */ // TODO: Was geschieht mit Set von deleteObject public void deleteLink( MLink link ) { auxDeleteLink( link ); if ( link instanceof MLinkObject ) { auxDeleteObject( ( MLinkObject ) link ); } } /** * Deletes a link from the state. The link is indirectly specified * by the association and objects. * * @exception MSystemException link does not exist * @return the removed link. */ public Set[] deleteLink( MAssociation assoc, List objects ) throws MSystemException { Set[] result = new Set[3]; result[REMOVED_LINKS] = new HashSet(); result[REMOVED_OBJECTS] = new HashSet(); result[REMOVED_OBJECTSTATES] = new HashSet(); MLink link = null; MLinkSet linkSet = linksOfAssociation( assoc ); Iterator linkIter = linkSet.links().iterator(); while (linkIter.hasNext() ) { MLink l = (MLink) linkIter.next(); if (l.linkedObjects().equals( new HashSet(objects) ) ) { link = l; break; } } if ( link == null ) { throw new MSystemException( "Link `" + assoc.name() + "' between (" + StringUtil.fmtSeq( objects.iterator(), "," ) + ") does not exist." ); } linkSet.remove( link ); result[REMOVED_LINKS].add( link ); if ( link instanceof MLinkObject ) { Set[] res = auxDeleteObject( ( MLinkObject ) link ); result[REMOVED_LINKS].addAll( res[REMOVED_LINKS] ); result[REMOVED_OBJECTS].addAll( res[REMOVED_OBJECTS] ); result[REMOVED_OBJECTSTATES].addAll( res[REMOVED_OBJECTSTATES] ); } return result; // if ( assoc instanceof MAssociationClass ) {// MAssociationClass assocClass = ( MAssociationClass ) assoc;// String assocClassName = getNameOfLinkObject( assocClass, objects );// link = new MLinkObjectImpl( assocClass, assocClassName, objects );// } else {// link = new MLinkImpl( assoc, objects );// } // // get link set for association// MLinkSet linkSet = ( MLinkSet ) fLinkSets.get( assoc );// if ( !linkSet.contains( link ) )// throw new MSystemException( "Link " + link + " does not exist." );// linkSet.remove( link );// if ( link instanceof MLinkObject ) {// auxDeleteObject( ( MLinkObject ) link );// }// return link; }// private String getNameOfLinkObject( MAssociationClass assocClass, List objects ) {// HashSet set = new HashSet( objects );// Iterator it = linksOfAssociation( assocClass ).links().iterator();// while ( it.hasNext() ) {// MLinkObject linkObject = ( MLinkObject ) it.next();// if ( linkObject.linkedObjects().equals( set ) ) {// return linkObject.name();// }// }// return "";// } /** * Creates and adds a new link to the state. * * @exception MSystemException link invalid or already existing * @return the newly created link. */ public MLinkObject createLinkObject( MAssociationClass assocClass, String name, List objects ) throws MSystemException { if ( objectByName( name ) != null ) { throw new MSystemException("An object with name `" + name + "' already exists."); } MLinkObject linkobj = new MLinkObjectImpl( assocClass, name, objects ); // Part from createObject method MObjectState objState = new MObjectState( linkobj ); fObjectStates.put( linkobj, objState ); fClassObjects.put( assocClass, linkobj ); // Part from createLink method MLinkSet linkSet = ( MLinkSet ) fLinkSets.get( assocClass ); if ( linkSet.contains( linkobj ) ) throw new MSystemException( "Link " + linkobj + " already exists." ); linkSet.add( linkobj ); return linkobj; } /** * Returns the state of an object in a specific system state. * * @return null if object does not exist in the state */ MObjectState getObjectState(MObject obj) { return (MObjectState) fObjectStates.get(obj); } /** * Returns a list of objects at <code>dstEnd</code> which are * linked to <code>obj</code> at srcEnd. * * @return List(MObject) */ List getLinkedObjects(MObject obj, MAssociationEnd srcEnd, MAssociationEnd dstEnd) { ArrayList res = new ArrayList(); // get association MAssociation assoc = dstEnd.association(); // get link set for association MLinkSet linkSet = (MLinkSet) fLinkSets.get(assoc); // if link set is empty return empty result list Log.trace(this, "linkSet size of association `" + assoc.name() + "' = " + linkSet.size()); if (linkSet.size() == 0 ) return res; // select links with srcEnd == obj Set links = linkSet.select(srcEnd, obj); Log.trace(this, "linkSet.select for object `" + obj + "', size = " + links.size()); // project tuples to destination end component Iterator it = links.iterator(); while (it.hasNext() ) { MLink link = (MLink) it.next(); MLinkEnd linkEnd = link.linkEnd(dstEnd); res.add(linkEnd.object()); } return res; } /** * Returns a list of objects at <code>dst</code> which are * connected to this object at <code>src</code>. This is needed for navigation. * * @return List(MObject) */ public List getNavigableObjects( MObject obj, MNavigableElement src, MNavigableElement dst ) { ArrayList res = new ArrayList(); // get association MAssociation assoc = dst.association(); // get link set for association MLinkSet linkSet = ( MLinkSet ) fLinkSets.get( assoc ); // if link set is empty return empty result list Log.trace( this, "linkSet size of association `" + assoc.name() + "' = " + linkSet.size() ); if ( linkSet.size() == 0 ) return res; // navigation from a linkobject if ( src instanceof MAssociationClass ) { if ( dst instanceof MAssociationClass ) { throw new RuntimeException( "Wrong navigation expression." ); } MLinkEnd linkEnd = ( ( MLinkObject ) obj ).linkEnd( ( MAssociationEnd ) dst ); res.add( linkEnd.object() ); } else { if ( src instanceof MAssociationClass ) { throw new RuntimeException( "Wrong navigation expression." ); } MAssociationEnd srcEnd = ( MAssociationEnd ) src; // select links with srcEnd == obj Set links = linkSet.select( srcEnd, obj ); Log.trace( this, "linkSet.select for object `" + obj + "', size = " + links.size() ); // navigation to a linkobject if ( dst instanceof MAssociationClass ) { return new ArrayList( links ); } else { MAssociationEnd dstEnd = ( MAssociationEnd ) dst; // project tuples to destination end component Iterator it = links.iterator(); while ( it.hasNext() ) { MLink link = ( MLink ) it.next(); MLinkEnd linkEnd = link.linkEnd( dstEnd ); res.add( linkEnd.object() ); } } } return res; } /** * Checks for a valid system state. Returns true if all * constraints hold for all objects. Prints result of * subexpressions for failing constraints to the log if * traceEvaluation is true. */ public boolean check(PrintWriter out, boolean traceEvaluation, boolean showDetails, boolean allInvariants, List invNames) { boolean valid = true; Evaluator evaluator = new Evaluator(); MModel model = fSystem.model(); // model inherent constraints: check whether cardinalities of // association links match their declaration of multiplicities if (! checkStructure(out) ) { //return false; valid = false; } if (Options.EVAL_NUMTHREADS > 1 ) out.println("checking invariants (using " + Options.EVAL_NUMTHREADS + " concurrent threads)..."); else out.println("checking invariants..."); out.flush(); int numChecked = 0; int numFailed = 0; long tAll = System.currentTimeMillis(); ArrayList invList = new ArrayList(); ArrayList negatedList = new ArrayList(); ArrayList exprList = new ArrayList(); if (allInvariants ) { // get all invariants (loaded and normal classinvariants) // it doesn't matter if specific invariants are given or not // get all loaded Invariants (generator) Iterator it = fSystem.generator().flaggedInvariants().iterator(); while (it.hasNext() ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -