909cd3be2f9111eb62b608363c2fa8b2fe13784e
[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                                 return new FilteredIterator<Attribute>(
50                                                 attributes_.iterator(),
51                                                 new Filter<Attribute>() {
52                                                         public boolean match(Attribute element) {
53                                                                 return element.type == type;
54                                                         }
55                                                 });
56                         }
57                 };
58         }
59         
60         public Iterable<Attribute> attributes(final String type, final String rel)
61         {
62                 return new Iterable<Attribute>() {
63                         public Iterator<Attribute> iterator() {
64                                 return new FilteredIterator<Attribute>(
65                                                 attributes_.iterator(),
66                                                 new Filter<Attribute>() {
67                                                         public boolean match(Attribute element) {
68                                                                 return element.type == type && element.rel == rel;
69                                                         }
70                                                 });
71                         }
72                 };
73         }
74
75 }