[1573] | 1 | // Attribute.java |
---|
| 2 | // |
---|
| 3 | // (c) 1999-2001 PAL Development Core Team |
---|
| 4 | // |
---|
| 5 | // This package may be distributed under the |
---|
| 6 | // terms of the Lesser GNU General Public License (LGPL) |
---|
| 7 | |
---|
| 8 | package de.ugoe.cs.autoquest.tasktrees.alignment.pal.misc; |
---|
| 9 | |
---|
| 10 | |
---|
| 11 | |
---|
| 12 | /** |
---|
| 13 | * An immutable attribute has a name and value. |
---|
| 14 | * A convenience constructor for conversion from |
---|
| 15 | * string to types Boolean, Integer, Double, Float is available. |
---|
| 16 | * |
---|
| 17 | * @version $Id: Attribute.java,v 1.1 2001/11/21 22:17:07 alexi Exp $ |
---|
| 18 | * |
---|
| 19 | * @author Alexei Drummond |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | public class Attribute { |
---|
| 24 | |
---|
| 25 | public static final String STRING = "string"; |
---|
| 26 | public static final String INTEGER = "integer"; |
---|
| 27 | public static final String BOOLEAN = "boolean"; |
---|
| 28 | public static final String DOUBLE = "double"; |
---|
| 29 | public static final String FLOAT = "float"; |
---|
| 30 | |
---|
| 31 | /** the name of this attribute */ |
---|
| 32 | private String name = null; |
---|
| 33 | |
---|
| 34 | /** the value of this attribute */ |
---|
| 35 | private Object value = null; |
---|
| 36 | |
---|
| 37 | /** |
---|
| 38 | * @param name the name of the attribute. |
---|
| 39 | * @param val the value as a string |
---|
| 40 | * @param type a string description of the type the value is. One of 'boolean', |
---|
| 41 | * 'integer', 'double', 'float', 'string' |
---|
| 42 | */ |
---|
| 43 | public Attribute(String name, String val, String type) { |
---|
| 44 | |
---|
| 45 | this.name = name; |
---|
| 46 | |
---|
| 47 | if (type == null) { |
---|
| 48 | try { |
---|
| 49 | value = new Integer(val); |
---|
| 50 | } catch (NumberFormatException nfe1) { |
---|
| 51 | try { |
---|
| 52 | value = new Double(val); |
---|
| 53 | } catch (NumberFormatException nfe2) { |
---|
| 54 | value = val; |
---|
| 55 | } |
---|
| 56 | } |
---|
| 57 | } else if (type.equals(BOOLEAN)) { |
---|
| 58 | value = new Boolean(val); |
---|
| 59 | } else if (type.equals(INTEGER)) { |
---|
| 60 | value = new Integer(val); |
---|
| 61 | } else if (type.equals(DOUBLE)) { |
---|
| 62 | value = new Double(val); |
---|
| 63 | } else if (type.equals(FLOAT)) { |
---|
| 64 | value = new Float(val); |
---|
| 65 | } |
---|
| 66 | value = val; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | public Attribute(String name, Object value) { |
---|
| 70 | this.name = name; |
---|
| 71 | this.value = value; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | public String getName() { |
---|
| 75 | return name; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | public Object getValue() { |
---|
| 79 | return value; |
---|
| 80 | } |
---|
| 81 | } |
---|
| 82 | |
---|