Last change
on this file since 193 was
193,
checked in by Maciej Komosinski, 10 years ago
|
Set svn:eol-style native for all textual files
|
-
Property svn:eol-style set to
native
|
File size:
1.0 KB
|
Rev | Line | |
---|
[107] | 1 | package com.framsticks.params; |
---|
| 2 | |
---|
| 3 | import java.util.Iterator; |
---|
| 4 | import java.util.Map; |
---|
| 5 | import java.util.Map.Entry; |
---|
| 6 | import java.util.TreeMap; |
---|
| 7 | |
---|
| 8 | import com.framsticks.util.lang.Casting; |
---|
| 9 | |
---|
| 10 | public class MapBasedObject implements Iterable<Map.Entry<String, Object>> { |
---|
| 11 | |
---|
| 12 | protected final String framsTypeName; |
---|
| 13 | protected final Map<String, Object> values = new TreeMap<>(); |
---|
| 14 | |
---|
| 15 | /** |
---|
| 16 | * @param framsTypeName |
---|
| 17 | */ |
---|
| 18 | public MapBasedObject(String framsTypeName) { |
---|
| 19 | this.framsTypeName = framsTypeName; |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | public <T> void set(String id, T value) { |
---|
| 23 | values.put(id, value); |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | public <T> T get(String id, Class<T> type) { |
---|
| 27 | return Casting.nullOrThrowCast(type, values.get(id)); |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | public void clear() { |
---|
| 31 | values.clear(); |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | public int size() { |
---|
| 35 | return values.size(); |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | @Override |
---|
| 39 | public String toString() { |
---|
| 40 | return values.toString(); |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | /** |
---|
| 44 | * @return the framsTypeName |
---|
| 45 | */ |
---|
| 46 | public String getFramsTypeName() { |
---|
| 47 | return framsTypeName; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | @Override |
---|
| 51 | public Iterator<Entry<String, Object>> iterator() { |
---|
| 52 | return values.entrySet().iterator(); |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.