Java Code Examples for com.google.common.primitives.Longs.toArray()

The following are Jave code examples for showing how to use toArray() of the com.google.common.primitives.Longs class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ArchUnit   File: JavaClassProcessor.java   View Source Code Vote up 6 votes
@SuppressWarnings({"unchecked", "rawtypes"}) // NOTE: We assume the component type matches the list
private Object toArray(Class<?> componentType, List<Object> values) {
    if (componentType == boolean.class) {
        return Booleans.toArray((Collection) values);
    } else if (componentType == byte.class) {
        return Bytes.toArray((Collection) values);
    } else if (componentType == short.class) {
        return Shorts.toArray((Collection) values);
    } else if (componentType == int.class) {
        return Ints.toArray((Collection) values);
    } else if (componentType == long.class) {
        return Longs.toArray((Collection) values);
    } else if (componentType == float.class) {
        return Floats.toArray((Collection) values);
    } else if (componentType == double.class) {
        return Doubles.toArray((Collection) values);
    } else if (componentType == char.class) {
        return Chars.toArray((Collection) values);
    }
    return values.toArray((Object[]) Array.newInstance(componentType, values.size()));
}
 
Example 2
Project: guava-mock   File: QuantilesTest.java   View Source Code Vote up 5 votes
public void testScale_index_compute_longVarargs() {
  long[] dataset = Longs.toArray(SIXTEEN_SQUARES_LONGS);
  assertThat(Quantiles.scale(10).index(1).compute(dataset))
      .isWithin(ALLOWED_ERROR)
      .of(SIXTEEN_SQUARES_DECILE_1);
  assertThat(dataset).asList().isEqualTo(SIXTEEN_SQUARES_LONGS);
}
 
Example 3
Project: guava-mock   File: QuantilesTest.java   View Source Code Vote up 5 votes
public void testScale_indexes_varargs_compute_longVarargs() {
  long[] dataset = Longs.toArray(SIXTEEN_SQUARES_LONGS);
  assertThat(Quantiles.scale(10).indexes(0, 10, 5, 1, 8, 1).compute(dataset))
      .comparingValuesUsing(QUANTILE_CORRESPONDENCE)
      .containsExactly(
          0, SIXTEEN_SQUARES_MIN,
          10, SIXTEEN_SQUARES_MAX,
          5, SIXTEEN_SQUARES_MEDIAN,
          1, SIXTEEN_SQUARES_DECILE_1,
          8, SIXTEEN_SQUARES_DECILE_8);
  assertThat(dataset).asList().isEqualTo(SIXTEEN_SQUARES_LONGS);
}
 
Example 4
Project: googles-monorepo-demo   File: QuantilesTest.java   View Source Code Vote up 5 votes
public void testScale_indexes_varargs_compute_longVarargs() {
  long[] dataset = Longs.toArray(SIXTEEN_SQUARES_LONGS);
  ImmutableMap<Integer, Double> expected = ImmutableMap.of(
      0, SIXTEEN_SQUARES_MIN,
      10, SIXTEEN_SQUARES_MAX,
      5, SIXTEEN_SQUARES_MEDIAN,
      1, SIXTEEN_SQUARES_DECILE_1,
      8, SIXTEEN_SQUARES_DECILE_8
      );
  assertQuantilesMap(expected, Quantiles.scale(10).indexes(0, 10, 5, 1, 8, 1).compute(dataset));
  assertDatasetInOrder(SIXTEEN_SQUARES_LONGS, dataset);
}
 
Example 5
Project: dremio-oss   File: DremioMetaImpl.java   View Source Code Vote up 5 votes
@Override
public ExecuteBatchResult executeBatch(StatementHandle h, List<List<TypedValue>> parameterValueLists)
    throws NoSuchStatementException {
  final List<Long> updateCounts = new ArrayList<>();
  for (List<TypedValue> parameterValueList : parameterValueLists) {
    ExecuteResult executeResult = execute(h, parameterValueList, -1);
    final long updateCount =
        executeResult.resultSets.size() == 1
            ? executeResult.resultSets.get(0).updateCount
            : -1L;
    updateCounts.add(updateCount);
  }
  return new ExecuteBatchResult(Longs.toArray(updateCounts));
}
 
Example 6
Project: googles-monorepo-demo   File: QuantilesTest.java   View Source Code Vote up 4 votes
public void testScale_index_compute_longVarargs() {
  long[] dataset = Longs.toArray(SIXTEEN_SQUARES_LONGS);
  assertQuantile(1, SIXTEEN_SQUARES_DECILE_1, Quantiles.scale(10).index(1).compute(dataset));
  assertDatasetInOrder(SIXTEEN_SQUARES_LONGS, dataset);
}