Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/metacosm/util/Property.java


1   /*
2       Metacosm, an object-oriented network game framework
3       Copyright (C) 1999-2001 Metacosm Development Team
4   
5       This program is free software; you can redistribute it and/or modify
6       it under the terms of the GNU General Public License as published by
7       the Free Software Foundation; either version 2 of the License, or
8       (at your option) any later version.
9   
10      This program is distributed in the hope that it will be useful,
11      but WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13      GNU General Public License for more details.
14  
15      You should have received a copy of the GNU General Public License
16      along with this program; if not, write to the Free Software
17      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19  
20  package org.metacosm.util;
21  
22  import org.metacosm.framework.persistence.Persistent;
23  
24  /**
25   * Properties describe a particular aspect of an Entity. A Property is
26   * defined by a name and a value, which can be limited to some field.
27   * There are two main types of Properties: numeric ones and non-numeric
28   * ones.<br>
29   * Note: we haven't found some useful example where a 'null' value
30   * could be useful, so 'null' value is tested against.
31   */
32  public abstract class Property implements Cloneable, Persistent {
33  
34    /**
35     * @throws IllegalArgumentException if the name is null
36     */
37    public Property( String name) throws IllegalArgumentException {
38      if (name == null) {
39        throw new IllegalArgumentException();
40      }
41      this.name = name;
42    }
43  
44    /**
45     * @return the non-null name of the Property
46     */
47    final public String getName() {
48      return name;
49    }
50  
51    /**
52     * @return the non-null value of the Property
53     */
54    public abstract Object getValue();
55  
56    public Object clone() {
57      try {
58        return super.clone();
59      } catch (CloneNotSupportedException e) {
60        return null;
61      }
62    }
63  
64    /**
65     * Called by an Influence to modify the value absolutely.
66     */
67    public abstract void applyModifier( AbsoluteModifier modifier);
68  
69    /**
70     * Called by an Influence to remove an absolute value.
71     */
72    public abstract void removeModifier( AbsoluteModifier modifier);
73  
74    /**
75     * Called by an Influence to modify the value relatively.
76     */
77    public abstract void applyModifier( RelativeModifier modifier);
78  
79    /**
80     * Called by an Influence to remove a relative value.
81     */
82    public abstract void removeModifier( RelativeModifier modifier);
83  
84    /**
85     * Non-null name
86     */
87    protected String name;
88  }