X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fservice%2FResourceUID.java;h=e4214be5bb75522642a9be212226f6f28cb02906;hp=8ee9037e1df523a92bc348df6b7b732ba92b1540;hb=refs%2Fchanges%2F38%2F238%2F2;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.db/src/org/simantics/db/service/ResourceUID.java b/bundles/org.simantics.db/src/org/simantics/db/service/ResourceUID.java index 8ee9037e1..e4214be5b 100644 --- a/bundles/org.simantics.db/src/org/simantics/db/service/ResourceUID.java +++ b/bundles/org.simantics.db/src/org/simantics/db/service/ResourceUID.java @@ -1,68 +1,68 @@ -package org.simantics.db.service; - - - -public final class ResourceUID { - public static final ResourceUID Null = new ResourceUID(null); - private final ClusterUID clusterUID; - private final short index; - private ResourceUID(ResourceUID a) { - assert(null == a); - clusterUID = ClusterUID.Null; - index = 0; - } - public ResourceUID(long first, long second, long index) { - this.clusterUID = ClusterUID.make(first, second); - if (index < 1 || index > 1<<14) // TODO: use ClusterTraits.RESOURCE_USED_BITS - throw new IllegalArgumentException("Trying to create illegal resource. index=" + index + " cluster=" + clusterUID); - this.index = (short)index; - } - public ResourceUID(long[] longs, int offset) { - if (longs.length < offset + 3) - throw new IllegalArgumentException("Not enough data to create resource uid. length=" + longs.length + " offset=" + offset); - this.clusterUID = ClusterUID.make(longs[offset+0], longs[offset+1]); - index = (short)longs[offset+2]; - if (index < 1 || index > 1<<14) // TODO: use ClusterTraits.RESOURCE_USED_BITS - throw new IllegalArgumentException("Trying to create illegal resource. index=" + index + " cluster=" + clusterUID); - } - public int getIndex() { - return index; - } - public ClusterUID asCID() { - return clusterUID; - } - public static ResourceUID parse(String s) { - String[] ss = s.split("#"); - if(ss.length != 3) throw new IllegalArgumentException("'" + s + "' is not a valid serialized ResourceUID"); - long first = Long.parseLong(ss[0]); - long second = Long.parseLong(ss[1]); - short index = Short.parseShort(ss[2]); - return new ResourceUID(first, second, index); - } - public String serialized() { - return /*clusterUID.first +*/ "0#" + clusterUID.second + "#" + index; - } - public void toLong(long[] longs, int offset) { - int i = clusterUID.toLong(longs, offset); - longs[i] = index; - } - @Override - public String toString() { - return clusterUID.toString() + "." + index; - } - @Override - public boolean equals(Object o) { - if (this == o) - return true; - else if (!(o instanceof ResourceUID)) - return false; - ResourceUID x = (ResourceUID)o; - return clusterUID.equals(x.clusterUID) && index == x.index; - } - @Override - public int hashCode() { - int result = clusterUID.hashCode(); - result = 31 * result + index; - return result; - } -} +package org.simantics.db.service; + + + +public final class ResourceUID { + public static final ResourceUID Null = new ResourceUID(null); + private final ClusterUID clusterUID; + private final short index; + private ResourceUID(ResourceUID a) { + assert(null == a); + clusterUID = ClusterUID.Null; + index = 0; + } + public ResourceUID(long first, long second, long index) { + this.clusterUID = ClusterUID.make(first, second); + if (index < 1 || index > 1<<14) // TODO: use ClusterTraits.RESOURCE_USED_BITS + throw new IllegalArgumentException("Trying to create illegal resource. index=" + index + " cluster=" + clusterUID); + this.index = (short)index; + } + public ResourceUID(long[] longs, int offset) { + if (longs.length < offset + 3) + throw new IllegalArgumentException("Not enough data to create resource uid. length=" + longs.length + " offset=" + offset); + this.clusterUID = ClusterUID.make(longs[offset+0], longs[offset+1]); + index = (short)longs[offset+2]; + if (index < 1 || index > 1<<14) // TODO: use ClusterTraits.RESOURCE_USED_BITS + throw new IllegalArgumentException("Trying to create illegal resource. index=" + index + " cluster=" + clusterUID); + } + public int getIndex() { + return index; + } + public ClusterUID asCID() { + return clusterUID; + } + public static ResourceUID parse(String s) { + String[] ss = s.split("#"); + if(ss.length != 3) throw new IllegalArgumentException("'" + s + "' is not a valid serialized ResourceUID"); + long first = Long.parseLong(ss[0]); + long second = Long.parseLong(ss[1]); + short index = Short.parseShort(ss[2]); + return new ResourceUID(first, second, index); + } + public String serialized() { + return /*clusterUID.first +*/ "0#" + clusterUID.second + "#" + index; + } + public void toLong(long[] longs, int offset) { + int i = clusterUID.toLong(longs, offset); + longs[i] = index; + } + @Override + public String toString() { + return clusterUID.toString() + "." + index; + } + @Override + public boolean equals(Object o) { + if (this == o) + return true; + else if (!(o instanceof ResourceUID)) + return false; + ResourceUID x = (ResourceUID)o; + return clusterUID.equals(x.clusterUID) && index == x.index; + } + @Override + public int hashCode() { + int result = clusterUID.hashCode(); + result = 31 * result + index; + return result; + } +}