Search in sources :

Example 76 with ListIterator

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;
}
Also used : ASTHelper.hasOperator(org.autorefactor.refactoring.ASTHelper.hasOperator) Operator(org.eclipse.jdt.core.dom.InfixExpression.Operator) InfixExpression(org.eclipse.jdt.core.dom.InfixExpression) Expression(org.eclipse.jdt.core.dom.Expression) PrefixExpression(org.eclipse.jdt.core.dom.PrefixExpression) PrefixExpression(org.eclipse.jdt.core.dom.PrefixExpression) Refactorings(org.autorefactor.refactoring.Refactorings) InfixExpression(org.eclipse.jdt.core.dom.InfixExpression) ArrayList(java.util.ArrayList) List(java.util.List) ListIterator(java.util.ListIterator) ASTBuilder(org.autorefactor.refactoring.ASTBuilder)

Example 77 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 78 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 79 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 80 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)81 List (java.util.List)30 ArrayList (java.util.ArrayList)29 LinkedList (java.util.LinkedList)26 Iterator (java.util.Iterator)15 AbstractList (java.util.AbstractList)7 AbstractSequentialList (java.util.AbstractSequentialList)6 RandomAccess (java.util.RandomAccess)5 SelectResults (org.apache.geode.cache.query.SelectResults)5 Test (org.junit.Test)5 Map (java.util.Map)4 NoSuchElementException (java.util.NoSuchElementException)4 SipURI (javax.sip.address.SipURI)4 StructTypeImpl (org.apache.geode.cache.query.internal.types.StructTypeImpl)4 File (java.io.File)3 IOException (java.io.IOException)3 SipException (javax.sip.SipException)3 ObjectType (org.apache.geode.cache.query.types.ObjectType)3 StructType (org.apache.geode.cache.query.types.StructType)3 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)2