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;
}
}
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);
}
}
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();
}
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());
}
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);
}
}
});
}
Aggregations