/** * Arrays.asList()的加强版, 返回一个底层为原始类型long的List * * 与保存Long相比节约空间,同时只在读取数据时AutoBoxing. * * @see java.util.Arrays#asList(Object...) * @see com.google.common.primitives.Longs#asList(long...) */ public static List<Long> longAsList(long... backingArray) { return Longs.asList(backingArray); }
public static Iterable<Long> $in(long[] elements) { return Longs.asList(elements); }
private static List<Long> asList(Long[] values) { long[] temp = new long[values.length]; for (int i = 0; i < values.length; i++) { temp[i] = checkNotNull(values[i]); // checkNotNull for GWT (do not optimize). } return Longs.asList(temp); }
public static IterableChecker<List<Long>, Long> check(long[] actualLongArray) { return check(actualLongArray == null ? null : Longs.asList(actualLongArray)); }
/** * Sets a new named binding. * * @param name name of the binding * @param value a long value or a list of long values that binds to a given name */ public Builder<V> setBinding(String name, long... value) { namedBindings.put(name, toBinding(LongValue.MARSHALLER, Longs.asList(value))); return this; }
/** * Sets a new positional binding. * * @param value a long value or a list of long values to be set as a new positional binding */ public Builder<V> addBinding(long... value) { positionalBindings.add(toBinding(LongValue.MARSHALLER, Longs.asList(value))); return this; }
public void testAsListEmpty() { assertSame(Collections.emptyList(), Longs.asList(EMPTY)); }
/** * @return the next item in the sequence. * @throws NoSuchElementException when sequence is exhausted. */ @Override public List<Long> next() throws NoSuchElementException { if (!SpecifiedIndex.this.hasNext()) throw new NoSuchElementException(); return Longs.asList(SpecifiedIndex.this.next()); } }
public void testAsList_isAView() { long[] array = {(long) 0, (long) 1}; List<Long> list = Longs.asList(array); list.set(0, (long) 2); assertTrue(Arrays.equals(new long[] {(long) 2, (long) 1}, array)); array[1] = (long) 3; assertEquals(Arrays.asList((long) 2, (long) 3), list); }
public void testAsList_toArray_roundTrip() { long[] array = {(long) 0, (long) 1, (long) 2}; List<Long> list = Longs.asList(array); long[] newArray = Longs.toArray(list); // Make sure it returned a copy list.set(0, (long) 4); assertTrue(Arrays.equals(new long[] {(long) 0, (long) 1, (long) 2}, newArray)); newArray[1] = (long) 5; assertEquals((long) 1, (long) list.get(1)); }
public void testAsList_subList_toArray_roundTrip() { long[] array = {(long) 0, (long) 1, (long) 2, (long) 3}; List<Long> list = Longs.asList(array); assertTrue(Arrays.equals(new long[] {(long) 1, (long) 2}, Longs.toArray(list.subList(1, 3)))); assertTrue(Arrays.equals(new long[] {}, Longs.toArray(list.subList(2, 2)))); }
public void testToArray() { // need explicit type parameter to avoid javac warning!? List<Long> none = Arrays.<Long>asList(); assertTrue(Arrays.equals(EMPTY, Longs.toArray(none))); List<Long> one = Arrays.asList((long) 1); assertTrue(Arrays.equals(ARRAY1, Longs.toArray(one))); long[] array = {(long) 0, (long) 1, 0x0FF1C1AL}; List<Long> three = Arrays.asList((long) 0, (long) 1, 0x0FF1C1AL); assertTrue(Arrays.equals(array, Longs.toArray(three))); assertTrue(Arrays.equals(array, Longs.toArray(Longs.asList(array)))); }
public IterableSubject asList() { return checkNoNeedToDisplayBothValues("asList()").that(Longs.asList(actual())); } }
public void testToArray_threadSafe() { for (int delta : new int[] {+1, 0, -1}) { for (int i = 0; i < VALUES.length; i++) { List<Long> list = Longs.asList(VALUES).subList(0, i); Collection<Long> misleadingSize = Helpers.misleadingSizeCollection(delta); misleadingSize.addAll(list); long[] arr = Longs.toArray(misleadingSize); assertEquals(i, arr.length); for (int j = 0; j < i; j++) { assertEquals(VALUES[j], arr[j]); } } } }
@Test public void testConstantIterator() { testMerge(Longs.asList(1, 1, 1)); }
void addBloomFilterEntry() { if (createBloomFilter) { bloomFilterEntry.setNumHashFunctions(bloomFilter.getNumHashFunctions()); bloomFilterEntry.addAllBitset(Longs.asList(bloomFilter.getBitSet())); bloomFilterIndex.addBloomFilter(bloomFilterEntry.build()); bloomFilter.reset(); bloomFilterEntry.clear(); } }
bloomFilterBuilder.addAllBitset(Longs.asList(bloomFilterWrite.getBitSet())); bloomFilterBuilder.setNumHashFunctions(bloomFilterWrite.getNumHashFunctions());
private static OrcProto.BloomFilter toOrcBloomFilter(BloomFilter bloomFilter) { OrcProto.BloomFilter.Builder builder = OrcProto.BloomFilter.newBuilder(); builder.addAllBitset(Longs.asList(bloomFilter.getBitSet())); builder.setNumHashFunctions(bloomFilter.getNumHashFunctions()); return builder.build(); }
@Test public void group_count_by_template_and_permission() { PermissionTemplateDto template1 = templateDb.insertTemplate(); PermissionTemplateDto template2 = templateDb.insertTemplate(); PermissionTemplateDto template3 = templateDb.insertTemplate(); PermissionTemplateDto template4 = templateDb.insertTemplate(); GroupDto group1 = db.users().insertGroup(newGroupDto()); GroupDto group2 = db.users().insertGroup(newGroupDto()); GroupDto group3 = db.users().insertGroup(newGroupDto()); templateDb.addGroupToTemplate(template1.getId(), group1.getId(), CODEVIEWER); templateDb.addGroupToTemplate(template1.getId(), group2.getId(), CODEVIEWER); templateDb.addGroupToTemplate(template1.getId(), group3.getId(), CODEVIEWER); templateDb.addGroupToTemplate(template1.getId(), null, CODEVIEWER); templateDb.addGroupToTemplate(template1.getId(), group1.getId(), ADMIN); templateDb.addGroupToTemplate(template2.getId(), group1.getId(), ADMIN); templateDb.addGroupToTemplate(template4.getId(), group1.getId(), ISSUE_ADMIN); final List<CountByTemplateAndPermissionDto> result = new ArrayList<>(); underTest.groupsCountByTemplateIdAndPermission(dbSession, asList(template1.getId(), template2.getId(), template3.getId()), context -> result.add(context.getResultObject())); assertThat(result).extracting(CountByTemplateAndPermissionDto::getPermission, CountByTemplateAndPermissionDto::getTemplateId, CountByTemplateAndPermissionDto::getCount) .containsOnly(tuple(ADMIN, template1.getId(), 1), tuple(CODEVIEWER, template1.getId(), 4), tuple(ADMIN, template2.getId(), 1)); }