1 package jp.sourceforge.stigmata;
4 import java.util.HashMap;
5 import java.util.Iterator;
9 * This class manages a set of birthmarks which extracted from a target.
11 * @author Haruaki TAMADA
13 public class BirthmarkSet implements Iterable<Birthmark>{
20 * location of target is loaded from.
27 private Map<String, Birthmark> birthmarks = new HashMap<String, Birthmark>();
32 public BirthmarkSet(String name, URL location){
34 this.location = location;
38 * return the sum of all element count of birthmarks this instance has.
40 public int getSumOfElementCount(){
42 for(Iterator<String> i = birthmarkTypes(); i.hasNext();){
43 Birthmark birthmark = getBirthmark(i.next());
44 count += birthmark.getElementCount();
50 * return the number of birthmarks.
52 public int getBirthmarksCount(){
53 return birthmarks.size();
59 public String getName(){
64 * return the location.
66 public URL getLocation(){
71 * add given birthmark to this instance.
72 * @throws NullPointerException given birthmark is null.
74 public void addBirthmark(Birthmark birthmark){
75 if(birthmark == null){
76 throw new NullPointerException("given birthmark is null");
78 birthmarks.put(birthmark.getType(), birthmark);
82 * return the given type of birthmark.
84 public Birthmark getBirthmark(String type){
85 return birthmarks.get(type);
89 * does this object have the given birthmark type.
91 public boolean hasBirthmark(String type){
92 return birthmarks.get(type) != null;
96 * returns an array containing all of the birthmarks in this object.
98 public Birthmark[] getBirthmarks(){
99 Birthmark[] b = new Birthmark[getBirthmarksCount()];
101 for(Iterator<String> i = birthmarkTypes(); i.hasNext();){
102 b[index] = getBirthmark(i.next());
109 * returns an iterator over the birthmarks in this birthmark-set.
112 public Iterator<Birthmark> iterator(){
113 return birthmarks.values().iterator();
117 * returns an iterator over the birthmark types.
119 public Iterator<String> birthmarkTypes(){
120 return birthmarks.keySet().iterator();
124 * returns an array of birthmark types.
126 public synchronized String[] getBirthmarkTypes(){
127 return birthmarks.keySet().toArray(new String[birthmarks.size()]);