- * You can learn more about FAIR in our documentation. + * You can learn more about FAIR in our + * documentation. *
*/ public static final class Fair extends Term { @@ -248,22 +567,18 @@ public Fair(@JsonProperty("value") String fair) { super(fair); } - /** - * Return the Fast Automaton Internal Representation (FAIR). - * - * @return The FAIR. - */ @JsonProperty("value") + @Override public String getFair() { return getValue(); } } - /** * This term represents a regular expression. *- * You can learn more about regular expression in our documentation + * You can learn more about regular expression in our + * documentation *
*/ public static final class Regex extends Term { @@ -276,12 +591,8 @@ public Regex(@JsonProperty("value") String regex) { super(regex); } - /** - * Return the regular expression pattern. - * - * @return The regular expression pattern. - */ @JsonProperty("value") + @Override public String getPattern() { return getValue(); } diff --git a/src/main/java/com/regexsolver/api/dto/Cardinality.java b/src/main/java/com/regexsolver/api/dto/Cardinality.java index f62261b..d4689be 100644 --- a/src/main/java/com/regexsolver/api/dto/Cardinality.java +++ b/src/main/java/com/regexsolver/api/dto/Cardinality.java @@ -9,9 +9,9 @@ */ @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") @JsonSubTypes({ - @JsonSubTypes.Type(value = Cardinality.BigInteger.class, name = "BigInteger"), - @JsonSubTypes.Type(value = Cardinality.Infinite.class, name = "Infinite"), - @JsonSubTypes.Type(value = Cardinality.Integer.class, name = "Integer") + @JsonSubTypes.Type(value = Cardinality.BigInteger.class, name = "bigInteger"), + @JsonSubTypes.Type(value = Cardinality.Infinite.class, name = "infinite"), + @JsonSubTypes.Type(value = Cardinality.Integer.class, name = "integer") }) public abstract class Cardinality { /** diff --git a/src/main/java/com/regexsolver/api/dto/Details.java b/src/main/java/com/regexsolver/api/dto/Details.java deleted file mode 100644 index 0d78d67..0000000 --- a/src/main/java/com/regexsolver/api/dto/Details.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.regexsolver.api.dto; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.regexsolver.api.ResponseContent; -import com.regexsolver.api.Term; - -import java.util.Objects; - -/** - * Contains details about the requested {@link Term}. - */ -public final class Details implements ResponseContent { - private final Cardinality cardinality; - private final Length length; - private final boolean empty; - private final boolean total; - - /** - * @param cardinality the number of possible values. - * @param length the minimum and maximum length of possible values. - * @param empty true if is an empty set (does not contain any value), false otherwise. - * @param total true if is a total set (contains all values), false otherwise. - */ - public Details( - @JsonProperty("cardinality") Cardinality cardinality, - @JsonProperty("length") Length length, - @JsonProperty("empty") boolean empty, - @JsonProperty("total") boolean total - ) { - this.cardinality = cardinality; - this.length = length; - this.empty = empty; - this.total = total; - } - - /** - * @return The number of possible values. - */ - public Cardinality getCardinality() { - return cardinality; - } - - /** - * @return The minimum and maximum length of possible values. - */ - public Length getLength() { - return length; - } - - /** - * @return true if is an empty set (does not contain any value), false otherwise. - */ - public boolean isEmpty() { - return empty; - } - - /** - * @return true if is a total set (contains all values), false otherwise. - */ - public boolean isTotal() { - return total; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) return true; - if (obj == null || obj.getClass() != this.getClass()) return false; - var that = (Details) obj; - return Objects.equals(this.cardinality, that.cardinality) && - Objects.equals(this.length, that.length) && - this.empty == that.empty && - this.total == that.total; - } - - @Override - public int hashCode() { - return Objects.hash(cardinality, length, empty, total); - } - - @Override - public String toString() { - return "Details[" + - "cardinality=" + cardinality + ", " + - "length=" + length + ", " + - "empty=" + empty + ", " + - "total=" + total + ']'; - } -} diff --git a/src/main/java/com/regexsolver/api/dto/Length.java b/src/main/java/com/regexsolver/api/dto/Length.java index 3e1200f..785870e 100644 --- a/src/main/java/com/regexsolver/api/dto/Length.java +++ b/src/main/java/com/regexsolver/api/dto/Length.java @@ -1,6 +1,7 @@ package com.regexsolver.api.dto; import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; @@ -18,8 +19,10 @@ public final class Length { private final Long maximum; /** - * @param minimum the minimum length of possible values, empty if is an empty set. - * @param maximum the maximum length of possible values, empty if the maximum length is infinite or if is an empty set. + * @param minimum the minimum length of possible values, empty if is an empty + * set. + * @param maximum the maximum length of possible values, empty if the maximum + * length is infinite or if is an empty set. */ Length(Long minimum, Long maximum) { this.minimum = minimum; @@ -37,7 +40,8 @@ public OptionalLong getMinimum() { } /** - * @return The maximum length of possible values, empty if the maximum length is infinite or if is an empty set. + * @return The maximum length of possible values, empty if the maximum length is + * infinite or if is an empty set. */ public OptionalLong getMaximum() { if (maximum == null) { @@ -48,8 +52,10 @@ public OptionalLong getMaximum() { @Override public boolean equals(Object obj) { - if (obj == this) return true; - if (obj == null || obj.getClass() != this.getClass()) return false; + if (obj == this) + return true; + if (obj == null || obj.getClass() != this.getClass()) + return false; var that = (Length) obj; return Objects.equals(this.minimum, that.minimum) && Objects.equals(this.maximum, that.maximum); @@ -71,15 +77,41 @@ static class LengthDeserializer extends JsonDeserializer* To start using this library you need to first request an API token at RegexSolver Console, - * then call RegexSolverApiWrapper.initialize("YOUR_TOKEN") to set it. + * set it as environment variable in REGEXSOLVER_API_TOKEN then call RegexSolverApiWrapper.initialize(). *
*
* You can find some examples in our documentation.
diff --git a/src/test/java/com/regexsolver/api/IntegrationTest.java b/src/test/java/com/regexsolver/api/IntegrationTest.java
new file mode 100644
index 0000000..beba50d
--- /dev/null
+++ b/src/test/java/com/regexsolver/api/IntegrationTest.java
@@ -0,0 +1,201 @@
+package com.regexsolver.api;
+
+import com.regexsolver.api.dto.Cardinality;
+import com.regexsolver.api.dto.Length;
+import com.regexsolver.api.exception.ApiError;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.junit.Assert.*;
+
+public class IntegrationTest {
+ @Before
+ public void setUp() throws Exception {
+ RegexSolver.initialize();
+ }
+
+ // Analyze
+
+ @Test
+ public void test_analyze_cardinality() throws Exception {
+ Term term = Term.regex("[0-4]");
+
+ Cardinality cardinality = term.getCardinality();
+ assertEquals("Integer(5)", cardinality.toString());
+ }
+
+ @Test
+ public void test_analyze_dot() throws Exception {
+ Term term = Term.regex("(abc|de)");
+ String dot = term.getDot();
+ assertTrue(dot.startsWith("digraph "));
+ }
+
+ @Test
+ public void test_analyze_empty_string() throws Exception {
+ Term term = Term.regex("");
+ boolean result = term.isEmptyString();
+ assertTrue(result);
+ }
+
+ @Test
+ public void test_analyze_empty() throws Exception {
+ Term term = Term.regex("[]");
+ boolean result = term.isEmpty();
+ assertTrue(result);
+ }
+
+ @Test
+ public void test_analyze_total() throws Exception {
+ Term term = Term.regex(".*");
+ boolean result = term.isTotal();
+ assertTrue(result);
+ }
+
+ @Test
+ public void test_analyze_equivalent() throws Exception {
+ Term term1 = Term.regex("(abc|de)");
+ Term term2 = Term.fair(
+ "