jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r794743 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene: AbstractExcerpt.java AbstractIndex.java AggregateRuleImpl.java CaseTermQuery.java ChildAxisQuery.java
Date Thu, 16 Jul 2009 16:37:47 GMT
Author: jukka
Date: Thu Jul 16 16:37:47 2009
New Revision: 794743

URL: http://svn.apache.org/viewvc?rev=794743&view=rev
Log:
JCR-2087: Upgrade to Java 5 as the base platform

Some more Java 5 cleanups.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractExcerpt.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AggregateRuleImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/CaseTermQuery.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ChildAxisQuery.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractExcerpt.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractExcerpt.java?rev=794743&r1=794742&r2=794743&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractExcerpt.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractExcerpt.java
Thu Jul 16 16:37:47 2009
@@ -36,7 +36,6 @@
 import java.io.Reader;
 import java.util.Set;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.TreeMap;
 import java.util.SortedMap;
 import java.util.Arrays;
@@ -177,14 +176,12 @@
     /**
      * @return the extracted terms from the query.
      */
-    protected final Set getQueryTerms() {
-        Set extractedTerms = new HashSet();
-        Set relevantTerms = new HashSet();
+    protected final Set<Term> getQueryTerms() {
+        Set<Term> extractedTerms = new HashSet<Term>();
+        Set<Term> relevantTerms = new HashSet<Term>();
         query.extractTerms(extractedTerms);
         // only keep terms for fulltext fields
-        Iterator it = extractedTerms.iterator();
-        while (it.hasNext()) {
-            Term t = (Term) it.next();
+        for (Term t : extractedTerms) {
             if (t.field().equals(FieldNames.FULLTEXT)) {
                 relevantTerms.add(t);
             } else {
@@ -230,7 +227,8 @@
      */
     private TermPositionVector createTermPositionVector(String text) {
         // term -> TermVectorOffsetInfo[]
-        final SortedMap termMap = new TreeMap();
+        final SortedMap<String, TermVectorOffsetInfo[]> termMap =
+            new TreeMap<String, TermVectorOffsetInfo[]>();
         Reader r = new StringReader(text);
         TokenStream ts = index.getTextAnalyzer().tokenStream("", r);
         Token t = new Token();

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java?rev=794743&r1=794742&r2=794743&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java
Thu Jul 16 16:37:47 2009
@@ -33,7 +33,7 @@
 import java.io.PrintStream;
 import java.io.StringReader;
 import java.util.BitSet;
-import java.util.Iterator;
+import java.util.List;
 
 /**
  * Implements common functionality for a lucene index.
@@ -462,15 +462,14 @@
      * @throws IOException if the document cannot be added to the indexing
      *                     queue.
      */
+    @SuppressWarnings("unchecked")
     private Document getFinishedDocument(Document doc) throws IOException {
         if (!Util.isDocumentReady(doc)) {
             Document copy = new Document();
             // mark the document that reindexing is required
             copy.add(new Field(FieldNames.REINDEXING_REQUIRED, "",
                     Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));
-            Iterator fields = doc.getFields().iterator();
-            while (fields.hasNext()) {
-                Fieldable f = (Fieldable) fields.next();
+            for (Fieldable f : (List<Fieldable>) doc.getFields()) {
                 Fieldable field = null;
                 Field.TermVector tv = getTermVectorParameter(f);
                 Field.Store stored = getStoreParameter(f);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AggregateRuleImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AggregateRuleImpl.java?rev=794743&r1=794742&r2=794743&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AggregateRuleImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AggregateRuleImpl.java
Thu Jul 16 16:37:47 2009
@@ -42,7 +42,6 @@
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Arrays;
-import java.util.Iterator;
 
 /**
  * <code>AggregateRule</code> defines a configuration for a node index
@@ -154,12 +153,12 @@
     public NodeState[] getAggregatedNodeStates(NodeState nodeState)
             throws ItemStateException {
         if (nodeState.getNodeTypeName().equals(nodeTypeName)) {
-            List nodeStates = new ArrayList();
+            List<NodeState> nodeStates = new ArrayList<NodeState>();
             for (int i = 0; i < nodeIncludes.length; i++) {
                 nodeStates.addAll(Arrays.asList(nodeIncludes[i].resolve(nodeState)));
             }
             if (nodeStates.size() > 0) {
-                return (NodeState[]) nodeStates.toArray(new NodeState[nodeStates.size()]);
+                return nodeStates.toArray(new NodeState[nodeStates.size()]);
             }
         }
         return null;
@@ -171,14 +170,13 @@
     public PropertyState[] getAggregatedPropertyStates(NodeState nodeState)
             throws ItemStateException {
         if (nodeState.getNodeTypeName().equals(nodeTypeName)) {
-            List propStates = new ArrayList();
+            List<PropertyState> propStates = new ArrayList<PropertyState>();
             for (int i = 0; i < propertyIncludes.length; i++) {
                 propStates.addAll(Arrays.asList(
                         propertyIncludes[i].resolvePropertyStates(nodeState)));
             }
             if (propStates.size() > 0) {
-                return (PropertyState[]) propStates.toArray(
-                        new PropertyState[propStates.size()]);
+                return propStates.toArray(new PropertyState[propStates.size()]);
             }
         }
         return null;
@@ -216,7 +214,7 @@
      */
     private NodeInclude[] getNodeIncludes(Node config)
             throws MalformedPathException, IllegalNameException, NamespaceException {
-        List includes = new ArrayList();
+        List<NodeInclude> includes = new ArrayList<NodeInclude>();
         NodeList childNodes = config.getChildNodes();
         for (int i = 0; i < childNodes.getLength(); i++) {
             Node n = childNodes.item(i);
@@ -226,19 +224,18 @@
                 if (ntAttr != null) {
                     ntName = resolver.getQName(ntAttr.getNodeValue());
                 }
-                String[] elements = Text.explode(getTextContent(n), '/');
                 PathBuilder builder = new PathBuilder();
-                for (int j = 0; j < elements.length; j++) {
-                    if (elements[j].equals("*")) {
+                for (String element : Text.explode(getTextContent(n), '/')) {
+                    if (element.equals("*")) {
                         builder.addLast(NameConstants.ANY_NAME);
                     } else {
-                        builder.addLast(resolver.getQName(elements[j]));
+                        builder.addLast(resolver.getQName(element));
                     }
                 }
                 includes.add(new NodeInclude(builder.getPath(), ntName));
             }
         }
-        return (NodeInclude[]) includes.toArray(new NodeInclude[includes.size()]);
+        return includes.toArray(new NodeInclude[includes.size()]);
     }
 
     /**
@@ -258,23 +255,22 @@
     private PropertyInclude[] getPropertyIncludes(Node config) throws
             MalformedPathException, IllegalNameException, NamespaceException,
             RepositoryException {
-        List includes = new ArrayList();
+        List<PropertyInclude> includes = new ArrayList<PropertyInclude>();
         NodeList childNodes = config.getChildNodes();
         for (int i = 0; i < childNodes.getLength(); i++) {
             Node n = childNodes.item(i);
             if (n.getNodeName().equals("include-property")) {
-                String[] elements = Text.explode(getTextContent(n), '/');
                 PathBuilder builder = new PathBuilder();
-                for (int j = 0; j < elements.length; j++) {
-                    if (elements[j].equals("*")) {
+                for (String element : Text.explode(getTextContent(n), '/')) {
+                    if (element.equals("*")) {
                         throw new IllegalNameException("* not supported in include-property");
                     }
-                    builder.addLast(resolver.getQName(elements[j]));
+                    builder.addLast(resolver.getQName(element));
                 }
                 includes.add(new PropertyInclude(builder.getPath()));
             }
         }
-        return (PropertyInclude[]) includes.toArray(new PropertyInclude[includes.size()]);
+        return includes.toArray(new PropertyInclude[includes.size()]);
     }
 
     //---------------------------< internal >-----------------------------------
@@ -378,10 +374,10 @@
          * @throws ItemStateException if an error occurs while accessing node
          *                            states.
          */
-        protected void resolve(NodeState nodeState, List collector, int offset)
+        protected void resolve(NodeState nodeState, List<NodeState> collector, int
offset)
                 throws ItemStateException {
             Name currentName = pattern.getElements()[offset].getName();
-            List cne;
+            List<ChildNodeEntry> cne;
             if (currentName.getLocalName().equals("*")) {
                 // matches all
                 cne = nodeState.getChildNodeEntries();
@@ -390,10 +386,8 @@
             }
             if (pattern.getLength() - 1 == offset) {
                 // last segment -> add to collector if node type matches
-                Iterator it = cne.iterator();
-                while (it.hasNext()) {
-                    NodeId id = ((ChildNodeEntry) it.next()).getId();
-                    NodeState ns = (NodeState) ism.getItemState(id);
+                for (ChildNodeEntry entry : cne) {
+                    NodeState ns = (NodeState) ism.getItemState(entry.getId());
                     if (nodeTypeName == null || ns.getNodeTypeName().equals(nodeTypeName))
{
                         collector.add(ns);
                     }
@@ -401,9 +395,8 @@
             } else {
                 // traverse
                 offset++;
-                Iterator it = cne.iterator();
-                while (it.hasNext()) {
-                    NodeId id = ((ChildNodeEntry) it.next()).getId();
+                for (ChildNodeEntry entry : cne) {
+                    NodeId id = entry.getId();
                     resolve((NodeState) ism.getItemState(id), collector, offset);
                 }
             }
@@ -433,9 +426,9 @@
          *                            node states.
          */
         NodeState[] resolve(NodeState nodeState) throws ItemStateException {
-            List nodeStates = new ArrayList();
+            List<NodeState> nodeStates = new ArrayList<NodeState>();
             resolve(nodeState, nodeStates, 0);
-            return (NodeState[]) nodeStates.toArray(new NodeState[nodeStates.size()]);
+            return nodeStates.toArray(new NodeState[nodeStates.size()]);
         }
     }
 
@@ -459,18 +452,16 @@
          */
         PropertyState[] resolvePropertyStates(NodeState nodeState)
                 throws ItemStateException {
-            List nodeStates = new ArrayList();
+            List<NodeState> nodeStates = new ArrayList<NodeState>();
             resolve(nodeState, nodeStates, 0);
-            List propStates = new ArrayList();
-            for (Iterator it = nodeStates.iterator(); it.hasNext(); ) {
-                NodeState state = (NodeState) it.next();
+            List<PropertyState> propStates = new ArrayList<PropertyState>();
+            for (NodeState state : nodeStates) {
                 if (state.hasPropertyName(propertyName)) {
                     PropertyId propId = new PropertyId(state.getNodeId(), propertyName);
-                    propStates.add(ism.getItemState(propId));
+                    propStates.add((PropertyState) ism.getItemState(propId));
                 }
             }
-            return (PropertyState[]) propStates.toArray(
-                    new PropertyState[propStates.size()]);
+            return propStates.toArray(new PropertyState[propStates.size()]);
         }
     }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/CaseTermQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/CaseTermQuery.java?rev=794743&r1=794742&r2=794743&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/CaseTermQuery.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/CaseTermQuery.java
Thu Jul 16 16:37:47 2009
@@ -79,14 +79,15 @@
         CaseTermEnum(IndexReader reader) throws IOException {
             // gather all terms that match
             // keep them in order and remember the doc frequency as value
-            final Map orderedTerms = new LinkedHashMap();
+            final Map<Term, Integer> orderedTerms =
+                new LinkedHashMap<Term, Integer>();
 
             Term term = getTerm();
 
             // there are always two range scanse: one with an initial
             // lower case character and another one with an initial upper case
             // character
-            List rangeScans = new ArrayList(2);
+            List<RangeScan> rangeScans = new ArrayList<RangeScan>(2);
             nameLength = FieldNames.getNameLength(term.text());
             String propName = term.text().substring(0, nameLength);
             this.termText = new OffsetCharSequence(nameLength, term.text());
@@ -125,16 +126,14 @@
                     rangeScans.add(new RangeScan(reader, term, term));
                 }
 
-                Iterator it = rangeScans.iterator();
-                while (it.hasNext()) {
-                    TermEnum terms = (TermEnum) it.next();
+                for (TermEnum terms : rangeScans) {
                     do {
                         Term t = terms.term();
                         if (t != null) {
                             currentTerm.setBase(t.text());
                             int compare = currentTerm.compareTo(termText);
                             if (compare == 0) {
-                                orderedTerms.put(t, new Integer(terms.docFreq()));
+                                orderedTerms.put(t, terms.docFreq());
                             } else if (compare < 0) {
                                 // try next one
                             } else {
@@ -146,9 +145,7 @@
                     } while (terms.next());
                 }
             } finally {
-                Iterator it = rangeScans.iterator();
-                while (it.hasNext()) {
-                    TermEnum terms = (TermEnum) it.next();
+                for (TermEnum terms : rangeScans) {
                     try {
                         terms.close();
                     } catch (IOException e) {
@@ -157,7 +154,7 @@
                 }
             }
 
-            final Iterator it = orderedTerms.keySet().iterator();
+            final Iterator<Term> it = orderedTerms.keySet().iterator();
 
             setEnum(new TermEnum() {
 
@@ -177,7 +174,7 @@
                 }
 
                 public int docFreq() {
-                    Integer docFreq = (Integer) orderedTerms.get(current);
+                    Integer docFreq = orderedTerms.get(current);
                     return docFreq != null ? docFreq.intValue() : 0;
                 }
 
@@ -186,7 +183,7 @@
                 }
 
                 private void getNext() {
-                    current = it.hasNext() ? (Term) it.next() : null;
+                    current = it.hasNext() ? it.next() : null;
                 }
             });
         }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ChildAxisQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ChildAxisQuery.java?rev=794743&r1=794742&r2=794743&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ChildAxisQuery.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ChildAxisQuery.java
Thu Jul 16 16:37:47 2009
@@ -43,7 +43,6 @@
 import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 import java.util.HashMap;
@@ -451,18 +450,18 @@
                     calc[0] = new SimpleChildrenCalculator(reader, hResolver);
                     contextScorer.score(new HitCollector() {
 
-                        private List docIds = new ArrayList();
+                        private List<Integer> docIds = new ArrayList<Integer>();
 
                         public void collect(int doc, float score) {
                             calc[0].collectContextHit(doc);
                             if (docIds != null) {
-                                docIds.add(new Integer(doc));
+                                docIds.add(doc);
                                 if (docIds.size() > CONTEXT_SIZE_THRESHOLD) {
                                     // switch
                                     calc[0] = new HierarchyResolvingChildrenCalculator(
                                             reader, hResolver);
-                                    for (Iterator it = docIds.iterator(); it.hasNext(); )
{
-                                        calc[0].collectContextHit(((Integer) it.next()).intValue());
+                                    for (int docId : docIds) {
+                                        calc[0].collectContextHit(docId);
                                     }
                                     // indicate that we switched
                                     docIds = null;
@@ -486,19 +485,17 @@
                     if (nameTest == null) {
                         // only select this node if it is the child at
                         // specified position
+                        List<ChildNodeEntry> childNodes = state.getChildNodeEntries();
                         if (position == LocationStepQueryNode.LAST) {
                             // only select last
-                            List childNodes = state.getChildNodeEntries();
                             if (childNodes.size() == 0
-                                    || !((ChildNodeEntry) childNodes.get(childNodes.size()
- 1))
-                                        .getId().equals(id)) {
+                                    || !(childNodes.get(childNodes.size() - 1)).getId().equals(id))
{
                                 return false;
                             }
                         } else {
-                            List childNodes = state.getChildNodeEntries();
                             if (position < 1
                                     || childNodes.size() < position
-                                    || !((ChildNodeEntry) childNodes.get(position - 1)).getId().equals(id))
{
+                                    || !(childNodes.get(position - 1)).getId().equals(id))
{
                                 return false;
                             }
                         }
@@ -515,10 +512,9 @@
                             } else {
                                 // only use the last one
                                 Name name = entry.getName();
-                                List childNodes = state.getChildNodeEntries(name);
+                                List<ChildNodeEntry> childNodes = state.getChildNodeEntries(name);
                                 if (childNodes.size() == 0
-                                        || !((ChildNodeEntry) childNodes.get(childNodes.size()
- 1))
-                                            .getId().equals(id)) {
+                                        || !(childNodes.get(childNodes.size() - 1)).getId().equals(id))
{
                                     return false;
                                 }
                             }
@@ -619,31 +615,30 @@
          */
         public Hits getHits() throws IOException {
             // read the uuids of the context nodes
-            Map uuids = new HashMap();
+            Map<Integer, String> uuids = new HashMap<Integer, String>();
             for (int i = contextHits.next(); i > -1; i = contextHits.next()) {
                 String uuid = reader.document(i, FieldSelectors.UUID).get(FieldNames.UUID);
-                uuids.put(new Integer(i), uuid);
+                uuids.put(i, uuid);
             }
 
             // get child node entries for each hit
             Hits childrenHits = new AdaptingHits();
-            for (Iterator it = uuids.values().iterator(); it.hasNext(); ) {
-                String uuid = (String) it.next();
+            for (String uuid : uuids.values()) {
                 NodeId id = new NodeId(uuid);
                 try {
                     long time = System.currentTimeMillis();
                     NodeState state = (NodeState) itemMgr.getItemState(id);
                     time = System.currentTimeMillis() - time;
-                    log.debug("got NodeState with id {} in {} ms.", id, new Long(time));
-                    Iterator entries;
+                    log.debug("got NodeState with id {} in {} ms.", id, time);
+                    List<ChildNodeEntry> entries;
                     if (nameTest != null) {
-                        entries = state.getChildNodeEntries(nameTest).iterator();
+                        entries = state.getChildNodeEntries(nameTest);
                     } else {
                         // get all children
-                        entries = state.getChildNodeEntries().iterator();
+                        entries = state.getChildNodeEntries();
                     }
-                    while (entries.hasNext()) {
-                        NodeId childId = ((ChildNodeEntry) entries.next()).getId();
+                    for (ChildNodeEntry entry : entries) {
+                        NodeId childId = entry.getId();
                         Term uuidTerm = new Term(FieldNames.UUID, childId.toString());
                         TermDocs docs = reader.termDocs(uuidTerm);
                         try {
@@ -673,7 +668,7 @@
         /**
          * The document numbers of the context hits.
          */
-        private final Set docIds = new HashSet();
+        private final Set<Integer> docIds = new HashSet<Integer>();
 
         /**
          * Creates a new hierarchy resolving children calculator.
@@ -690,7 +685,7 @@
          * {@inheritDoc}
          */
         protected void collectContextHit(int doc) {
-            docIds.add(new Integer(doc));
+            docIds.add(doc);
         }
 
         /**
@@ -705,12 +700,12 @@
                 docs = hResolver.getParents(h, docs);
                 if (docs.length == 1) {
                     // optimize single value
-                    if (docIds.contains(new Integer(docs[0]))) {
+                    if (docIds.contains(docs[0])) {
                         childrenHits.set(h);
                     }
                 } else {
                     for (int i = 0; i < docs.length; i++) {
-                        if (docIds.contains(new Integer(docs[i]))) {
+                        if (docIds.contains(docs[i])) {
                             childrenHits.set(h);
                         }
                     }
@@ -718,7 +713,7 @@
             }
             time = System.currentTimeMillis() - time;
 
-            log.debug("Filtered hits in {} ms.", new Long(time));
+            log.debug("Filtered hits in {} ms.", time);
             return childrenHits;
         }
     }



Mime
View raw message