1 package jp.sourceforge.stigmata;
8 import java.util.HashMap;
9 import java.util.Iterator;
13 * This class manages a set of birthmarks which extracted from a target.
15 * @author Haruaki TAMADA
18 public class BirthmarkSet implements Iterable<Birthmark>{
25 * location of target is loaded from.
32 private Map<String, Birthmark> birthmarks = new HashMap<String, Birthmark>();
37 public BirthmarkSet(String name, URL location){
39 this.location = location;
43 * return the sum of all element count of birthmarks this instance has.
45 public int getSumOfElementCount(){
47 for(Iterator<String> i = birthmarkTypes(); i.hasNext();){
48 Birthmark birthmark = getBirthmark(i.next());
49 count += birthmark.getElementCount();
55 * return the number of birthmarks.
57 public int getBirthmarksCount(){
58 return birthmarks.size();
64 public String getName(){
69 * return the location.
71 public URL getLocation(){
76 * add given birthmark to this instance.
77 * @throws NullPointerException given birthmark is null.
79 public void addBirthmark(Birthmark birthmark){
80 if(birthmark == null){
81 throw new NullPointerException("given birthmark is null");
83 birthmarks.put(birthmark.getType(), birthmark);
87 * return the given type of birthmark.
89 public Birthmark getBirthmark(String type){
90 return birthmarks.get(type);
94 * does this object have the given birthmark type.
96 public boolean hasBirthmark(String type){
97 return birthmarks.get(type) != null;
101 * returns an array containing all of the birthmarks in this object.
103 public Birthmark[] getBirthmarks(){
104 Birthmark[] b = new Birthmark[getBirthmarksCount()];
106 for(Iterator<String> i = birthmarkTypes(); i.hasNext();){
107 b[index] = getBirthmark(i.next());
114 * returns an iterator over the birthmarks in this birthmark-set.
117 public Iterator<Birthmark> iterator(){
118 return birthmarks.values().iterator();
122 * returns an iterator over the birthmark types.
124 public Iterator<String> birthmarkTypes(){
125 return birthmarks.keySet().iterator();
129 * returns an array of birthmark types.
131 public synchronized String[] getBirthmarkTypes(){
132 return birthmarks.keySet().toArray(new String[birthmarks.size()]);