- Timestamp:
- 09/23/13 18:54:07 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/params/UniqueListAccess.java
r105 r107 187 187 } 188 188 189 public int setUidOf(Object value, String uid) { 190 return uidAccess.select(value).set(uidName, uid); 191 } 192 193 protected int uidCounter = 1; 194 195 public String generateNextUid() { 196 return containedTypeName.substring(0, 1).toUpperCase() + Integer.toString(uidCounter++); 197 } 198 199 public String findNextFreeUid() { 200 String uid; 201 do { 202 uid = generateNextUid(); 203 } while (get(uid, Object.class) != null); 204 return uid; 205 } 206 189 207 protected int setByUid(Object object, String uid) { 190 208 if (uid == null) { 191 209 uid = getUidOf(object); 192 210 if (uid == null) { 193 log.error("failed to set - missing uid");194 return 0;211 uid = findNextFreeUid(); 212 setUidOf(object, uid); 195 213 } 196 214 } … … 205 223 @Override 206 224 public <T> int set(int i, T value) { 207 if (i != map.size()) { 208 throw new FramsticksUnsupportedOperationException().msg("setting element in unique list through index is available only for addition"); 209 } 210 set(getUidOf(value), value); 211 return 0; 225 if (value != null) { 226 if (i != map.size()) { 227 throw new FramsticksUnsupportedOperationException().msg("setting element in unique list through index is available only for addition"); 228 } 229 set(getUidOf(value), value); 230 return 0; 231 } 232 if (i >= map.size()) { 233 throw new FramsticksUnsupportedOperationException().msg("invalid index for removal"); 234 } 235 Object current = get(i, Object.class); 236 return setByUid(null, getUidOf(current)); 212 237 } 213 238 214 239 @Override 215 240 public <T> int set(String id, T value) { 241 if (id == null) { 242 return setByUid(value, null); 243 } 216 244 Integer i = Numbers.parse(id, Integer.class); 217 245 if (i != null) {
Note: See TracChangeset
for help on using the changeset viewer.