16 package uk.ac.cam.eng.extraction.hadoop.datatypes;
18 import java.io.DataInput;
19 import java.io.DataOutput;
20 import java.io.IOException;
21 import java.util.Collection;
22 import java.util.HashMap;
26 import org.apache.hadoop.io.DoubleWritable;
27 import org.apache.hadoop.io.IntWritable;
28 import org.apache.hadoop.io.Writable;
29 import org.apache.hadoop.io.WritableUtils;
40 Map<IntWritable, DoubleWritable> {
43 public DoubleWritable
put(IntWritable key, DoubleWritable value) {
44 throw new UnsupportedOperationException();
48 private Map<IntWritable, DoubleWritable> instance =
new HashMap<>();
55 for (Entry<IntWritable, DoubleWritable> entry : value.
entrySet()) {
56 put(entry.getKey(), entry.getValue());
61 return instance.size();
65 return instance.isEmpty();
69 return instance.containsKey(key);
73 return instance.containsValue(value);
76 public DoubleWritable
get(Object key) {
77 return instance.get(key);
80 public DoubleWritable
put(IntWritable key, DoubleWritable value) {
81 return instance.put(key, value);
87 public DoubleWritable
put(
int key,
double value) {
89 if (instance.containsKey(keyObject) && instance.get(keyObject) != null) {
90 instance.get(keyObject).set(value);
91 return instance.get(keyObject);
93 return instance.put(keyObject,
new DoubleWritable(value));
98 public DoubleWritable
remove(Object key) {
99 return instance.remove(key);
102 public void putAll(Map<? extends IntWritable, ? extends DoubleWritable> m) {
111 return instance.keySet();
114 public Collection<DoubleWritable>
values() {
115 return instance.values();
118 public Set<java.util.Map.Entry<IntWritable, DoubleWritable>>
entrySet() {
119 return instance.entrySet();
123 return instance.equals(o);
127 return instance.hashCode();
131 return instance.toString();
135 int expectedSize =
size() + other.
size();
137 if (expectedSize !=
size()) {
138 throw new RuntimeException(
"Two features with the same id: " +
this 144 public void write(DataOutput out)
throws IOException {
145 WritableUtils.writeVInt(out, instance.size());
146 for (Entry<IntWritable, DoubleWritable> entry : instance.entrySet()) {
147 WritableUtils.writeVInt(out, entry.getKey().get());
148 entry.getValue().write(out);
155 int length = WritableUtils.readVInt(in);
156 for (
int i = 0; i < length; ++i) {
157 int key = WritableUtils.readVInt(in);
158 double value = in.readDouble();
fst::TropicalWeightTpl< F > Map(double)