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

The following are Jave code examples for showing how to use toArray() of the com.google.common.primitives.Ints class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: coherence-sql   File: PofExtractorFactory.java   Source Code and License Vote up 7 votes
private <T> ValueExtractor provideExtractorForValue(Class<T> clazz, int target, List<String> chainOfProperties) {
    Class<?> propertyClass = clazz;
    List<Integer> indices = Lists.newArrayList();

    for (String property : chainOfProperties) {
        Field field;
        try {
            field = clazz.getDeclaredField(property);
        } catch (NoSuchFieldException e) {
            throw new InvalidQueryException(e);
        }

        PortableProperty portablePropertyAnnotation = field.getAnnotation(PortableProperty.class);
        if (portablePropertyAnnotation == null) {
            throw new InvalidQueryException("");
        }

        // TODO add support for customs codecs some day ;)
        int index = portablePropertyAnnotation.value();
        indices.add(index);
        propertyClass = field.getDeclaringClass();
    }

    return new PofExtractor<>(propertyClass, new SimplePofPath(Ints.toArray(indices)), target);
}
 
Example 2
Project: ArchUnit   File: JavaClassProcessor.java   Source Code and License 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 3
Project: vt-support   File: StorageImpl.java   Source Code and License Vote up 6 votes
private int[] getZoomLevels() {
  final List<Integer> zoomLevels = new ArrayList<>();
  final File[] files = directory.listFiles();

  if (files == null) {
    return new int[]{};
  }

  final Pattern pattern = Pattern.compile("^([0-9]|1[0-9]|2[0-2])$");
  for (final File file : files) {
    final String fileName = file.getName();
    final Matcher matcher = pattern.matcher(fileName);
    if (matcher.matches()) {
      final int value = Integer.parseInt(matcher.group());
      zoomLevels.add(value);
    }
  }
  final int[] result = Ints.toArray(zoomLevels);
  Arrays.sort(result);
  return result;
}
 
Example 4
Project: guava-mock   File: QuantilesTest.java   Source Code and License Vote up 5 votes
public void testScale_index_compute_intVarargs() {
  int[] dataset = Ints.toArray(SIXTEEN_SQUARES_INTEGERS);
  assertThat(Quantiles.scale(10).index(1).compute(dataset))
      .isWithin(ALLOWED_ERROR)
      .of(SIXTEEN_SQUARES_DECILE_1);
  assertThat(dataset).asList().isEqualTo(SIXTEEN_SQUARES_INTEGERS);
}
 
Example 5
Project: guava-mock   File: QuantilesTest.java   Source Code and License Vote up 5 votes
public void testScale_indexes_varargs_compute_intVarargs() {
  int[] dataset = Ints.toArray(SIXTEEN_SQUARES_INTEGERS);
  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_INTEGERS);
}
 
Example 6
Project: ProjectEon   File: GuidePage.java   Source Code and License Vote up 5 votes
private void finishPage() {
    // Create and add the page
    IGuideElement[] pageElements = elems.toArray(new IGuideElement[elems.size()]);
    int[] pageStartPoints = Ints.toArray(startPoints);
    int[] pageEndPoints = Ints.toArray(endPoints);
    int[] translationPoints = Ints.toArray(heights);
    pages.add(new GuidePage(guide, pageElements, pageStartPoints, pageEndPoints, translationPoints));

    // Reset all values
    elems.clear();
    heights.clear();
    startPoints.clear();
    endPoints.clear();
    y = 0;
}
 
Example 7
Project: googles-monorepo-demo   File: QuantilesTest.java   Source Code and License Vote up 5 votes
public void testScale_indexes_varargs_compute_intVarargs() {
  int[] dataset = Ints.toArray(SIXTEEN_SQUARES_INTEGERS);
  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_INTEGERS, dataset);
}
 
Example 8
Project: instalint   File: FileMetadata.java   Source Code and License Vote up 4 votes
private Metadata(int lines, List<Integer> originalLineOffsets, int lastValidOffset) {
  this.lines = lines;
  this.originalLineOffsets = Ints.toArray(originalLineOffsets);
  this.lastValidOffset = lastValidOffset;
}
 
Example 9
Project: Neutrino   File: IntArrayTypeSerialiser.java   Source Code and License Vote up 4 votes
@Override public int[] deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException {
    List<Integer> list = value.getList(ttb);
    return Ints.toArray(list);
}
 
Example 10
Project: googles-monorepo-demo   File: QuantilesTest.java   Source Code and License Vote up 4 votes
public void testScale_index_compute_intVarargs() {
  int[] dataset = Ints.toArray(SIXTEEN_SQUARES_INTEGERS);
  assertQuantile(1, SIXTEEN_SQUARES_DECILE_1, Quantiles.scale(10).index(1).compute(dataset));
  assertDatasetInOrder(SIXTEEN_SQUARES_INTEGERS, dataset);
}