Subversion Repository Public Repository

litesoft

Diff Revisions 758 vs 759 for /trunk/Java/GWT/Client/src/org/litesoft/GWT/client/localstorage/LocalStorageImpl.java

Diff revisions: vs.
  @@ -9,6 +9,7 @@
9 9 public class LocalStorageImpl extends AbstractMap<String, String> implements LocalStorage
10 10 {
11 11 private final Html5LocalStorage mHtml5LS;
12 + private int mVersion = 0;
12 13
13 14 public LocalStorageImpl( Html5LocalStorage pHtml5LS )
14 15 {
  @@ -41,7 +42,14 @@
41 42 @Override
42 43 public void clear()
43 44 {
44 - mHtml5LS.clear();
45 + synchronized ( mHtml5LS )
46 + {
47 + if ( mHtml5LS.length() != 0 )
48 + {
49 + mHtml5LS.clear();
50 + mVersion++;
51 + }
52 + }
45 53 }
46 54
47 55 @Override
  @@ -58,6 +66,7 @@
58 66 {
59 67 throw new UnsupportedOperationException();
60 68 }
69 + mVersion++;
61 70 return zPrevValue;
62 71 }
63 72 }
  @@ -72,6 +81,7 @@
72 81 if ( zPrevValue != null )
73 82 {
74 83 mHtml5LS.removeItem( zKey );
84 + mVersion++;
75 85 }
76 86 return zPrevValue;
77 87 }
  @@ -80,7 +90,67 @@
80 90 @Override
81 91 public Set<Entry<String, String>> entrySet()
82 92 {
83 - throw new IllegalStateException( "xxx" );
93 + return new AbstractSet<Entry<String, String>>()
94 + {
95 + @Override
96 + public int size()
97 + {
98 + return mHtml5LS.length();
99 + }
100 +
101 + @Override
102 + public Iterator<Entry<String, String>> iterator()
103 + {
104 + return new AbstractReadOnlyIterator<Entry<String, String>>()
105 + {
106 + private final int mVersion = getVersion();
107 + private final int mSize = size();
108 + private int mNextIndex = 0;
109 +
110 + private boolean versionOK()
111 + {
112 + return mVersion == getVersion();
113 + }
114 +
115 + private boolean indexOK()
116 + {
117 + return mNextIndex < mSize;
118 + }
119 +
120 + @Override
121 + public boolean hasNext()
122 + {
123 + synchronized ( mHtml5LS )
124 + {
125 + return versionOK() && indexOK();
126 + }
127 + }
128 +
129 + @Override
130 + public Entry<String, String> next()
131 + {
132 + synchronized ( mHtml5LS )
133 + {
134 + if ( !versionOK() )
135 + {
136 + throw new ConcurrentModificationException();
137 + }
138 + if ( !indexOK() )
139 + {
140 + throw new NoSuchElementException();
141 + }
142 + String zKey = mHtml5LS.key( mNextIndex++ );
143 + return new SimpleImmutableEntry<String, String>( zKey, mHtml5LS.getItem( zKey ) );
144 + }
145 + }
146 + };
147 + }
148 + };
149 + }
150 +
151 + private int getVersion()
152 + {
153 + return mVersion;
84 154 }
85 155
86 156 private String innerGet( String pKey )