+public abstract class ImmutableOffsetMap<K, V> implements UnmodifiableMapPhase<K, V>, Serializable {
+ static final class Ordered<K, V> extends ImmutableOffsetMap<K, V> {
+ private static final long serialVersionUID = 1L;
+
+ Ordered(final Map<K, Integer> offsets, final V[] objects) {
+ super(offsets, objects);
+ }
+
+ @Override
+ public MutableOffsetMap<K, V> toModifiableMap() {
+ return MutableOffsetMap.orderedCopyOf(this);
+ }
+
+ @Override
+ void setFields(final List<K> keys, final V[] values) throws IOException {
+ setField(this, OFFSETS_FIELD, OffsetMapCache.orderedOffsets(keys));
+ setField(this, ARRAY_FIELD, values);
+ }
+ }
+
+ static final class Unordered<K, V> extends ImmutableOffsetMap<K, V> {
+ private static final long serialVersionUID = 1L;
+
+ Unordered(final Map<K, Integer> offsets, final V[] objects) {
+ super(offsets, objects);
+ }
+
+ @Override
+ public MutableOffsetMap<K, V> toModifiableMap() {
+ return MutableOffsetMap.unorderedCopyOf(this);
+ }
+
+ @Override
+ void setFields(final List<K> keys, final V[] values) throws IOException {
+ final Map<K, Integer> offsets = OffsetMapCache.unorderedOffsets(keys);
+
+ setField(this, OFFSETS_FIELD, offsets);
+ setField(this, ARRAY_FIELD, OffsetMapCache.adjustedArray(offsets, keys, values));
+ }
+ }
+