Add custom properties.
[demoscenemusic.git] / src / main / java / net / pterodactylus / demoscenemusic / data / Properties.java
1 /*
2  * DemosceneMusic - Properties.java - Copyright © 2012 David Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.demoscenemusic.data;
19
20 import java.util.HashMap;
21 import java.util.Iterator;
22 import java.util.Map;
23 import java.util.Map.Entry;
24
25 /**
26  * Container for custom properties that can be attached to all data containers.
27  *
28  * @see Base#getProperties()
29  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
30  */
31 public class Properties implements Iterable<Entry<String, String>> {
32
33         /** The properties. */
34         private final Map<String, String> properties = new HashMap<String, String>();
35
36         //
37         // ACCESSORS
38         //
39
40         /**
41          * Returns the value of the property with the given name.
42          *
43          * @param property
44          *            The name of the property
45          * @return The value of the property, or {@code null} if the property with
46          *         the given name does not exist
47          */
48         public String get(String property) {
49                 return properties.get(property);
50         }
51
52         /**
53          * Sets the value of the property with the given name.
54          *
55          * @param property
56          *            The name of the property
57          * @param value
58          *            The new value of the property
59          * @return These properties
60          */
61         public Properties set(String property, String value) {
62                 properties.put(property, value);
63                 return this;
64         }
65
66         /**
67          * Removes the property with the given name.
68          *
69          * @param property
70          *            The name of the property
71          * @return These properties
72          */
73         public Properties remove(String property) {
74                 properties.remove(property);
75                 return this;
76         }
77
78         /**
79          * Removes all properties.
80          *
81          * @return These properties
82          */
83         public Properties removeAll() {
84                 properties.clear();
85                 return this;
86         }
87
88         //
89         // ITERABLE METHODS
90         //
91
92         /**
93          * {@inheritDoc}
94          */
95         @Override
96         public Iterator<Entry<String, String>> iterator() {
97                 return properties.entrySet().iterator();
98         }
99
100 }