@Override protected SortedSet<String> create(String[] elements) { List<String> list = Lists.newArrayList(elements); list.add("\0"); list.add("zzz"); return ImmutableSortedSet.copyOf(list).subSet("\0\0", "zzy"); } }
public void addNested(ValueType nested) { if (this.nested.isEmpty()) { this.nested = Lists.newArrayList(); } this.nested.add(nested); nested.enclosingValue = this; }
@Override public UserInfo findByUserId(String userId) { List<UserInfo> userInfoList = this.findByUserIds(Lists.newArrayList(userId)); if (CollectionUtils.isEmpty(userInfoList)) { return null; } return userInfoList.get(0); }
private static <T> List<T> shuffledCopy(List<T> in, Random random) { List<T> mutable = newArrayList(in); List<T> out = newArrayList(); while (!mutable.isEmpty()) { out.add(mutable.remove(random.nextInt(mutable.size()))); } return out; } }
private void addToCategory(BehaviorNodeComponent component) { List<BehaviorNodeComponent> list = categoryComponents.get(component.category); if (list == null) { list = Lists.newArrayList(); categoryComponents.put(component.category, list); } list.add(component); }
/** * {@inheritDoc} */ @Override public List<Integer> chooseTasks(int taskId, List<Object> values) { try { int n = Math.abs((int) hashes(getKeyValues(values)) % targetTasks.size()); return Lists.newArrayList(targetTasks.get(n)); } catch (IOException e) { throw new FailedException(e); } }
public List<Long> getSpanningCuboid(long cuboidId) { TreeNode node = index.get(cuboidId); if (node == null) { throw new IllegalArgumentException("the cuboid:" + cuboidId + " is not exist in the tree"); } List<Long> result = Lists.newArrayList(); for (TreeNode child : node.children) { result.add(child.cuboidId); } return result; }
@Test public void testDepthFirstIteratorIterateExpandedOnly() { List<GenericTree<Integer>> expected = Arrays.asList(nodes.get(0), nodes.get(1), nodes.get(2), nodes.get(4), nodes.get(5), nodes.get(6), nodes.get(9)); List<GenericTree<Integer>> actual = Lists.newArrayList(); Iterator i = nodes.get(0).getDepthFirstIterator(true); while (i.hasNext()) { actual.add((GenericTree<Integer>) i.next()); } assertEquals(expected, actual); }
@Override public Map<String, Object> asMap(List<StreamRule> streamRules) { Map<String, Object> result = asMap(); List<Map<String, Object>> streamRulesMap = Lists.newArrayList(); for (StreamRule streamRule : streamRules) { streamRulesMap.add(streamRule.asMap()); } result.put(FIELD_RULES, streamRulesMap); return result; }
/** Causes teardown to execute. */ public final void runTearDown() { List<Throwable> exceptions = new ArrayList<>(); List<TearDown> stackCopy; synchronized (stack) { stackCopy = Lists.newArrayList(stack); stack.clear(); } for (TearDown tearDown : stackCopy) { try { tearDown.tearDown(); } catch (Throwable t) { if (suppressThrows) { logger.log(Level.INFO, "exception thrown during tearDown", t); } else { exceptions.add(t); } } } if (!suppressThrows && (exceptions.size() > 0)) { throw ClusterException.create(exceptions); } } }
private Element[] createQueries(Set<Element> elementsInSet, int numQueries) { List<Element> queryList = Lists.newArrayListWithCapacity(numQueries); int numGoodQueries = (int) (numQueries * hitRate + 0.5); // add good queries int size = elementsInSet.size(); if (size > 0) { int minCopiesOfEachGoodQuery = numGoodQueries / size; int extras = numGoodQueries % size; for (int i = 0; i < minCopiesOfEachGoodQuery; i++) { queryList.addAll(elementsInSet); } List<Element> tmp = Lists.newArrayList(elementsInSet); Collections.shuffle(tmp, random); queryList.addAll(tmp.subList(0, extras)); } // now add bad queries while (queryList.size() < numQueries) { Element candidate = newElement(); if (!elementsInSet.contains(candidate)) { queryList.add(candidate); } } Collections.shuffle(queryList, random); return queryList.toArray(new Element[0]); }
/** * This is just here to illustrate how {@code Arrays#asList} differs from {@code * Lists#newArrayList}. */ public void testArraysAsList() { List<String> ourWay = Lists.newArrayList("foo", "bar", "baz"); List<String> otherWay = asList("foo", "bar", "baz"); // They're logically equal assertEquals(ourWay, otherWay); // The result of Arrays.asList() is mutable otherWay.set(0, "FOO"); assertEquals("FOO", otherWay.get(0)); // But it can't grow try { otherWay.add("nope"); fail("no exception thrown"); } catch (UnsupportedOperationException expected) { } // And it can't shrink try { otherWay.remove(2); fail("no exception thrown"); } catch (UnsupportedOperationException expected) { } }
@Test public void testScrewsUpOnOutOfOrderBeginningOfList() { final ArrayList<Iterator<Integer>> iterators = new ArrayList<>(); iterators.add(Arrays.asList(1, 3, 5, 7, 9).iterator()); iterators.add(Arrays.asList(4, 6).iterator()); iterators.add(Arrays.asList(2, 8).iterator()); OrderedMergeIterator<Integer> iter = new OrderedMergeIterator<Integer>( Ordering.natural(), iterators.iterator() ); Assert.assertEquals(Arrays.asList(1, 3, 4, 2, 5, 6, 7, 8, 9), Lists.newArrayList(iter)); }
public void testCopyOf_concurrentlyMutating() { List<String> sample = Lists.newArrayList("a", "b", "c"); for (int delta : new int[] {-1, 0, 1}) { for (int i = 0; i < sample.size(); i++) { Collection<String> misleading = Helpers.misleadingSizeCollection(delta); List<String> expected = sample.subList(0, i); misleading.addAll(expected); assertEquals(expected, ImmutableList.copyOf(misleading)); assertEquals(expected, ImmutableList.copyOf((Iterable<String>) misleading)); } } }
@Test public void testOrderByWithLimit() { List<String> expected = rawInput.subList(0, Math.min(limit, rawInput.size())); List<String> inputs = Lists.newArrayList(rawInput); Collections.shuffle(inputs, new Random(2)); Sequence<String> result = new TopNSequence<String>(Sequences.simple(inputs), ordering, limit); Assert.assertEquals(expected, result.toList()); } }
@Test(expected = ISE.class) public void testDuplicateDimensionsFirstOccurrence() throws IndexSizeExceededException { IncrementalIndex index = closerRule.closeLater(indexCreator.createIndex()); index.add( new MapBasedInputRow( System.currentTimeMillis() - 1, Lists.newArrayList("billy", "joe", "joe"), ImmutableMap.of("billy", "A", "joe", "B") ) ); }
protected final ContiguousSet<Integer> checkedCreate(SortedSet<Integer> elementsSet) { List<Integer> elements = newArrayList(elementsSet); /* * A ContiguousSet can't have holes. If a test demands a hole, it should be changed so that it * doesn't need one, or it should be suppressed for ContiguousSet. */ for (int i = 0; i < elements.size() - 1; i++) { assertEquals(elements.get(i) + 1, (int) elements.get(i + 1)); } Range<Integer> range = elements.isEmpty() ? Range.closedOpen(0, 0) : Range.encloseAll(elements); return ContiguousSet.create(range, DiscreteDomain.integers()); } }
/** * Adds a block to the list of added blocks in this heartbeat period. * * @param blockId the id of the block to add * @param tierAlias alias of the storage tier containing the block */ private void addBlockToAddedBlocks(long blockId, String tierAlias) { if (mAddedBlocks.containsKey(tierAlias)) { mAddedBlocks.get(tierAlias).add(blockId); } else { mAddedBlocks.put(tierAlias, Lists.newArrayList(blockId)); } }
void testBinarySearch() { for (int i = 0; i < strictlyOrderedList.size(); i++) { assertEquals(i, ordering.binarySearch(strictlyOrderedList, strictlyOrderedList.get(i))); } List<T> newList = Lists.newArrayList(strictlyOrderedList); T valueNotInList = newList.remove(1); assertEquals(-2, ordering.binarySearch(newList, valueNotInList)); }
private void loadBlocks() { blockFamilyIds = Maps.newHashMap(); gameInfo.getManifest().getBlockIdMap().entrySet().forEach(blockId -> { String familyName = blockId.getKey().split(":")[0].toLowerCase(); blockFamilyIds.computeIfAbsent(familyName, k -> new ArrayList<>()); blockFamilyIds.get(familyName).add(blockId.toString()); }); blocks.setList(Lists.newArrayList(blockFamilyIds.keySet())); }