MCPcopy Create free account
hub / github.com/apple/foundationdb / fromTuples

Method fromTuples

recipes/java-recipes/MicroDoc.java:106–151  ·  view source on GitHub ↗
(ArrayList<Tuple> tuples)

Source from the content-addressed store, hash-verified

104 }
105
106 private static Object fromTuples(ArrayList<Tuple> tuples){
107 if(tuples == null){
108 return null;
109 }
110
111 Tuple first = tuples.get(0); // Determine kind of object from
112 // first tuple.
113 if(first.size() == 1){
114 return first.get(0); // Primitive type.
115 }
116
117 if(first.equals(Tuple.from(EMPTY_OBJECT, null))){
118 return new HashMap<Object,Object>(); // Empty map.
119 }
120
121 if(first.equals(Tuple.from(EMPTY_ARRAY))){
122 return new ArrayList<Object>(); // Empty list.
123 }
124
125 HashMap<Object,ArrayList<Tuple>> groups = new HashMap<Object,ArrayList<Tuple>>();
126 for(Tuple t : tuples){
127 if(groups.containsKey(t.get(0))){
128 groups.get(t.get(0)).add(t);
129 } else {
130 ArrayList<Tuple> list = new ArrayList<Tuple>();
131 list.add(t);
132 groups.put(t.get(0),list);
133 }
134 }
135
136 if(first.get(0).equals(0l)){
137 // Array.
138 ArrayList<Object> array = new ArrayList<Object>();
139 for(Entry<Object,ArrayList<Tuple>> g : groups.entrySet()){
140 array.add(fromTuples(getTruncated(g.getValue())));
141 }
142 return array;
143 } else {
144 // Object.
145 HashMap<Object,Object> map = new HashMap<Object,Object>();
146 for(Entry<Object,ArrayList<Tuple>> g : groups.entrySet()){
147 map.put(g.getKey(), fromTuples(getTruncated(g.getValue())));
148 }
149 return map;
150 }
151 }
152
153 public static Object insertDoc(TransactionContext tcx, final Map<Object,Object> doc){
154 return tcx.run(new Function<Transaction,Object>() {

Callers 1

applyMethod · 0.95

Calls 11

sizeMethod · 0.95
getMethod · 0.95
equalsMethod · 0.95
fromMethod · 0.95
getTruncatedMethod · 0.95
putMethod · 0.80
getMethod · 0.65
getKeyMethod · 0.65
addMethod · 0.45
equalsMethod · 0.45
getValueMethod · 0.45

Tested by

no test coverage detected