Java Code Examples for com.google.common.collect.ObjectArrays#newArray()

The following examples show how to use com.google.common.collect.ObjectArrays#newArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DictionaryBuilder.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public Iterable<T> build() {
  Preconditions.checkArgument(!isBuilt, "build can only be called once");
  isBuilt = true;

  if (valueAccumulator.isEmpty()) {
    return Collections.emptyList();
  }

  final T[] values = ObjectArrays.newArray(clazzType, valueAccumulator.size());

  for (ObjectIntCursor<T> entry : valueAccumulator) {
    values[entry.value] = entry.key;
  }

  return Arrays.asList(values);
}
 
Example 2
Source File: InitializeArray.java    From levelup-java-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void initialize_string_array_java_with_guava () {
	
	String[] nflNorthStadiums = ObjectArrays.newArray(String.class, 4);

	nflNorthStadiums[0] = "Lambeau Field";
       nflNorthStadiums[1] = "Soldier Field";
       nflNorthStadiums[2] = "Mall of America Fielddagger";
       nflNorthStadiums[3] = "Ford Fielddagger";
       
       assertTrue(nflNorthStadiums.length == 4);
}
 
Example 3
Source File: InitializeArray.java    From levelup-java-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void initialize_string_array_java_with_guava_reference_type () {

	String[] nflStadiums = {""};

	String[] nflNorthStadiums = ObjectArrays.newArray(nflStadiums, 4);
	
	nflNorthStadiums[0] = "Lambeau Field";
       nflNorthStadiums[1] = "Soldier Field";
       nflNorthStadiums[2] = "Mall of America Fielddagger";
       nflNorthStadiums[3] = "Ford Fielddagger";
       
       assertEquals(4, nflNorthStadiums.length);
}