MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / normalize

Method normalize

src/main/java/field/utility/Conversions.java:273–301  ·  view source on GitHub ↗
(List<Class> to, SetMultimap<List<Class>, Conversion> m)

Source from the content-addressed store, hash-verified

271 return d.getShortestPathTo(nto);
272
273 }
274
275 private static List<Class> normalize(List<Class> to, SetMultimap<List<Class>, Conversion> m) {
276 if (m.containsKey(to)) return to;
277
278 List<List<Class>> alternatives = new ArrayList<>();
279 for (Class c : to) {
280 alternatives.add(new ArrayList<>(alternativesFor(c)));
281 }
282
283 int[] counts = new int[to.size()];
284 while (true) {
285 counts[0] += 1;
286 int in = 0;
287 while (counts[in] > alternatives.get(in)
288 .size() - 1) {
289 counts[in] = 0;
290 in++;
291 if (in > alternatives.size() - 1) return null;
292 counts[in]++;
293 }
294
295 List<Class> assembled = new ArrayList<>();
296 for (int index = 0; index < counts.length; index++) {
297 assembled.add(alternatives.get(index)
298 .get(counts[index]));
299 }
300
301 if (m.containsKey(assembled)) return assembled;
302 }
303 }
304

Callers 1

getConversionMethod · 0.95

Calls 5

alternativesForMethod · 0.95
getMethod · 0.65
containsKeyMethod · 0.45
addMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected