use of java.util.ListIterator in project AutoRefactor by JnRouvignac.
the class PushNegationDownRefactoring method visit.
@Override
public boolean visit(PrefixExpression node) {
if (!hasOperator(node, NOT)) {
return VISIT_SUBTREE;
}
final ASTBuilder b = ctx.getASTBuilder();
final Refactorings r = ctx.getRefactorings();
final Expression operand = removeParentheses(node.getOperand());
if (operand instanceof PrefixExpression) {
final PrefixExpression pe = (PrefixExpression) operand;
if (hasOperator(pe, NOT)) {
r.replace(node, b.move(pe.getOperand()));
return DO_NOT_VISIT_SUBTREE;
}
} else if (operand instanceof InfixExpression) {
final InfixExpression ie = (InfixExpression) operand;
final Operator reverseOp = (Operator) OperatorEnum.getOperator(ie).getReverseBooleanOperator();
if (reverseOp != null) {
final List<Expression> allOperands = new ArrayList<Expression>(allOperands(ie));
if (hasType(ie.getLeftOperand(), "boolean", "java.lang.Boolean") && hasType(ie.getRightOperand(), "boolean", "java.lang.Boolean")) {
for (ListIterator<Expression> it = allOperands.listIterator(); it.hasNext(); ) {
it.set(b.negate(it.next()));
}
r.replace(node, b.parenthesize(b.infixExpr(reverseOp, allOperands)));
} else {
r.replace(node, b.parenthesize(b.infixExpr(reverseOp, b.move(allOperands))));
}
return DO_NOT_VISIT_SUBTREE;
}
} else {
final Boolean constant = getBooleanLiteral(operand);
if (constant != null) {
r.replace(node, b.boolean0(!constant));
return DO_NOT_VISIT_SUBTREE;
}
}
return VISIT_SUBTREE;
}
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 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 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 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