File: Priority.java

package info (click to toggle)
libxt-java 0.19991105-5
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,908 kB
  • ctags: 2,762
  • sloc: java: 12,823; makefile: 52; xml: 46
file content (35 lines) | stat: -rw-r--r-- 838 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.jclark.xsl.tr;

final class Priority {
  private final double n;
  static private final Priority defaultCache[] = new Priority[]{
    new Priority(-0.5),
    new Priority(-0.25),
    new Priority(0.0),
    new Priority(0.5)
  };

  private Priority(double n) {
    this.n = n;
  }

  // -2 means -0.5; -1 means -0.25; 0 means 0; 1 means 0.5
  public static Priority createDefault(int p) {
    if (p < -2 || p > 1)
      throw new IllegalArgumentException("bad default");
    return defaultCache[p + 2];
  }

  public static Priority create(String s) throws NumberFormatException {
    if (s == null)
      return null;
    return new Priority(Double.valueOf(s).doubleValue());
  }
  
  public int compareTo(Priority p) {
    if (n == p.n)
      return 0;
    return n < p.n ? -1 : 1;
  }

}