View Javadoc

1   /*
2    * JDiskCatalog
3    *
4    * Copyright 2007 Przemek Więch
5    *
6    * This file is part of JDiskCatalog.
7    *
8    * JDiskCatalog is free software; you can redistribute it and/or modify
9    * it under the terms of the GNU General Public License as published by
10   * the Free Software Foundation; either version 2 of the License, or
11   * (at your option) any later version.
12   *
13   * This program is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   * GNU General Public License for more details.
17  
18   * You should have received a copy of the GNU General Public License
19   * along with this program; if not, write to the Free Software
20   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21   */
22  
23  package net.sf.jdiskcatalog.model;
24  
25  import java.util.Collection;
26  import java.util.HashMap;
27  import java.util.Map;
28  
29  import net.sf.jdiskcatalog.api.MutableNodeInfo;
30  
31  
32  public class NodeInfoImpl implements MutableNodeInfo
33  {
34  	private Type type;
35  
36  	private String name;
37  
38  	private Map<String, Object> properties = new HashMap<String, Object>();
39  
40  	public NodeInfoImpl(String name, Type type)
41  	{
42  		this.type = type;
43  		this.name = name;
44  	}
45  
46  	public String getName()
47  	{
48  		return name;
49  	}
50  
51  	public Type getType()
52  	{
53  		return type;
54  	}
55  
56  	public Object getProperty(String name)
57  	{
58  		return properties.get(name);
59  	}
60  
61  	public <T> T getProperty(String name, T defaultValue)
62  	{
63  		@SuppressWarnings("unchecked")
64  		T value = (T)properties.get(name);
65  		if (value == null)
66  			value = defaultValue;
67  		return value;
68  	}
69  
70  	@Override
71  	public String toString()
72  	{
73  		return getName();
74  	}
75  
76  	public void setProperty(String name, Object value)
77  	{
78  		properties.put(name, value);
79  	}
80  
81  	public boolean hasProperty(String name)
82  	{
83  		return properties.containsKey(name);
84  	}
85  
86  	public Collection<String> getProperties()
87  	{
88  		return properties.keySet();
89  	}
90  }