From b20806f5cbfffa1e9a55494ebf2996200e4b092a Mon Sep 17 00:00:00 2001 From: Jeff Nelson Date: Sun, 19 May 2019 19:36:41 -0500 Subject: [PATCH 1/7] Refactor Criteria to be an interface that applies to all buildable states --- .../concourse/lang/BuildableStartState.java | 4 +- .../concourse/lang/BuildableState.java | 23 ++- .../concourse/lang/BuiltCriteria.java | 169 ++++++++++++++++++ .../com/cinchapi/concourse/lang/Criteria.java | 125 +------------ .../com/cinchapi/concourse/lang/KeyState.java | 2 +- .../com/cinchapi/concourse/lang/Language.java | 4 +- .../concourse/lang/OperatorState.java | 2 +- .../cinchapi/concourse/lang/StartState.java | 2 +- .../com/cinchapi/concourse/lang/State.java | 6 +- .../concourse/lang/TimestampState.java | 2 +- .../cinchapi/concourse/lang/ValueState.java | 2 +- .../cinchapi/concourse/lang/CriteriaTest.java | 6 +- .../cinchapi/concourse/lang/ParserTest.java | 58 +++--- 13 files changed, 241 insertions(+), 164 deletions(-) create mode 100644 concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuiltCriteria.java diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuildableStartState.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuildableStartState.java index 9e8fa903a9..282623548a 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuildableStartState.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuildableStartState.java @@ -30,8 +30,8 @@ public class BuildableStartState extends BuildableState { * * @param criteria */ - protected BuildableStartState(Criteria criteria) { + protected BuildableStartState(BuiltCriteria criteria) { super(criteria); } - + } diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuildableState.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuildableState.java index b1d06f0d84..b35287e8ae 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuildableState.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuildableState.java @@ -15,7 +15,11 @@ */ package com.cinchapi.concourse.lang; +import java.util.List; + import com.cinchapi.ccl.grammar.ConjunctionSymbol; +import com.cinchapi.ccl.grammar.Symbol; +import com.cinchapi.concourse.Timestamp; /** * The base class for a language state that can be transformed into a complete @@ -23,14 +27,14 @@ * * @author Jeff Nelson */ -public abstract class BuildableState extends State { +public abstract class BuildableState extends State implements Criteria { /** * Construct a new instance. * * @param criteria */ - protected BuildableState(Criteria criteria) { + protected BuildableState(BuiltCriteria criteria) { super(criteria); } @@ -63,5 +67,20 @@ public StartState or() { criteria.add(ConjunctionSymbol.OR); return new StartState(criteria); } + + @Override + public Criteria at(Timestamp timestamp) { + return build().at(timestamp); + } + + @Override + public String getCclString() { + return build().getCclString(); + } + + @Override + public List symbols() { + return build().symbols(); + } } diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuiltCriteria.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuiltCriteria.java new file mode 100644 index 0000000000..465fa0f00b --- /dev/null +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuiltCriteria.java @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2013-2019 Cinchapi Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.cinchapi.concourse.lang; + +import java.util.Collections; +import java.util.List; +import java.util.Objects; + +import com.cinchapi.ccl.Parser; +import com.cinchapi.ccl.Parsing; +import com.cinchapi.ccl.grammar.Expression; +import com.cinchapi.ccl.grammar.ParenthesisSymbol; +import com.cinchapi.ccl.grammar.Symbol; +import com.cinchapi.ccl.grammar.TimestampSymbol; +import com.cinchapi.common.reflect.Reflection; +import com.cinchapi.concourse.Timestamp; +import com.cinchapi.concourse.util.Parsers; +import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; + +/** + * A {@link Criteria} that has been {@link BuildableState#build()}. + * + * @author Jeff Nelson + */ +public class BuiltCriteria implements Criteria { + + /** + * A flag that indicates whether this {@link Criteria} has been built. + */ + private boolean built = false; + + /** + * The collection of {@link Symbol}s that make up this {@link Criteria}. + */ + List symbols; + + /** + * Construct a new instance. + */ + protected BuiltCriteria() { + this.symbols = Lists.newArrayList(); + } + + /** + * Return this {@link Criteria} with each expression (e.g. {key} {operator} + * {values}) pinned to the specified {@code timestamp}. + * + * NOTE: 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 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) + } + }); + BuiltCriteria criteria = new BuiltCriteria(); + symbols = Parsing.ungroupExpressions(symbols); + criteria.symbols = symbols; + return criteria; + } + + @Override + public boolean equals(Object obj) { + if(obj instanceof Criteria) { + return Objects.equals(symbols, ((Criteria) obj).symbols()); + } + else { + return false; + } + } + + /** + * Return a CCL string that is equivalent to this object. + * + * @return an equivalent CCL string + */ + public String getCclString() { + StringBuilder sb = new StringBuilder(); + boolean first = true; + for (Symbol symbol : symbols) { + if(!first) { + sb.append(" "); + } + sb.append(symbol); + first = false; + } + return sb.toString(); + } + + @Override + public int hashCode() { + return Objects.hash(symbols); + } + + @Override + public List symbols() { + return Collections.unmodifiableList(symbols); + } + + @Override + public String toString() { + return getCclString(); + } + + /** + * Expand any sub/grouped Criteria. + * + * @param symbols + * @param expanded + */ + private void expand(List symbols, List expanded) { + for (Symbol symbol : symbols) { + if(symbol instanceof Criteria) { + expanded.add(ParenthesisSymbol.LEFT); + expand(((Criteria) symbol).symbols(), expanded); + expanded.add(ParenthesisSymbol.RIGHT); + } + else { + expanded.add(symbol); + } + } + } + + /** + * Add a {@link Symbol} to this {@link Criteria}. + * + * @param symbol + */ + protected void add(Symbol symbol) { + Preconditions.checkState(!built, + "Cannot add a symbol to a built Criteria"); + symbols.add(symbol); + } + + /** + * Mark this {@link Criteria} as {@code built}. + */ + protected void close() { + built = !built ? true : built; + List expanded = Lists.newArrayList(); + expand(symbols, expanded); + this.symbols = expanded; + } + +} diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/Criteria.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/Criteria.java index 00123ab67a..cf1d24427f 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/Criteria.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/Criteria.java @@ -15,23 +15,14 @@ */ package com.cinchapi.concourse.lang; -import java.util.Collections; import java.util.List; -import java.util.Objects; - import com.cinchapi.ccl.Parser; -import com.cinchapi.ccl.Parsing; import com.cinchapi.ccl.SyntaxException; -import com.cinchapi.ccl.grammar.Expression; -import com.cinchapi.ccl.grammar.ParenthesisSymbol; import com.cinchapi.ccl.grammar.Symbol; -import com.cinchapi.ccl.grammar.TimestampSymbol; import com.cinchapi.common.base.CheckedExceptions; -import com.cinchapi.common.reflect.Reflection; import com.cinchapi.concourse.ParseException; import com.cinchapi.concourse.Timestamp; import com.cinchapi.concourse.util.Parsers; -import com.google.common.base.Preconditions; import com.google.common.collect.Lists; /** @@ -50,7 +41,7 @@ * * @author Jeff Nelson */ -public class Criteria implements Symbol { +public interface Criteria extends Symbol { /** * Return a {@link Criteria} object that expresses the same as the @@ -61,7 +52,7 @@ public class Criteria implements Symbol { */ public static Criteria parse(String ccl) { Parser parser = Parsers.create(ccl); - Criteria criteria = new Criteria(); + BuiltCriteria criteria = new BuiltCriteria(); try { criteria.symbols = Lists.newArrayList(parser.tokenize()); return criteria; @@ -87,25 +78,9 @@ public static Criteria parse(String ccl) { * @return the Criteria builder */ public static StartState where() { - return new StartState(new Criteria()); + return new StartState(new BuiltCriteria()); } - /** - * A flag that indicates whether this {@link Criteria} has been built. - */ - private boolean built = false; - - /** - * The collection of {@link Symbol}s that make up this {@link Criteria}. - */ - private List symbols; - - /** - * Construct a new instance. - */ - protected Criteria() { - this.symbols = Lists.newArrayList(); - } /** * Return this {@link Criteria} with each expression (e.g. {key} {operator} @@ -119,107 +94,21 @@ protected Criteria() { * * @return this {@link Criteria} pinned to {@code timestamp} */ - public Criteria at(Timestamp timestamp) { - Parser parser = Parsers.create(getCclString()); - List 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; - } - - @Override - public boolean equals(Object obj) { - if(obj instanceof Criteria) { - return Objects.equals(symbols, ((Criteria) obj).symbols); - } - else { - return false; - } - } + public Criteria at(Timestamp timestamp); /** * Return a CCL string that is equivalent to this object. * * @return an equivalent CCL string */ - public String getCclString() { - StringBuilder sb = new StringBuilder(); - boolean first = true; - for (Symbol symbol : symbols) { - if(!first) { - sb.append(" "); - } - sb.append(symbol); - first = false; - } - return sb.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(symbols); - } - - @Override - public String toString() { - return getCclString(); - } - - /** - * Add a {@link Symbol} to this {@link Criteria}. - * - * @param symbol - */ - protected void add(Symbol symbol) { - Preconditions.checkState(!built, - "Cannot add a symbol to a built Criteria"); - symbols.add(symbol); - } - - /** - * Mark this {@link Criteria} as {@code built}. - */ - protected void close() { - built = !built ? true : built; - List expanded = Lists.newArrayList(); - expand(symbols, expanded); - this.symbols = expanded; - } - + public String getCclString(); + /** * Return the order list of symbols that make up this {@link Criteria}. * * @return symbols */ - protected List getSymbols() { - return Collections.unmodifiableList(symbols); - } + public List symbols(); - /** - * Expand any sub/grouped Criteria. - * - * @param symbols - * @param expanded - */ - private void expand(List symbols, List expanded) { - for (Symbol symbol : symbols) { - if(symbol instanceof Criteria) { - expanded.add(ParenthesisSymbol.LEFT); - expand(((Criteria) symbol).symbols, expanded); - expanded.add(ParenthesisSymbol.RIGHT); - } - else { - expanded.add(symbol); - } - } - } } diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/KeyState.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/KeyState.java index a7a4fc70d1..c3492d27b4 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/KeyState.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/KeyState.java @@ -31,7 +31,7 @@ public class KeyState extends State { * * @param criteria */ - protected KeyState(Criteria criteria) { + protected KeyState(BuiltCriteria criteria) { super(criteria); } diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/Language.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/Language.java index 34269c2ad0..54b6ede121 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/Language.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/Language.java @@ -103,7 +103,7 @@ else if(tsymbol.getType() == TSymbolType.TIMESTAMP) { */ public static TCriteria translateToThriftCriteria(Criteria criteria) { List symbols = Lists.newArrayList(); - for (Symbol symbol : criteria.getSymbols()) { + for (Symbol symbol : criteria.symbols()) { symbols.add(translateToThriftSymbol(symbol)); } return new TCriteria(symbols); @@ -116,7 +116,7 @@ public static TCriteria translateToThriftCriteria(Criteria criteria) { * @return the analogous Java {@link Criteria} */ public static Criteria translateFromThriftCriteria(TCriteria tcriteria) { - Criteria criteria = new Criteria(); + BuiltCriteria criteria = new BuiltCriteria(); for (TSymbol tsymbol : tcriteria.getSymbols()) { criteria.add(translateFromThriftSymbol(tsymbol)); } diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/OperatorState.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/OperatorState.java index 1036d61f34..2bee4274c8 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/OperatorState.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/OperatorState.java @@ -29,7 +29,7 @@ public class OperatorState extends State { * * @param criteria */ - protected OperatorState(Criteria criteria) { + protected OperatorState(BuiltCriteria criteria) { super(criteria); } diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/StartState.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/StartState.java index 848afae075..6b996e52b0 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/StartState.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/StartState.java @@ -29,7 +29,7 @@ public class StartState extends State { * * @param criteria */ - public StartState(Criteria criteria) { + public StartState(BuiltCriteria criteria) { super(criteria); } diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/State.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/State.java index e867ab5f88..ab5cb17be4 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/State.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/State.java @@ -30,16 +30,16 @@ public abstract class State { /** - * A reference to the {@link Criteria} that is being built. + * A reference to the {@link BuiltCriteria} that is being built. */ - protected final Criteria criteria; + protected final BuiltCriteria criteria; /** * Construct a new instance. * * @param criteria */ - protected State(Criteria criteria) { + protected State(BuiltCriteria criteria) { this.criteria = criteria; } diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/TimestampState.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/TimestampState.java index 193e52bbac..c6db8aa777 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/TimestampState.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/TimestampState.java @@ -28,7 +28,7 @@ public class TimestampState extends BuildableState { * * @param criteria */ - protected TimestampState(Criteria criteria) { + protected TimestampState(BuiltCriteria criteria) { super(criteria); } diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/ValueState.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/ValueState.java index c86d8ceb58..fc871d6b46 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/ValueState.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/ValueState.java @@ -32,7 +32,7 @@ public class ValueState extends BuildableState { * * @param criteria */ - protected ValueState(Criteria criteria) { + protected ValueState(BuiltCriteria criteria) { super(criteria); } diff --git a/concourse-driver-java/src/test/java/com/cinchapi/concourse/lang/CriteriaTest.java b/concourse-driver-java/src/test/java/com/cinchapi/concourse/lang/CriteriaTest.java index a8b06e4746..8103f8570a 100644 --- a/concourse-driver-java/src/test/java/com/cinchapi/concourse/lang/CriteriaTest.java +++ b/concourse-driver-java/src/test/java/com/cinchapi/concourse/lang/CriteriaTest.java @@ -42,7 +42,7 @@ public class CriteriaTest { public void testCannotAddSymbolToBuiltCriteria() { Criteria criteria = Criteria.where().key("foo") .operator(Operator.EQUALS).value("bar").build(); - criteria.add(new KeySymbol("baz")); + ((BuiltCriteria) criteria).add(new KeySymbol("baz")); } @Test @@ -65,7 +65,7 @@ public void testTimestampPinning() { .build(); Timestamp timestamp = Timestamp.now(); criteria = criteria.at(timestamp); - List symbols = Parsing.groupExpressions(criteria.getSymbols()); + List symbols = Parsing.groupExpressions(criteria.symbols()); symbols.forEach((symbol) -> { if(symbol instanceof Expression) { Expression expression = (Expression) symbol; @@ -86,7 +86,7 @@ public void testTimestampPinningSomeTimestamps() { .build(); Timestamp timestamp = Timestamp.now(); criteria = criteria.at(timestamp); - List symbols = Parsing.groupExpressions(criteria.getSymbols()); + List symbols = Parsing.groupExpressions(criteria.symbols()); symbols.forEach((symbol) -> { if(symbol instanceof Expression) { Expression expression = (Expression) symbol; diff --git a/concourse-server/src/test/java/com/cinchapi/concourse/lang/ParserTest.java b/concourse-server/src/test/java/com/cinchapi/concourse/lang/ParserTest.java index 759d3295f4..ae763f60f2 100644 --- a/concourse-server/src/test/java/com/cinchapi/concourse/lang/ParserTest.java +++ b/concourse-server/src/test/java/com/cinchapi/concourse/lang/ParserTest.java @@ -56,7 +56,7 @@ public void testGroupSingle() { Object value = TestData.getObject(); Criteria criteria = Criteria.where().key(key).operator(operator) .value(value).build(); - List symbols = Parsing.groupExpressions(criteria.getSymbols()); + List symbols = Parsing.groupExpressions(criteria.symbols()); Expression exp = (Expression) symbols.get(0); Assert.assertEquals(1, symbols.size()); Assert.assertEquals(exp.raw().key(), key); @@ -75,7 +75,7 @@ public void testGroupAnd() { Criteria criteria = Criteria.where().key(key0).operator(operator0) .value(value0).and().key(key1).operator(operator1).value(value1) .build(); - List symbols = Parsing.groupExpressions(criteria.getSymbols()); + List symbols = Parsing.groupExpressions(criteria.symbols()); Expression exp0 = (Expression) symbols.get(0); ConjunctionSymbol sym = (ConjunctionSymbol) symbols.get(1); Expression exp1 = (Expression) symbols.get(2); @@ -100,7 +100,7 @@ public void testGroupOr() { Criteria criteria = Criteria.where().key(key0).operator(operator0) .value(value0).or().key(key1).operator(operator1).value(value1) .build(); - List symbols = Parsing.groupExpressions(criteria.getSymbols()); + List symbols = Parsing.groupExpressions(criteria.symbols()); Expression exp0 = (Expression) symbols.get(0); ConjunctionSymbol sym = (ConjunctionSymbol) symbols.get(1); Expression exp1 = (Expression) symbols.get(2); @@ -138,7 +138,7 @@ public void testGroupSub() { .value(value1).or().key(key2).operator(operator2) .value(value2).build()) .build(); - List symbols = Parsing.groupExpressions(criteria.getSymbols()); + List symbols = Parsing.groupExpressions(criteria.symbols()); Expression exp0 = (Expression) symbols.get(0); ConjunctionSymbol sym1 = (ConjunctionSymbol) symbols.get(1); ParenthesisSymbol sym2 = (ParenthesisSymbol) symbols.get(2); @@ -170,7 +170,7 @@ public void testGroupSingleBetween() { Object value1 = TestData.getObject(); Criteria criteria = Criteria.where().key(key).operator(operator) .value(value).value(value1).build(); - List symbols = Parsing.groupExpressions(criteria.getSymbols()); + List symbols = Parsing.groupExpressions(criteria.symbols()); Expression exp = (Expression) symbols.get(0); Assert.assertEquals(1, symbols.size()); Assert.assertEquals(exp.raw().key(), key); @@ -184,7 +184,7 @@ public void testToPostfixNotationSimple() { Criteria criteria = Criteria.where().key("foo") .operator(Operator.EQUALS).value("bar").build(); Queue pfn = Parsing - .toPostfixNotation(criteria.getSymbols()); + .toPostfixNotation(criteria.symbols()); Assert.assertEquals(pfn.size(), 1); Assert.assertEquals(((Expression) Iterables.getOnlyElement(pfn)).key(), new KeySymbol("foo")); @@ -202,7 +202,7 @@ public void testParseCclSimple() { .operator(Operator.EQUALS).value("bar").build(); String ccl = "where foo = bar"; Parser parser = Parsers.create(ccl); - Assert.assertEquals(Parsing.toPostfixNotation(criteria.getSymbols()), + Assert.assertEquals(Parsing.toPostfixNotation(criteria.symbols()), parser.order()); } @@ -212,7 +212,7 @@ public void testToPostfixNotationSimpleBetween() { Criteria criteria = Criteria.where().key("foo") .operator(Operator.BETWEEN).value("bar").value("baz").build(); Queue pfn = Parsing - .toPostfixNotation(criteria.getSymbols()); + .toPostfixNotation(criteria.symbols()); Assert.assertEquals(pfn.size(), 1); Assert.assertEquals(((Expression) Iterables.getOnlyElement(pfn)).key(), new KeySymbol("foo")); @@ -234,10 +234,10 @@ public void testParseCclBetween() { String ccl = "where foo bw bar baz"; String ccl2 = "where foo >< bar baz"; Parser parser = Parsers.create(ccl); - Assert.assertEquals(Parsing.toPostfixNotation(criteria.getSymbols()), + Assert.assertEquals(Parsing.toPostfixNotation(criteria.symbols()), parser.order()); Parser parser2 = Parsers.create(ccl2); - Assert.assertEquals(Parsing.toPostfixNotation(criteria.getSymbols()), + Assert.assertEquals(Parsing.toPostfixNotation(criteria.symbols()), parser2.order()); } @@ -247,7 +247,7 @@ public void testToPostfixNotationSimpleAnd() { .value(1).and().key("b").operator(Operator.EQUALS).value(2) .build(); Queue pfn = Parsing - .toPostfixNotation(criteria.getSymbols()); + .toPostfixNotation(criteria.symbols()); Assert.assertEquals(pfn.size(), 3); Assert.assertEquals(((Expression) Iterables.get(pfn, 0)), new Expression(new KeySymbol("a"), @@ -267,7 +267,7 @@ public void testParseCclSimpleAnd() { .build(); String ccl = "a = 1 and b = 2"; Parser parser = Parsers.create(ccl); - Assert.assertEquals(Parsing.toPostfixNotation(criteria.getSymbols()), + Assert.assertEquals(Parsing.toPostfixNotation(criteria.symbols()), parser.order()); } @@ -277,7 +277,7 @@ public void testToPostfixNotationSimpleOr() { .value(1).or().key("b").operator(Operator.EQUALS).value(2) .build(); Queue pfn = Parsing - .toPostfixNotation(criteria.getSymbols()); + .toPostfixNotation(criteria.symbols()); Assert.assertEquals(pfn.size(), 3); Assert.assertEquals(((Expression) Iterables.get(pfn, 0)), new Expression(new KeySymbol("a"), @@ -297,7 +297,7 @@ public void testParseCclSimpleOr() { .build(); String ccl = "a = 1 or b = 2"; Parser parser = Parsers.create(ccl); - Assert.assertEquals(Parsing.toPostfixNotation(criteria.getSymbols()), + Assert.assertEquals(Parsing.toPostfixNotation(criteria.symbols()), parser.order()); } @@ -307,7 +307,7 @@ public void testToPostfixNotationAndOr() { .value(1).and().key("b").operator(Operator.EQUALS).value(2).or() .key("c").operator(Operator.EQUALS).value(3).build(); Queue pfn = Parsing - .toPostfixNotation(criteria.getSymbols()); + .toPostfixNotation(criteria.symbols()); Assert.assertEquals(pfn.size(), 5); Assert.assertEquals(((Expression) Iterables.get(pfn, 0)), new Expression(new KeySymbol("a"), @@ -332,7 +332,7 @@ public void testParseCclAndOr() { .or().key("c").operator(Operator.EQUALS).value(3).build(); String ccl = "a = '1' and b = 2 or c = 3"; Parser parser = Parsers.create(ccl); - Assert.assertEquals(Parsing.toPostfixNotation(criteria.getSymbols()), + Assert.assertEquals(Parsing.toPostfixNotation(criteria.symbols()), parser.order()); } @@ -345,7 +345,7 @@ public void testToPostfixNotationAndGroupOr() { .value(3).build()) .build(); Queue pfn = Parsing - .toPostfixNotation(criteria.getSymbols()); + .toPostfixNotation(criteria.symbols()); Assert.assertEquals(((Expression) Iterables.get(pfn, 0)), new Expression(new KeySymbol("a"), new OperatorSymbol(Operator.EQUALS), @@ -373,7 +373,7 @@ public void testPostfixNotationAndGroupOr() { .build(); String ccl = "a = 1 and (b = 2 or c = 3)"; Parser parser = Parsers.create(ccl); - Assert.assertEquals(Parsing.toPostfixNotation(criteria.getSymbols()), + Assert.assertEquals(Parsing.toPostfixNotation(criteria.symbols()), parser.order()); } @@ -389,7 +389,7 @@ public void testToPostfixNotationGroupOrAndGroupOr() { .value(4).build()) .build(); Queue pfn = Parsing - .toPostfixNotation(criteria.getSymbols()); + .toPostfixNotation(criteria.symbols()); Assert.assertEquals(((Expression) Iterables.get(pfn, 0)), new Expression(new KeySymbol("a"), new OperatorSymbol(Operator.EQUALS), @@ -425,7 +425,7 @@ public void testParseCclGroupOrAndGroupOr() { .build(); String ccl = "(a = 1 or b = 2) AND (c = 3 or d = 4)"; Parser parser = Parsers.create(ccl); - Assert.assertEquals(Parsing.toPostfixNotation(criteria.getSymbols()), + Assert.assertEquals(Parsing.toPostfixNotation(criteria.symbols()), parser.order()); } @@ -442,7 +442,7 @@ public void testParseCclGroupOrAndGroupOrConjuctions() { .build(); String ccl = "(a = 1 || b = 2) && (c = 3 || d = 4)"; Parser parser = Parsers.create(ccl); - Assert.assertEquals(Parsing.toPostfixNotation(criteria.getSymbols()), + Assert.assertEquals(Parsing.toPostfixNotation(criteria.symbols()), parser.order()); } @@ -460,7 +460,7 @@ public void testParseCclGroupOrAndGroupOrConjuctionsWithSingleAmpersand() { .build(); String ccl = "(a = 1 || b = 2) & (c = 3 || d = 4)"; Parser parser = Parsers.create(ccl); - Assert.assertEquals(Parsing.toPostfixNotation(criteria.getSymbols()), + Assert.assertEquals(Parsing.toPostfixNotation(criteria.symbols()), parser.order()); } @@ -476,7 +476,7 @@ public void testToPostfixNotationGroupOrOrGroupOr() { .value(4).build()) .build(); Queue pfn = Parsing - .toPostfixNotation(criteria.getSymbols()); + .toPostfixNotation(criteria.symbols()); Assert.assertEquals(((Expression) Iterables.get(pfn, 0)), new Expression(new KeySymbol("a"), new OperatorSymbol(Operator.EQUALS), @@ -512,7 +512,7 @@ public void testParseCclGroupOrOrGroupOr() { .build(); String ccl = "(a = 1 or b = 2) or (c = 3 or d = 4)"; Parser parser = Parsers.create(ccl); - Assert.assertEquals(Parsing.toPostfixNotation(criteria.getSymbols()), + Assert.assertEquals(Parsing.toPostfixNotation(criteria.symbols()), parser.order()); } @@ -529,7 +529,7 @@ public void testParseCclGroupOrOrConjuction() { .build(); String ccl = "(a = 1 || b = 2) || (c = 3 || d = 4)"; Parser parser = Parsers.create(ccl); - Assert.assertEquals(Parsing.toPostfixNotation(criteria.getSymbols()), + Assert.assertEquals(Parsing.toPostfixNotation(criteria.symbols()), parser.order()); } @@ -651,7 +651,7 @@ public void testParseCclLocalReferences() { data.put("age", 30); data.put("team", "Cleveland Cavaliers"); Parser parser = Parsers.create(ccl, data); - Assert.assertEquals(Parsing.toPostfixNotation(criteria.getSymbols()), + Assert.assertEquals(Parsing.toPostfixNotation(criteria.symbols()), parser.order()); } @@ -688,7 +688,7 @@ public void testParseCclBetweenWithBothReferences() { data.put("retireAge", 35); data.put("team", "Cleveland Cavaliers"); Parser parser = Parsers.create(ccl, data); - Assert.assertEquals(Parsing.toPostfixNotation(criteria.getSymbols()), + Assert.assertEquals(Parsing.toPostfixNotation(criteria.symbols()), parser.order()); } @@ -702,7 +702,7 @@ public void testParseCclBetweenWithFirstReference() { data.put("age", 30); data.put("team", "Cleveland Cavaliers"); Parser parser = Parsers.create(ccl, data); - Assert.assertEquals(Parsing.toPostfixNotation(criteria.getSymbols()), + Assert.assertEquals(Parsing.toPostfixNotation(criteria.symbols()), parser.order()); } @@ -716,7 +716,7 @@ public void testParseCclBetweenWithSecondReference() { data.put("age", 30); data.put("team", "Cleveland Cavaliers"); Parser parser = Parsers.create(ccl, data); - Assert.assertEquals(Parsing.toPostfixNotation(criteria.getSymbols()), + Assert.assertEquals(Parsing.toPostfixNotation(criteria.symbols()), parser.order()); } From 2d708f58488eb389f992b2063f1ef34da824100b Mon Sep 17 00:00:00 2001 From: Jeff Nelson Date: Sun, 19 May 2019 19:52:08 -0500 Subject: [PATCH 2/7] Remove driver methods that took a generic Object criteria parameter. These are now unnecessary since the Criteria interface is implemented by BuiildableState --- .../com/cinchapi/concourse/Concourse.java | 437 +----------------- .../concourse/ConcourseThriftDriver.java | 152 ------ .../concourse/lang/BuildableState.java | 11 +- .../server/ManagedConcourseServer.java | 83 ---- .../importer/debug/ImportDryRunConcourse.java | 73 --- .../cinchapi/concourse/FindCriteriaTest.java | 19 +- 6 files changed, 23 insertions(+), 752 deletions(-) diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/Concourse.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/Concourse.java index f7ee0309dc..10caa04c31 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/Concourse.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/Concourse.java @@ -827,25 +827,6 @@ public abstract Map>> diff(String key, */ public abstract Set find(Criteria criteria); - /** - * Return the set of records that satisfy the {@code criteria}. - *

- * This method is syntactic sugar for {@link #find(Criteria)}. The only - * difference is that this method takes a in-process {@link Criteria} - * building sequence for convenience. - *

- * - * @param criteria an in-process {@link Criteria} building sequence that - * contains an {@link BuildableState#build() unfinalized}, - * but well-formed filter for the desired records - * @return the records that match the {@code criteria} - */ - public abstract Set find(Object criteria); // this method exists in - // case the caller - // forgets - // to called #build() on - // the CriteriaBuilder - /** * Return the set of records that satisfy the {@code ccl} filter. * @@ -1444,59 +1425,6 @@ public abstract Map get(Collection keys, public abstract Map get(Collection keys, long record, Timestamp timestamp); - /** - * For each of the {@code keys} in every record that matches the - * {@code criteria}, return the stored value that was most recently - * added. - *

- * This method is syntactic sugar for {@link #get(Collection, Criteria)}. - * The only difference is that this method takes a in-process - * {@link Criteria} building sequence for convenience. - *

- * - * @param keys a collection of field names - * @param criteria an in-process {@link Criteria} building sequence that - * contains an {@link BuildableState#build() unfinalized}, - * but well-formed filter for the desired - * records - * @return a {@link Map} associating each of the matching records to another - * {@link Map} associating each of the {@code keys} to the freshest - * value in the field - */ - public abstract Map> get(Collection keys, - Object criteria); - - /** - * For each of the {@code keys} in every record that matches the - * {@code criteria}, return the stored value that was most recently - * added at {@code timestamp}. - *

- * This method is syntactic sugar for - * {@link #get(Collection, Criteria, Timestamp)}. The only difference is - * that this method takes a in-process {@link Criteria} building sequence - * for convenience. - *

- * - * @param keys a collection of field names - * @param criteria an in-process {@link Criteria} building sequence that - * contains an {@link BuildableState#build() unfinalized}, - * but well-formed filter for the desired - * records - * @param timestamp a {@link Timestamp} that represents the historical - * instant to use in the lookup – created from either a - * {@link Timestamp#fromString(String) natural language - * description} of a point in time (i.e. two weeks ago), OR - * the {@link Timestamp#fromMicros(long) number - * of microseconds} since the Unix epoch, OR - * a {@link Timestamp#fromJoda(org.joda.time.DateTime) Joda - * DateTime} object - * @return a {@link Map} associating each of the matching records to another - * {@link Map} associating each of the {@code keys} to the freshest - * value in the field at {@code timestamp} - */ - public abstract Map> get(Collection keys, - Object criteria, Timestamp timestamp); - /** * For each of the {@code keys} in every record that matches the {@code ccl} * filter, return the stored value that was most recently added. @@ -1567,43 +1495,6 @@ public abstract Map> get(Collection keys, public abstract Map> get(Criteria criteria, Timestamp timestamp); - /** - * For every key in every record that matches the {@code criteria}, return - * the stored value that was most recently added. - * - * @param criteria an in-process {@link Criteria} building sequence that - * contains an {@link BuildableState#build() unfinalized}, - * but well-formed filter for the desired - * records - * @return a {@link Map} associating each of the matching records to another - * {@link Map} associating each of the record's keys to the freshest - * value in the field - */ - public abstract Map> get(Object criteria); - - /** - * For every key in every record that matches the {@code criteria}, return - * the stored value that was most recently added at {@code timestamp}. - * - * @param criteria an in-process {@link Criteria} building sequence that - * contains an {@link BuildableState#build() unfinalized}, - * but well-formed filter for the desired - * records - * @param timestamp a {@link Timestamp} that represents the historical - * instant to use in the lookup – created from either a - * {@link Timestamp#fromString(String) natural language - * description} of a point in time (i.e. two weeks ago), OR - * the {@link Timestamp#fromMicros(long) number - * of microseconds} since the Unix epoch, OR - * a {@link Timestamp#fromJoda(org.joda.time.DateTime) Joda - * DateTime} object - * @return a {@link Map} associating each of the matching records to another - * {@link Map} associating each of the record's keys to the freshest - * value in the field at {@code timestamp} - */ - public abstract Map> get(Object criteria, - Timestamp timestamp); - /** * For every key in every record that matches the {@code ccl} filter, return * the stored value that was most recently added. @@ -1747,55 +1638,6 @@ public final T get(String key, Long record, Timestamp timestamp) { return get(key, record.longValue(), timestamp); } - /** - * For every record that matches the {@code criteria}, return the stored - * value in the {@code key} field that was most recently added. - *

- * This method is syntactic sugar for {@link #get(String, Criteria)}. The - * only difference is that this method takes a in-process {@link Criteria} - * building sequence for convenience. - *

- * - * @param criteria an in-process {@link Criteria} building sequence that - * contains an {@link BuildableState#build() unfinalized}, - * but well-formed filter for the desired - * records - * @return a {@link Map} associating each of the matching records to another - * {@link Map} associating each of the record's keys to the freshest - * value in the field - */ - public abstract Map get(String key, Object criteria); - - /** - * For every record that matches the {@code criteria}, return the - * stored value in the {@code key} field that was most recently added at - * {@code timestamp}. - *

- * This method is syntactic sugar for - * {@link #get(String, Criteria, Timestamp)}. The only difference is that - * this method takes a in-process {@link Criteria} building sequence for - * convenience. - *

- * - * @param key the field name - * @param criteria an in-process {@link Criteria} building sequence that - * contains an {@link BuildableState#build() unfinalized}, - * but well-formed filter for the desired - * records - * @param timestamp a {@link Timestamp} that represents the historical - * instant to use in the lookup – created from either a - * {@link Timestamp#fromString(String) natural language - * description} of a point in time (i.e. two weeks ago), OR - * the {@link Timestamp#fromMicros(long) number - * of microseconds} since the Unix epoch, OR - * a {@link Timestamp#fromJoda(org.joda.time.DateTime) Joda - * DateTime} object - * @return a {@link Map} associating each of the matching records to the - * freshest value in the {@code key} field - */ - public abstract Map get(String key, Object criteria, - Timestamp timestamp); - /** * For every record that matches the {@code ccl} filter, return the * stored value in the {@code key} field that was most recently added. @@ -2437,68 +2279,6 @@ public abstract Map>> navigate( public abstract Map>> navigate( Collection keys, long record, Timestamp timestamp); - /** - * Traverse the document-graph along each of the navigation {@code keys}, - * starting at each of the records that match the {@code criteria} and - * return the data contained at each of the destinations. - * - * @param keys a collection of navigation keys - * @param criteria a {@link Criteria} that contains a well-formed filter for - * the desired records - * @return a {@link Map} associating each of the destination {@code records} - * to another {@link Map} associating each of the destination - * {@code keys} to a {@link Set} containing all the values stored in - * the respective fields - * @see https://docs.cinchapi.com/concourse/guide/glossary/#navigation-key - */ - public final Map>> navigate( - Collection keys, Object criteria) { - if(criteria instanceof BuildableState) { - return navigate(keys, ((BuildableState) criteria).build()); - } - else { - throw new IllegalArgumentException(criteria - + " is not a valid argument for the navigate method"); - } - } - - /** - * Traverse the document-graph at {@code timestamp} along each of the - * navigation {@code keys}, starting at each of the records that matched the - * {@code criteria} and return the data contained at each of the - * destinations at {@code timestamp}. - * - * @param keys a collection of navigation keys - * @param criteria a {@link Criteria} that contains a well-formed filter for - * the desired records - * @param timestamp a {@link Timestamp} that represents the historical - * instant to use in the lookup – created from either a - * {@link Timestamp#fromString(String) natural language - * description} of a point in time (i.e. two weeks ago), OR - * the {@link Timestamp#fromMicros(long) number - * of microseconds} since the Unix epoch, OR - * a {@link Timestamp#fromJoda(org.joda.time.DateTime) Joda - * DateTime} object - * @return a {@link Map} associating each of the destination {@code records} - * to another {@link Map} associating each of the destination - * {@code keys} to a {@link Set} containing all the values stored in - * the respective fields at {@code timestamp} - * @see https://docs.cinchapi.com/concourse/guide/glossary/#navigation-key - */ - public final Map>> navigate( - Collection keys, Object criteria, Timestamp timestamp) { - if(criteria instanceof BuildableState) { - return navigate(keys, ((BuildableState) criteria).build(), - timestamp); - } - else { - throw new IllegalArgumentException(criteria - + " is not a valid argument for the navigate method"); - } - } - /** * Traverse the document-graph along each of the navigation {@code keys}, * starting at each of the records that match the {@code criteria} and @@ -2705,68 +2485,6 @@ public final Map> navigate(String key, Long record, return navigate(key, record.longValue(), timestamp); } - /** - * Return all the values stored for {@code key} in every record that - * matches the {@link Criteria} filter. Navigates through the key splited - * with dot(.) operator. - *

- * Iterates only if the key has a link as value which - * points to another record. - *

- * - * @param key the field name - * @param ccl a well-formed criteria expressed using the Concourse Criteria - * Language - * @return a {@link Map} associating each of the the matching records to a - * {@link Set} containing all the values stored in the respective - * field - */ - public final Map> navigate(String key, Object criteria) { - if(criteria instanceof BuildableState) { - return navigate(key, ((BuildableState) criteria).build()); - } - else { - throw new IllegalArgumentException(criteria - + " is not a valid argument for the navigate method"); - } - } - - /** - * Return all the values stored for {@code key} in every record that - * matches the {@link Criteria} filter. Navigates through the key splited - * with dot(.) operator. - *

- * Iterates only if the key has a link as value which - * points to another record. - *

- * - * @param key the field name - * @param ccl a well-formed criteria expressed using the Concourse Criteria - * Language - * @param timestamp a {@link Timestamp} that represents the historical - * instant to use in the lookup – created from either a - * {@link Timestamp#fromString(String) natural language - * description} of a point in time (i.e. two weeks ago), OR - * the {@link Timestamp#fromMicros(long) number - * of microseconds} since the Unix epoch, OR - * a {@link Timestamp#fromJoda(org.joda.time.DateTime) Joda - * DateTime} object - * @return a {@link Map} associating each of the the matching records to a - * {@link Set} containing all the values stored in the respective - * field - */ - public final Map> navigate(String key, Object criteria, - Timestamp timestamp) { - if(criteria instanceof BuildableState) { - return navigate(key, ((BuildableState) criteria).build(), - timestamp); - } - else { - throw new IllegalArgumentException(criteria - + " is not a valid argument for the navigate method"); - } - } - /** * Return all the values stored for {@code key} in every record that * matches the {@code ccl} filter. Navigates through the key splited @@ -3112,60 +2830,7 @@ public abstract Map> select(Collection keys, */ public abstract Map> select(Collection keys, long record, Timestamp timestamp); - - /** - * Return all the values stored for each of the {@code keys} in every record - * that matches the {@code criteria}. - *

- * This method is syntactic sugar for {@link #select(Collection, Criteria)}. - * The only difference is that this method takes a in-process - * {@link Criteria} building sequence for convenience. - *

- * - * @param keys a collection of field names - * @param criteria an in-process {@link Criteria} building sequence that - * contains an {@link BuildableState#build() unfinalized}, - * but well-formed filter for the desired - * records - * @return a {@link Map} associating each of the matching records to another - * {@link Map} associating each of the {@code keys} in that record - * to a {@link Set} containing all the values stored in the - * respective field - */ - public abstract Map>> select( - Collection keys, Object criteria); - - /** - * Return all the values stored for each of the {@code keys} at - * {@code timestamp} in every record that matches the {@code criteria}. - *

- * This method is syntactic sugar for - * {@link #select(Collection, Criteria, Timestamp)}. The only difference is - * that this method takes a in-process {@link Criteria} building sequence - * for convenience. - *

- * - * @param keys a collection of field names - * @param criteria an in-process {@link Criteria} building sequence that - * contains an {@link BuildableState#build() unfinalized}, - * but well-formed filter for the desired - * records - * @param timestamp a {@link Timestamp} that represents the historical - * instant to use in the lookup – created from either a - * {@link Timestamp#fromString(String) natural language - * description} of a point in time (i.e. two weeks ago), OR - * the {@link Timestamp#fromMicros(long) number - * of microseconds} since the Unix epoch, OR - * a {@link Timestamp#fromJoda(org.joda.time.DateTime) Joda - * DateTime} object - * @return a {@link Map} associating each of the matching records to another - * {@link Map} associating each of the {@code keys} in that record - * to a {@link Set} containing all the values stored in the - * respective field at {@code timestamp} - */ - public abstract Map>> select( - Collection keys, Object criteria, Timestamp timestamp); - + /** * Return all the values stored for each of the {@code keys} in every record * that matches the {@code ccl} filter. @@ -3303,56 +2968,6 @@ public final Map> select(Long record, return select(record.longValue(), timestamp); } - /** - * Return all the data from every record that matches {@code criteria}. - *

- * This method is syntactic sugar for {@link #select(Criteria)}. The only - * difference is that this method takes a in-process {@link Criteria} - * building sequence for convenience. - *

- * - * @param keys a collection of field names - * @param criteria an in-process {@link Criteria} building sequence that - * contains an {@link BuildableState#build() unfinalized}, - * but well-formed filter for the desired - * records - * @return a {@link Map} associating each of the matching records to another - * {@link Map} associating each of the {@code keys} in that record - * to a {@link Set} containing all the values stored in the - * respective field - */ - public abstract Map>> select(Object criteria); - - /** - * Return all the data at {@code timestamp} from every record that - * matches the {@code criteria}. - *

- * This method is syntactic sugar for {@link #select(Criteria, Timestamp)}. - * The only difference is that this method takes a in-process - * {@link Criteria} building sequence for convenience. - *

- * - * @param keys a collection of field names - * @param criteria an in-process {@link Criteria} building sequence that - * contains an {@link BuildableState#build() unfinalized}, - * but well-formed filter for the desired - * records - * @param timestamp a {@link Timestamp} that represents the historical - * instant to use in the lookup – created from either a - * {@link Timestamp#fromString(String) natural language - * description} of a point in time (i.e. two weeks ago), OR - * the {@link Timestamp#fromMicros(long) number - * of microseconds} since the Unix epoch, OR - * a {@link Timestamp#fromJoda(org.joda.time.DateTime) Joda - * DateTime} object - * @return a {@link Map} associating each of the matching records to another - * {@link Map} associating each of the {@code keys} in that record - * to a {@link Set} containing all the values stored in the - * respective field at {@code timestamp} - */ - public abstract Map>> select(Object criteria, - Timestamp timestamp); - /** * Return all the data from every record that matches {@code ccl} filter. * @@ -3496,56 +3111,6 @@ public final Set select(String key, Long record, return select(key, record.longValue(), timestamp); } - /** - * Return all the values stored for {@code key} in every record that - * matches the {@code criteria}. - *

- * This method is syntactic sugar for {@link #select(String, Criteria)}. The - * only difference is that this method takes a in-process {@link Criteria} - * building sequence for convenience. - *

- * - * @param key the field name - * @param criteria an in-process {@link Criteria} building sequence that - * contains an {@link BuildableState#build() unfinalized}, - * but well-formed filter for the desired - * records - * @return a {@link Map} associating each of the matching records to a - * {@link Set} containing all the values stored in the respective - * field - */ - public abstract Map> select(String key, Object criteria); - - /** - * Return all the values stored for {@code key} at {@code timestamp} in - * every record that matches the {@code criteria}. - *

- * This method is syntactic sugar for - * {@link #select(String, Criteria, Timestamp)}. The only difference is that - * this method takes a in-process {@link Criteria} building sequence for - * convenience. - *

- * - * @param key the field name - * @param criteria an in-process {@link Criteria} building sequence that - * contains an {@link BuildableState#build() unfinalized}, - * but well-formed filter for the desired - * records - * @param timestamp a {@link Timestamp} that represents the historical - * instant to use in the lookup – created from either a - * {@link Timestamp#fromString(String) natural language - * description} of a point in time (i.e. two weeks ago), OR - * the {@link Timestamp#fromMicros(long) number - * of microseconds} since the Unix epoch, OR - * a {@link Timestamp#fromJoda(org.joda.time.DateTime) Joda - * DateTime} object - * @return a {@link Map} associating each of the matching records to a - * {@link Set} containing all the values stored in the respective - * field at {@code timestamp} - */ - public abstract Map> select(String key, Object criteria, - Timestamp timestamp); - /** * Return all the values stored for {@code key} in every record that * matches the {@code ccl} filter. diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/ConcourseThriftDriver.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/ConcourseThriftDriver.java index a500bcf3e2..dee609f25a 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/ConcourseThriftDriver.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/ConcourseThriftDriver.java @@ -36,7 +36,6 @@ import com.cinchapi.common.base.CheckedExceptions; import com.cinchapi.concourse.config.ConcourseClientPreferences; -import com.cinchapi.concourse.lang.BuildableState; import com.cinchapi.concourse.lang.Criteria; import com.cinchapi.concourse.lang.Language; import com.cinchapi.concourse.security.ClientSecurity; @@ -830,17 +829,6 @@ public Set find(Criteria criteria) { }); } - @Override - public Set find(Object criteria) { - if(criteria instanceof BuildableState) { - return find(((BuildableState) criteria).build()); - } - else { - throw new IllegalArgumentException( - criteria + " is not a valid argument for the find method"); - } - } - @Override public Set find(String ccl) { return execute(() -> { @@ -1063,30 +1051,6 @@ public Map get(Collection keys, long record, }); } - @Override - public Map> get(Collection keys, - Object criteria) { - if(criteria instanceof BuildableState) { - return get(keys, ((BuildableState) criteria).build()); - } - else { - throw new IllegalArgumentException( - criteria + " is not a valid argument for the get method"); - } - } - - @Override - public Map> get(Collection keys, - Object criteria, Timestamp timestamp) { - if(criteria instanceof BuildableState) { - return get(keys, ((BuildableState) criteria).build(), timestamp); - } - else { - throw new IllegalArgumentException( - criteria + " is not a valid argument for the get method"); - } - } - @Override public Map> get(Collection keys, String ccl) { @@ -1172,29 +1136,6 @@ public Map> get(Criteria criteria, }); } - @Override - public Map> get(Object criteria) { - if(criteria instanceof BuildableState) { - return get(((BuildableState) criteria).build()); - } - else { - throw new IllegalArgumentException( - criteria + " is not a valid argument for the get method"); - } - } - - @Override - public Map> get(Object criteria, - Timestamp timestamp) { - if(criteria instanceof BuildableState) { - return get(((BuildableState) criteria).build(), timestamp); - } - else { - throw new IllegalArgumentException( - criteria + " is not a valid argument for the get method"); - } - } - @Override public Map> get(String ccl) { return execute(() -> { @@ -1324,29 +1265,6 @@ public T get(String key, long record, Timestamp timestamp) { }); } - @Override - public Map get(String key, Object criteria) { - if(criteria instanceof BuildableState) { - return get(key, ((BuildableState) criteria).build()); - } - else { - throw new IllegalArgumentException( - criteria + " is not a valid argument for the get method"); - } - } - - @Override - public Map get(String key, Object criteria, - Timestamp timestamp) { - if(criteria instanceof BuildableState) { - return get(key, ((BuildableState) criteria).build(), timestamp); - } - else { - throw new IllegalArgumentException( - criteria + " is not a valid argument for the get method"); - } - } - @SuppressWarnings("unchecked") @Override public Map get(String key, String ccl) { @@ -2112,30 +2030,6 @@ public Map> select(Collection keys, long record, }); } - @Override - public Map>> select(Collection keys, - Object criteria) { - if(criteria instanceof BuildableState) { - return select(keys, ((BuildableState) criteria).build()); - } - else { - throw new IllegalArgumentException(criteria - + " is not a valid argument for the select method"); - } - } - - @Override - public Map>> select(Collection keys, - Object criteria, Timestamp timestamp) { - if(criteria instanceof BuildableState) { - return select(keys, ((BuildableState) criteria).build(), timestamp); - } - else { - throw new IllegalArgumentException(criteria - + " is not a valid argument for the select method"); - } - } - @Override public Map>> select(Collection keys, String ccl) { @@ -2266,29 +2160,6 @@ public Map> select(long record, Timestamp timestamp) { }); } - @Override - public Map>> select(Object criteria) { - if(criteria instanceof BuildableState) { - return select(((BuildableState) criteria).build()); - } - else { - throw new IllegalArgumentException( - criteria + " is not a valid argument for the get method"); - } - } - - @Override - public Map>> select(Object criteria, - Timestamp timestamp) { - if(criteria instanceof BuildableState) { - return select(((BuildableState) criteria).build(), timestamp); - } - else { - throw new IllegalArgumentException( - criteria + " is not a valid argument for the get method"); - } - } - @Override public Map>> select(String ccl) { return execute(() -> { @@ -2420,29 +2291,6 @@ public Set select(String key, long record, Timestamp timestamp) { }); } - @Override - public Map> select(String key, Object criteria) { - if(criteria instanceof BuildableState) { - return select(key, ((BuildableState) criteria).build()); - } - else { - throw new IllegalArgumentException(criteria - + " is not a valid argument for the select method"); - } - } - - @Override - public Map> select(String key, Object criteria, - Timestamp timestamp) { - if(criteria instanceof BuildableState) { - return select(key, ((BuildableState) criteria).build(), timestamp); - } - else { - throw new IllegalArgumentException(criteria - + " is not a valid argument for the select method"); - } - } - @Override public Map> select(String key, String ccl) { return execute(() -> { diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuildableState.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuildableState.java index b35287e8ae..2fb58a8011 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuildableState.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuildableState.java @@ -67,20 +67,25 @@ public StartState or() { criteria.add(ConjunctionSymbol.OR); return new StartState(criteria); } - + @Override public Criteria at(Timestamp timestamp) { return build().at(timestamp); } @Override - public String getCclString() { + public final String getCclString() { return build().getCclString(); } @Override - public List symbols() { + public final List symbols() { return build().symbols(); } + @Override + public final String toString() { + return build().toString(); + } + } diff --git a/concourse-ete-test-core/src/main/java/com/cinchapi/concourse/server/ManagedConcourseServer.java b/concourse-ete-test-core/src/main/java/com/cinchapi/concourse/server/ManagedConcourseServer.java index 4ea893bb79..bad10a7c18 100644 --- a/concourse-ete-test-core/src/main/java/com/cinchapi/concourse/server/ManagedConcourseServer.java +++ b/concourse-ete-test-core/src/main/java/com/cinchapi/concourse/server/ManagedConcourseServer.java @@ -1211,11 +1211,6 @@ public Set find(Criteria criteria) { return invoke("find", Criteria.class).with(criteria); } - @Override - public Set find(Object criteria) { - return invoke("find", Object.class).with(criteria); - } - @Override public Set find(String ccl) { return invoke("find", String.class).with(ccl); @@ -1349,20 +1344,6 @@ public Map get(Collection keys, long record, .with(keys, record, timestamp); } - @Override - public Map> get(Collection keys, - Object criteria) { - return invoke("get", Collection.class, Object.class).with(keys, - criteria); - } - - @Override - public Map> get(Collection keys, - Object criteria, Timestamp timestamp) { - return invoke("get", Collection.class, Object.class, - Timestamp.class).with(keys, criteria, timestamp); - } - @Override public Map> get(Collection keys, String ccl) { @@ -1389,18 +1370,6 @@ public Map> get(Criteria criteria, timestamp); } - @Override - public Map> get(Object criteria) { - return invoke("get", Object.class).with(criteria); - } - - @Override - public Map> get(Object criteria, - Timestamp timestamp) { - return invoke("get", Object.class, Timestamp.class).with(criteria, - timestamp); - } - @Override public Map> get(String ccl) { return invoke("get", String.class).with(ccl); @@ -1443,19 +1412,6 @@ public T get(String key, long record, Timestamp timestamp) { .with(key, record, timestamp); } - @Override - public Map get(String key, Object criteria) { - return invoke("get", String.class, Object.class).with(key, - criteria); - } - - @Override - public Map get(String key, Object criteria, - Timestamp timestamp) { - return invoke("get", String.class, Object.class, Timestamp.class) - .with(key, criteria, timestamp); - } - @Override public Map get(String key, String ccl) { return invoke("get", String.class, String.class).with(key, ccl); @@ -1816,20 +1772,6 @@ public Map> select(Collection keys, Timestamp.class).with(keys, record, timestamp); } - @Override - public Map>> select( - Collection keys, Object criteria) { - return invoke("select", Collection.class, Object.class).with(keys, - criteria); - } - - @Override - public Map>> select( - Collection keys, Object criteria, Timestamp timestamp) { - return invoke("select", Collection.class, Object.class, - Timestamp.class).with(keys, criteria, timestamp); - } - @Override public Map>> select( Collection keys, String ccl) { @@ -1868,18 +1810,6 @@ public Map> select(long record, timestamp); } - @Override - public Map>> select(Object criteria) { - return invoke("select", Object.class).with(criteria); - } - - @Override - public Map>> select(Object criteria, - Timestamp timestamp) { - return invoke("select", Object.class, Timestamp.class) - .with(criteria, timestamp); - } - @Override public Map>> select(String ccl) { return invoke("select", String.class).with(ccl); @@ -1923,19 +1853,6 @@ public Set select(String key, long record, Timestamp timestamp) { .with(key, record, timestamp); } - @Override - public Map> select(String key, Object criteria) { - return invoke("select", String.class, Object.class).with(key, - criteria); - } - - @Override - public Map> select(String key, Object criteria, - Timestamp timestamp) { - return invoke("select", String.class, Object.class, Timestamp.class) - .with(key, criteria, timestamp); - } - @Override public Map> select(String key, String ccl) { return invoke("select", String.class, String.class).with(key, ccl); diff --git a/concourse-import/src/main/java/com/cinchapi/concourse/importer/debug/ImportDryRunConcourse.java b/concourse-import/src/main/java/com/cinchapi/concourse/importer/debug/ImportDryRunConcourse.java index 445c9f199a..3a820dbe58 100644 --- a/concourse-import/src/main/java/com/cinchapi/concourse/importer/debug/ImportDryRunConcourse.java +++ b/concourse-import/src/main/java/com/cinchapi/concourse/importer/debug/ImportDryRunConcourse.java @@ -304,11 +304,6 @@ public Set find(Criteria criteria) { throw new UnsupportedOperationException(); } - @Override - public Set find(Object criteria) { - throw new UnsupportedOperationException(); - } - @Override public Set find(String ccl) { throw new UnsupportedOperationException(); @@ -423,18 +418,6 @@ public Map get(Collection keys, long record, throw new UnsupportedOperationException(); } - @Override - public Map> get(Collection keys, - Object criteria) { - throw new UnsupportedOperationException(); - } - - @Override - public Map> get(Collection keys, - Object criteria, Timestamp timestamp) { - throw new UnsupportedOperationException(); - } - @Override public Map> get(Collection keys, String ccl) { @@ -458,17 +441,6 @@ public Map> get(Criteria criteria, throw new UnsupportedOperationException(); } - @Override - public Map> get(Object criteria) { - throw new UnsupportedOperationException(); - } - - @Override - public Map> get(Object criteria, - Timestamp timestamp) { - throw new UnsupportedOperationException(); - } - @Override public Map> get(String ccl) { throw new UnsupportedOperationException(); @@ -506,17 +478,6 @@ public T get(String key, long record, Timestamp timestamp) { throw new UnsupportedOperationException(); } - @Override - public Map get(String key, Object criteria) { - throw new UnsupportedOperationException(); - } - - @Override - public Map get(String key, Object criteria, - Timestamp timestamp) { - throw new UnsupportedOperationException(); - } - @Override public Map get(String key, String ccl) { throw new UnsupportedOperationException(); @@ -826,18 +787,6 @@ public Map> select(Collection keys, long record, throw new UnsupportedOperationException(); } - @Override - public Map>> select(Collection keys, - Object criteria) { - throw new UnsupportedOperationException(); - } - - @Override - public Map>> select(Collection keys, - Object criteria, Timestamp timestamp) { - throw new UnsupportedOperationException(); - } - @Override public Map>> select(Collection keys, String ccl) { @@ -871,17 +820,6 @@ public Map> select(long record, Timestamp timestamp) { throw new UnsupportedOperationException(); } - @Override - public Map>> select(Object criteria) { - throw new UnsupportedOperationException(); - } - - @Override - public Map>> select(Object criteria, - Timestamp timestamp) { - throw new UnsupportedOperationException(); - } - @Override public Map>> select(String ccl) { throw new UnsupportedOperationException(); @@ -919,17 +857,6 @@ public Set select(String key, long record, Timestamp timestamp) { throw new UnsupportedOperationException(); } - @Override - public Map> select(String key, Object criteria) { - throw new UnsupportedOperationException(); - } - - @Override - public Map> select(String key, Object criteria, - Timestamp timestamp) { - throw new UnsupportedOperationException(); - } - @Override public Map> select(String key, String ccl) { throw new UnsupportedOperationException(); diff --git a/concourse-integration-tests/src/test/java/com/cinchapi/concourse/FindCriteriaTest.java b/concourse-integration-tests/src/test/java/com/cinchapi/concourse/FindCriteriaTest.java index e29b3ea7e8..41d0275839 100644 --- a/concourse-integration-tests/src/test/java/com/cinchapi/concourse/FindCriteriaTest.java +++ b/concourse-integration-tests/src/test/java/com/cinchapi/concourse/FindCriteriaTest.java @@ -90,11 +90,6 @@ public void testBuildableStateParamSucceeds() { .operator(Operator.GREATER_THAN).value(90).build())); } - @Test(expected = IllegalArgumentException.class) - public void testNonBuildableStateParamDoesNotSucceed() { - client.find(new Object()); - } - @Test public void testSimple() { Assert.assertTrue(hasSameResults(Criteria.where().key("graduation_rate") @@ -197,6 +192,20 @@ public void testReproCON_634() { Assert.assertTrue(true); // lack of Exception means test passes } + @Test + public void testFindCriteriaImplicitBuild() { + Assert.assertTrue(hasSameResults(Criteria.where() + .group(Criteria.where().key("graduation_rate") + .operator(Operator.GREATER_THAN).value(90).or() + .key("yield_men").operator(Operator.EQUALS).value(20)) + .and() + .group(Criteria.where().key("percent_undergrad_black") + .operator(Operator.GREATER_THAN_OR_EQUALS).value(5).or() + .key("total_cost_out_state") + .operator(Operator.GREATER_THAN).value(50000) + .build()))); + } + /** * Validate that the {@code criteria} returns the same result in Concourse * as it does in a relational database. From 2ead5cf36c1d0ac79cedebca7e08be444659ecca Mon Sep 17 00:00:00 2001 From: Jeff Nelson Date: Sun, 19 May 2019 19:55:59 -0500 Subject: [PATCH 3/7] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28819f1ff5..d29692cf8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * The `Transform` class contains functions for common data transformations. * Removed the `Strings` utility class in favor of `AnyStrings` from `accent4j`. * Removed the `StringSplitter` framework in favor of the same from `accent4j`. +* Refactored the `Criteria` class into an interface that is implemented by any language symbols that can be immediately transformed to a well-built criteria (e.g. `ValueState` and `TimestampState`). The primary benefit of this change is that methods that took a generic Object parameter and checked whether that object could be built into a `Criteria` have now been removed from the `Concourse` driver since that logic is automatically captured within the new class hiearchy. Another positive side effect of this change is that it is no longer necessary to explicitly build a nested `Criteria` when using the `group` functionality of the `Criteria` builder. #### Version 0.9.6 (February 16, 2019) * Fixed a bug that caused a `ParseException` to be thrown when trying to use a `Criteria` object containing a string value wrapped in single or double quotes out of necessity (i.e. because the value contained a keyword). This bug happened because the wrapping quotes were dropped by Concourse Server when parsing the `Criteria`. From 5571e4e90a21b8d65e79961138da61c937802d8c Mon Sep 17 00:00:00 2001 From: Jeff Nelson Date: Sun, 19 May 2019 19:56:46 -0500 Subject: [PATCH 4/7] fix formatting --- .../src/main/java/com/cinchapi/concourse/Concourse.java | 2 +- .../com/cinchapi/concourse/lang/BuildableStartState.java | 2 +- .../src/main/java/com/cinchapi/concourse/lang/Criteria.java | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/Concourse.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/Concourse.java index 10caa04c31..e702336dd2 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/Concourse.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/Concourse.java @@ -2830,7 +2830,7 @@ public abstract Map> select(Collection keys, */ public abstract Map> select(Collection keys, long record, Timestamp timestamp); - + /** * Return all the values stored for each of the {@code keys} in every record * that matches the {@code ccl} filter. diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuildableStartState.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuildableStartState.java index 282623548a..7351441efc 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuildableStartState.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuildableStartState.java @@ -33,5 +33,5 @@ public class BuildableStartState extends BuildableState { protected BuildableStartState(BuiltCriteria criteria) { super(criteria); } - + } diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/Criteria.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/Criteria.java index cf1d24427f..11f3533253 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/Criteria.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/Criteria.java @@ -16,6 +16,7 @@ package com.cinchapi.concourse.lang; import java.util.List; + import com.cinchapi.ccl.Parser; import com.cinchapi.ccl.SyntaxException; import com.cinchapi.ccl.grammar.Symbol; @@ -81,7 +82,6 @@ public static StartState where() { return new StartState(new BuiltCriteria()); } - /** * Return this {@link Criteria} with each expression (e.g. {key} {operator} * {values}) pinned to the specified {@code timestamp}. @@ -102,7 +102,7 @@ public static StartState where() { * @return an equivalent CCL string */ public String getCclString(); - + /** * Return the order list of symbols that make up this {@link Criteria}. * @@ -110,5 +110,4 @@ public static StartState where() { */ public List symbols(); - } From a6b319229d03bf980183acaab7e6374d0a320dda Mon Sep 17 00:00:00 2001 From: Jeff Nelson Date: Sun, 19 May 2019 20:02:55 -0500 Subject: [PATCH 5/7] Deprecate Criteria#getCclString in favor of Criteria#ccl --- CHANGELOG.md | 1 + .../java/com/cinchapi/concourse/Link.java | 2 +- .../concourse/lang/BuildableState.java | 4 +-- .../concourse/lang/BuiltCriteria.java | 30 ++++++++----------- .../com/cinchapi/concourse/lang/Criteria.java | 13 +++++++- .../com/cinchapi/concourse/util/Parsers.java | 10 +++---- .../cinchapi/concourse/lang/CriteriaTest.java | 2 +- 7 files changed, 34 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d29692cf8c..65f593a648 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ * Removed the `Strings` utility class in favor of `AnyStrings` from `accent4j`. * Removed the `StringSplitter` framework in favor of the same from `accent4j`. * Refactored the `Criteria` class into an interface that is implemented by any language symbols that can be immediately transformed to a well-built criteria (e.g. `ValueState` and `TimestampState`). The primary benefit of this change is that methods that took a generic Object parameter and checked whether that object could be built into a `Criteria` have now been removed from the `Concourse` driver since that logic is automatically captured within the new class hiearchy. Another positive side effect of this change is that it is no longer necessary to explicitly build a nested `Criteria` when using the `group` functionality of the `Criteria` builder. +* Deprecated `Criteria#getCclString` in favor of `Criteria#ccl`. #### Version 0.9.6 (February 16, 2019) * Fixed a bug that caused a `ParseException` to be thrown when trying to use a `Criteria` object containing a string value wrapped in single or double quotes out of necessity (i.e. because the value contained a keyword). This bug happened because the wrapping quotes were dropped by Concourse Server when parsing the `Criteria`. diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/Link.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/Link.java index 3bdf08261e..52f87280b7 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/Link.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/Link.java @@ -118,7 +118,7 @@ public static String toWhere(String ccl) { * resolvable link instruction} */ public static String toWhere(Criteria criteria) { - return toWhere(criteria.getCclString()); + return toWhere(criteria.ccl()); } /** diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuildableState.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuildableState.java index 2fb58a8011..515849a6ee 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuildableState.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuildableState.java @@ -74,8 +74,8 @@ public Criteria at(Timestamp timestamp) { } @Override - public final String getCclString() { - return build().getCclString(); + public final String ccl() { + return build().ccl(); } @Override diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuiltCriteria.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuiltCriteria.java index 465fa0f00b..8760b660e6 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuiltCriteria.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuiltCriteria.java @@ -68,7 +68,7 @@ protected BuiltCriteria() { * @return this {@link Criteria} pinned to {@code timestamp} */ public Criteria at(Timestamp timestamp) { - Parser parser = Parsers.create(getCclString()); + Parser parser = Parsers.create(ccl()); List symbols = Parsing.groupExpressions(parser.tokenize()); TimestampSymbol ts = new TimestampSymbol(timestamp.getMicros()); symbols.forEach((symbol) -> { @@ -84,21 +84,7 @@ public Criteria at(Timestamp timestamp) { } @Override - public boolean equals(Object obj) { - if(obj instanceof Criteria) { - return Objects.equals(symbols, ((Criteria) obj).symbols()); - } - else { - return false; - } - } - - /** - * Return a CCL string that is equivalent to this object. - * - * @return an equivalent CCL string - */ - public String getCclString() { + public String ccl() { StringBuilder sb = new StringBuilder(); boolean first = true; for (Symbol symbol : symbols) { @@ -111,6 +97,16 @@ public String getCclString() { return sb.toString(); } + @Override + public boolean equals(Object obj) { + if(obj instanceof Criteria) { + return Objects.equals(symbols, ((Criteria) obj).symbols()); + } + else { + return false; + } + } + @Override public int hashCode() { return Objects.hash(symbols); @@ -123,7 +119,7 @@ public List symbols() { @Override public String toString() { - return getCclString(); + return ccl(); } /** diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/Criteria.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/Criteria.java index 11f3533253..028e5237f4 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/Criteria.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/Criteria.java @@ -101,7 +101,18 @@ public static StartState where() { * * @return an equivalent CCL string */ - public String getCclString(); + public String ccl(); + + /** + * Return a CCL string that is equivalent to this object. + * + * @return an equivalent CCL string + * @deprecated in favor of {@link #ccl()} + */ + @Deprecated + public default String getCclString() { + return ccl(); + } /** * Return the order list of symbols that make up this {@link Criteria}. diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/util/Parsers.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/util/Parsers.java index df2ab84b37..11f331b7cd 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/util/Parsers.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/util/Parsers.java @@ -36,7 +36,7 @@ public final class Parsers { * @return a {@link Parser} */ public static Parser create(Criteria criteria) { - return create(criteria.getCclString()); + return create(criteria.ccl()); } /** @@ -49,7 +49,7 @@ public static Parser create(Criteria criteria) { */ public static Parser create(Criteria criteria, Multimap data) { - return create(criteria.getCclString(), data); + return create(criteria.ccl(), data); } /** @@ -83,8 +83,7 @@ public static Parser create(String ccl, Multimap data) { * @return a {@link Parser} */ public static Parser create(TCriteria criteria) { - return create( - Language.translateFromThriftCriteria(criteria).getCclString()); + return create(Language.translateFromThriftCriteria(criteria).ccl()); } /** @@ -97,8 +96,7 @@ public static Parser create(TCriteria criteria) { */ public static Parser create(TCriteria criteria, Multimap data) { - return create( - Language.translateFromThriftCriteria(criteria).getCclString(), + return create(Language.translateFromThriftCriteria(criteria).ccl(), data); } diff --git a/concourse-driver-java/src/test/java/com/cinchapi/concourse/lang/CriteriaTest.java b/concourse-driver-java/src/test/java/com/cinchapi/concourse/lang/CriteriaTest.java index 8103f8570a..cfcc49bd76 100644 --- a/concourse-driver-java/src/test/java/com/cinchapi/concourse/lang/CriteriaTest.java +++ b/concourse-driver-java/src/test/java/com/cinchapi/concourse/lang/CriteriaTest.java @@ -101,7 +101,7 @@ public void testParseCcl() { String ccl = "name = jeff AND (company = Cinchapi at 12345 or company = Blavity)"; Criteria criteria = Criteria.parse(ccl); Parser parser1 = Parsers.create(ccl); - Parser parser2 = Parsers.create(criteria.getCclString()); + Parser parser2 = Parsers.create(criteria.ccl()); Assert.assertEquals(Parsing.groupExpressions(parser1.tokenize()), Parsing.groupExpressions(parser2.tokenize())); } From 367400ba07f7f31b33f379713bb85b56af8e6a6e Mon Sep 17 00:00:00 2001 From: Jeff Nelson Date: Mon, 20 May 2019 10:19:45 -0400 Subject: [PATCH 6/7] make method final --- .../main/java/com/cinchapi/concourse/lang/BuildableState.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuildableState.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuildableState.java index 515849a6ee..99f5e51b62 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuildableState.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuildableState.java @@ -69,7 +69,7 @@ public StartState or() { } @Override - public Criteria at(Timestamp timestamp) { + public final Criteria at(Timestamp timestamp) { return build().at(timestamp); } From 107307df51c4fe467a2ba1cbb6c2fc0254aa0b3a Mon Sep 17 00:00:00 2001 From: Jeff Nelson Date: Mon, 20 May 2019 10:36:29 -0400 Subject: [PATCH 7/7] Revert "make method final" This reverts commit 367400ba07f7f31b33f379713bb85b56af8e6a6e. --- .../main/java/com/cinchapi/concourse/lang/BuildableState.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuildableState.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuildableState.java index 99f5e51b62..515849a6ee 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuildableState.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/lang/BuildableState.java @@ -69,7 +69,7 @@ public StartState or() { } @Override - public final Criteria at(Timestamp timestamp) { + public Criteria at(Timestamp timestamp) { return build().at(timestamp); }