1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.sf.sail.common.persistance.memory;
24
25 import java.util.Date;
26 import java.util.Iterator;
27 import java.util.Stack;
28
29 import net.sf.sail.core.entity.ISock;
30 import net.sf.sail.core.entity.ISockEntry;
31 import net.sf.sail.core.entity.Rim;
32
33 public class MemorySock<T> extends Stack<T> implements ISock<T> {
34
35
36
37
38
39 public final class MemorySockEntry implements ISockEntry<T> {
40
41 public Date getDate() {
42 throw new UnsupportedOperationException(
43 "date not yet implemented on MemorySockEntry");
44 }
45
46 public T getValue() {
47 return peek();
48 }
49
50 }
51
52
53
54
55 private static final long serialVersionUID = -752831757729119985L;
56
57 transient static int sockCount = 0;
58
59 transient int sockSerial = ++sockCount;
60
61 private Rim<T> rim;
62
63
64
65
66 public MemorySock(Rim<T> rim) {
67 this.rim = rim;
68 }
69
70 public synchronized boolean add(T o, boolean replace) {
71 return add(o);
72 }
73
74 @Override
75 public synchronized boolean add(T o) {
76 final Class<?> clazz = o.getClass();
77 final Class<T> shape = rim.getShape();
78 if (!shape.isAssignableFrom(clazz))
79 throw new ClassCastException("sock " + this + " is shaped " + shape);
80 return super.add(o);
81 }
82
83 @Override
84 public synchronized String toString() {
85 return "ISock@" + sockSerial + super.toString();
86 }
87
88
89
90
91 public Iterator<ISockEntry<T>> entryIterator() {
92 return new Iterator<ISockEntry<T>>() {
93
94 public boolean hasNext() {
95 return false;
96 }
97
98 public ISockEntry<T> next() {
99 return null;
100 }
101
102 public void remove() {
103 throw new UnsupportedOperationException(
104 "no remove on this iterator");
105 }
106
107 };
108 }
109
110 public ISockEntry<T> entryPeek() {
111 return new MemorySockEntry();
112 }
113
114 }