Search in sources :

Example 91 with ListIterator

use of java.util.ListIterator in project zm-mailbox by Zimbra.

the class LuceneQueryOperation method expandLazyMultiPhraseQuery.

private Query expandLazyMultiPhraseQuery(Query query) throws IOException {
    if (query instanceof LazyMultiPhraseQuery) {
        LazyMultiPhraseQuery lazy = (LazyMultiPhraseQuery) query;
        int max = LC.zimbra_index_wildcard_max_terms_expanded.intValue();
        MultiPhraseQuery mquery = new MultiPhraseQuery();
        for (Term[] terms : lazy.getTermArrays()) {
            if (terms.length != 1) {
                mquery.add(terms);
                continue;
            }
            Term base = terms[0];
            if (!lazy.expand.contains(base)) {
                mquery.add(terms);
                continue;
            }
            List<Term> expanded = Lists.newArrayList();
            TermFieldEnumeration itr = searcher.getIndexReader().getTermsForField(base.field(), base.text());
            try {
                while (itr.hasMoreElements()) {
                    BrowseTerm term = itr.nextElement();
                    if (term != null && term.getText().startsWith(base.text())) {
                        if (expanded.size() >= max) {
                            // too many terms expanded
                            break;
                        }
                        expanded.add(new Term(base.field(), term.getText()));
                    } else {
                        break;
                    }
                }
            } finally {
                Closeables.closeQuietly(itr);
            }
            if (expanded.isEmpty()) {
                return null;
            } else {
                mquery.add(expanded.toArray(new Term[expanded.size()]));
            }
        }
        return mquery;
    } else if (query instanceof BooleanQuery) {
        ListIterator<BooleanClause> itr = ((BooleanQuery) query).clauses().listIterator();
        while (itr.hasNext()) {
            BooleanClause clause = itr.next();
            Query result = expandLazyMultiPhraseQuery(clause.getQuery());
            if (result == null) {
                if (clause.isRequired()) {
                    return null;
                } else {
                    itr.remove();
                }
            } else if (result != clause.getQuery()) {
                clause.setQuery(result);
            }
        }
        return ((BooleanQuery) query).clauses().isEmpty() ? null : query;
    } else {
        return query;
    }
}
Also used : BooleanClause(org.apache.lucene.search.BooleanClause) BooleanQuery(org.apache.lucene.search.BooleanQuery) Query(org.apache.lucene.search.Query) MultiPhraseQuery(org.apache.lucene.search.MultiPhraseQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) TermFieldEnumeration(com.zimbra.cs.index.ZimbraIndexReader.TermFieldEnumeration) MultiPhraseQuery(org.apache.lucene.search.MultiPhraseQuery) Term(org.apache.lucene.index.Term) ListIterator(java.util.ListIterator)

Example 92 with ListIterator

use of java.util.ListIterator in project jdk8u_jdk by JetBrains.

the class AuthList method put.

/**
     * Puts the authenticator timestamp into the cache in descending order,
     * and throw an exception if it's already there.
     */
public void put(AuthTimeWithHash t, KerberosTime currentTime) throws KrbApErrException {
    if (entries.isEmpty()) {
        entries.addFirst(t);
    } else {
        AuthTimeWithHash temp = entries.getFirst();
        int cmp = temp.compareTo(t);
        if (cmp < 0) {
            // This is the most common case, newly received authenticator
            // has larger timestamp.
            entries.addFirst(t);
        } else if (cmp == 0) {
            throw new KrbApErrException(Krb5.KRB_AP_ERR_REPEAT);
        } else {
            //unless client clock being re-adjusted.
            ListIterator<AuthTimeWithHash> it = entries.listIterator(1);
            boolean found = false;
            while (it.hasNext()) {
                temp = it.next();
                cmp = temp.compareTo(t);
                if (cmp < 0) {
                    // Find an older one, put in front of it
                    entries.add(entries.indexOf(temp), t);
                    found = true;
                    break;
                } else if (cmp == 0) {
                    throw new KrbApErrException(Krb5.KRB_AP_ERR_REPEAT);
                }
            }
            if (!found) {
                // All is newer than the newcomer. Sigh.
                entries.addLast(t);
            }
        }
    }
    // let us cleanup while we are here
    long timeLimit = currentTime.getSeconds() - lifespan;
    ListIterator<AuthTimeWithHash> it = entries.listIterator(0);
    AuthTimeWithHash temp = null;
    int index = -1;
    while (it.hasNext()) {
        // search expired timestamps.
        temp = it.next();
        if (temp.ctime < timeLimit) {
            index = entries.indexOf(temp);
            break;
        }
    }
    // It would be nice if LinkedList has a method called truncate(index).
    if (index > -1) {
        do {
            // remove expired timestamps from the list.
            entries.removeLast();
        } while (entries.size() > index);
    }
}
Also used : ListIterator(java.util.ListIterator) KrbApErrException(sun.security.krb5.internal.KrbApErrException)

Example 93 with ListIterator

use of java.util.ListIterator in project karaf by apache.

the class CopyOnWriteArrayIdentityList method equals.

public boolean equals(Object o) {
    if (o == this) {
        return true;
    }
    if (!(o instanceof List)) {
        return false;
    }
    List l = (List) o;
    Iterator it = l.listIterator();
    Iterator ourIt = listIterator();
    while (it.hasNext()) {
        if (!ourIt.hasNext()) {
            return false;
        }
        Object thisListElem = it.next();
        Object anotherListElem = ourIt.next();
        if (thisListElem != anotherListElem) {
            return false;
        }
    }
    return !ourIt.hasNext();
}
Also used : Iterator(java.util.Iterator) ListIterator(java.util.ListIterator) List(java.util.List)

Example 94 with ListIterator

use of java.util.ListIterator in project platform_external_apache-http by android.

the class RequestQueue method dump.

/**
     * debug tool: prints request queue to log
     */
synchronized void dump() {
    HttpLog.v("dump()");
    StringBuilder dump = new StringBuilder();
    int count = 0;
    Iterator<Map.Entry<HttpHost, LinkedList<Request>>> iter;
    if (!mPending.isEmpty()) {
        iter = mPending.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry<HttpHost, LinkedList<Request>> entry = iter.next();
            String hostName = entry.getKey().getHostName();
            StringBuilder line = new StringBuilder("p" + count++ + " " + hostName + " ");
            LinkedList<Request> reqList = entry.getValue();
            ListIterator reqIter = reqList.listIterator(0);
            while (iter.hasNext()) {
                Request request = (Request) iter.next();
                line.append(request + " ");
            }
            dump.append(line);
            dump.append("\n");
        }
    }
    HttpLog.v(dump.toString());
}
Also used : HttpHost(org.apache.http.HttpHost) ListIterator(java.util.ListIterator) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedList(java.util.LinkedList)

Example 95 with ListIterator

use of java.util.ListIterator in project lucene-solr by apache.

the class TestRandomFaceting method capFacetCountsTo1.

/*
   * {
  "response":{"numFound":6,"start":0,"docs":[]
  },
  "facet_counts":{
    "facet_queries":{},
    "facet_fields":{
      "foo_i":[
        "6",2,
        "2",1,
        "3",1]},
    "facet_ranges":{},
    "facet_intervals":{},
    "facet_heatmaps":{}}} 
   * */
@SuppressWarnings({ "rawtypes", "unchecked" })
private String capFacetCountsTo1(String expected) throws IOException {
    return transformFacetFields(expected, e -> {
        List<Object> facetValues = (List<Object>) e.getValue();
        for (ListIterator iterator = facetValues.listIterator(); iterator.hasNext(); ) {
            Object value = iterator.next();
            Long count = (Long) iterator.next();
            if (value != null && count > 1) {
                iterator.set(1);
            }
        }
    });
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ListIterator(java.util.ListIterator)

Aggregations

ListIterator (java.util.ListIterator)121 ArrayList (java.util.ArrayList)42 List (java.util.List)41 LinkedList (java.util.LinkedList)26 Iterator (java.util.Iterator)21 Map (java.util.Map)12 Handler (com.sun.jsftemplating.annotation.Handler)8 AbstractList (java.util.AbstractList)7 HashMap (java.util.HashMap)7 AbstractSequentialList (java.util.AbstractSequentialList)6 IOException (java.io.IOException)5 RandomAccess (java.util.RandomAccess)5 SelectResults (org.apache.geode.cache.query.SelectResults)5 Test (org.junit.Test)5 File (java.io.File)4 HashSet (java.util.HashSet)4 NoSuchElementException (java.util.NoSuchElementException)4 SipURI (javax.sip.address.SipURI)4 ArgumentIntKey (lucee.runtime.type.scope.ArgumentIntKey)4 StructTypeImpl (org.apache.geode.cache.query.internal.types.StructTypeImpl)4