com.google.common.collect.Iterators#get ( )源码实例Demo

下面列出了com.google.common.collect.Iterators#get ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: 2018-highload-kv   文件: ClusterTestBase.java
@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)));
}
 
源代码2 项目: 2018-highload-kv   文件: ClusterTestBase.java
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();
    }
}
 
源代码3 项目: 2017-highload-kv   文件: ClusterTestBase.java
@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;
}
 
源代码4 项目: Lemur   文件: FocusTraversalAdapter.java
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;
}
 
源代码5 项目: stratio-cassandra   文件: SmartThriftClient.java
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);
}
 
源代码6 项目: metanome-algorithms   文件: UnorderedPair.java
public T getFirst() {
	Iterator<T> iterator = pair.iterator();
	return Iterators.get(iterator, 0);
}
 
源代码7 项目: metanome-algorithms   文件: UnorderedPair.java
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);
}
 
源代码8 项目: vespa   文件: LoadBalancerProvisionerTest.java
private static <T> T get(Set<T> set, int position) {
    return Iterators.get(set.iterator(), position, null);
}
 
源代码9 项目: Lemur   文件: FocusTraversalAdapter.java
protected Spatial getFirst() {
    Spatial first = Iterators.get(new ChildIterator(TraversalDirection.PageHome), 0, null);
    return first;     
}
 
源代码10 项目: BashSupport   文件: BashAbstractProcessor.java
/**
 * 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;
    }
}
 
源代码11 项目: gama   文件: IMap.java
@Override
default V firstValue(final IScope scope) throws GamaRuntimeException {
	if (length(scope) == 0) { return null; }
	return Iterators.get(values().iterator(), 0);
}
 
源代码12 项目: gama   文件: IMap.java
default V valueAt(final int index) {
	if (size() == 0) { return null; }
	return Iterators.get(values().iterator(), index);
}
 
源代码13 项目: yangtools   文件: StackedReversePathArguments.java
@Override
public PathArgument get(final int index) {
    return Iterators.get(iterator(), index);
}
 
源代码14 项目: gef   文件: Connection.java
/**
 * 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);
}