Java Code Examples for com.google.common.collect.Iterators#get()
The following examples show how to use
com.google.common.collect.Iterators#get() .
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: ClusterTestBase.java From 2018-highload-kv with Apache License 2.0 | 5 votes |
@NotNull private HttpClient client(final int node) { final String endpoint = Iterators.get(endpoints.iterator(), node); return hostToClient.computeIfAbsent( endpoint, key -> new HttpClient(new ConnectionString(key + "?timeout=" + TIMEOUT))); }
Example 2
Source File: ClusterTestBase.java From 2018-highload-kv with Apache License 2.0 | 5 votes |
private void resetClient(final int node) { final String endpoint = Iterators.get(endpoints.iterator(), node); final HttpClient client = hostToClient.remove(endpoint); if (client != null) { client.close(); } }
Example 3
Source File: ClusterTestBase.java From 2017-highload-kv with Apache License 2.0 | 5 votes |
@NotNull private String url( final int node, @NotNull final String id, final int ack, final int from) { final String endpoint = Iterators.get(endpoints.iterator(), node); return endpoint + "/v0/entity?id=" + id + "&replicas=" + ack + "/" + from; }
Example 4
Source File: FocusTraversalAdapter.java From Lemur with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected Spatial getNext( Spatial from ) { Spatial next = Iterators.get(new ChildIterator(from, null, TraversalDirection.PageHome), 0, null); if( next == null && focusRoot ) { next = getFirst(); } return next; }
Example 5
Source File: SmartThriftClient.java From stratio-cassandra with Apache License 2.0 | 5 votes |
private Client get(ByteBuffer pk) { Set<Host> hosts = metadata.getReplicas(metadata.quote(keyspace), pk); InetAddress address = null; if (hosts.size() > 0) { int pos = roundrobin.incrementAndGet() % hosts.size(); for (int i = 0 ; address == null && i < hosts.size() ; i++) { if (pos < 0) pos = -pos; Host host = Iterators.get(hosts.iterator(), (pos + i) % hosts.size()); if (whiteset == null || whiteset.contains(host.getAddress())) address = host.getAddress(); } } if (address == null) address = whitelist.get(ThreadLocalRandom.current().nextInt(whitelist.size())); ConcurrentLinkedQueue<Client> q = cache.get(address); if (q == null) { ConcurrentLinkedQueue<Client> newQ = new ConcurrentLinkedQueue<Client>(); q = cache.putIfAbsent(address, newQ); if (q == null) q = newQ; } Client tclient = q.poll(); if (tclient != null) return tclient; return new Client(settings.getRawThriftClient(address.getHostAddress()), address); }
Example 6
Source File: UnorderedPair.java From metanome-algorithms with Apache License 2.0 | 4 votes |
public T getFirst() { Iterator<T> iterator = pair.iterator(); return Iterators.get(iterator, 0); }
Example 7
Source File: UnorderedPair.java From metanome-algorithms with Apache License 2.0 | 4 votes |
public T getSecond() { //if values are same then there is only one element. Thus, take last element int last = pair.size() - 1; Iterator<T> iterator = pair.iterator(); return Iterators.get(iterator, last); }
Example 8
Source File: LoadBalancerProvisionerTest.java From vespa with Apache License 2.0 | 4 votes |
private static <T> T get(Set<T> set, int position) { return Iterators.get(set.iterator(), position, null); }
Example 9
Source File: FocusTraversalAdapter.java From Lemur with BSD 3-Clause "New" or "Revised" License | 4 votes |
protected Spatial getFirst() { Spatial first = Iterators.get(new ChildIterator(TraversalDirection.PageHome), 0, null); return first; }
Example 10
Source File: BashAbstractProcessor.java From BashSupport with Apache License 2.0 | 4 votes |
/** * Returns the best results. It takes all the elements which have been rated the best * and returns the first / last, depending on the parameter. * * @param results The results to check * @param firstResult If the first element of the best element list should be returned. * @param referenceElement * @return The result */ private PsiElement findBestResult(Multimap<Integer, PsiElement> results, boolean firstResult, PsiElement referenceElement) { if (!hasResults()) { return null; } if (firstResult) { return Iterators.get(results.values().iterator(), 0); } //if the first should not be used return the best element int referenceLevel = preferNeigbourhood && (referenceElement != null) ? BashPsiUtils.blockNestingLevel(referenceElement) : 0; // find the best suitable result rating // The best one is as close as possible to the given referenceElement int bestRating = Integer.MAX_VALUE; int bestDelta = Integer.MAX_VALUE; for (int rating : results.keySet()) { final int delta = Math.abs(referenceLevel - rating); if (delta < bestDelta) { bestDelta = delta; bestRating = rating; } } // now get the best result // if there are equal definitions on the same level we prefer the first if the neighbourhood is not preferred if (preferNeigbourhood) { return Iterators.getLast(results.get(bestRating).iterator()); } else { //return the element which has the lowest textOffset long smallestOffset = Integer.MAX_VALUE; PsiElement bestElement = null; for (PsiElement e : results.get(bestRating)) { //if the element is injected compute the text offset in the real file int textOffset = e.getTextOffset(); if (BashPsiUtils.isInjectedElement(e)) { //fixme optimize this PsiLanguageInjectionHost injectionHost = InjectedLanguageManager.getInstance(e.getProject()).getInjectionHost(e); if (injectionHost != null) { textOffset = textOffset + injectionHost.getTextOffset(); } } // comparing the offset is only meaningful within the same file // for definitions in included files we need to compare against the offset of the include command Collection<PsiElement> includeCommands = this.includeCommands != null ? this.includeCommands.get(e) : Collections.emptyList(); if (!includeCommands.isEmpty()) { for (PsiElement includeCommand : includeCommands) { int includeOffset = includeCommand.getTextOffset(); if (includeOffset < smallestOffset) { smallestOffset = includeOffset; bestElement = e; } } } else if (textOffset < smallestOffset) { smallestOffset = textOffset; bestElement = e; } } return bestElement; } }
Example 11
Source File: IMap.java From gama with GNU General Public License v3.0 | 4 votes |
@Override default V firstValue(final IScope scope) throws GamaRuntimeException { if (length(scope) == 0) { return null; } return Iterators.get(values().iterator(), 0); }
Example 12
Source File: IMap.java From gama with GNU General Public License v3.0 | 4 votes |
default V valueAt(final int index) { if (size() == 0) { return null; } return Iterators.get(values().iterator(), index); }
Example 13
Source File: StackedReversePathArguments.java From yangtools with Eclipse Public License 1.0 | 4 votes |
@Override public PathArgument get(final int index) { return Iterators.get(iterator(), index); }
Example 14
Source File: Connection.java From gef with Eclipse Public License 2.0 | 2 votes |
/** * Returns the {@link AnchorKey} for the given anchor index, i.e. the * reverse of {@link #getAnchorIndex(AnchorKey)}. * * @param anchorIndex * The anchor index for which to determine the {@link AnchorKey}. * @return The {@link AnchorKey} for the given anchor index. */ protected AnchorKey getAnchorKey(int anchorIndex) { return Iterators.get(anchorsByKeys.keySet().iterator(), anchorIndex); }