jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r800269 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DefaultHighlighter.java
Date Mon, 03 Aug 2009 09:21:55 GMT
Author: mreutegg
Date: Mon Aug  3 09:21:54 2009
New Revision: 800269

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

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DefaultHighlighter.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DefaultHighlighter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DefaultHighlighter.java?rev=800269&r1=800268&r2=800269&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DefaultHighlighter.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DefaultHighlighter.java
Mon Aug  3 09:21:54 2009
@@ -23,6 +23,7 @@
 import java.util.Set;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.List;
 
 import org.apache.lucene.document.Field;
 import org.apache.lucene.index.TermPositionVector;
@@ -92,7 +93,7 @@
      *         highlighted
      */
     public static String highlight(TermPositionVector tvec,
-                                   Set queryTerms,
+                                   Set<Term> queryTerms,
                                    String text,
                                    String excerptStart,
                                    String excerptEnd,
@@ -119,7 +120,7 @@
      *         highlighted
      */
     public static String highlight(TermPositionVector tvec,
-                                   Set queryTerms,
+                                   Set<Term> queryTerms,
                                    String text,
                                    int maxFragments,
                                    int surround)
@@ -133,7 +134,7 @@
      * @see #highlight(TermPositionVector, Set, String, String, String, String, String, String,
String, int, int)
      */
     protected String doHighlight(TermPositionVector tvec,
-                                 Set queryTerms,
+                                 Set<Term> queryTerms,
                                  String text,
                                  String excerptStart,
                                  String excerptEnd,
@@ -144,18 +145,18 @@
                                  int maxFragments,
                                  int surround) throws IOException {
         String[] terms = new String[queryTerms.size()];
-        Iterator it = queryTerms.iterator();
+        Iterator<Term> it = queryTerms.iterator();
         for (int i = 0; it.hasNext(); i++) {
-            terms[i] = ((Term) it.next()).text();
+            terms[i] = it.next().text();
         }
-        ArrayList list = new ArrayList();
+        List<TermVectorOffsetInfo> list = new ArrayList<TermVectorOffsetInfo>();
         int[] tvecindexes = tvec.indexesOf(terms, 0, terms.length);
-        for (int i = 0; i < tvecindexes.length; i++) {
-            TermVectorOffsetInfo[] termoffsets = tvec.getOffsets(tvecindexes[i]);
+        for (int tvecindex : tvecindexes) {
+            TermVectorOffsetInfo[] termoffsets = tvec.getOffsets(tvecindex);
             list.addAll(Arrays.asList(termoffsets));
         }
 
-        TermVectorOffsetInfo[] offsets = (TermVectorOffsetInfo[]) list.toArray(new TermVectorOffsetInfo[list.size()]);
+        TermVectorOffsetInfo[] offsets = list.toArray(new TermVectorOffsetInfo[list.size()]);
         // sort offsets
         if (terms.length > 1) {
             Arrays.sort(offsets, new TermVectorOffsetInfoSorter());
@@ -182,7 +183,7 @@
                     fragmentStart, fragmentEnd, surround * 2);
         }
         int lastOffset = offsets.length; // Math.min(10, offsets.length); // 10 terms is
plenty?
-        ArrayList fragmentInfoList = new ArrayList();
+        List<FragmentInfo> fragmentInfoList = new ArrayList<FragmentInfo>();
         if (offsets[0].getEndOffset() <= text.length()) {
             FragmentInfo fi = new FragmentInfo(offsets[0], surround * 2);
             for (int i = 1; i < lastOffset; i++) {
@@ -208,7 +209,7 @@
         Collections.sort(fragmentInfoList, new FragmentInfoScoreSorter());
 
         // extract best fragments
-        ArrayList bestFragmentsList = new ArrayList();
+        List<FragmentInfo> bestFragmentsList = new ArrayList<FragmentInfo>();
         for (int i = 0; i < Math.min(fragmentInfoList.size(), maxFragments); i++) {
             bestFragmentsList.add(fragmentInfoList.get(i));
         }
@@ -226,7 +227,7 @@
         int skippedChars;
         int firstWhitespace;
         for (int i = 0; i < bestFragmentsList.size(); i++) {
-            FragmentInfo fi = (FragmentInfo) bestFragmentsList.get(i);
+            FragmentInfo fi = bestFragmentsList.get(i);
             fi.trim();
             nextStart = fi.getStartOffset();
             skip = nextStart - pos;
@@ -396,14 +397,14 @@
     }
 
     private static class FragmentInfo {
-        ArrayList offsetInfosList;
+        List<TermVectorOffsetInfo> offsetInfosList;
         int startOffset;
         int endOffset;
         int mergeGap;
         int numTerms;
 
         public FragmentInfo(TermVectorOffsetInfo offsetinfo, int mergeGap) {
-            offsetInfosList = new ArrayList();
+            offsetInfosList = new ArrayList<TermVectorOffsetInfo>();
             offsetInfosList.add(offsetinfo);
             startOffset = offsetinfo.getStartOffset();
             endOffset = offsetinfo.getEndOffset();
@@ -439,9 +440,9 @@
 
         public void trim() {
             int end = startOffset + (mergeGap / 2);
-            Iterator it = offsetInfosList.iterator();
+            Iterator<TermVectorOffsetInfo> it = offsetInfosList.iterator();
             while (it.hasNext()) {
-                TermVectorOffsetInfo tvoi = (TermVectorOffsetInfo) it.next();
+                TermVectorOffsetInfo tvoi = it.next();
                 if (tvoi.getStartOffset() > end) {
                     it.remove();
                 }
@@ -450,51 +451,42 @@
     }
 
     private static class FragmentInfoScoreSorter
-            implements java.util.Comparator {
-        public int compare(Object o1, Object o2) {
-            int s1 = ((FragmentInfo) o1).numTerms();
-            int s2 = ((FragmentInfo) o2).numTerms();
+            implements java.util.Comparator<FragmentInfo> {
+
+        public int compare(FragmentInfo o1, FragmentInfo o2) {
+            int s1 = o1.numTerms();
+            int s2 = o2.numTerms();
             if (s1 == s2) {
-                return ((FragmentInfo) o1).getStartOffset() < ((FragmentInfo) o2).getStartOffset()
? -1 : 1;
+                return o1.getStartOffset() < o2.getStartOffset() ? -1 : 1;
             }
             return s1 > s2 ? -1 : 1;
         }
-
-        public boolean equals(Object obj) {
-            return false;
-        }
     }
 
     private static class FragmentInfoPositionSorter
-            implements java.util.Comparator {
-        public int compare(Object o1, Object o2) {
-            int s1 = ((FragmentInfo) o1).getStartOffset();
-            int s2 = ((FragmentInfo) o2).getStartOffset();
+            implements java.util.Comparator<FragmentInfo> {
+
+        public int compare(FragmentInfo o1, FragmentInfo o2) {
+            int s1 = o1.getStartOffset();
+            int s2 = o2.getStartOffset();
             if (s1 == s2) {
                 return 0;
             }
             return s1 < s2 ? -1 : 1;
         }
-
-        public boolean equals(Object obj) {
-            return false;
-        }
     }
 
     private static class TermVectorOffsetInfoSorter
-            implements java.util.Comparator {
-        public int compare(Object o1, Object o2) {
-            int s1 = ((TermVectorOffsetInfo) o1).getStartOffset();
-            int s2 = ((TermVectorOffsetInfo) o2).getStartOffset();
+            implements java.util.Comparator<TermVectorOffsetInfo> {
+
+        public int compare(TermVectorOffsetInfo o1, TermVectorOffsetInfo o2) {
+            int s1 = o1.getStartOffset();
+            int s2 = o2.getStartOffset();
             if (s1 == s2) {
                 return 0;
             }
             return s1 < s2 ? -1 : 1;
         }
-
-        public boolean equals(Object obj) {
-            return false;
-        }
     }
 
 }



Mime
View raw message