### Question:
Vectors { public static Long2DoubleMap addScalar(Long2DoubleMap vec, double val) { SortedKeyIndex keys = SortedKeyIndex.fromCollection(vec.keySet()); final int n = keys.size(); double[] values = new double[n]; if (vec instanceof Long2DoubleSortedArrayMap) { Long2DoubleSortedArrayMap sorted = (Long2DoubleSortedArrayMap) vec; for (int i = 0; i < n; i++) { assert sorted.getKeyByIndex(i) == keys.getKey(i); values[i] = sorted.getValueByIndex(i) + val; } } else { for (int i = 0; i < n; i++) { values[i] = vec.get(keys.getKey(i)) + val; } } return Long2DoubleSortedArrayMap.wrap(keys, values); } private  Vectors(); static Iterator<Long2DoubleMap.Entry> fastEntryIterator(Long2DoubleMap map); static Iterable<Long2DoubleMap.Entry> fastEntries(final Long2DoubleMap map); static double sum(Long2DoubleMap v); static double sumAbs(Long2DoubleMap v); static double sumOfSquares(Long2DoubleMap v); static double sumOfSquares(Long2DoubleSortedArrayMap v); static double euclideanNorm(Long2DoubleMap v); static Long2DoubleMap unitVector(Long2DoubleMap v); static double dotProduct(Long2DoubleMap v1, Long2DoubleMap v2); static double dotProduct(Long2DoubleSortedArrayMap v1, Long2DoubleSortedArrayMap v2); static double mean(Long2DoubleMap vec); static Long2DoubleMap combine(Long2DoubleMap x, Long2DoubleFunction y, double sy, double o); static Long2DoubleMap addScalar(Long2DoubleMap vec, double val); @Nonnull static Long2DoubleMap multiplyScalar(Long2DoubleMap vector, double value); static Long2DoubleMap transform(Long2DoubleMap input, DoubleUnaryOperator function); static RealVector matrixRow(RealMatrix mat, int row);  }### Answer:
@Test public void testAddScalar() { for (Map<Long,Double> map: someMaps(longs(), doubles(-1000, 1000))) { double scalar = doubles(-250, 250).next(); Long2DoubleMap m = new Long2DoubleOpenHashMap(map); Long2DoubleMap result = Vectors.addScalar(m, scalar); assertThat(Vectors.sum(result), closeTo(Vectors.sum(m) + m.size() * scalar, 1.0e-6)); for (long key: result.keySet()) { assertThat(result.get(key), closeTo(map.get(key) + scalar, 1.0e-6)); } } }