Fix javadoc warnings in ImmutableOffsetMap
[yangtools.git] / common / util / src / main / java / org / opendaylight / yangtools / util / ImmutableOffsetMap.java
index 131d69277bd1baae1ec3e5561ff64f0cfa1035f3..66b20fbdf1ec9be8cdb47ef557bc897be1b08d38 100644 (file)
@@ -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.
  *
+ * <p>
+ * In case the set of keys is statically known, you can use {@link ImmutableOffsetMapTemplate} to efficiently create
+ * {@link ImmutableOffsetMap} instances.
+ *
  * @param <K> the type of keys maintained by this map
  * @param <V> the type of mapped values
  */
@@ -112,6 +117,8 @@ public abstract class ImmutableOffsetMap<K, V> implements UnmodifiableMapPhase<K
      * {@link #toModifiableMap()}) and makes an efficient copy of its contents. All other maps are converted to an
      * {@link ImmutableOffsetMap} with the same iteration order as input.
      *
+     * @param <K> the type of keys maintained by the map
+     * @param <V> 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<K, V> implements UnmodifiableMapPhase<K
      * {@link #toModifiableMap()}) and makes an efficient copy of its contents. All other maps are converted to an
      * {@link ImmutableOffsetMap}. Iterator order is not guaranteed to be retained.
      *
+     * @param <K> the type of keys maintained by the map
+     * @param <V> 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<K, V> implements UnmodifiableMapPhase<K
             return common;
         }
 
-        final int size = map.size();
-        if (size == 1) {
+        if (map.size() == 1) {
             // Efficient single-entry implementation
             final Entry<K, V> e = map.entrySet().iterator().next();
             return SharedSingletonMap.unorderedOf(e.getKey(), e.getValue());
@@ -278,8 +286,8 @@ public abstract class ImmutableOffsetMap<K, V> implements UnmodifiableMapPhase<K
 
     @Override
     public final V get(final Object key) {
-        final Integer offset = offsets.get(key);
-        return offset == null ? null : objects[offset];
+        Integer offset;
+        return (offset = offsets.get(key)) == null ? null : objects[offset];
     }
 
     @Override
@@ -324,9 +332,7 @@ public abstract class ImmutableOffsetMap<K, V> implements UnmodifiableMapPhase<K
         final Iterator<K> 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<K, V> implements UnmodifiableMapPhase<K
         @Override
         public @NonNull Iterator<Entry<K, V>> iterator() {
             final Iterator<Entry<K, Integer>> it = offsets.entrySet().iterator();
-            return new UnmodifiableIterator<Entry<K, V>>() {
+            return new UnmodifiableIterator<>() {
                 @Override
                 public boolean hasNext() {
                     return it.hasNext();
@@ -391,6 +397,8 @@ public abstract class ImmutableOffsetMap<K, V> implements UnmodifiableMapPhase<K
         return f;
     }
 
+    @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
+            justification = "https://github.com/spotbugs/spotbugs/issues/811")
     private static void setField(final @NonNull ImmutableOffsetMap<?, ?> map, final @NonNull Field field,
             final Object value) throws IOException {
         try {