예제 #1
0
 @Override
 public String toString() {
   final TokenBuilder tb = new TokenBuilder().add(var.toString()).add(' ').add(ASSIGN);
   tb.add(' ').add(expr.toString());
   if (coll != null) tb.add(' ').add(COLLATION).add(" \"").add(coll.uri()).add('"');
   return tb.toString();
 }
예제 #2
0
 @Override
 public String toString() {
   final TokenBuilder tb = new TokenBuilder();
   if (name == null) tb.add('*');
   else tb.add(name.string());
   if (ext != null) tb.add(',').addExt(ext);
   return tb.toString();
 }
예제 #3
0
 @Override
 public String toString() {
   final int es = expr.length;
   final TokenBuilder tb = new TokenBuilder(expr[es - 1].toString()).add('(');
   for (int e = 0; e < es - 1; e++) {
     tb.add(expr[e].toString());
     if (e < es - 2) tb.add(", ");
   }
   return tb.add(')').toString();
 }
예제 #4
0
파일: Dur.java 프로젝트: james-jw/basex
 @Override
 public byte[] string(final InputInfo ii) {
   final TokenBuilder tb = new TokenBuilder();
   final int ss = sec.signum();
   if (mon < 0 || ss < 0) tb.add('-');
   date(tb);
   time(tb);
   if (mon == 0 && ss == 0) tb.add("T0S");
   return tb.finish();
 }
예제 #5
0
 @Override
 public String toString() {
   final TokenBuilder tb = new TokenBuilder("map { ");
   boolean key = true;
   for (final Expr e : expr) {
     tb.add(key ? tb.size() > 6 ? ", " : "" : ":=").add(e.toString());
     key ^= true;
   }
   return tb.add(" }").toString();
 }
예제 #6
0
파일: ADate.java 프로젝트: jefferya/basex
 /**
  * Adds the time zone to the specified token builder.
  *
  * @param tb token builder
  */
 void zone(final TokenBuilder tb) {
   if (tz == Short.MAX_VALUE) return;
   if (tz == 0) {
     tb.add('Z');
   } else {
     tb.add(tz > 0 ? '+' : '-');
     prefix(tb, Math.abs(tz) / 60, 2);
     tb.add(':');
     prefix(tb, Math.abs(tz) % 60, 2);
   }
 }
예제 #7
0
파일: Dur.java 프로젝트: james-jw/basex
 /**
  * Adds the time to the specified token builder.
  *
  * @param tb token builder
  */
 final void time(final TokenBuilder tb) {
   if (sec.remainder(DAYSECONDS).signum() == 0) return;
   tb.add('T');
   final long h = hou();
   if (h != 0) {
     tb.addLong(Math.abs(h));
     tb.add('H');
   }
   final long m = min();
   if (m != 0) {
     tb.addLong(Math.abs(m));
     tb.add('M');
   }
   final BigDecimal sc = sec();
   if (sc.signum() == 0) return;
   tb.add(Token.chopNumber(Token.token(sc.abs().toPlainString()))).add('S');
 }
예제 #8
0
파일: Dur.java 프로젝트: james-jw/basex
 /**
  * Adds the date to the specified token builder.
  *
  * @param tb token builder
  */
 final void date(final TokenBuilder tb) {
   tb.add('P');
   final long y = yea();
   if (y != 0) {
     tb.addLong(Math.abs(y));
     tb.add('Y');
   }
   final long m = mon();
   if (m != 0) {
     tb.addLong(Math.abs(m));
     tb.add('M');
   }
   final long d = day();
   if (d != 0) {
     tb.addLong(Math.abs(d));
     tb.add('D');
   }
 }
예제 #9
0
  /** Tests the specified instance. */
  @Test
  public void test() {
    final StringBuilder sb = new StringBuilder();
    int fail = 0;

    for (final Object[] qu : queries) {
      final boolean correct = qu.length == 3;
      final String query = qu[correct ? 2 : 1].toString();
      final Value cmp = correct ? (Value) qu[1] : null;

      final QueryProcessor qp = new QueryProcessor(query, context);
      try {
        final Value val = qp.value();
        if (!correct || !new DeepCompare().equal(val, cmp)) {
          sb.append("[" + qu[0] + "] " + query);
          String s = correct && cmp.size() != 1 ? "#" + cmp.size() : "";
          sb.append("\n[E" + s + "] ");
          if (correct) {
            final String cp = cmp.toString();
            sb.append('\'');
            sb.append(cp.length() > 1000 ? cp.substring(0, 1000) + "..." : cp);
            sb.append('\'');
          } else {
            sb.append("error");
          }
          final TokenBuilder types = new TokenBuilder();
          for (final Item it : val) types.add(it.type.toString()).add(" ");
          s = val.size() == 1 ? "" : "#" + val.size();
          sb.append("\n[F" + s + "] '" + val + "', " + types + details() + '\n');
          ++fail;
        }
      } catch (final Exception ex) {
        final String msg = ex.getMessage();
        if (correct || msg == null || msg.contains("mailman")) {
          final String cp = correct && cmp.data() != null ? cmp.toString() : "()";
          sb.append(
              "["
                  + qu[0]
                  + "] "
                  + query
                  + "\n[E] "
                  + cp
                  + "\n[F] "
                  + (msg == null ? Util.className(ex) : msg.replaceAll("\r\n?|\n", " "))
                  + ' '
                  + details()
                  + '\n');
          ex.printStackTrace();
          ++fail;
        }
      } finally {
        qp.close();
      }
    }
    if (fail != 0) fail(fail + " Errors. [E] = expected, [F] = found:\n" + sb.toString().trim());
  }
예제 #10
0
파일: ADate.java 프로젝트: jefferya/basex
 @Override
 public byte[] string(final InputInfo ii) {
   final TokenBuilder tb = new TokenBuilder();
   final boolean ymd = yea != Long.MAX_VALUE;
   if (ymd) {
     if (yea <= 0) tb.add('-');
     prefix(tb, Math.abs(yea()), 4);
     tb.add('-');
     prefix(tb, mon(), 2);
     tb.add('-');
     prefix(tb, day(), 2);
   }
   if (hou >= 0) {
     if (ymd) tb.add('T');
     prefix(tb, hou(), 2);
     tb.add(':');
     prefix(tb, min(), 2);
     tb.add(':');
     if (sec.intValue() < 10) tb.add('0');
     tb.addExt(Token.chopNumber(Token.token(sec().abs().toPlainString())));
   }
   zone(tb);
   return tb.finish();
 }
예제 #11
0
파일: ADate.java 프로젝트: jefferya/basex
 /**
  * Prefixes the specified number of zero digits before a number.
  *
  * @param tb token builder
  * @param number number to be printed
  * @param zero maximum number of zero digits
  */
 static void prefix(final TokenBuilder tb, final long number, final int zero) {
   final byte[] t = Token.token(number);
   for (int i = t.length; i < zero; i++) tb.add('0');
   tb.add(t);
 }