/** * Start building a new {@link Criteria}. * * @return the Criteria builder */ public static StartState where() { return new StartState(new Criteria()); }
/** * Translate the {@code tcriteria} to its Java analog. * * @param tcriteria * @return the analogous Java {@link Criteria} */ public static Criteria translateFromThriftCriteria(TCriteria tcriteria) { Criteria criteria = new Criteria(); for (TSymbol tsymbol : tcriteria.getSymbols()) { criteria.add(translateFromThriftSymbol(tsymbol)); } return criteria; }
/** * Return a {@link Criteria} object that expresses the same as the * {@code ccl} statement. * * @param ccl the CCL statement to parse * @return an equivalanet {@link Criteria} object */ public static Criteria parse(String ccl) { Parser parser = Parsers.create(ccl); Criteria criteria = new Criteria(); try { criteria.symbols = Lists.newArrayList(parser.tokenize()); return criteria; } catch (Exception e) { if(e instanceof SyntaxException || e instanceof IllegalStateException || e.getCause() != null && e .getCause() instanceof com.cinchapi.ccl.v2.generated.ParseException) { throw new ParseException( new com.cinchapi.concourse.thrift.ParseException( e.getMessage())); } else { throw CheckedExceptions.throwAsRuntimeException(e); } } }
/** * Return this {@link Criteria} with each expression (e.g. {key} {operator} * {values}) pinned to the specified {@code timestamp}. * * <strong>NOTE:</strong> Any timestamps that are pinned to any expressions * within this Criteria will be replaced by the specified {@code timestamp}. * * @param timestamp the {@link Timestamp} to which the returned * {@link Criteria} is pinned * * @return this {@link Criteria} pinned to {@code timestamp} */ public Criteria at(Timestamp timestamp) { Parser parser = Parsers.create(getCclString()); List<Symbol> symbols = Parsing.groupExpressions(parser.tokenize()); TimestampSymbol ts = new TimestampSymbol(timestamp.getMicros()); symbols.forEach((symbol) -> { if(symbol instanceof Expression) { Expression expression = (Expression) symbol; Reflection.set("timestamp", ts, expression); // (authorized) } }); Criteria criteria = new Criteria(); symbols = Parsing.ungroupExpressions(symbols); criteria.symbols = symbols; return criteria; }