X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.databoard%2Fsrc%2Forg%2Fsimantics%2Fdataboard%2Faccessor%2Fbinary%2FBinaryMap.java;h=4a90524fb4f198c83d4abb153b70cb708e14f4eb;hb=refs%2Fchanges%2F38%2F238%2F2;hp=0915acfc623824361d7225832bab0f6e9d8129ff;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.databoard/src/org/simantics/databoard/accessor/binary/BinaryMap.java b/bundles/org.simantics.databoard/src/org/simantics/databoard/accessor/binary/BinaryMap.java index 0915acfc6..4a90524fb 100644 --- a/bundles/org.simantics.databoard/src/org/simantics/databoard/accessor/binary/BinaryMap.java +++ b/bundles/org.simantics.databoard/src/org/simantics/databoard/accessor/binary/BinaryMap.java @@ -1,58 +1,58 @@ -/******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ package org.simantics.databoard.accessor.binary; -import java.io.IOException; -import java.lang.ref.SoftReference; -import java.util.Map; -import java.util.TreeMap; -import java.util.concurrent.Executor; - -import org.simantics.databoard.accessor.Accessor; -import org.simantics.databoard.accessor.MapAccessor; -import org.simantics.databoard.accessor.error.AccessorConstructionException; -import org.simantics.databoard.accessor.error.AccessorException; -import org.simantics.databoard.accessor.error.ReferenceException; -import org.simantics.databoard.accessor.event.Event; -import org.simantics.databoard.accessor.event.MapEntryAdded; -import org.simantics.databoard.accessor.event.MapEntryRemoved; -import org.simantics.databoard.accessor.event.ValueAssigned; -import org.simantics.databoard.accessor.file.FileMapAccessor; -import org.simantics.databoard.accessor.impl.AccessorParams; -import org.simantics.databoard.accessor.impl.ListenerEntry; -import org.simantics.databoard.accessor.interestset.InterestSet; -import org.simantics.databoard.accessor.interestset.MapInterestSet; -import org.simantics.databoard.accessor.reference.ChildReference; -import org.simantics.databoard.accessor.reference.KeyReference; -import org.simantics.databoard.accessor.reference.LabelReference; -import org.simantics.databoard.adapter.AdaptException; -import org.simantics.databoard.adapter.Adapter; -import org.simantics.databoard.adapter.AdapterConstructionException; -import org.simantics.databoard.binding.ArrayBinding; -import org.simantics.databoard.binding.Binding; -import org.simantics.databoard.binding.MapBinding; -import org.simantics.databoard.binding.error.BindingConstructionException; -import org.simantics.databoard.binding.error.BindingException; -import org.simantics.databoard.binding.mutable.MutableVariant; -import org.simantics.databoard.parser.repository.DataTypeSyntaxError; -import org.simantics.databoard.parser.repository.DataValueRepository; -import org.simantics.databoard.serialization.RuntimeSerializerConstructionException; -import org.simantics.databoard.serialization.SerializationException; -import org.simantics.databoard.serialization.Serializer; -import org.simantics.databoard.serialization.SerializerConstructionException; -import org.simantics.databoard.type.Datatype; -import org.simantics.databoard.type.MapType; -import org.simantics.databoard.util.binary.Blob; -import org.simantics.databoard.util.binary.RandomAccessBinary.ByteSide; +import java.io.IOException; +import java.lang.ref.SoftReference; +import java.util.Map; +import java.util.TreeMap; +import java.util.concurrent.Executor; + +import org.simantics.databoard.accessor.Accessor; +import org.simantics.databoard.accessor.MapAccessor; +import org.simantics.databoard.accessor.error.AccessorConstructionException; +import org.simantics.databoard.accessor.error.AccessorException; +import org.simantics.databoard.accessor.error.ReferenceException; +import org.simantics.databoard.accessor.event.Event; +import org.simantics.databoard.accessor.event.MapEntryAdded; +import org.simantics.databoard.accessor.event.MapEntryRemoved; +import org.simantics.databoard.accessor.event.ValueAssigned; +import org.simantics.databoard.accessor.file.FileMapAccessor; +import org.simantics.databoard.accessor.impl.AccessorParams; +import org.simantics.databoard.accessor.impl.ListenerEntry; +import org.simantics.databoard.accessor.interestset.InterestSet; +import org.simantics.databoard.accessor.interestset.MapInterestSet; +import org.simantics.databoard.accessor.reference.ChildReference; +import org.simantics.databoard.accessor.reference.KeyReference; +import org.simantics.databoard.accessor.reference.LabelReference; +import org.simantics.databoard.adapter.AdaptException; +import org.simantics.databoard.adapter.Adapter; +import org.simantics.databoard.adapter.AdapterConstructionException; +import org.simantics.databoard.binding.ArrayBinding; +import org.simantics.databoard.binding.Binding; +import org.simantics.databoard.binding.MapBinding; +import org.simantics.databoard.binding.error.BindingConstructionException; +import org.simantics.databoard.binding.error.BindingException; +import org.simantics.databoard.binding.mutable.MutableVariant; +import org.simantics.databoard.parser.repository.DataTypeSyntaxError; +import org.simantics.databoard.parser.repository.DataValueRepository; +import org.simantics.databoard.serialization.RuntimeSerializerConstructionException; +import org.simantics.databoard.serialization.SerializationException; +import org.simantics.databoard.serialization.Serializer; +import org.simantics.databoard.serialization.SerializerConstructionException; +import org.simantics.databoard.type.Datatype; +import org.simantics.databoard.type.MapType; +import org.simantics.databoard.util.binary.Blob; +import org.simantics.databoard.util.binary.RandomAccessBinary.ByteSide; /** * BinaryMap is accessor to a map structure in a file or byte memory. @@ -195,7 +195,7 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces return higherChildEntry(key); } - Entry getEntryAt(long pos) throws SerializationException, IOException, BindingException { + Entry getEntryAt(long pos) throws SerializationException, IOException, BindingException { Object k = getKeyAt(pos); if (k==null) return null; return new Entry(k, pos, getChild(k)); @@ -215,22 +215,22 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces } @Override - public void clear() throws AccessorException { - assert b.isOpen(); + public void clear() throws AccessorException { + assert b.isOpen(); writeLock(); try { clearNoflush(); b.flush(); } catch (IOException e) { throw new AccessorException( e ); - } finally { - writeUnlock(); + } finally { + writeUnlock(); } } @Override - public int size() throws AccessorException { - assert b.isOpen(); + public int size() throws AccessorException { + assert b.isOpen(); readLock(); try { if (constantSize != null) return (int) ((b.length()-4) / constantSize); @@ -238,15 +238,15 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces return b.readInt(); } catch (IOException e) { throw new AccessorException( e ); - } finally { - readUnlock(); + } finally { + readUnlock(); } } @Override public boolean containsKey(Binding keyBinding, Object key) - throws AccessorException { - assert b.isOpen(); + throws AccessorException { + assert b.isOpen(); readLock(); try { Object lk = adapt(key, keyBinding, kb); @@ -254,17 +254,17 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces return e != null; } catch (AdaptException e) { throw new AccessorException(e); - } catch (AdapterConstructionException e) { - throw new AccessorException(e); - } finally { - readUnlock(); + } catch (AdapterConstructionException e) { + throw new AccessorException(e); + } finally { + readUnlock(); } } @Override public boolean containsValue(Binding valueBinding, Object value) - throws AccessorException { - assert b.isOpen(); + throws AccessorException { + assert b.isOpen(); readLock(); try { Serializer vs = params.serializerScheme.getSerializer( valueBinding ); @@ -277,18 +277,18 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces } } catch (IOException e) { throw new AccessorException(e); - } catch (SerializerConstructionException e) { - throw new AccessorException(e); - } finally { - readUnlock(); + } catch (SerializerConstructionException e) { + throw new AccessorException(e); + } finally { + readUnlock(); } return false; } @Override public Object get(Binding keyBinding, Object key, Binding valueBinding) - throws AccessorException { - assert b.isOpen(); + throws AccessorException { + assert b.isOpen(); readLock(); try { Object lk = adapt(key, keyBinding, kb); @@ -304,19 +304,19 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces throw new AccessorException(e); } catch (RuntimeSerializerConstructionException e) { throw new AccessorException(e); - } catch (AdapterConstructionException e) { - throw new AccessorException(e); - } catch (SerializerConstructionException e) { - throw new AccessorException(e); - } finally { - readUnlock(); + } catch (AdapterConstructionException e) { + throw new AccessorException(e); + } catch (SerializerConstructionException e) { + throw new AccessorException(e); + } finally { + readUnlock(); } } @Override public void getAll(Binding keyBinding, Binding valueBinding, Map to) throws AccessorException { - assert b.isOpen(); + assert b.isOpen(); readLock(); try { Adapter ka = params.adapterScheme.getAdapter(kb, keyBinding, true, false); @@ -337,8 +337,8 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces throw new AccessorException(e); } catch (AdaptException e) { throw new AccessorException(e); - } finally { - readUnlock(); + } finally { + readUnlock(); } } @@ -346,7 +346,7 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces @Override public void getAll(Binding keyBinding, Binding valueBinding, Object[] keys, Object[] values) throws AccessorException { - assert b.isOpen(); + assert b.isOpen(); readLock(); try { Adapter ka = params.adapterScheme.getAdapter(kb, keyBinding, true, false); @@ -370,154 +370,154 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces throw new AccessorException(e); } catch (AdaptException e) { throw new AccessorException(e); - } finally { - readUnlock(); + } finally { + readUnlock(); } - } - - @Override - public int count(Binding keyBinding, Object from, boolean fromInclusive, - Object end, boolean endInclusive) throws AccessorException { - assert b.isOpen(); - readLock(); - try { - Object lf = params.adapterScheme.adapt(from, keyBinding, kb); - Object le = params.adapterScheme.adapt(end, keyBinding, kb); - - Entry fromEntry = fromInclusive ? index.ceiling(lf) : index.higher(lf); - Entry endEntry = endInclusive ? index.floor(le) : index.lower(le); - if (endEntry==null || fromEntry == null) return 0; - - if (fromEntry.pos>endEntry.pos) return 0; - if (fromEntry.pos==endEntry.pos) return 1; - - if (constantSize != null) { - return (int) ((endEntry.pos-fromEntry.pos)/constantSize)+1; - } - - int result = 1; - b.position(fromEntry.pos); - while (b.position()=0 && i>=limit) break; - Object key = ks.deserialize(b); - if (adaptKey) key = ka.adapt(key); - Object value = vs.deserialize(b); - if (adaptValue) value = va.adapt(value); - - if (iendEntry.pos) return 0; + if (fromEntry.pos==endEntry.pos) return 1; + + if (constantSize != null) { + return (int) ((endEntry.pos-fromEntry.pos)/constantSize)+1; + } + + int result = 1; + b.position(fromEntry.pos); + while (b.position()=0 && i>=limit) break; + Object key = ks.deserialize(b); + if (adaptKey) key = ka.adapt(key); + Object value = vs.deserialize(b); + if (adaptValue) value = va.adapt(value); + + if (i T getComponent(ChildReference reference) throws AccessorConstructionException { - if (reference==null) return (T) this; - - if (reference instanceof LabelReference) { - LabelReference lr = (LabelReference) reference; - try { - DataValueRepository rep = new DataValueRepository(); - kb.parseValue(lr.label, rep); - Object value = rep.get( rep.getValueNames().iterator().next() ); - - Accessor result = (T) getValueAccessor(kb, value); - if (reference.getChildReference() != null) - result = result.getComponent(reference.getChildReference()); - return (T) result; - } catch ( BindingException e1 ) { - throw new ReferenceException(e1); - } catch ( DataTypeSyntaxError e2 ) { - throw new ReferenceException(e2); - } + if (reference==null) return (T) this; + + if (reference instanceof LabelReference) { + LabelReference lr = (LabelReference) reference; + try { + DataValueRepository rep = new DataValueRepository(); + kb.parseValue(lr.label, rep); + Object value = rep.get( rep.getValueNames().iterator().next() ); + + Accessor result = (T) getValueAccessor(kb, value); + if (reference.getChildReference() != null) + result = result.getComponent(reference.getChildReference()); + return (T) result; + } catch ( BindingException e1 ) { + throw new ReferenceException(e1); + } catch ( DataTypeSyntaxError e2 ) { + throw new ReferenceException(e2); + } } else if (reference instanceof KeyReference) { KeyReference ref = (KeyReference) reference; @@ -677,8 +677,8 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces @Override public T getValueAccessor(Binding keyBinding, Object key) throws AccessorConstructionException { - - assert b.isOpen(); + + assert b.isOpen(); readLock(); try { Object rk = key; @@ -755,16 +755,16 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces throw new AccessorConstructionException(e); } catch (AccessorException e) { throw new AccessorConstructionException(e); - } finally { - readUnlock(); + } finally { + readUnlock(); } } @Override - public Object[] getValues(Binding valueBinding) throws AccessorException { - assert b.isOpen(); + public Object[] getValues(Binding valueBinding) throws AccessorException { + assert b.isOpen(); readLock(); - try { + try { Serializer rvs = params.serializerScheme.getSerializer(valueBinding); b.position(0L); int count = b.readInt(); @@ -776,19 +776,19 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces return result; } catch (IOException e) { throw new AccessorException( e ); - } catch (SerializerConstructionException e) { - throw new AccessorException( e ); - } finally { - readUnlock(); + } catch (SerializerConstructionException e) { + throw new AccessorException( e ); + } finally { + readUnlock(); } } @Override public void setValueNoflush(Binding binding, Object mapValue) throws AccessorException { - assert b.isOpen(); + assert b.isOpen(); MapBinding mb = (MapBinding) binding; - if (children.isEmpty() && listeners==null) { + if (children.isEmpty() && listeners==null) { writeLock(); try { // Write @@ -800,13 +800,13 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces s.serialize(b, null, mapValue); } catch (IOException e) { throw new AccessorException( e ); - } catch (SerializerConstructionException e) { - throw new AccessorException( e ); - } finally { - writeUnlock(); + } catch (SerializerConstructionException e) { + throw new AccessorException( e ); + } finally { + writeUnlock(); } } else { - + writeLock(); try { int nc = mb.size(mapValue); @@ -816,8 +816,8 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces setAllNoflush(mb.getKeyBinding(), mb.getValueBinding(), nks, nvs); } catch (BindingException e) { throw new AccessorException(e); - } finally { - writeUnlock(); + } finally { + writeUnlock(); } } @@ -826,7 +826,7 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces @Override public void clearNoflush() throws AccessorException { - assert b.isOpen(); + assert b.isOpen(); writeLock(); try { boolean hasListeners = listeners!=null; @@ -862,8 +862,8 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces } catch (IOException e) { throw new AccessorException( e ); - } finally { - writeUnlock(); + } finally { + writeUnlock(); } } @@ -893,26 +893,26 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces if (!hadPreviousValue) newItemsCount++; } - if (newItemsCount>0) { - assert b.isOpen(); + if (newItemsCount>0) { + assert b.isOpen(); writeLock(); try { b.position(0L); int oldCount = b.readInt(); - b.position(0L); + b.position(0L); b.writeInt( oldCount + newItemsCount); } catch (IOException e) { throw new AccessorException(e); - } finally { - writeUnlock(); + } finally { + writeUnlock(); } } } public void setAllNoflush(Binding kb, Binding vb, - Object[] nks, Object[] nvs) throws AccessorException { - assert b.isOpen(); + Object[] nks, Object[] nvs) throws AccessorException { + assert b.isOpen(); writeLock(); try { Serializer ks = params.serializerScheme.getSerializer( kb ); @@ -1036,7 +1036,7 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces ks.serialize(b, null, nk); vs.serialize(b, null, nv); long endPos = b.position(); - long len = endPos - startPos; + long len = endPos - startPos; Object lk = params.adapterScheme.adapt(nk, kb, this.kb); BinaryObject sa = getChild(lk); if (sa!=null) sa.b.setPositionInSource(startPos, len); @@ -1047,18 +1047,18 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces throw new AccessorException(e); } catch (AdaptException e) { throw new AccessorException(e); - } catch (SerializerConstructionException e) { - throw new AccessorException(e); - } finally { - writeUnlock(); + } catch (SerializerConstructionException e) { + throw new AccessorException(e); + } finally { + writeUnlock(); } } @Override public void putNoflush(Binding kb, Object key, - Binding vb, Object value) throws AccessorException { - assert b.isOpen(); + Binding vb, Object value) throws AccessorException { + assert b.isOpen(); writeLock(); try { boolean hadPreviousEntry = _putNoflush(kb, key, vb, value); @@ -1073,8 +1073,8 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces throw new AccessorException(e); } catch (RuntimeSerializerConstructionException e) { throw new AccessorException(e); - } finally { - writeUnlock(); + } finally { + writeUnlock(); } } @@ -1092,7 +1092,7 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces Binding vb, Object value) throws AccessorException { writeLock(); try { - Object lk = adapt(key, kb, this.kb); + Object lk = adapt(key, kb, this.kb); long insertPos = index.getInsertPos(lk); Serializer ks = params.serializerScheme.getSerializer( kb ); Serializer vs = params.serializerScheme.getSerializer( vb ); @@ -1197,20 +1197,20 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces throw new AccessorException(e); } catch (RuntimeSerializerConstructionException e) { throw new AccessorException(e); - } catch (AdapterConstructionException e) { - throw new AccessorException(e); - } catch (SerializerConstructionException e) { - throw new AccessorException(e); - } finally { - writeUnlock(); + } catch (AdapterConstructionException e) { + throw new AccessorException(e); + } catch (SerializerConstructionException e) { + throw new AccessorException(e); + } finally { + writeUnlock(); } } @Override public void removeNoflush(Binding keyBinding, Object key) - throws AccessorException { - assert b.isOpen(); + throws AccessorException { + assert b.isOpen(); writeLock(); try { Object lk = params.adapterScheme.getAdapter(keyBinding, kb, true, listeners!=null).adapt(key); @@ -1253,8 +1253,8 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces throw new AccessorException(e); } catch (AdapterConstructionException e) { throw new AccessorException(e); - } finally { - writeUnlock(); + } finally { + writeUnlock(); } } @@ -1311,18 +1311,18 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces Event applyLocal(Event e, boolean makeRollback) throws AccessorException { Event rollback = null; - if (e instanceof ValueAssigned) { - try { - ValueAssigned va = (ValueAssigned) e; - if (makeRollback) { - Binding binding = params.bindingScheme.getBinding(type()); - rollback = new ValueAssigned(binding, getValue(binding)); - } - setValueNoflush(va.newValue.getBinding(), va.newValue.getValue()); - return rollback; - } catch (BindingConstructionException e1) { - throw new AccessorException( e1 ); - } + if (e instanceof ValueAssigned) { + try { + ValueAssigned va = (ValueAssigned) e; + if (makeRollback) { + Binding binding = params.bindingScheme.getBinding(type()); + rollback = new ValueAssigned(binding, getValue(binding)); + } + setValueNoflush(va.newValue.getBinding(), va.newValue.getValue()); + return rollback; + } catch (BindingConstructionException e1) { + throw new AccessorException( e1 ); + } } else if (e instanceof MapEntryAdded) { MapEntryAdded ea = (MapEntryAdded) e; if (ea.key==null) throw new AccessorException("Cannot apply entry added event because key is missing"); @@ -1335,7 +1335,7 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces } putNoflush(ea.key.getBinding(), ea.key.getValue(), ea.value.getBinding(), ea.value.getValue()); - return rollback; + return rollback; } else if (e instanceof MapEntryRemoved) { MapEntryRemoved er = (MapEntryRemoved) e; @@ -1354,10 +1354,10 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces } removeNoflush( er.key.getBinding(), er.key.getValue() ); - return rollback; + return rollback; - } else { - throw new AccessorException("Cannot apply "+e.getClass().getName()+" to Map Type"); + } else { + throw new AccessorException("Cannot apply "+e.getClass().getName()+" to Map Type"); } } @@ -1365,60 +1365,60 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces @Override public void put(Binding keyBinding, Object key, Binding valueBinding, - Object value) throws AccessorException { - assert b.isOpen(); + Object value) throws AccessorException { + assert b.isOpen(); writeLock(); try { putNoflush(keyBinding, key, valueBinding, value); b.flush(); } catch (IOException e) { throw new AccessorException(e); - } finally { - writeUnlock(); + } finally { + writeUnlock(); } } @Override public void putAll(Binding keyBinding, Binding valueBinding, - Map from) throws AccessorException { - assert b.isOpen(); + Map from) throws AccessorException { + assert b.isOpen(); writeLock(); try { putAllNoflush(keyBinding, valueBinding, from); b.flush(); } catch (IOException e) { throw new AccessorException(e); - } finally { - writeUnlock(); + } finally { + writeUnlock(); } } @Override public void putAll(Binding keyBinding, Binding valueBinding, Object[] keys, - Object[] values) throws AccessorException { - assert b.isOpen(); + Object[] values) throws AccessorException { + assert b.isOpen(); writeLock(); try { putAllNoflush(keyBinding, valueBinding, keys, values); b.flush(); } catch (IOException e) { throw new AccessorException(e); - } finally { - writeUnlock(); + } finally { + writeUnlock(); } } @Override - public void remove(Binding keyBinding, Object key) throws AccessorException { - assert b.isOpen(); + public void remove(Binding keyBinding, Object key) throws AccessorException { + assert b.isOpen(); writeLock(); try { removeNoflush(keyBinding, key); b.flush(); } catch (IOException e) { throw new AccessorException(e); - } finally { - writeUnlock(); + } finally { + writeUnlock(); } } @@ -1429,7 +1429,7 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces * Get insert pos * @param key * @return if >0 position of existing entry of same key, <0 insertion position - * @throws AccessorException + * @throws AccessorException */ abstract long getInsertPos(Object key) throws AccessorException; @@ -1528,15 +1528,15 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces int indexOf(long pos) { return (int) ((pos - 4L) / constantSize); } - - - /** - * - * @param fromIndex - * @param toIndex exclusive - * @param key - * @return - * @throws AccessorException + + + /** + * + * @param fromIndex + * @param toIndex exclusive + * @param key + * @return + * @throws AccessorException */ int binarySearch(int fromIndex, int toIndex, Object key) throws AccessorException { int low = fromIndex; @@ -1624,16 +1624,16 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces long pos = getInsertPos(key); if (pos>0) { - // Exact match + // Exact match int index = indexOf(pos)+1; - if (index>=count()) return null; + if (index>=count()) return null; pos = getPos(index); key = getKeyAt(pos); return new Entry(key, pos, null); - } else { + } else { // Insert here match int index = indexOf(-pos); - if (index>=count()) return null; + if (index>=count()) return null; pos = getPos(index); key = getKeyAt(pos); return new Entry(key, pos, null); @@ -1693,13 +1693,13 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces /** Variable size enetry, Sequential search */ class Sequential extends Index { - - /** - * Get insert pos - * @param key - * @return if >0 position of existing entry of same key, <0 insertion position - * @throws AccessorException - */ + + /** + * Get insert pos + * @param key + * @return if >0 position of existing entry of same key, <0 insertion position + * @throws AccessorException + */ @Override long getInsertPos(Object key) throws AccessorException { try { @@ -1741,18 +1741,18 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces @Override Entry last() throws AccessorException { try { - Entry e = lastChildEntry(); - long startPos = e!=null ? e.pos : 4L; - b.position(startPos); - Entry result = e!=null ? new Entry(e.key, e.pos, e.accessor) : new Entry(null, 0, null); + Entry e = lastChildEntry(); + long startPos = e!=null ? e.pos : 4L; + b.position(startPos); + Entry result = e!=null ? new Entry(e.key, e.pos, e.accessor) : new Entry(null, 0, null); while (b.position() < b.length()) { - result.key = ks.deserialize(b, null); + result.key = ks.deserialize(b, null); result.pos = b.position(); vs.skip(b, null); long valueLen = b.position() - result.pos; result.accessor = createSubAccessor(vb.type(), result.pos, valueLen, params); children.put(result.key, new SoftReference( result.accessor )); - } + } return (result.key == null) ? null : result; } catch (IOException e) { throw new AccessorException(e); @@ -1843,16 +1843,16 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces pos = b.position(); prevK = k; k = ks.deserialize(b, null); - long valuePos = b.position(); - + long valuePos = b.position(); + // Compare current key with search key - int c = kb.compare(key, k); + int c = kb.compare(key, k); if (c<=0) { if (prevK==null) return null; return new Entry(prevK, prevPos, null); } vs.skip(b, null); - long valueLen = b.position() - valuePos; + long valueLen = b.position() - valuePos; assert(valueLen>=0); java.lang.ref.Reference ref = children.get(k); BinaryObject sa = ref!=null?ref.get():null; @@ -1860,7 +1860,7 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces sa = createSubAccessor(vb.type(), valuePos, valueLen, params); children.put(k, new SoftReference(sa)); } - } + } // There was no match, return the last entry return new Entry(k, pos, null); } catch (IOException e) { @@ -1885,17 +1885,17 @@ public class BinaryMap extends BinaryObject implements MapAccessor, FileMapAcces long pos = start==null ? 4L : start.pos; long prevPos = 0; Object k = null; - Object prevK = null; - BinaryObject prevAccessor = null; + Object prevK = null; + BinaryObject prevAccessor = null; b.position(pos); while (b.position()(prevAccessor)); - } - // Exact match - if (c==0) { - return new Entry(k, pos, prevAccessor); + } + // Exact match + if (c==0) { + return new Entry(k, pos, prevAccessor); } } return new Entry(k, pos, prevAccessor);