Rename pimstuff -> jpim and move to Maven
[jpim.git] / src / main / java / de / j32 / jpim / data / Entry.java
diff --git a/src/main/java/de/j32/jpim/data/Entry.java b/src/main/java/de/j32/jpim/data/Entry.java
new file mode 100644 (file)
index 0000000..5eda18a
--- /dev/null
@@ -0,0 +1,78 @@
+package de.j32.jpim.data;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import de.j32.util.Filter;
+import de.j32.util.FilteredIterator;
+
+public class Entry
+{
+    long id_ = 0;
+    String name_ = "";
+    ArrayList<Attribute> attributes_ = new ArrayList<Attribute>();
+
+    public void name(String name)
+    {
+        name_ = name;
+    }
+
+    public String name()
+    {
+        return name_;
+    }
+
+    public void id(long id)
+    {
+        id_ = id;
+    }
+
+    public long id()
+    {
+        return id_;
+    }
+
+    public void attribute(String type, String rel, String value)
+    {
+        attributes_.add(new Attribute(type, rel, value, attributes_.size()));
+    }
+
+    public Iterable<Attribute> attributes()
+    {
+        return attributes_;
+    }
+
+    public Iterable<Attribute> attributes(final String type)
+    {
+        return new Iterable<Attribute>() {
+            public Iterator<Attribute> iterator()
+            {
+                return new FilteredIterator<Attribute>(attributes_.iterator(),
+                        new Filter<Attribute>() {
+                            public boolean match(Attribute element)
+                            {
+                                return element.type == type;
+                            }
+                        });
+            }
+        };
+    }
+
+    public Iterable<Attribute> attributes(final String type, final String rel)
+    {
+        return new Iterable<Attribute>() {
+            public Iterator<Attribute> iterator()
+            {
+                return new FilteredIterator<Attribute>(attributes_.iterator(),
+                        new Filter<Attribute>() {
+                            public boolean match(Attribute element)
+                            {
+                                return element.type == type
+                                        && element.rel == rel;
+                            }
+                        });
+            }
+        };
+    }
+
+}