View Javadoc

1   // Copyright 2006-2007, by the California Institute of Technology.
2   // ALL RIGHTS RESERVED. United States Government Sponsorship acknowledged.
3   // Any commercial use must be negotiated with the Office of Technology Transfer
4   // at the California Institute of Technology.
5   //
6   // This software is subject to U. S. export control laws and regulations
7   // (22 C.F.R. 120-130 and 15 C.F.R. 730-774). To the extent that the software
8   // is subject to U.S. export control laws and regulations, the recipient has
9   // the responsibility to obtain export licenses or other export authority as
10  // may be required before exporting such information to foreign countries or
11  // providing access to foreign nationals.
12  //
13  // $Id: Numeric.java 2606 2007-04-18 19:35:09Z pramirez $ 
14  //
15  
16  package gov.nasa.pds.tools.label;
17  
18  /***
19   * This class represents a numeric scalar. It is not type 
20   * specific so everything is represented as a String. 
21   * @author pramirez
22   * @version $Revision: 2606 $
23   * 
24   */
25  public class Numeric extends Scalar {
26      private String units;
27      private int radix;
28      
29      /***
30       * Constructs a Numeric with the given value
31       * @param value of numeric
32       */
33      public Numeric(String value) {
34          this(value, null, 10);
35      }
36      
37      /***
38       * Constructs a Numeric with the given value and units
39       * @param value of numeric
40       * @param units of numeric
41       */
42      public Numeric(String value, String units) {
43          this(value, units, 10);
44      }
45      
46      /***
47       * Constructs a Numeric with the given value and radix
48       * @param value of numeric
49       * @param radix of numeric
50       */
51      public Numeric(String value, int radix) {
52          this(value, null, radix);
53      }
54      
55      /***
56       * Constructs a Numeric with the given value, units and radix
57       * @param value of numeric
58       * @param units of numeric
59       * @param radix of numeric
60       */
61      public Numeric(String value, String units, int radix) {
62          super(value);
63          this.units = units;
64          this.radix = radix;
65      }
66  
67      /***
68       * Sets the units
69       * @param units of the numeric
70       */
71      public void setUnits(String units) {
72          //Remove angle brackets if found
73          if (units.startsWith("<") && units.endsWith(">"))
74             this.units = units.substring(1, units.length()-1).trim();
75          else
76              this.units = units.trim();
77      }
78      
79      /***
80       * Retrieves the units
81       * @return units
82       */
83      public String getUnits() {
84          return units;
85      }
86      
87      /***
88       * Sets the radix
89       * @param radix of the numeric
90       */
91      public void setRadix(int radix) {
92          this.radix = radix;
93      }
94      
95      /***
96       * Retrieves the base
97       * @return base
98       */
99      public int getRadix() {
100         return radix;
101     }
102 
103 }