Exemplo n.º 1
0
    /**
     * 组装TermRangeQuery
     *
     * @param elements
     * @return
     */
    private TermRangeQuery toTermRangeQuery(Element fieldNameEle, LinkedList<Element> elements) {

      boolean includeFirst = false;
      boolean includeLast = false;
      String firstValue = null;
      String lastValue = null;
      // 检查第一个元素是否是[或者{
      Element first = elements.getFirst();
      if ('[' == first.type) {
        includeFirst = true;
      } else if ('{' == first.type) {
        includeFirst = false;
      } else {
        throw new IllegalStateException("表达式异常");
      }
      // 检查最后一个元素是否是]或者}
      Element last = elements.getLast();
      if (']' == last.type) {
        includeLast = true;
      } else if ('}' == last.type) {
        includeLast = false;
      } else {
        throw new IllegalStateException("表达式异常, RangeQuery缺少结束括号");
      }
      if (elements.size() < 4 || elements.size() > 5) {
        throw new IllegalStateException("表达式异常, RangeQuery 错误");
      }
      // 读出中间部分
      Element e2 = elements.get(1);
      if ('\'' == e2.type) {
        firstValue = e2.toString();
        //
        Element e3 = elements.get(2);
        if (',' != e3.type) {
          throw new IllegalStateException("表达式异常, RangeQuery缺少逗号分隔");
        }
        //
        Element e4 = elements.get(3);
        if ('\'' == e4.type) {
          lastValue = e4.toString();
        } else if (e4 != last) {
          throw new IllegalStateException("表达式异常,RangeQuery格式错误");
        }
      } else if (',' == e2.type) {
        firstValue = null;
        //
        Element e3 = elements.get(2);
        if ('\'' == e3.type) {
          lastValue = e3.toString();
        } else {
          throw new IllegalStateException("表达式异常,RangeQuery格式错误");
        }

      } else {
        throw new IllegalStateException("表达式异常, RangeQuery格式错误");
      }

      return TermRangeQuery.newStringRange(
          fieldNameEle.toString(), firstValue, lastValue, includeFirst, includeLast);
    }
 private void processExclusions() {
   for (Element element : getElements(QueryExclude.class)) {
     if (element instanceof PackageElement) {
       conf.addExcludedPackage(((PackageElement) element).getQualifiedName().toString());
     } else if (element instanceof TypeElement) {
       conf.addExcludedClass(((TypeElement) element).getQualifiedName().toString());
     } else {
       throw new IllegalArgumentException(element.toString());
     }
   }
 }
Exemplo n.º 3
0
  private static String wrapText(Element element, AnnotationMirror mirror, String text) {
    StringBuilder b = new StringBuilder();
    if (element != null) {
      b.append("Element " + element.toString());
    }
    if (mirror != null) {
      b.append(" at annotation @" + Utils.getSimpleName(mirror.getAnnotationType()));
    }

    if (b.length() > 0) {
      b.append(" is erroneous: ").append(text);
      return b.toString();
    } else {
      return text;
    }
  }
Exemplo n.º 4
0
 private void parse(Element node) {
   if (!showThumbs) {
     // do not show any thumbnails
     return;
   }
   int count = node.getElementCount();
   for (int i = 0; i < count; i++) {
     Element elm = node.getElement(i);
     Debug.log(8, elm.toString());
     if (elm.isLeaf()) {
       int start = elm.getStartOffset(), end = elm.getEndOffset();
       parseRange(start, end);
     } else {
       parse(elm);
     }
   }
 }
Exemplo n.º 5
0
    @Override
    public JsonType visitDeclared(DeclaredType declaredType, Void o) {
      if (isJsonPrimitive(declaredType)) {
        // 'primitive'-ish things
        return new JsonPrimitive(declaredType.toString());

      } else if (isInstanceOf(declaredType, Collection.class)) {

        if (declaredType.getTypeArguments().size() == 0) {
          return new JsonArray(new JsonPrimitive(Object.class.getName()));
        } else {
          TypeMirror elem = declaredType.getTypeArguments().get(0);
          return new JsonArray(elem.accept(this, o));
        }

      } else if (isInstanceOf(declaredType, Map.class)) {

        if (declaredType.getTypeArguments().size() == 0) {
          return new JsonDict(
              new JsonPrimitive(Object.class.getName()), new JsonPrimitive(Object.class.getName()));
        } else {
          TypeMirror key = declaredType.getTypeArguments().get(0);
          TypeMirror val = declaredType.getTypeArguments().get(1);
          return new JsonDict(key.accept(this, o), val.accept(this, o));
        }

      } else {
        TypeElement element = (TypeElement) declaredType.asElement();
        if (element.getKind() == ElementKind.ENUM) {
          List<String> enumConstants = new ArrayList();
          for (Element e : element.getEnclosedElements()) {
            if (e.getKind() == ElementKind.ENUM_CONSTANT) {
              enumConstants.add(e.toString());
            }
          }
          JsonPrimitive primitive =
              new JsonPrimitive(String.class.getName()); // TODO is this always a string?
          primitive.setRestrictions(enumConstants);
          return primitive;
        } else {
          return buildType(declaredType, element);
        }
      }
    }
Exemplo n.º 6
0
 public String toString(String indent) {
   StringBuilder buffer = new StringBuilder(128);
   buffer.append(indent);
   buffer.append('<');
   buffer.append(name);
   if (attributes != null) {
     for (Entry<String, String> entry : attributes.entries()) {
       buffer.append(' ');
       buffer.append(entry.key);
       buffer.append("=\"");
       buffer.append(entry.value);
       buffer.append('\"');
     }
   }
   if (children == null && (text == null || text.length() == 0)) buffer.append("/>");
   else {
     buffer.append(">\n");
     String childIndent = indent + '\t';
     if (text != null && text.length() > 0) {
       buffer.append(childIndent);
       buffer.append(text);
       buffer.append('\n');
     }
     if (children != null) {
       for (Element child : children) {
         buffer.append(child.toString(childIndent));
         buffer.append('\n');
       }
     }
     buffer.append(indent);
     buffer.append("</");
     buffer.append(name);
     buffer.append('>');
   }
   return buffer.toString();
 }
Exemplo n.º 7
0
  private static AttributeData[] createAttributeData(VertexBuffer vbuffer) {
    List<AttributeData> attribute = new ArrayList<>();
    for (Element el : vbuffer.layout.getElements()) {
      if (el.equals(POSITION) || el.equals(NORMAL) || el.equals(TEX_COORD)) {
        continue;
      }

      if (el.getDataType() != FLOAT
          || el.getVectorType().getElementCount() > CTM_ATTR_ELEMENT_COUNT) {
        logger.warn(
            "The mesh-attribute "
                + el.toString()
                + " can't be exported to the ctm format! Only float "
                + "attributes with max. 4 elements are supported.");
        continue;
      }

      float[] values = new float[vbuffer.getVcount() * CTM_ATTR_ELEMENT_COUNT];

      {
        int k = 0;
        for (Vertex v : vbuffer) {
          copyToBuffer(values, k, v, el);
          k += CTM_ATTR_ELEMENT_COUNT;
        }
      }

      attribute.add(
          new AttributeData(el.getBezeichnung(), null, AttributeData.STANDARD_PRECISION, values));
    }

    AttributeData[] atts = new AttributeData[attribute.size()];
    attribute.toArray(atts);

    return atts;
  }
Exemplo n.º 8
0
 @Override
 public String toString() {
   return source.toString() + " ---[" + description + "]---> " + destination.toString();
 }
Exemplo n.º 9
0
  /**
   * Looks up Records in the Cache. This follows CNAMEs and handles negatively cached data.
   *
   * @param name The name to look up
   * @param type The type to look up
   * @param minCred The minimum acceptable credibility
   * @return A SetResponse object
   * @see SetResponse
   * @see Credibility
   */
  public SetResponse lookupRecords(Name name, short type, byte minCred) {
    SetResponse cr = null;
    boolean verbose = Options.check("verbosecache");
    Object o = lookup(name, type);

    if (verbose) logLookup(name, type, "Starting");

    if (o == null || o == NXRRSET) {
      /*
       * The name exists, but the type was not found.  Or, the
       * name does not exist and no parent does either.  Punt.
       */
      if (verbose) logLookup(name, type, "no information found");
      return SetResponse.ofType(SetResponse.UNKNOWN);
    }

    Object[] objects;
    if (o instanceof Element) objects = new Object[] {o};
    else objects = (Object[]) o;

    int nelements = 0;
    for (int i = 0; i < objects.length; i++) {
      Element element = (Element) objects[i];
      if (element.expired()) {
        if (verbose) {
          logLookup(name, type, element.toString());
          logLookup(name, type, "expired: ignoring");
        }
        removeSet(name, type, element);
        objects[i] = null;
      } else if (element.credibility < minCred) {
        if (verbose) {
          logLookup(name, type, element.toString());
          logLookup(name, type, "not credible: ignoring");
        }
        objects[i] = null;
      } else {
        nelements++;
      }
    }
    if (nelements == 0) {
      /* We have data, but can't use it.  Punt. */
      if (verbose) logLookup(name, type, "no useful data found");
      return SetResponse.ofType(SetResponse.UNKNOWN);
    }

    /*
     * We have something at the name.  It could be the answer,
     * a CNAME, DNAME, or NS, or a negative cache entry.
     *
     * Ignore wildcards, since it's pretty unlikely that any will be
     * cached.  The occasional extra query is easily balanced by the
     * reduced number of lookups.
     */

    for (int i = 0; i < objects.length; i++) {
      if (objects[i] == null) continue;
      Element element = (Element) objects[i];
      if (verbose) logLookup(name, type, element.toString());
      RRset rrset = null;
      if (element instanceof PositiveElement) rrset = ((PositiveElement) element).rrset;

      /* Is this a negatively cached entry? */
      if (rrset == null) {
        /*
         * If this is an NXDOMAIN entry, return NXDOMAIN.
         */
        if (element.getType() == 0) {
          if (verbose) logLookup(name, type, "NXDOMAIN");
          return SetResponse.ofType(SetResponse.NXDOMAIN);
        }

        /*
         * If we're not looking for type ANY, return NXRRSET.
         * Otherwise ignore this.
         */
        if (type != Type.ANY) {
          if (verbose) logLookup(name, type, "NXRRSET");
          return SetResponse.ofType(SetResponse.NXRRSET);
        } else {
          if (verbose) logLookup(name, type, "ANY query; " + "ignoring NXRRSET");
          continue;
        }
      }

      short rtype = rrset.getType();
      Name rname = rrset.getName();
      if (name.equals(rname)) {
        if (type != Type.CNAME && type != Type.ANY && rtype == Type.CNAME) {
          if (verbose) logLookup(name, type, "cname");
          return new SetResponse(SetResponse.CNAME, rrset);
        } else if (type != Type.NS && type != Type.ANY && rtype == Type.NS) {
          if (verbose) logLookup(name, type, "exact delegation");
          return new SetResponse(SetResponse.DELEGATION, rrset);
        } else {
          if (verbose) logLookup(name, type, "exact match");
          if (cr == null) cr = new SetResponse(SetResponse.SUCCESSFUL);
          cr.addRRset(rrset);
        }
      } else if (name.subdomain(rname)) {
        if (rtype == Type.DNAME) {
          if (verbose) logLookup(name, type, "dname");
          return new SetResponse(SetResponse.DNAME, rrset);
        } else if (rtype == Type.NS) {
          if (verbose) logLookup(name, type, "parent delegation");
          return new SetResponse(SetResponse.DELEGATION, rrset);
        } else {
          if (verbose)
            logLookup(name, type, "ignoring rrset (" + rname + " " + Type.string(rtype) + ")");
        }
      } else {
        if (verbose)
          logLookup(name, type, "ignoring rrset (" + rname + " " + Type.string(rtype) + ")");
      }
    }

    /*
     * As far as I can tell, the only legitimate time cr will be null is
     * if we queried for ANY and only saw negative responses, but not an
     * NXDOMAIN.  Return UNKNOWN.
     */
    if (cr == null && type == Type.ANY) return SetResponse.ofType(SetResponse.UNKNOWN);
    else if (cr == null)
      throw new IllegalStateException(
          "looking up (" + name + " " + Type.string(type) + "): " + "cr == null.");
    return cr;
  }
Exemplo n.º 10
0
    /** 语法解析 */
    private void parseSyntax() {
      for (int i = 0; i < this.elements.size(); i++) {
        Element e = this.elements.get(i);
        if ('F' == e.type) {
          Element e2 = this.elements.get(i + 1);
          if ('=' != e2.type && ':' != e2.type) {
            throw new IllegalStateException("表达式异常: = 或 : 号丢失");
          }
          Element e3 = this.elements.get(i + 2);
          // 处理 = 和 : 运算
          if ('\'' == e3.type) {
            i += 2;
            if ('=' == e2.type) {
              TermQuery tQuery = new TermQuery(new Term(e.toString(), e3.toString()));
              this.querys.push(tQuery);
            } else if (':' == e2.type) {
              String keyword = e3.toString();
              if (keyword.startsWith("^") && keyword.endsWith("$")) {
                Query pQuery = this.luceneQueryParse(e.toString(), keyword);
                this.querys.push(pQuery);
              } else {
                Query tQuery = IKQueryParser.parse(e.toString(), e3.toString());
                this.querys.push(tQuery);
              }
            }

          } else if ('[' == e3.type || '{' == e3.type) {
            i += 2;
            // 处理 [] 和 {}
            LinkedList<Element> eQueue = new LinkedList<Element>();
            eQueue.add(e3);
            for (i++; i < this.elements.size(); i++) {
              Element eN = this.elements.get(i);
              eQueue.add(eN);
              if (']' == eN.type || '}' == eN.type) {
                break;
              }
            }
            // 翻译RangeQuery
            Query rangeQuery = this.toTermRangeQuery(e, eQueue);
            this.querys.push(rangeQuery);
          } else {
            throw new IllegalStateException("表达式异常:匹配值丢失");
          }

        } else if ('(' == e.type) {
          this.operates.push(e);

        } else if (')' == e.type) {
          boolean doPop = true;
          while (doPop && !this.operates.empty()) {
            Element op = this.operates.pop();
            if ('(' == op.type) {
              doPop = false;
            } else {
              Query q = toQuery(op);
              this.querys.push(q);
            }
          }
        } else {

          if (this.operates.isEmpty()) {
            this.operates.push(e);
          } else {
            boolean doPeek = true;
            while (doPeek && !this.operates.isEmpty()) {
              Element eleOnTop = this.operates.peek();
              if ('(' == eleOnTop.type) {
                doPeek = false;
                this.operates.push(e);
              } else if (compare(e, eleOnTop) == 1) {
                this.operates.push(e);
                doPeek = false;
              } else if (compare(e, eleOnTop) == 0) {
                Query q = toQuery(eleOnTop);
                this.operates.pop();
                this.querys.push(q);
              } else {
                Query q = toQuery(eleOnTop);
                this.operates.pop();
                this.querys.push(q);
              }
            }

            if (doPeek && this.operates.empty()) {
              this.operates.push(e);
            }
          }
        }
      }

      while (!this.operates.isEmpty()) {
        Element eleOnTop = this.operates.pop();
        Query q = toQuery(eleOnTop);
        this.querys.push(q);
      }
    }
Exemplo n.º 11
0
 @Override
 public String toString() {
   return eleLeft.toString() + dim + ":" + "\n" + eleRight.toString();
 }