Exemplo n.º 1
0
 @Override
 CompoundSpiderDiagram createSD(
     Map<String, Entry<Object, CommonTree>> attributes, CommonTree mainNode)
     throws ReadingException {
   String operator = (String) attributes.remove(SDTextOperatorAttribute).getKey();
   ArrayList<SpiderDiagram> operands = new ArrayList<>();
   int i = 1;
   Entry<Object, CommonTree> curSD, lastSD = null;
   while ((curSD = attributes.remove(CompoundSpiderDiagram.SDTextArgAttribute + i++)) != null
       && curSD.getKey() instanceof SpiderDiagram) {
     operands.add((SpiderDiagram) curSD.getKey());
     lastSD = curSD;
   }
   if (curSD != null) {
     throw new ReadingException(
         i18n("GERR_ILLEGAL_STATE"), (CommonTree) curSD.getValue().getChild(0));
   }
   if (!attributes.isEmpty()) {
     throw new ReadingException(
         i18n("ERR_TRANSLATE_UNKNOWN_ATTRIBUTES", attributes.keySet()),
         (CommonTree) attributes.values().iterator().next().getValue().getChild(0));
   }
   try {
     return SpiderDiagrams.createCompoundSD(operator, operands, false);
   } catch (Exception e) {
     throw new ReadingException(
         e.getLocalizedMessage(),
         lastSD == null ? mainNode : (CommonTree) lastSD.getValue().getChild(0));
   }
 }
Exemplo n.º 2
0
 @Override
 @SuppressWarnings("unchecked")
 public Map<String, Region> fromASTNode(CommonTree treeNode) throws ReadingException {
   ArrayList<ArrayList<Object>> rawHabitats = regionListTranslator.fromASTNode(treeNode);
   if (rawHabitats == null || rawHabitats.size() < 1) {
     return null;
   }
   HashMap<String, Region> habitats = new HashMap<>();
   for (ArrayList<Object> rawHabitat : rawHabitats) {
     if (rawHabitat.size() == 2) {
       habitats.put((String) rawHabitat.get(0), new Region((ArrayList<Zone>) rawHabitat.get(1)));
     }
   }
   return habitats;
 }
Exemplo n.º 3
0
 @Override
 public ArrayList<V> fromASTNode(CommonTree treeNode) throws ReadingException {
   if (treeNode.token != null && treeNode.token.getType() == headTokenType) {
     checkNode(treeNode);
     if (treeNode.getChildCount() < 1) {
       return null;
     }
     ArrayList<V> objs = new ArrayList<>(treeNode.getChildCount());
     int i = 0;
     for (Object obj : treeNode.getChildren()) {
       objs.add(fromASTChildAt(i++, (CommonTree) obj));
     }
     return objs;
   }
   throw new ReadingException(
       i18n("ERR_TRANSLATE_UNEXPECTED_ELEMENT", i18n(i18n("ERR_TRANSLATE_LIST_OR_SLIST"))),
       treeNode);
 }