KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > tools > indexer > Word


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.tools.indexer;
6
7 import java.util.ArrayList JavaDoc;
8 import java.util.Collections JavaDoc;
9 import java.util.Comparator JavaDoc;
10 import java.util.HashMap JavaDoc;
11
12 public class Word {
13     String JavaDoc name;
14     HashMap JavaDoc pages = new HashMap JavaDoc();
15     ArrayList JavaDoc weightList;
16     
17     Word(String JavaDoc name) {
18         this.name = name;
19     }
20     
21     void addPage(Page page, int weight) {
22         Weight w = (Weight) pages.get(page);
23         if(w == null) {
24             w = new Weight();
25             w.page = page;
26             pages.put(page, w);
27         }
28         w.value += weight;
29         page.relations++;
30     }
31     
32     ArrayList JavaDoc getSortedWeights() {
33         if(weightList == null) {
34             weightList = new ArrayList JavaDoc(pages.values());
35             Collections.sort(weightList, new Comparator JavaDoc() {
36                 public int compare(Object JavaDoc o0, Object JavaDoc o1) {
37                     Weight w0 = (Weight) o0;
38                     Weight w1 = (Weight) o1;
39                     return w0.value < w1.value ? 1 : w0.value == w1.value ? 0 : -1;
40                 }
41             });
42         }
43         return weightList;
44     }
45 }
46
Popular Tags