edu.mit.csail.sdg.alloy4viz
Class AlloyModel

java.lang.Object
  extended by edu.mit.csail.sdg.alloy4viz.AlloyModel

public final class AlloyModel
extends java.lang.Object

Immutable; represents an Alloy model.

Thread Safety: Can be called only by the AWT event thread.


Constructor Summary
AlloyModel(java.util.Collection<AlloyType> types, java.util.Collection<AlloySet> sets, java.util.Collection<AlloyRelation> rels, AlloyModel old)
          Construct a new AlloyModel object.
AlloyModel(java.util.Collection<AlloyType> types, java.util.Collection<AlloySet> sets, java.util.Collection<AlloyRelation> rels, java.util.Map<AlloyType,AlloyType> map)
          Construct a new AlloyModel object.
 
Method Summary
 boolean equals(java.lang.Object other)
          Two AlloyModel objects are equal if they have the same types, sets, relations, and extension relationship.
 ConstList<AlloyType> getDirectSubTypes(AlloyType type)
          Returns a sorted, unmodifiable list of types that are direct subtypes of the given type.
 java.util.Set<AlloyRelation> getRelations()
          Returns an unmodifiable sorted set of all AlloyRelation(s) in this model.
 java.util.Set<AlloySet> getSets()
          Returns an unmodifiable sorted set of all AlloySet(s) in this model.
 ConstList<AlloyType> getSubTypes(AlloyType type)
          Returns a sorted, unmodifiable list of types that are direct or indirect subtypes of the given type.
 AlloyType getSuperType(AlloyType type)
          If type==univ, return null; otherwise, return a nonnull AlloyType object representing its super type.
 AlloyType getTopmostSuperType(AlloyType type)
          If type==univ, return null; otherwise, return a nonnull AlloyType object representing its topmost non-univ super type.
 java.util.Set<AlloyType> getTypes()
          Returns an unmodifiable sorted set of all AlloyType(s) in this model.
 int hashCode()
          Compute a hashcode based on the types, sets, relations, and the extension relationship.
 AlloyRelation hasRelation(java.lang.String name, java.util.List<AlloyType> types)
          Returns the AlloyRelation object if this model contains the given relation; or return null otherwise.
 AlloySet hasSet(java.lang.String name, AlloyType type)
          Returns the AlloyRelation object if this model contains the given relation; or return null otherwise.
 boolean hasType(AlloyType type)
          Returns true if this model contains the given type.
 AlloyType hasType(java.lang.String name)
          Returns the AlloyType object if this model contains the given type; or return null otherwise.
static boolean isCycle(java.util.Map<AlloyType,AlloyType> map, AlloyType x)
          Returns true iff the nodes x, map.get(x), map.get(map.get(x))...
 boolean isDirectSubtype(AlloyType subType, AlloyType superType)
          Returns true iff "subType" is a direct subsig of "superType".
 boolean isEqualOrSubtype(AlloyType subType, AlloyType superType)
          Returns true iff "subType" is equal to, or is a direct or indirect subsig of "superType".
 boolean isSubtype(AlloyType subType, AlloyType superType)
          Returns true iff "subType" is a direct or indirect subsig of "superType".
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AlloyModel

public AlloyModel(java.util.Collection<AlloyType> types,
                  java.util.Collection<AlloySet> sets,
                  java.util.Collection<AlloyRelation> rels,
                  java.util.Map<AlloyType,AlloyType> map)
Construct a new AlloyModel object.

Parameters:
types - - the types; we will always add "univ" to it if it's not there already
sets - - the sets
rels - - the relations
map - - we consult this "sig to parent sig" map and extract the mappings relevant to this model. (If we detect a cycle, we will arbitrarily break the cycle)

AlloyModel

public AlloyModel(java.util.Collection<AlloyType> types,
                  java.util.Collection<AlloySet> sets,
                  java.util.Collection<AlloyRelation> rels,
                  AlloyModel old)
Construct a new AlloyModel object.

Parameters:
types - - the types ; we will always add "univ" to it if it's not there already
sets - - the sets
rels - - the relations
old - - we consult this model's "sig to parent sig" map, and extract the mappings relevant to this model.
Method Detail

isCycle

public static boolean isCycle(java.util.Map<AlloyType,AlloyType> map,
                              AlloyType x)
Returns true iff the nodes x, map.get(x), map.get(map.get(x))... form an infinite chain of nonnull objects.

Parameters:
map - - a map from AlloyType to AlloyType
x - - the AlloyType object we want to check

getSuperType

public AlloyType getSuperType(AlloyType type)
If type==univ, return null; otherwise, return a nonnull AlloyType object representing its super type.
(In particular, if "type" does not exist in this model, we'll return "univ" as the answer).


getTopmostSuperType

public AlloyType getTopmostSuperType(AlloyType type)
If type==univ, return null; otherwise, return a nonnull AlloyType object representing its topmost non-univ super type.

Thus, if "type" is in this model, but its supertype is univ, then we'll return type as-is.

Note: if "type" does not exist in this model, we'll return it as-is.


getSubTypes

public ConstList<AlloyType> getSubTypes(AlloyType type)
Returns a sorted, unmodifiable list of types that are direct or indirect subtypes of the given type.
This method will search recursively, so if the subtypes themselves have subtypes, they too are included.
If type==null, or it does not exist in this model, or it has no subsigs, then we return an empty set.


getDirectSubTypes

public ConstList<AlloyType> getDirectSubTypes(AlloyType type)
Returns a sorted, unmodifiable list of types that are direct subtypes of the given type.
This method will only return types that are direct subtypes of the given argument.
If type==null, or it does not exist in this model, or it has no subsigs, then we return an empty set.


isSubtype

public boolean isSubtype(AlloyType subType,
                         AlloyType superType)
Returns true iff "subType" is a direct or indirect subsig of "superType".
If subType==null or superType==null, it always returns false.


isDirectSubtype

public boolean isDirectSubtype(AlloyType subType,
                               AlloyType superType)
Returns true iff "subType" is a direct subsig of "superType".
If subType==null or superType==null, it always returns false.


isEqualOrSubtype

public boolean isEqualOrSubtype(AlloyType subType,
                                AlloyType superType)
Returns true iff "subType" is equal to, or is a direct or indirect subsig of "superType".
If subType==null or superType==null, it always returns false.


equals

public boolean equals(java.lang.Object other)
Two AlloyModel objects are equal if they have the same types, sets, relations, and extension relationship.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Compute a hashcode based on the types, sets, relations, and the extension relationship.

Overrides:
hashCode in class java.lang.Object

hasType

public boolean hasType(AlloyType type)
Returns true if this model contains the given type.


hasType

public AlloyType hasType(java.lang.String name)
Returns the AlloyType object if this model contains the given type; or return null otherwise.


hasSet

public AlloySet hasSet(java.lang.String name,
                       AlloyType type)
Returns the AlloyRelation object if this model contains the given relation; or return null otherwise.


hasRelation

public AlloyRelation hasRelation(java.lang.String name,
                                 java.util.List<AlloyType> types)
Returns the AlloyRelation object if this model contains the given relation; or return null otherwise.


getTypes

public java.util.Set<AlloyType> getTypes()
Returns an unmodifiable sorted set of all AlloyType(s) in this model.


getSets

public java.util.Set<AlloySet> getSets()
Returns an unmodifiable sorted set of all AlloySet(s) in this model.


getRelations

public java.util.Set<AlloyRelation> getRelations()
Returns an unmodifiable sorted set of all AlloyRelation(s) in this model.