canonical example by Tabnine
private void mappingWordsLength(List<String> wordsList) { Map<Integer, Set<String>> mapping = new HashMap<>(); for (String word : wordsList) { mapping.computeIfAbsent(word.length(), HashSet::new).add(word); } List<Integer> lengths = new LinkedList<>(mapping.keySet()); Collections.sort(lengths); lengths.forEach(n -> System.out.println(mapping.get(n).size() + " words with " + n + " chars")); }
@Override public List<Object> get() { return new LinkedList<>(); } }
public static <T> LinkedList<T> filter(Collection<T> collection, Filter<T> filter) { LinkedList<T> filtered = new LinkedList<T>(); for (T t : collection) { if (!filter.isOut(t)) { filtered.add(t); } } return filtered; }
public boolean isEmpty() { boolean empty = false; if (_categoryElements.size() == 0) { empty = true; } return (empty); }
public void removeLast() { //TODO: add specific test for synchronization of this block (it is tested by InvocationContainerImplTest at the moment) synchronized (invocations) { if (! invocations.isEmpty()) { invocations.removeLast(); } } }
/** * Ensures that the MRU list will have a MaxSize. */ protected void setMaxSize(int maxSize) { if (maxSize < _mruFileList.size()) { for (int i = 0; i < _mruFileList.size() - maxSize; i++) { _mruFileList.removeLast(); } } _maxSize = maxSize; } //--------------------------------------------------------------------------
public void add(Invocation invocation) { synchronized (invocations) { invocations.add(invocation); } }
/** * Create a new buffer and store it in the LinkedList * <p>Adds a new buffer that can store at least {@code minCapacity} bytes. */ private void addBuffer(int minCapacity) { if (this.buffers.peekLast() != null) { this.alreadyBufferedSize += this.index; this.index = 0; } if (this.nextBlockSize < minCapacity) { this.nextBlockSize = nextPowerOf2(minCapacity); } this.buffers.add(new byte[this.nextBlockSize]); this.nextBlockSize *= 2; // block size doubles each time }
/** * Returns a tree-style representation of the current {@code ParseState}. */ @Override public String toString() { StringBuilder sb = new StringBuilder(); for (int x = 0; x < this.state.size(); x++) { if (x > 0) { sb.append('\n'); for (int y = 0; y < x; y++) { sb.append(TAB); } sb.append("-> "); } sb.append(this.state.get(x)); } return sb.toString(); }
@Override public Reference<K, V> pollForPurge() { if (TestWeakConcurrentCache.this.disableTestHooks) { return super.pollForPurge(); } return TestWeakConcurrentCache.this.queue.isEmpty() ? null : TestWeakConcurrentCache.this.queue.removeFirst(); } };
public boolean isEmpty() { synchronized (invocations) { return invocations.isEmpty(); } }
private void runNext() { tasks.removeFirst().run(); } }
@Override public boolean add(Pipe<M, M> pipe) { return pipeList.add(pipe); }
public static Invocation findPreviousVerifiedInOrder(List<Invocation> invocations, InOrderContext context) { LinkedList<Invocation> verifiedOnly = ListUtil.filter(invocations, new RemoveUnverifiedInOrder(context)); if (verifiedOnly.isEmpty()) { return null; } else { return verifiedOnly.getLast(); } }
@Override public boolean isEmpty() { return pipeList.isEmpty(); }