01: /*
02: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05:
06: package com.sun.portal.search.rdm;
07:
08: import java.util.*;
09:
10: /**
11: * RDM View Hits
12: *
13: * The View Hits object specifies a range for result sets.
14: * Use _Parse() to load a new object from an RDM string.
15: *
16: * Example:
17: * RDMViewHits *vhp1 = RDMViewHits_Parse("100") for 1..100
18: * RDMViewHits *vhp2 = RDMViewHits_Parse("1..100") for 1..100
19: */
20: public class RDMViewHits {
21:
22: public static final int RDMVIEWHITS_UNBOUNDED = -1;
23: public static final int RDMVIEWHITS_DEFAULT = 20; // config?
24: public static final int RDMVIEWHITS_MAX = 1000000; // 1 million
25:
26: public int min = 1, max = RDMVIEWHITS_DEFAULT;
27:
28: /** create a view hits object - if the input is bad, you will get the default */
29: public RDMViewHits(String str) {
30: if (str != null) {
31: try {
32: String minstr = null, maxstr = null;
33: StringTokenizer st = new StringTokenizer(str, ".");
34: minstr = st.nextToken();
35: if (st.hasMoreTokens())
36: maxstr = st.nextToken();
37: else {
38: maxstr = minstr;
39: minstr = null;
40: }
41: if (minstr != null)
42: min = Integer.parseInt(minstr);
43: if (maxstr != null) {
44: max = Integer.parseInt(maxstr);
45: if (max == -1)
46: max = RDMVIEWHITS_MAX;
47: }
48:
49: if (min < 0 || max < -1 || min == 0 && max > 0) {
50: // invalid input => default display
51: min = 1;
52: max = RDMVIEWHITS_DEFAULT;
53: } else if (min > max || max == 0) {
54: // 0 or 0..0 7..6 1..0 => display nb of docs
55: min = 0;
56: max = 0;
57: }
58: } catch (Exception e) {
59: // ignore errors - use default
60: min = 1;
61: max = RDMVIEWHITS_DEFAULT;
62: }
63: }
64: }
65:
66: public RDMViewHits(int min, int max) {
67: this .min = min;
68: this .max = max;
69: }
70:
71: /** To generate a string representation of the View-Hits,
72: * use toString(). It'll generate the following strings:
73: *
74: * min max string
75: * 1 10 "1..10"
76: * UNBOUND 100 "1..100"
77: * UNBOUND UNBOUND "1..1000000"
78: * 10 UNBOUND "10..1000000"
79: * 100 UNBOUND "100..1000000"
80: */
81: protected String tostring() {
82: return min + ".." + max;
83: }
84:
85: }
|