| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
package jaggregate; |
| 7 | |
|
| 8 | |
import java.io.IOException; |
| 9 | |
import java.io.ObjectInputStream; |
| 10 | |
import java.io.ObjectOutputStream; |
| 11 | |
import java.io.Serializable; |
| 12 | |
|
| 13 | |
import static jaggregate.Bag.*; |
| 14 | |
import static jaggregate.Set.emptySet; |
| 15 | |
import static jaggregate.internal.EquivalenceTester.*; |
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | 86 | public class Dictionary<K, V> extends AbstractDictionaryImpl<K, V> |
| 31 | |
implements Serializable { |
| 32 | |
|
| 33 | |
private static final long serialVersionUID = -1L; |
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
public Dictionary() { |
| 39 | 1221 | super( OBJECT_ATTRIBUTES ); |
| 40 | 1221 | } |
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
public Dictionary( AbstractDictionary<? extends K, ? extends V> associations ) { |
| 49 | 7 | super( associations, OBJECT_ATTRIBUTES ); |
| 50 | 6 | } |
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
public Dictionary( Pair<? extends K, ? extends V>... associations ) { |
| 60 | 55 | super( OBJECT_ATTRIBUTES ); |
| 61 | |
|
| 62 | 190 | for ( Pair<? extends K, ? extends V> each : associations ) |
| 63 | 137 | putAt( each.key(), each.value() ); |
| 64 | 52 | } |
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
public static <T, U> Dictionary<T, U> emptyDictionary() { |
| 74 | 1221 | return new Dictionary<T, U>(); |
| 75 | |
} |
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
public static <T, U> Dictionary<T, U> dictionaryFrom( |
| 87 | |
AbstractDictionary<? extends T, ? extends U> associations ) { |
| 88 | |
|
| 89 | 6 | return new Dictionary<T, U>( associations ); |
| 90 | |
} |
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
public static <T, U> Dictionary<T, U> dictionaryFrom( |
| 103 | |
Pair<? extends T, ? extends U>[] associations ) { |
| 104 | |
|
| 105 | 55 | return new Dictionary<T, U>( associations ); |
| 106 | |
} |
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | |
public static <T, U> Dictionary<T, U> dictionaryWith( |
| 121 | |
Pair<? extends T, ? extends U> firstAssociation, |
| 122 | |
Pair<? extends T, ? extends U>... restOfAssociations ) { |
| 123 | |
|
| 124 | 23 | Dictionary<T, U> dictionary = dictionaryFrom( restOfAssociations ); |
| 125 | 22 | dictionary.putAt( firstAssociation.key(), firstAssociation.value() ); |
| 126 | 21 | return dictionary; |
| 127 | |
} |
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
@Override |
| 133 | |
public <R> Bag<R> collect( |
| 134 | |
UnaryFunctor<? super Pair<K, V>, ? extends R> transformer ) { |
| 135 | |
|
| 136 | 3 | return (Bag<R>) super.collect( transformer ); |
| 137 | |
} |
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | |
@Override |
| 143 | |
public <R> Dictionary<K, R> collectValues( |
| 144 | |
UnaryFunctor<? super V, ? extends R> transformer ) { |
| 145 | |
|
| 146 | 5 | return (Dictionary<K, R>) super.collectValues( transformer ); |
| 147 | |
} |
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
@Override |
| 153 | |
public Dictionary<K, V> reject( UnaryCondition<? super Pair<K, V>> discriminator ) { |
| 154 | 6 | return (Dictionary<K, V>) super.reject( discriminator ); |
| 155 | |
} |
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
|
| 160 | |
@Override |
| 161 | |
public Dictionary<K, V> rejectValues( UnaryCondition<? super V> discriminator ) { |
| 162 | 5 | return (Dictionary<K, V>) super.rejectValues( discriminator ); |
| 163 | |
} |
| 164 | |
|
| 165 | |
|
| 166 | |
|
| 167 | |
|
| 168 | |
@Override |
| 169 | |
public Dictionary<K, V> select( UnaryCondition<? super Pair<K, V>> discriminator ) { |
| 170 | 6 | return (Dictionary<K, V>) super.select( discriminator ); |
| 171 | |
} |
| 172 | |
|
| 173 | |
|
| 174 | |
|
| 175 | |
|
| 176 | |
@Override |
| 177 | |
public Dictionary<K, V> selectValues( UnaryCondition<? super V> discriminator ) { |
| 178 | 5 | return (Dictionary<K, V>) super.selectValues( discriminator ); |
| 179 | |
} |
| 180 | |
|
| 181 | |
|
| 182 | |
|
| 183 | |
|
| 184 | |
@Override |
| 185 | |
protected Class<? extends AbstractDictionary> getImplementationClass() { |
| 186 | 836 | return Dictionary.class; |
| 187 | |
} |
| 188 | |
|
| 189 | |
|
| 190 | |
|
| 191 | |
|
| 192 | |
@Override |
| 193 | |
protected <T, U> Dictionary<T, U> newEmptyDictionary() { |
| 194 | 22 | return emptyDictionary(); |
| 195 | |
} |
| 196 | |
|
| 197 | |
|
| 198 | |
|
| 199 | |
|
| 200 | |
@Override |
| 201 | |
protected <R> Bag<R> newEmptyExtensibleResultCollection() { |
| 202 | 6 | return emptyBag(); |
| 203 | |
} |
| 204 | |
|
| 205 | |
|
| 206 | |
|
| 207 | |
|
| 208 | |
@Override |
| 209 | |
protected <T> Set<T> newEmptySet() { |
| 210 | 44 | return emptySet(); |
| 211 | |
} |
| 212 | |
|
| 213 | |
|
| 214 | |
|
| 215 | |
|
| 216 | |
@Override |
| 217 | |
protected String asString( Object keyOrValue ) { |
| 218 | 12 | return String.valueOf( keyOrValue ); |
| 219 | |
} |
| 220 | |
|
| 221 | |
private void writeObject( ObjectOutputStream outputStream ) |
| 222 | |
throws IOException { |
| 223 | |
|
| 224 | 3 | serializeTo( outputStream ); |
| 225 | 3 | } |
| 226 | |
|
| 227 | |
private void readObject( ObjectInputStream inputStream ) |
| 228 | |
throws IOException, ClassNotFoundException { |
| 229 | |
|
| 230 | 3 | deserializeFrom( inputStream, OBJECT_ATTRIBUTES ); |
| 231 | 3 | } |
| 232 | |
} |