Debian Codegraph @

src/dr/util/Attributable.java

raw symbols SCIP
1 /*
2 * Attributable.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.util;
27
28 import java.io.Serializable;
29 import java.util.HashMap;
30 import java.util.Iterator;
31
32 /**
33 * Interface for associating attributes with an object.
34 *
35 * @version $Id: Attributable.java,v 1.6 2005/05/24 20:26:01 rambaut Exp $
36 *
37 * @author Andrew Rambaut
38 */
39 public interface Attributable extends Serializable {
40
41 public final static String ATTRIBUTE = "att";
42 public final static String NAME = "name";
43 public final static String VALUE = "value";
44
45 /**
46 * Sets an named attribute for this object.
47 * @param name the name of the attribute.
48 * @param value the new value of the attribute.
49 */
50 public void setAttribute(String name, Object value);
51
52 /**
53 * @return an object representing the named attributed for this object.
54 * @param name the name of the attribute of interest.
55 */
56 public Object getAttribute(String name);
57
58 /**
59 * @return an iterator of the attributes that this object has.
60 */
61 Iterator<String> getAttributeNames();
62
63 public static final class AttributeHelper implements Attributable {
64 /**
65 * Sets an named attribute for this object.
66 * @param name the name of the attribute.
67 * @param value the new value of the attribute.
68 */
69 public void setAttribute(String name, Object value) {
70 attributes.put(name, value);
71 }
72
73 /**
74 * @return an object representing the named attributed for this object.
75 * @param name the name of the attribute of interest.
76 */
77 public Object getAttribute(String name) {
78 return attributes.get(name);
79 }
80
81 /**
82 * @param name attribute name
83 * @return boolean whether contains attribute by given its name
84 */
85 public boolean containsAttribute(String name) {
86 return attributes.containsKey(name);
87 }
88
89 /**
90 * @return an iterator of the attributes that this object has.
91 */
92 public Iterator<String> getAttributeNames() {
93 return attributes.keySet().iterator();
94 }
95
96 // **************************************************************
97 // INSTANCE VARIABLE
98 // **************************************************************
99
100 private final HashMap<String, Object> attributes = new HashMap<String, Object>();
101 }
102 }
103
104