import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;
import com.google.common.primitives.UnsignedInteger;
+import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
/**
* A map of Router identifier to an offset. Used to maintain a simple
- * offset-based lookup across multiple {@link RouteEntry} objects,
+ * offset-based lookup across multiple {@link AbstractRouteEntry} objects,
* which share either contributors or consumers.
*
* We also provide utility reformat methods, which provide access to
}
<T> T getValue(final T[] array, final int offset) {
- Preconditions.checkArgument(offset >= 0, "Invalid negative offset {}", offset);
+ Preconditions.checkArgument(offset >= 0, "Invalid negative offset %s", offset);
+ Preconditions.checkArgument(offset < routerIds.length, "Invalid offset %s for %s router IDs", offset, routerIds.length);
return array[offset];
}
<T> void setValue(final T[] array, final int offset, final T value) {
- Preconditions.checkArgument(offset >= 0, "Invalid negative offset {}", offset);
+ Preconditions.checkArgument(offset >= 0, "Invalid negative offset %s", offset);
+ Preconditions.checkArgument(offset < routerIds.length, "Invalid offset %s for %s router IDs", offset, routerIds.length);
array[offset] = value;
}
<T> T[] expand(final OffsetMap oldOffsets, final T[] oldArray, final int offset) {
@SuppressWarnings("unchecked")
- final T[] ret = (T[]) new Object[this.routerIds.length];
+ final T[] ret = (T[]) Array.newInstance(oldArray.getClass().getComponentType(), this.routerIds.length);
final int oldSize = oldOffsets.routerIds.length;
System.arraycopy(oldArray, 0, ret, 0, offset);