Revision 49029
Added by Claudio Atzori over 6 years ago
OafHbaseUtils.java | ||
---|---|---|
7 | 7 |
import com.google.common.collect.Iterables; |
8 | 8 |
import com.google.common.collect.Lists; |
9 | 9 |
import com.google.common.collect.Sets; |
10 |
import eu.dnetlib.data.proto.FieldTypeProtos.KeyValue; |
|
11 |
import eu.dnetlib.data.proto.FieldTypeProtos.Qualifier; |
|
12 |
import eu.dnetlib.data.proto.FieldTypeProtos.StringField; |
|
13 |
import eu.dnetlib.data.proto.FieldTypeProtos.StructuredProperty; |
|
10 |
import eu.dnetlib.data.proto.FieldTypeProtos.*; |
|
14 | 11 |
import eu.dnetlib.data.proto.PersonProtos.Person; |
15 | 12 |
import org.apache.hadoop.hbase.io.ImmutableBytesWritable; |
16 | 13 |
|
... | ... | |
29 | 26 |
} |
30 | 27 |
|
31 | 28 |
public static Function<ImmutableBytesWritable, OafDecoder> decoder() { |
32 |
return new Function<ImmutableBytesWritable, OafDecoder>() { |
|
33 |
|
|
34 |
@Override |
|
35 |
public OafDecoder apply(final ImmutableBytesWritable input) { |
|
36 |
return OafDecoder.decode(input.copyBytes()); |
|
37 |
} |
|
38 |
}; |
|
29 |
return input -> OafDecoder.decode(input.copyBytes()); |
|
39 | 30 |
} |
40 | 31 |
|
41 | 32 |
public static Iterable<Oaf> asOaf(final Iterable<ImmutableBytesWritable> in) { |
... | ... | |
43 | 34 |
} |
44 | 35 |
|
45 | 36 |
public static Function<ImmutableBytesWritable, Oaf> oafDecoder() { |
46 |
return new Function<ImmutableBytesWritable, Oaf>() { |
|
47 |
|
|
48 |
@Override |
|
49 |
public Oaf apply(final ImmutableBytesWritable input) { |
|
50 |
return parse(input); |
|
51 |
} |
|
52 |
}; |
|
37 |
return input -> parse(input); |
|
53 | 38 |
} |
54 | 39 |
|
55 | 40 |
public static Oaf parse(final ImmutableBytesWritable input) { |
... | ... | |
73 | 58 |
} |
74 | 59 |
|
75 | 60 |
public static <T> Set<String> hashSetValues(Iterable<T> ts) { |
76 |
return Sets.newHashSet(Iterables.transform(ts, new Function<T, String>() { |
|
77 |
@Override |
|
78 |
public String apply(final T t) { |
|
79 |
return mapValue(t); |
|
80 |
} |
|
81 |
})); |
|
61 |
return Sets.newHashSet(Iterables.transform(ts, t -> mapValue(t))); |
|
82 | 62 |
} |
83 | 63 |
|
84 | 64 |
public static <T> List<String> listValues(Iterable<T> ts) { |
85 |
return Lists.newArrayList(Iterables.transform(ts, new Function<T, String>() { |
|
86 |
@Override |
|
87 |
public String apply(final T t) { |
|
88 |
return mapValue(t); |
|
89 |
} |
|
90 |
})); |
|
65 |
return Lists.newArrayList(Iterables.transform(ts, t -> mapValue(t))); |
|
91 | 66 |
} |
92 | 67 |
|
93 | 68 |
public static <T> String getKey(Iterable<T> ts) { |
... | ... | |
95 | 70 |
} |
96 | 71 |
|
97 | 72 |
public static <T> List<String> listKeys(Iterable<T> ts) { |
98 |
return Lists.newArrayList(Iterables.transform(ts, new Function<T, String>() { |
|
99 |
@Override |
|
100 |
public String apply(final T t) { |
|
101 |
return mapKey(t); |
|
102 |
} |
|
103 |
})); |
|
73 |
return Lists.newArrayList(Iterables.transform(ts, t -> mapKey(t))); |
|
104 | 74 |
} |
105 | 75 |
|
106 | 76 |
public static <T> Set<String> hashSetKeys(Iterable<T> ts) { |
107 |
return Sets.newHashSet(Iterables.transform(ts, new Function<T, String>() { |
|
108 |
@Override |
|
109 |
public String apply(final T t) { |
|
110 |
return mapKey(t); |
|
111 |
} |
|
112 |
})); |
|
77 |
return Sets.newHashSet(Iterables.transform(ts, t -> mapKey(t))); |
|
113 | 78 |
} |
114 | 79 |
|
115 | 80 |
private static <T> String mapKey(final T t) { |
... | ... | |
127 | 92 |
if (t instanceof Person) return ((Person) t).getMetadata().getFullname().getValue(); |
128 | 93 |
if (t instanceof StringField) return ((StringField) t).getValue(); |
129 | 94 |
if (t instanceof Qualifier) return ((Qualifier) t).getClassname(); |
95 |
if (t instanceof Author) return ((Author) t).getFullname(); |
|
130 | 96 |
|
131 | 97 |
throw new IllegalArgumentException(String.format("type %s not mapped", t.getClass())); |
132 | 98 |
} |
Also available in: Unified diff
getting rid of person entities