String spinLoc=loc.getChildren().elementAt(0).getLabel();
spinLocSet.add(spinLoc);
} else {
- String lowerLoc=loc.getChildren().elementAt(0).getLabel();
- String higherLoc= loc.getChildren().elementAt(1).getLabel();
- locOrder.put(higherLoc, lowerLoc);
- if (locOrder.isIntroducingCycle(higherLoc)) {
- throw new Error("Error: the order relation " + lowerLoc + " < " + higherLoc
- + " introduces a cycle.");
+ if(loc.getChildren().size()==1){
+ String locIentifier=loc.getChildren().elementAt(0).getLabel();
+ locOrder.put(locIentifier);
+ }else{
+ String lowerLoc=loc.getChildren().elementAt(0).getLabel();
+ String higherLoc= loc.getChildren().elementAt(1).getLabel();
+ locOrder.put(higherLoc, lowerLoc);
+ if (locOrder.isIntroducingCycle(higherLoc)) {
+ throw new Error("Error: the order relation " + lowerLoc + " < " + higherLoc
+ + " introduces a cycle.");
+ }
}
}
}
return table.keySet();
}
+ public boolean put(T key) {
+ if (table.containsKey(key)) {
+ return false;
+ } else {
+ // new key, need to be connected with top/bottom
+ size++;
+ table.get(top).add(key);
+ Set<T> neightborSet = new HashSet<T>();
+ neightborSet.add(bottom);
+ table.put(key, neightborSet);
+ return true;
+ }
+ }
+
public boolean put(T key, T value) {
Set<T> s;
do {
oldReachableSize = reachableSet.size();
Set<T> nextLevelNeighbors = new HashSet<T>();
- for (Iterator<T> iterator = neighborSet.iterator(); iterator.hasNext(); ) {
+ for (Iterator<T> iterator = neighborSet.iterator(); iterator.hasNext();) {
T element = iterator.next();
Set<T> neighbors = get(element);
if (neighbors != null) {
return true;
} else {
boolean reachable = false;
- for (Iterator<T> iterator = neighborSet.iterator(); iterator.hasNext(); ) {
+ for (Iterator<T> iterator = neighborSet.iterator(); iterator.hasNext();) {
T neighbor = iterator.next();
reachable = reachable || isGreaterThan(neighbor, b);
}
Set<T> lowerSet = new HashSet<T>();
// get lower set of input locations
- for (Iterator<T> iterator = inputSet.iterator(); iterator.hasNext(); ) {
+ for (Iterator<T> iterator = inputSet.iterator(); iterator.hasNext();) {
T element = iterator.next();
lowerSet.addAll(getLowerSet(element, new HashSet<T>()));
lowerSet.add(element);
// an element of lower bound should be lower than every input set
Set<T> toberemoved = new HashSet<T>();
- for (Iterator<T> inputIterator = inputSet.iterator(); inputIterator.hasNext(); ) {
+ for (Iterator<T> inputIterator = inputSet.iterator(); inputIterator.hasNext();) {
T inputElement = inputIterator.next();
- for (Iterator iterator = lowerSet.iterator(); iterator.hasNext(); ) {
+ for (Iterator iterator = lowerSet.iterator(); iterator.hasNext();) {
T lowerElement = (T) iterator.next();
if (!inputElement.equals(lowerElement)) {
if (!isGreaterThan(inputElement, lowerElement)) {
// calculate the greatest element of lower set
// find an element A, where every lower bound B of lowerSet, B<A
- for (Iterator<T> iterator = lowerSet.iterator(); iterator.hasNext(); ) {
+ for (Iterator<T> iterator = lowerSet.iterator(); iterator.hasNext();) {
T lowerElement = iterator.next();
boolean isGreaterThanAll = true;
- for (Iterator<T> iterator2 = lowerSet.iterator(); iterator2.hasNext(); ) {
+ for (Iterator<T> iterator2 = lowerSet.iterator(); iterator2.hasNext();) {
T e = iterator2.next();
if (!lowerElement.equals(e)) {
if (!isGreaterThan(lowerElement, e)) {
Set<T> neighborSet = get(element);
if (neighborSet != null) {
lowerSet.addAll(neighborSet);
- for (Iterator<T> iterator = neighborSet.iterator(); iterator.hasNext(); ) {
+ for (Iterator<T> iterator = neighborSet.iterator(); iterator.hasNext();) {
T neighbor = iterator.next();
lowerSet = getLowerSet(neighbor, lowerSet);
}