9f96731e64951ce37f93eaa2d2630a13ccd15542
[jpim.git] / src / de / j32 / pimstuff / data / Entry.java
1 package de.j32.pimstuff.data;
2
3 import java.util.ArrayList;
4 import java.util.Iterator;
5
6 import de.j32.util.Filter;
7 import de.j32.util.FilteredIterator;
8
9 public class Entry
10 {
11     long id_ = 0;
12     String name_ = "";
13     ArrayList<Attribute> attributes_ = new ArrayList<Attribute>();
14
15     public void name(String name)
16     {
17         name_ = name;
18     }
19
20     public String name()
21     {
22         return name_;
23     }
24
25     public void id(long id)
26     {
27         id_ = id;
28     }
29
30     public long id()
31     {
32         return id_;
33     }
34
35     public void attribute(String type, String rel, String value)
36     {
37         attributes_.add(new Attribute(type, rel, value, attributes_.size()));
38     }
39
40     public Iterable<Attribute> attributes()
41     {
42         return attributes_;
43     }
44
45     public Iterable<Attribute> attributes(final String type)
46     {
47         return new Iterable<Attribute>() {
48             public Iterator<Attribute> iterator()
49             {
50                 return new FilteredIterator<Attribute>(attributes_.iterator(),
51                         new Filter<Attribute>() {
52                             public boolean match(Attribute element)
53                             {
54                                 return element.type == type;
55                             }
56                         });
57             }
58         };
59     }
60
61     public Iterable<Attribute> attributes(final String type, final String rel)
62     {
63         return new Iterable<Attribute>() {
64             public Iterator<Attribute> iterator()
65             {
66                 return new FilteredIterator<Attribute>(attributes_.iterator(),
67                         new Filter<Attribute>() {
68                             public boolean match(Attribute element)
69                             {
70                                 return element.type == type
71                                         && element.rel == rel;
72                             }
73                         });
74             }
75         };
76     }
77
78 }