01: /*
02: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
03: * (license2)
04: * Initial Developer: H2 Group
05: */
06: package org.h2.tools.indexer;
07:
08: import java.util.ArrayList;
09: import java.util.Collections;
10: import java.util.Comparator;
11: import java.util.HashMap;
12:
13: /**
14: * Represents a word of the full text index.
15: */
16: public class Word {
17: String name;
18: HashMap pages = new HashMap();
19: ArrayList weightList;
20:
21: Word(String name) {
22: this .name = name;
23: }
24:
25: void addPage(Page page, int weight) {
26: Weight w = (Weight) pages.get(page);
27: if (w == null) {
28: w = new Weight();
29: w.page = page;
30: pages.put(page, w);
31: }
32: w.value += weight;
33: page.relations++;
34: }
35:
36: ArrayList getSortedWeights() {
37: if (weightList == null) {
38: weightList = new ArrayList(pages.values());
39: Collections.sort(weightList, new Comparator() {
40: public int compare(Object o0, Object o1) {
41: Weight w0 = (Weight) o0;
42: Weight w1 = (Weight) o1;
43: return w0.value < w1.value ? 1
44: : w0.value == w1.value ? 0 : -1;
45: }
46: });
47: }
48: return weightList;
49: }
50: }
|