X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=common%2Futil%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Futil%2FImmutableOffsetMap.java;h=66b20fbdf1ec9be8cdb47ef557bc897be1b08d38;hb=refs%2Fchanges%2F71%2F99871%2F2;hp=131d69277bd1baae1ec3e5561ff64f0cfa1035f3;hpb=048042bd88cc9b1f481c018363c331bca83e4e1f;p=yangtools.git diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/ImmutableOffsetMap.java b/common/util/src/main/java/org/opendaylight/yangtools/util/ImmutableOffsetMap.java index 131d69277b..66b20fbdf1 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/ImmutableOffsetMap.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/ImmutableOffsetMap.java @@ -13,6 +13,7 @@ import static java.util.Objects.requireNonNull; import com.google.common.annotations.Beta; import com.google.common.collect.ImmutableMap; import com.google.common.collect.UnmodifiableIterator; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; @@ -35,6 +36,10 @@ import org.eclipse.jdt.annotation.Nullable; * a backing array. This is useful for situations where the same key set is shared across a multitude of maps, as this * class uses a global cache to share the key-to-offset mapping. * + *

+ * In case the set of keys is statically known, you can use {@link ImmutableOffsetMapTemplate} to efficiently create + * {@link ImmutableOffsetMap} instances. + * * @param the type of keys maintained by this map * @param the type of mapped values */ @@ -112,6 +117,8 @@ public abstract class ImmutableOffsetMap implements UnmodifiableMapPhase the type of keys maintained by the map + * @param the type of mapped values * @param map Input map, may not be null. * @return An isolated, immutable copy of the input map * @throws NullPointerException if {@code map} or any of its elements is null. @@ -147,6 +154,8 @@ public abstract class ImmutableOffsetMap implements UnmodifiableMapPhase the type of keys maintained by the map + * @param the type of mapped values * @param map Input map, may not be null. * @return An isolated, immutable copy of the input map * @throws NullPointerException if {@code map} or any of its elements is null. @@ -157,8 +166,7 @@ public abstract class ImmutableOffsetMap implements UnmodifiableMapPhase e = map.entrySet().iterator().next(); return SharedSingletonMap.unorderedOf(e.getKey(), e.getValue()); @@ -278,8 +286,8 @@ public abstract class ImmutableOffsetMap implements UnmodifiableMapPhase implements UnmodifiableMapPhase it = offsets.keySet().iterator(); int offset = 0; while (it.hasNext()) { - sb.append(it.next()); - sb.append('='); - sb.append(objects[offset++]); + sb.append(it.next()).append('=').append(objects[offset++]); if (it.hasNext()) { sb.append(", "); @@ -348,7 +354,7 @@ public abstract class ImmutableOffsetMap implements UnmodifiableMapPhase> iterator() { final Iterator> it = offsets.entrySet().iterator(); - return new UnmodifiableIterator>() { + return new UnmodifiableIterator<>() { @Override public boolean hasNext() { return it.hasNext(); @@ -391,6 +397,8 @@ public abstract class ImmutableOffsetMap implements UnmodifiableMapPhase map, final @NonNull Field field, final Object value) throws IOException { try {