X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.structural.synchronization.client%2Fsrc%2Forg%2Fsimantics%2Fstructural%2Fsynchronization%2Fbase%2FComponentBase.java;fp=bundles%2Forg.simantics.structural.synchronization.client%2Fsrc%2Forg%2Fsimantics%2Fstructural%2Fsynchronization%2Fbase%2FComponentBase.java;h=943b7970410440df56e167b75e4271bd55622543;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=2cf68bf6f8cf3e6ff9038851f23e4cb9bef6abd4;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/ComponentBase.java b/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/ComponentBase.java index 2cf68bf6f..943b79704 100644 --- a/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/ComponentBase.java +++ b/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/ComponentBase.java @@ -1,180 +1,180 @@ -package org.simantics.structural.synchronization.base; - -import gnu.trove.map.hash.THashMap; -import gnu.trove.procedure.TObjectObjectProcedure; -import gnu.trove.procedure.TObjectProcedure; - -import java.io.PrintWriter; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.atomic.AtomicReference; - -import org.simantics.databoard.annotations.Optional; - -abstract public class ComponentBase> { - - public int componentId; - - public String uid; - protected transient T parent; - - @Optional public String solverComponentName; - public boolean attached; - - public ComponentBase() { - } - - public ComponentBase(String uid) { - this.uid = uid; - } - - public ComponentBase(String uid, int moduleId) { - this.uid = uid; - this.componentId = moduleId; - } - - public ComponentBase(int moduleId) { - this.componentId = moduleId; - } - - /** - * Detaches a child by its UID. - */ - public void detachByUid(final String uid) { - final AtomicReference nameRef = new AtomicReference(); - getChildMap().forEachEntry(new TObjectObjectProcedure() { - @Override - public boolean execute(String name, T conf) { - if(conf.uid.equals(uid)) { - nameRef.set(name); - return false; - } - else - return true; - } - }); - String name = nameRef.get(); - getChildMap().remove(name); - } - - public Collection getChildren() { - if(getChildMap() == null) - return Collections.emptyList(); - else - return getChildMap().values(); - } - - public T getChild(String name) { - if(getChildMap() == null) - return null; - else - return getChildMap().get(name); - } - - public THashMap setChildMapAndReturnOld( - THashMap newChildMap) { - THashMap oldChildMap = getChildMap(); - setChildMap(newChildMap); - return oldChildMap; - } - - public int getModuleId() { - return componentId; - } - - public String getUid() { - return uid; - } - - public void setModuleId(int moduleId) { - this.componentId = moduleId; - } - - public void setUid(String uid) { - this.uid = uid; - } - - public boolean isComposite() { - return getChildMap() != null; - } - - public void printConfiguration(final int indentation) { - printConfiguration(new PrintWriter(System.out), indentation); - } - - public void printConfiguration(final PrintWriter out, final int indentation) { - out.println(uid + " " + solverComponentName + "(" + componentId + ")"); - if(getChildMap() != null) - getChildMap().forEachEntry(new TObjectObjectProcedure() { - @Override - public boolean execute(String a, T b) { - for(int i=0;i 0) - componentId = idMap[componentId]; - if(getChildMap() != null) - getChildMap().forEachValue(new TObjectProcedure() { - @Override - public boolean execute(T component) { - component.mapModuleIds(idMap); - return true; - } - }); - } - - abstract public THashMap getChildMap(); - abstract public void setChildMap(THashMap newChildMap); - - public int componentHashCode() { - return hashCode(); -// final int prime = 31; -// int result = 1; -// result = prime * result + ((parent == null) ? 0 : parent.hashCode()); -// result = prime * result + ((uid == null) ? 0 : uid.hashCode()); -// result = prime * result + getChildren().hashCode(); -// return result; - } - - public boolean componentEquals(Object obj) { - return this.equals(obj); -// if (this == obj) -// return true; -// if (obj == null) -// return false; -// if (getClass() != obj.getClass()) -// return false; -// ComponentBase other = (ComponentBase) obj; -// if (parent == null) { -// if (other.parent != null) -// return false; -// } else if (!parent.equals(other.parent)) -// return false; -// if (uid == null) { -// if (other.uid != null) -// return false; -// } else if (!uid.equals(other.uid)) -// return false; -// -// return getChildren().equals(other.getChildren()); -// -// //return true; -// - } - -} +package org.simantics.structural.synchronization.base; + +import gnu.trove.map.hash.THashMap; +import gnu.trove.procedure.TObjectObjectProcedure; +import gnu.trove.procedure.TObjectProcedure; + +import java.io.PrintWriter; +import java.util.Collection; +import java.util.Collections; +import java.util.concurrent.atomic.AtomicReference; + +import org.simantics.databoard.annotations.Optional; + +abstract public class ComponentBase> { + + public int componentId; + + public String uid; + protected transient T parent; + + @Optional public String solverComponentName; + public boolean attached; + + public ComponentBase() { + } + + public ComponentBase(String uid) { + this.uid = uid; + } + + public ComponentBase(String uid, int moduleId) { + this.uid = uid; + this.componentId = moduleId; + } + + public ComponentBase(int moduleId) { + this.componentId = moduleId; + } + + /** + * Detaches a child by its UID. + */ + public void detachByUid(final String uid) { + final AtomicReference nameRef = new AtomicReference(); + getChildMap().forEachEntry(new TObjectObjectProcedure() { + @Override + public boolean execute(String name, T conf) { + if(conf.uid.equals(uid)) { + nameRef.set(name); + return false; + } + else + return true; + } + }); + String name = nameRef.get(); + getChildMap().remove(name); + } + + public Collection getChildren() { + if(getChildMap() == null) + return Collections.emptyList(); + else + return getChildMap().values(); + } + + public T getChild(String name) { + if(getChildMap() == null) + return null; + else + return getChildMap().get(name); + } + + public THashMap setChildMapAndReturnOld( + THashMap newChildMap) { + THashMap oldChildMap = getChildMap(); + setChildMap(newChildMap); + return oldChildMap; + } + + public int getModuleId() { + return componentId; + } + + public String getUid() { + return uid; + } + + public void setModuleId(int moduleId) { + this.componentId = moduleId; + } + + public void setUid(String uid) { + this.uid = uid; + } + + public boolean isComposite() { + return getChildMap() != null; + } + + public void printConfiguration(final int indentation) { + printConfiguration(new PrintWriter(System.out), indentation); + } + + public void printConfiguration(final PrintWriter out, final int indentation) { + out.println(uid + " " + solverComponentName + "(" + componentId + ")"); + if(getChildMap() != null) + getChildMap().forEachEntry(new TObjectObjectProcedure() { + @Override + public boolean execute(String a, T b) { + for(int i=0;i 0) + componentId = idMap[componentId]; + if(getChildMap() != null) + getChildMap().forEachValue(new TObjectProcedure() { + @Override + public boolean execute(T component) { + component.mapModuleIds(idMap); + return true; + } + }); + } + + abstract public THashMap getChildMap(); + abstract public void setChildMap(THashMap newChildMap); + + public int componentHashCode() { + return hashCode(); +// final int prime = 31; +// int result = 1; +// result = prime * result + ((parent == null) ? 0 : parent.hashCode()); +// result = prime * result + ((uid == null) ? 0 : uid.hashCode()); +// result = prime * result + getChildren().hashCode(); +// return result; + } + + public boolean componentEquals(Object obj) { + return this.equals(obj); +// if (this == obj) +// return true; +// if (obj == null) +// return false; +// if (getClass() != obj.getClass()) +// return false; +// ComponentBase other = (ComponentBase) obj; +// if (parent == null) { +// if (other.parent != null) +// return false; +// } else if (!parent.equals(other.parent)) +// return false; +// if (uid == null) { +// if (other.uid != null) +// return false; +// } else if (!uid.equals(other.uid)) +// return false; +// +// return getChildren().equals(other.getChildren()); +// +// //return true; +// + } + +}