コード例 #1
0
 private void sortIfNeeded(Map<String, Resource> resources) {
   if (doSort) {
     LinkedHashMap<String, Resource> rs = (LinkedHashMap<String, Resource>) resources;
     ArrayList<Entry> rt = getEntries(rs);
     Collections.sort(rt);
     resources.clear();
     entriesToMap(resources, rt);
   }
 }
コード例 #2
0
 private void extractCommonPaths(Map<String, Resource> resources) {
   if (!extractCommonParts) {
     return;
   }
   LinkedHashMap<String, Resource> rs = (LinkedHashMap<String, Resource>) resources;
   ArrayList<Entry> rt = getEntries(rs);
   HashMap<String, ArrayList<Entry>> map = new HashMap<String, ArrayList<Entry>>();
   for (Entry e : rt) {
     Path c = new Path(e.path);
     if (c.segmentCount() > 1) {
       String segment = c.segment(0);
       ArrayList<Entry> arrayList = map.get(segment);
       if (arrayList == null) {
         arrayList = new ArrayList<RAMLModelHelper.Entry>();
         map.put(segment, arrayList);
       }
       arrayList.add(e);
     }
   }
   if (!map.isEmpty()) {
     // list of entries to collapse segment
     for (String s : map.keySet()) {
       ArrayList<Entry> e = map.get(s);
       Entry base = e.get(0);
       Resource r0 = base.res;
       Resource newRes = new Resource();
       String relativeUri = "/" + s;
       newRes.setRelativeUri(relativeUri);
       base.path = relativeUri;
       stripSegment(r0);
       newRes.getResources().put(r0.getRelativeUri(), r0);
       base.res = newRes;
       for (int a = 1; a < e.size(); a++) {
         Entry entry = e.get(a);
         stripSegment(entry.res);
         rt.remove(entry);
         newRes.getResources().put(entry.res.getRelativeUri(), entry.res);
       }
     }
   }
   resources.clear();
   entriesToMap(resources, rt);
 }