File: IdMapLoader.java

package info (click to toggle)
python-schema-salad 8.9.20251102115403-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,060 kB
  • sloc: python: 19,247; cpp: 2,631; cs: 1,869; java: 1,341; makefile: 187; xml: 184; sh: 103; javascript: 46
file content (51 lines) | stat: -rw-r--r-- 1,596 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package ${package}.utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;

public class IdMapLoader<T> implements Loader<T> {
  private final Loader<T> innerLoader;
  private final String mapSubject;
  private final String mapPredicate;

  public IdMapLoader(
      final Loader<T> innerLoader, final String mapSubject, final String mapPredicate) {
    this.innerLoader = innerLoader;
    this.mapSubject = mapSubject;
    this.mapPredicate = mapPredicate;
  }

  public T load(
      final Object doc_,
      final String baseUri,
      final LoadingOptions loadingOptions,
      final String docRoot) {
    Object doc = doc_;
    if (doc instanceof Map) {
      final Map<String, Object> docMap = (Map<String, Object>) doc;
      final List<Object> asList = new ArrayList();
      for (final String key : docMap.keySet()) {
        final Object el = docMap.get(key);
        if (el instanceof Map) {
          final Map<String, Object> v2 = new HashMap<String, Object>((Map<String, Object>) el);
          v2.put(this.mapSubject, key);
          asList.add(v2);
        } else {
          if (this.mapPredicate != null) {
            final Map<String, Object> v3 = new HashMap<String, Object>();
            v3.put(this.mapPredicate, el);
            v3.put(this.mapSubject, key);
            asList.add(v3);
          } else {
            throw new ValidationException("No mapPredicate");
          }
        }
      }
      doc = asList;
    }
    return this.innerLoader.load(doc, baseUri, loadingOptions);
  }
}