@Test public void testMultiplePutWithCapacity() { for (TimestampMap set : getAllInstances(10)) { Object[] defaultValues = getTestValues(set); Assert.assertTrue(set.put(1.0, defaultValues[0])); Assert.assertTrue(set.put(6.0, defaultValues[1])); testValues(set, new double[] { 1.0, 6.0 }, defaultValues); } }
@Override public boolean put(Double timestamp, T value) { if (value == null) { throw new NullPointerException(); } Object values = getValuesArray(); int valuesLength = Array.getLength(values); final int index = putInner(timestamp); if (index < 0) { int insertIndex = -index - 1; if (size - 1 < valuesLength) { if (insertIndex < size - 1) { System.arraycopy(values, insertIndex, values, insertIndex + 1, size - insertIndex - 1); } Array.set(values, insertIndex, value); } else { Object newArray = Array.newInstance(values.getClass().getComponentType(), valuesLength + 1); System.arraycopy(values, 0, newArray, 0, insertIndex); System.arraycopy(values, insertIndex, newArray, insertIndex + 1, valuesLength - insertIndex); Array.set(newArray, insertIndex, value); setValuesArray(newArray); } return true; } else { Array.set(values, index, value); } return false; }
TimestampMap implements TimeMap<Double, T> { @Override public boolean put(Double timestamp, T value) { if (value == null) { throw new NullPointerException(); } Object values = getValuesArray(); int valuesLength = Array.getLength(values); final int index = putInner(timestamp); if (index < 0) { int insertIndex = -index - 1; if (size - 1 < valuesLength) { if (insertIndex < size - 1) { System.arraycopy(values, insertIndex, values, insertIndex + 1, size - insertIndex - 1); } Array.set(values, insertIndex, value); } else { Object newArray = Array.newInstance(values.getClass().getComponentType(), valuesLength + 1); System.arraycopy(values, 0, newArray, 0, insertIndex); System.arraycopy(values, insertIndex, newArray, insertIndex + 1, valuesLength - insertIndex); Array.set(newArray, insertIndex, value); setValuesArray(newArray); } return true; } else { Array.set(values, index, value); } return false; } }
TimestampMap implements TimeMap<Double, T> { @Override public boolean put(Double timestamp, T value) { if (value == null) { throw new NullPointerException(); } Object values = getValuesArray(); int valuesLength = Array.getLength(values); final int index = putInner(timestamp); if (index < 0) { int insertIndex = -index - 1; if (size - 1 < valuesLength) { if (insertIndex < size - 1) { System.arraycopy(values, insertIndex, values, insertIndex + 1, size - insertIndex - 1); } Array.set(values, insertIndex, value); } else { Object newArray = Array.newInstance(values.getClass().getComponentType(), valuesLength + 1); System.arraycopy(values, 0, newArray, 0, insertIndex); System.arraycopy(values, insertIndex, newArray, insertIndex + 1, valuesLength - insertIndex); Array.set(newArray, insertIndex, value); setValuesArray(newArray); } return true; } else { Array.set(values, index, value); } return false; } TimestampMap();  TimestampMap(int capacity); protected  TimestampMap(double[] keys); }
TimestampMap implements TimeMap<Double, T> { @Override public boolean put(Double timestamp, T value) { if (value == null) { throw new NullPointerException(); } Object values = getValuesArray(); int valuesLength = Array.getLength(values); final int index = putInner(timestamp); if (index < 0) { int insertIndex = -index - 1; if (size - 1 < valuesLength) { if (insertIndex < size - 1) { System.arraycopy(values, insertIndex, values, insertIndex + 1, size - insertIndex - 1); } Array.set(values, insertIndex, value); } else { Object newArray = Array.newInstance(values.getClass().getComponentType(), valuesLength + 1); System.arraycopy(values, 0, newArray, 0, insertIndex); System.arraycopy(values, insertIndex, newArray, insertIndex + 1, valuesLength - insertIndex); Array.set(newArray, insertIndex, value); setValuesArray(newArray); } return true; } else { Array.set(values, index, value); } return false; } TimestampMap();  TimestampMap(int capacity); protected  TimestampMap(double[] keys); @Override boolean put(Double timestamp, T value); @Override boolean remove(Double timestamp); @Override T get(Double timestamp, T defaultValue); @Override Object get(Interval interval, Estimator estimator); @Override T[] toValuesArray(); @Override abstract Class<T> getTypeClass(); @Override abstract boolean isSupported(Estimator estimator); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Double timestamp); double[] getTimestamps(); @Override Double[] toKeysArray(); @Override void clear(); @Override int hashCode(); @Override boolean equals(Object obj); String toString(TimeFormat timeFormat, DateTimeZone timeZone); String toString(TimeFormat timeFormat); @Override String toString(); }
TimestampMap implements TimeMap<Double, T> { @Override public boolean put(Double timestamp, T value) { if (value == null) { throw new NullPointerException(); } Object values = getValuesArray(); int valuesLength = Array.getLength(values); final int index = putInner(timestamp); if (index < 0) { int insertIndex = -index - 1; if (size - 1 < valuesLength) { if (insertIndex < size - 1) { System.arraycopy(values, insertIndex, values, insertIndex + 1, size - insertIndex - 1); } Array.set(values, insertIndex, value); } else { Object newArray = Array.newInstance(values.getClass().getComponentType(), valuesLength + 1); System.arraycopy(values, 0, newArray, 0, insertIndex); System.arraycopy(values, insertIndex, newArray, insertIndex + 1, valuesLength - insertIndex); Array.set(newArray, insertIndex, value); setValuesArray(newArray); } return true; } else { Array.set(values, index, value); } return false; } TimestampMap();  TimestampMap(int capacity); protected  TimestampMap(double[] keys); @Override boolean put(Double timestamp, T value); @Override boolean remove(Double timestamp); @Override T get(Double timestamp, T defaultValue); @Override Object get(Interval interval, Estimator estimator); @Override T[] toValuesArray(); @Override abstract Class<T> getTypeClass(); @Override abstract boolean isSupported(Estimator estimator); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Double timestamp); double[] getTimestamps(); @Override Double[] toKeysArray(); @Override void clear(); @Override int hashCode(); @Override boolean equals(Object obj); String toString(TimeFormat timeFormat, DateTimeZone timeZone); String toString(TimeFormat timeFormat); @Override String toString();  }