private SnapshotHolderCache getDelegate(Holder macro) { if (macro == null) { throw new NullPointerException("null macro is illegal to share"); // NOI18N } int index = macro.hashCode() & segmentMask; return instances[index]; }
@Override public Iterator<Entry<CharSequence, V>> iterator() { if (storage == EMPTY) { return Collections.emptyIterator(); } else if (storage instanceof Map<?,?>) { return ((Map<CharSequence,V>)storage).entrySet().iterator(); } else if (storage instanceof Holder) { return ((Holder)storage).iterator(); } return Collections.emptyIterator(); }
/** * returns shared string instance equal to input text. * * @param test - interested shared string * @return the shared instance of text * @exception NullPointerException If the <code>text</code> parameter * is <code>null</code>. */ @Override public Holder getHolder(Holder arr) { if (arr == null) { throw new NullPointerException("null string is illegal to share"); // NOI18N } Holder outHolder = null; synchronized (lock) { outHolder = storage.putIfAbsent(arr); } assert (outHolder != null); assert (outHolder.equals(arr)); return outHolder; }
public APTMacroMapSnapshot(RepositoryDataInput input) throws IOException { super(APTSerializeUtils.readSnapshot(input)); int collSize = input.readInt(); if (collSize == -2) { this.storage = APTSerializeUtils.readMacro(input); } else if (collSize == -1) { this.storage = CharSequences.create(input.readCharSequenceUTF()); } else if (collSize == 0) { storage = EMPTY; } else { Object[] arr = readMacros(collSize, input); storage = SnapshotHolderCache.getManager().getHolder(new Holder(arr)); } }
@SuppressWarnings("unchecked") private void freeze() { if (storage instanceof Map<?,?>) { if (storage != EMPTY) { Object[] arr = compact((Map<CharSequence,Object>)storage); storage = cacheHolder(new Holder(arr)); } } }