1 19 package org.netbeans.mdr.persistence.memoryimpl; 20 21 import org.netbeans.mdr.persistence.*; 22 import java.util.ArrayList ; 23 import java.util.List ; 24 25 29 public class MultivaluedOrderedIndexImpl extends MultivaluedIndexImpl implements MultivaluedOrderedIndex, Streamable { 30 31 32 public MultivaluedOrderedIndexImpl(String name, StorageImpl storage, Storage.EntryType keyType, Storage.EntryType valueType, boolean unique) { 33 super (name, storage, keyType, valueType, unique); 34 } 35 36 public MultivaluedOrderedIndexImpl() { 37 } 38 39 public synchronized java.util.List getItemsOrdered(Object key) throws StorageException { 40 return (List ) getItems (key); 41 } 42 43 49 public synchronized java.util.Collection getObjectsOrdered (Object key, SinglevaluedIndex repos) throws StorageException { 50 return (List ) getObjects(key, repos); 51 } 52 53 56 public synchronized boolean remove(Object key,int index) throws StorageException { 57 List vals = (List ) entries.get (key); 58 Object orig; 59 if (vals != null && (orig = vals.remove(index)) != null) { 60 transLog.logRemove(key, orig, index); 61 return true; 62 } else { 63 return false; 64 } 65 } 66 67 70 public synchronized void add(Object key,int index,Object value) throws StorageException { 71 List vals = (List ) entries.get (key); 72 if (vals == null) { 73 vals = new ArrayList (); 74 entries.put(key, vals); 75 } else if (unique && vals.contains(value)) { 76 throw createValueAlreadyContainedExc(key, value); 77 } 78 vals.add(index, value); 79 transLog.logAdd(key, value, index); 80 } 81 82 90 public synchronized void replace(Object key,int index,Object element) throws StorageException { 91 List vals = (List ) entries.get (key); 92 try { 93 Object orig; 94 if (vals != null) { 95 if (unique && !isUniqueValue(vals, element, index)) { 96 throw createValueAlreadyContainedExc(key, element); 97 } 98 if ((orig = vals.set(index, element)) != null) { 99 transLog.logReplace(key, orig, index); 100 return; 101 } 102 } 103 } catch (IndexOutOfBoundsException e) { 104 } 105 throw new StorageBadRequestException ("Index out of range: " + index + " for key: " + key); 106 } 107 } 108 | Popular Tags |