diff --git a/src/main/java/com/speedment/api/field/Field.java b/src/main/java/com/speedment/api/field/Field.java index 88d4c5f4c4..aae0f8d582 100644 --- a/src/main/java/com/speedment/api/field/Field.java +++ b/src/main/java/com/speedment/api/field/Field.java @@ -29,14 +29,6 @@ @Api(version = "2.1") public interface Field { - /** - * Returns if this Field is {@code null} in the given entity. - * - * @param entity to use - * @return if this Field is {@code null} in the given entity - */ - boolean isNullIn(ENTITY entity); - /** * Returns the column name that corresponds to this Field. * @@ -44,4 +36,4 @@ public interface Field { */ String getColumnName(); -} +} \ No newline at end of file diff --git a/src/main/java/com/speedment/api/field/ReferenceComparableField.java b/src/main/java/com/speedment/api/field/ReferenceComparableField.java new file mode 100644 index 0000000000..78a44a8315 --- /dev/null +++ b/src/main/java/com/speedment/api/field/ReferenceComparableField.java @@ -0,0 +1,80 @@ +package com.speedment.api.field; + +import com.speedment.api.annotation.Api; +import com.speedment.api.field.builders.ComparablePredicateBuilder; + +/** + * + * @author pemi + * @param + * @param + */ +@Api(version = "2.1") +public interface ReferenceComparableField> extends ReferenceField { + + /** + * Returns a {@link java.util.function.Predicate} that will evaluate to + * {@code true}, if and only if this Field is equal to the given + * value. + * + * @param value to compare + * @return a Predicate that will evaluate to {@code true}, if and only if + * this Field is equal to the given value + */ + ComparablePredicateBuilder equal(V value); + + /** + * Returns a {@link java.util.function.Predicate} that will evaluate to + * {@code true}, if and only if this Field is not equal to the + * given value. + * + * @param value to compare + * @return a Predicate that will evaluate to {@code true}, if and only if + * this Field is not equal to the given value + */ + ComparablePredicateBuilder notEqual(V value); + + /** + * Returns a {@link java.util.function.Predicate} that will evaluate to + * {@code true}, if and only if this Field is less than the given + * value. + * + * @param value to compare + * @return a Predicate that will evaluate to {@code true}, if and only if + * this Field is less than the given value + */ + ComparablePredicateBuilder lessThan(V value); + + /** + * Returns a {@link java.util.function.Predicate} that will evaluate to + * {@code true}, if and only if this Field is less than or equal + * to the given value. + * + * @param value to compare + * @return a Predicate that will evaluate to {@code true}, if and only if + * this Field is less than or equal to the given value + */ + ComparablePredicateBuilder lessOrEqual(V value); + + /** + * Returns a {@link java.util.function.Predicate} that will evaluate to + * {@code true}, if and only if this Field is greater than + * the given value. + * + * @param value to compare + * @return a Predicate that will evaluate to {@code true}, if and only if + * this Field is greater than the given value + */ + ComparablePredicateBuilder greaterThan(V value); + + /** + * Returns a {@link java.util.function.Predicate} that will evaluate to + * {@code true}, if and only if this Field is greater than or equal + * to the given value. + * + * @param value to compare + * @return a Predicate that will evaluate to {@code true}, if and only if + * this Field is greater than or equal to the given value + */ + ComparablePredicateBuilder greaterOrEqual(V value); +} \ No newline at end of file diff --git a/src/main/java/com/speedment/api/field/ReferenceComparableForeignKeyField.java b/src/main/java/com/speedment/api/field/ReferenceComparableForeignKeyField.java new file mode 100644 index 0000000000..2ca957898e --- /dev/null +++ b/src/main/java/com/speedment/api/field/ReferenceComparableForeignKeyField.java @@ -0,0 +1,14 @@ +package com.speedment.api.field; + +import com.speedment.api.annotation.Api; + +/** + * + * @author pemi + * @param + * @param + * @param + */ +@Api(version = "2.1") +public interface ReferenceComparableForeignKeyField, FK> extends + ReferenceComparableField, ReferenceForeignKeyField {} \ No newline at end of file diff --git a/src/main/java/com/speedment/api/field/ReferenceComparableForeignKeyStringField.java b/src/main/java/com/speedment/api/field/ReferenceComparableForeignKeyStringField.java new file mode 100644 index 0000000000..1f353c4472 --- /dev/null +++ b/src/main/java/com/speedment/api/field/ReferenceComparableForeignKeyStringField.java @@ -0,0 +1,15 @@ +package com.speedment.api.field; + +import com.speedment.api.annotation.Api; + +/** + * + * @author pemi + * @param + * @param + */ +@Api(version = "2.1") +public interface ReferenceComparableForeignKeyStringField extends + ReferenceComparableField, + ReferenceForeignKeyField, + ReferenceComparableStringField {} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/reference/string/StringReferenceField.java b/src/main/java/com/speedment/api/field/ReferenceComparableStringField.java similarity index 50% rename from src/main/java/com/speedment/core/field/reference/string/StringReferenceField.java rename to src/main/java/com/speedment/api/field/ReferenceComparableStringField.java index f4c9c03b2c..385aabea60 100644 --- a/src/main/java/com/speedment/core/field/reference/string/StringReferenceField.java +++ b/src/main/java/com/speedment/api/field/ReferenceComparableStringField.java @@ -1,39 +1,16 @@ -/** - * - * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. - * - * 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.speedment.core.field.reference.string; +package com.speedment.api.field; -import com.speedment.core.field.StandardStringBinaryOperator; -import com.speedment.core.field.reference.ComparableReferenceField; -import com.speedment.core.field.reference.Getter; -import com.speedment.core.field.reference.Setter; +import com.speedment.api.annotation.Api; +import com.speedment.api.field.builders.StringPredicateBuilder; /** - * This class represents a String Reference Field. A String Field maps to a - * {@link String} Column. * * @author pemi - * @param The entity type + * @param */ -public class StringReferenceField extends ComparableReferenceField { - - public StringReferenceField(String columnName, Getter getter, Setter setter) { - super(columnName, getter, setter); - } - +@Api(version = "2.1") +public interface ReferenceComparableStringField extends ReferenceComparableField { + /** * Returns a {@link java.util.function.Predicate} that will evaluate to * {@code true}, if and only if this Field is equal to the given @@ -46,9 +23,7 @@ public StringReferenceField(String columnName, Getter getter, Se * * @see String#compareToIgnoreCase(java.lang.String) */ - public StringBinaryPredicateBuilder equalIgnoreCase(String value) { - return newBinary(value, StandardStringBinaryOperator.EQUAL_IGNORE_CASE); - } + StringPredicateBuilder equalIgnoreCase(String value); /** * Returns a {@link java.util.function.Predicate} that will evaluate to @@ -62,9 +37,7 @@ public StringBinaryPredicateBuilder equalIgnoreCase(String value) { * * @see String#compareToIgnoreCase(java.lang.String) */ - public StringBinaryPredicateBuilder notEqualIgnoreCase(String value) { - return newBinary(value, StandardStringBinaryOperator.NOT_EQUAL_IGNORE_CASE); - } + StringPredicateBuilder notEqualIgnoreCase(String value); /** * Returns a {@link java.util.function.Predicate} that will evaluate to @@ -77,9 +50,7 @@ public StringBinaryPredicateBuilder notEqualIgnoreCase(String value) { * * @see String#startsWith(java.lang.String) */ - public StringBinaryPredicateBuilder startsWith(String value) { - return newBinary(value, StandardStringBinaryOperator.STARTS_WITH); - } + StringPredicateBuilder startsWith(String value); /** * Returns a {@link java.util.function.Predicate} that will evaluate to @@ -92,9 +63,7 @@ public StringBinaryPredicateBuilder startsWith(String value) { * * @see String#endsWith(java.lang.String) */ - public StringBinaryPredicateBuilder endsWith(String value) { - return newBinary(value, StandardStringBinaryOperator.ENDS_WITH); - } + StringPredicateBuilder endsWith(String value); /** * Returns a {@link java.util.function.Predicate} that will evaluate to @@ -107,12 +76,5 @@ public StringBinaryPredicateBuilder endsWith(String value) { * * @see String#endsWith(java.lang.String) */ - public StringBinaryPredicateBuilder contains(String value) { - return newBinary(value, StandardStringBinaryOperator.CONTAINS); - } - - protected StringBinaryPredicateBuilder newBinary(String value, StandardStringBinaryOperator binaryOperator) { - return new StringBinaryPredicateBuilder<>(this, value, binaryOperator); - } - -} + StringPredicateBuilder contains(String value); +} \ No newline at end of file diff --git a/src/main/java/com/speedment/api/field/ReferenceField.java b/src/main/java/com/speedment/api/field/ReferenceField.java new file mode 100644 index 0000000000..01bfb7a9db --- /dev/null +++ b/src/main/java/com/speedment/api/field/ReferenceField.java @@ -0,0 +1,86 @@ +package com.speedment.api.field; + +import com.speedment.api.annotation.Api; +import com.speedment.api.field.methods.Getter; +import com.speedment.api.field.methods.Setter; +import com.speedment.api.field.builders.UnaryPredicateBuilder; +import com.speedment.api.field.builders.SetterBuilder; + +/** + * + * @author pemi + * @param + * @param + */ +@Api(version = "2.1") +public interface ReferenceField extends Field { + + /** + * Returns a reference to the setter for this field. + * + * @return the setter + */ + Setter setter(); + + /** + * Returns a reference to the getter of this field. + * + * @return the getter + */ + Getter getter(); + + /** + * Returns a {@link java.util.function.Function} that will set this field + * to a specific value for a entity and return that entity. + * + * @param newValue the value to set + * @return the function builder + */ + SetterBuilder set(V newValue); + + /** + * Returns the value of this field for the specified entity. + * + * @param entity the entity + * @return the value of the field + */ + V get(ENTITY entity); + + /** + * Returns a {@link java.util.function.Predicate} that will evaluate to + * {@code true}, if and only if this Field is {@code null}. + * + * @return a Predicate that will evaluate to {@code true}, if and + * only if this Field is {@code null} + */ + UnaryPredicateBuilder isNull(); + + /** + * Returns if this Field is {@code null} in the given entity. + * + * @param entity to use + * @return if this Field is {@code null} + */ + default boolean isNullIn(ENTITY entity) { + return isNull().test(entity); + } + + /** + * Returns a {@link java.util.function.Predicate} that will evaluate to + * {@code true}, if and only if this Field is not {@code null}. + * + * @return a Predicate that will evaluate to {@code true}, if and + * only if this Field is not {@code null} + */ + UnaryPredicateBuilder isNotNull(); + + /** + * Returns if this Field is not {@code null} in the given entity. + * + * @param entity to use + * @return if this Field is not {@code null} + */ + default boolean isNotNullIn(ENTITY entity) { + return isNotNull().test(entity); + } +} \ No newline at end of file diff --git a/src/main/java/com/speedment/api/field/ReferenceForeignKeyField.java b/src/main/java/com/speedment/api/field/ReferenceForeignKeyField.java new file mode 100644 index 0000000000..7ee3be06b0 --- /dev/null +++ b/src/main/java/com/speedment/api/field/ReferenceForeignKeyField.java @@ -0,0 +1,30 @@ +package com.speedment.api.field; + +import com.speedment.api.annotation.Api; +import com.speedment.api.field.methods.Getter; + +/** + * + * @author pemi + * @param + * @param + * @param + */ +@Api(version = "2.1") +public interface ReferenceForeignKeyField extends ReferenceField { + /** + * Returns a function that can find a foreign entity pointed out by this + * field. + * + * @return the finder + */ + Getter finder(); + + /** + * Finds and returns the foreign key Entity using the provided Entity. + * + * @param entity to use when finding the foreign key Entity + * @return the foreign key Entity + */ + FK findFrom(ENTITY entity); +} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/BinaryPredicateBuilder.java b/src/main/java/com/speedment/api/field/builders/ComparablePredicateBuilder.java similarity index 63% rename from src/main/java/com/speedment/core/field/BinaryPredicateBuilder.java rename to src/main/java/com/speedment/api/field/builders/ComparablePredicateBuilder.java index db93d84b38..387e85728f 100644 --- a/src/main/java/com/speedment/core/field/BinaryPredicateBuilder.java +++ b/src/main/java/com/speedment/api/field/builders/ComparablePredicateBuilder.java @@ -14,7 +14,11 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.speedment.core.field; +package com.speedment.api.field.builders; + +import com.speedment.api.annotation.Api; +import java.util.function.Predicate; +import com.speedment.api.field.operators.ComparableOperator; /** * @@ -22,10 +26,10 @@ * @param The entity type * @param the value type */ -public interface BinaryPredicateBuilder extends PredicateBuilder { - - V getValueAsObject(); +@Api(version = "2.1") +public interface ComparablePredicateBuilder> extends PredicateBuilder, Predicate { + + ComparableOperator getComparableOperator(); - @Override - BinaryOperator getOperator(); + V getValue(); } \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/PredicateBuilder.java b/src/main/java/com/speedment/api/field/builders/PredicateBuilder.java similarity index 87% rename from src/main/java/com/speedment/core/field/PredicateBuilder.java rename to src/main/java/com/speedment/api/field/builders/PredicateBuilder.java index 6115b965d2..60a7a3c3f5 100644 --- a/src/main/java/com/speedment/core/field/PredicateBuilder.java +++ b/src/main/java/com/speedment/api/field/builders/PredicateBuilder.java @@ -14,8 +14,9 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.speedment.core.field; +package com.speedment.api.field.builders; +import com.speedment.api.annotation.Api; import com.speedment.api.field.Field; /** @@ -23,10 +24,8 @@ * @author pemi * @param Entity type */ +@Api(version = "2.1") public interface PredicateBuilder { - + Field getField(); - - Operator getOperator(); - -} +} \ No newline at end of file diff --git a/src/main/java/com/speedment/api/field/builders/SetterBuilder.java b/src/main/java/com/speedment/api/field/builders/SetterBuilder.java new file mode 100644 index 0000000000..fe23bba026 --- /dev/null +++ b/src/main/java/com/speedment/api/field/builders/SetterBuilder.java @@ -0,0 +1,18 @@ +package com.speedment.api.field.builders; + +import com.speedment.api.annotation.Api; +import com.speedment.api.field.Field; +import java.util.function.Function; + +/** + * + * @author pemi + * @param + * @param + */ +@Api(version = "2.1") +public interface SetterBuilder extends Function { + + Field getField(); + V getValue(); +} \ No newline at end of file diff --git a/src/main/java/com/speedment/api/field/builders/StringPredicateBuilder.java b/src/main/java/com/speedment/api/field/builders/StringPredicateBuilder.java new file mode 100644 index 0000000000..b87021e659 --- /dev/null +++ b/src/main/java/com/speedment/api/field/builders/StringPredicateBuilder.java @@ -0,0 +1,19 @@ +package com.speedment.api.field.builders; + +import com.speedment.api.annotation.Api; +import com.speedment.api.field.operators.StringOperator; +import java.util.function.Predicate; + +/** + * + * @author pemi + * @param + */ +@Api(version = "2.1") +public interface StringPredicateBuilder + extends PredicateBuilder, Predicate { + + StringOperator getStringOperator(); + + String getValue(); +} \ No newline at end of file diff --git a/src/main/java/com/speedment/api/field/builders/UnaryPredicateBuilder.java b/src/main/java/com/speedment/api/field/builders/UnaryPredicateBuilder.java new file mode 100644 index 0000000000..1ced6d0947 --- /dev/null +++ b/src/main/java/com/speedment/api/field/builders/UnaryPredicateBuilder.java @@ -0,0 +1,17 @@ +package com.speedment.api.field.builders; + +import com.speedment.api.annotation.Api; +import com.speedment.api.field.operators.UnaryOperator; +import java.util.function.Predicate; + +/** + * + * @author pemi + * @param + */ +@Api(version = "2.1") +public interface UnaryPredicateBuilder + extends PredicateBuilder, Predicate { + + UnaryOperator getUnaryOperator(); +} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/reference/Getter.java b/src/main/java/com/speedment/api/field/methods/Getter.java similarity index 88% rename from src/main/java/com/speedment/core/field/reference/Getter.java rename to src/main/java/com/speedment/api/field/methods/Getter.java index 011d0e4e93..05650be929 100644 --- a/src/main/java/com/speedment/core/field/reference/Getter.java +++ b/src/main/java/com/speedment/api/field/methods/Getter.java @@ -14,8 +14,9 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.speedment.core.field.reference; +package com.speedment.api.field.methods; +import com.speedment.api.annotation.Api; import java.util.function.Function; /** @@ -23,4 +24,5 @@ * @param the entity * @param the type of the value to return */ +@Api(version = "2.1") public interface Getter extends Function {} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/reference/Setter.java b/src/main/java/com/speedment/api/field/methods/Setter.java similarity index 88% rename from src/main/java/com/speedment/core/field/reference/Setter.java rename to src/main/java/com/speedment/api/field/methods/Setter.java index 9f44615dac..01b9dfb5c2 100644 --- a/src/main/java/com/speedment/core/field/reference/Setter.java +++ b/src/main/java/com/speedment/api/field/methods/Setter.java @@ -14,8 +14,9 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.speedment.core.field.reference; +package com.speedment.api.field.methods; +import com.speedment.api.annotation.Api; import java.util.function.BiFunction; /** @@ -23,4 +24,5 @@ * @param the entity * @param the type of the value to return */ +@Api(version = "2.1") public interface Setter extends BiFunction {} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/BinaryOperator.java b/src/main/java/com/speedment/api/field/operators/ComparableOperator.java similarity index 76% rename from src/main/java/com/speedment/core/field/BinaryOperator.java rename to src/main/java/com/speedment/api/field/operators/ComparableOperator.java index 4a0726729b..73632fe14a 100644 --- a/src/main/java/com/speedment/core/field/BinaryOperator.java +++ b/src/main/java/com/speedment/api/field/operators/ComparableOperator.java @@ -14,13 +14,18 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.speedment.core.field; +package com.speedment.api.field.operators; + +import com.speedment.api.annotation.Api; +import java.util.function.IntPredicate; /** * Marker interface for a BinaryOperator. A BinaryOperator takes two arguments. * * @author Emil Forslund */ -public interface BinaryOperator extends Operator { - -} +@Api(version = "2.1") +public interface ComparableOperator { + + IntPredicate getComparator(); +} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/StandardBinaryOperator.java b/src/main/java/com/speedment/api/field/operators/StandardComparableOperator.java similarity index 79% rename from src/main/java/com/speedment/core/field/StandardBinaryOperator.java rename to src/main/java/com/speedment/api/field/operators/StandardComparableOperator.java index e2218cf799..4fcf47cfe8 100644 --- a/src/main/java/com/speedment/core/field/StandardBinaryOperator.java +++ b/src/main/java/com/speedment/api/field/operators/StandardComparableOperator.java @@ -14,16 +14,19 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.speedment.core.field; +package com.speedment.api.field.operators; +import com.speedment.api.annotation.Api; import java.util.Objects; import java.util.function.IntPredicate; +import java.util.function.Predicate; /** * * @author pemi */ -public enum StandardBinaryOperator implements BinaryOperator { +@Api(version = "2.1") +public enum StandardComparableOperator implements ComparableOperator { EQUAL(i -> i == 0), NOT_EQUAL(i -> i != 0), @@ -34,11 +37,12 @@ public enum StandardBinaryOperator implements BinaryOperator { private final IntPredicate comparator; - StandardBinaryOperator(IntPredicate comparator) { + StandardComparableOperator(IntPredicate comparator) { this.comparator = Objects.requireNonNull(comparator); } + @Override public IntPredicate getComparator() { return comparator; } -} +} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/StandardStringBinaryOperator.java b/src/main/java/com/speedment/api/field/operators/StandardStringOperator.java similarity index 77% rename from src/main/java/com/speedment/core/field/StandardStringBinaryOperator.java rename to src/main/java/com/speedment/api/field/operators/StandardStringOperator.java index 607d9b0730..0f367b0b85 100644 --- a/src/main/java/com/speedment/core/field/StandardStringBinaryOperator.java +++ b/src/main/java/com/speedment/api/field/operators/StandardStringOperator.java @@ -14,8 +14,9 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.speedment.core.field; +package com.speedment.api.field.operators; +import com.speedment.api.annotation.Api; import java.util.Objects; import java.util.function.BiPredicate; @@ -23,7 +24,8 @@ * * @author pemi */ -public enum StandardStringBinaryOperator implements BinaryOperator { +@Api(version = "2.1") +public enum StandardStringOperator implements StringOperator { STARTS_WITH(String::startsWith), ENDS_WITH(String::endsWith), @@ -33,11 +35,12 @@ public enum StandardStringBinaryOperator implements BinaryOperator { private final BiPredicate biPredicate; - StandardStringBinaryOperator(BiPredicate biPredicate) { + StandardStringOperator(BiPredicate biPredicate) { this.biPredicate = Objects.requireNonNull(biPredicate); } - public BiPredicate getComparator() { + @Override + public BiPredicate getStringFilter() { return biPredicate; } -} +} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/StandardUnaryOperator.java b/src/main/java/com/speedment/api/field/operators/StandardUnaryOperator.java similarity index 81% rename from src/main/java/com/speedment/core/field/StandardUnaryOperator.java rename to src/main/java/com/speedment/api/field/operators/StandardUnaryOperator.java index 04f3ec8d3c..60224262c3 100644 --- a/src/main/java/com/speedment/core/field/StandardUnaryOperator.java +++ b/src/main/java/com/speedment/api/field/operators/StandardUnaryOperator.java @@ -14,8 +14,9 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.speedment.core.field; +package com.speedment.api.field.operators; +import com.speedment.api.annotation.Api; import java.util.Objects; import java.util.function.Predicate; @@ -23,7 +24,8 @@ * * @author pemi */ -public enum StandardUnaryOperator implements Operator { +@Api(version = "2.1") +public enum StandardUnaryOperator implements UnaryOperator { IS_NULL(Objects::isNull), IS_NOT_NULL(Objects::nonNull); @@ -34,7 +36,8 @@ public enum StandardUnaryOperator implements Operator { this.predicate = Objects.requireNonNull(predicate); } - public Predicate getComparator() { + @Override + public Predicate getUnaryFilter() { return predicate; } -} +} \ No newline at end of file diff --git a/src/main/java/com/speedment/api/field/operators/StringOperator.java b/src/main/java/com/speedment/api/field/operators/StringOperator.java new file mode 100644 index 0000000000..a837df6f03 --- /dev/null +++ b/src/main/java/com/speedment/api/field/operators/StringOperator.java @@ -0,0 +1,13 @@ +package com.speedment.api.field.operators; + +import com.speedment.api.annotation.Api; +import java.util.function.BiPredicate; + +/** + * + * @author pemi + */ +@Api(version = "2.1") +public interface StringOperator { + BiPredicate getStringFilter(); +} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/UnaryPredicateBuilder.java b/src/main/java/com/speedment/api/field/operators/UnaryOperator.java similarity index 75% rename from src/main/java/com/speedment/core/field/UnaryPredicateBuilder.java rename to src/main/java/com/speedment/api/field/operators/UnaryOperator.java index bc1854f825..fdba4e2f02 100644 --- a/src/main/java/com/speedment/core/field/UnaryPredicateBuilder.java +++ b/src/main/java/com/speedment/api/field/operators/UnaryOperator.java @@ -14,16 +14,16 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.speedment.core.field; +package com.speedment.api.field.operators; + +import com.speedment.api.annotation.Api; +import java.util.function.Predicate; /** * * @author pemi - * @param The entity type */ -public interface UnaryPredicateBuilder extends PredicateBuilder { - - @Override - StandardUnaryOperator getOperator(); - +@Api(version = "2.1") +public interface UnaryOperator { + Predicate getUnaryFilter(); } \ No newline at end of file diff --git a/src/main/java/com/speedment/core/code/model/java/entity/EntityTranslatorSupport.java b/src/main/java/com/speedment/core/code/model/java/entity/EntityTranslatorSupport.java index 6cd79a895c..edd1c8f536 100644 --- a/src/main/java/com/speedment/core/code/model/java/entity/EntityTranslatorSupport.java +++ b/src/main/java/com/speedment/core/code/model/java/entity/EntityTranslatorSupport.java @@ -35,10 +35,10 @@ import com.speedment.api.config.Project; import com.speedment.api.config.Table; import com.speedment.core.exception.SpeedmentException; -import com.speedment.core.field.reference.ComparableReferenceField; -import com.speedment.core.field.reference.ComparableReferenceForeignKeyField; -import com.speedment.core.field.reference.ReferenceField; -import com.speedment.core.field.reference.ReferenceForeignKeyField; +import com.speedment.core.field.ReferenceComparableFieldImpl; +import com.speedment.core.field.newimpl.ComparableReferenceForeignKeyField; +import com.speedment.core.field.ReferenceFieldImpl; +import com.speedment.core.field.ReferenceForeignKeyFieldImpl; import com.speedment.core.field.reference.string.StringReferenceField; import com.speedment.core.field.reference.string.StringReferenceForeignKeyField; import com.speedment.core.encoder.JsonEncoder; @@ -94,7 +94,7 @@ public static Type getReferenceFieldType(File file, Table table, Column column, .add(Generic.of().add(Type.of(mapping))) .add(Generic.of().add(fkType)); } else { - t = Type.of(ReferenceForeignKeyField.class) + t = Type.of(ReferenceForeignKeyFieldImpl.class) .add(Generic.of().add(entityType)) .add(Generic.of().add(Type.of(mapping))) .add(Generic.of().add(fkType)); @@ -108,11 +108,11 @@ public static Type getReferenceFieldType(File file, Table table, Column column, return Type.of(StringReferenceField.class) .add(Generic.of().add(entityType)); } else if (Comparable.class.isAssignableFrom(mapping)) { - return Type.of(ComparableReferenceField.class) + return Type.of(ReferenceComparableFieldImpl.class) .add(Generic.of().add(entityType)) .add(Generic.of().add(Type.of(mapping))); } else { - return Type.of(ReferenceField.class) + return Type.of(ReferenceFieldImpl.class) .add(Generic.of().add(entityType)) .add(Generic.of().add(Type.of(mapping))); } diff --git a/src/main/java/com/speedment/core/encoder/Encoder.java b/src/main/java/com/speedment/core/encoder/Encoder.java index 86a34d347a..6b37df96bd 100644 --- a/src/main/java/com/speedment/core/encoder/Encoder.java +++ b/src/main/java/com/speedment/core/encoder/Encoder.java @@ -19,9 +19,9 @@ import com.speedment.core.field.doubles.DoubleField; import com.speedment.core.field.ints.IntField; import com.speedment.core.field.longs.LongField; -import com.speedment.core.field.reference.ComparableReferenceForeignKeyField; -import com.speedment.core.field.reference.ReferenceField; -import com.speedment.core.field.reference.ReferenceForeignKeyField; +import com.speedment.core.field.newimpl.ComparableReferenceForeignKeyField; +import com.speedment.core.field.ReferenceFieldImpl; +import com.speedment.core.field.ReferenceForeignKeyFieldImpl; import com.speedment.core.field.reference.string.StringReferenceForeignKeyField; import java.util.function.Function; import java.util.function.ToDoubleFunction; @@ -55,7 +55,7 @@ public interface Encoder, OUTP * @param field to add to the renderer * @return a reference to a resulting JsonFormatter */ - R put(ReferenceField field); + R put(ReferenceFieldImpl field); /** * Adds this Integer Field to the output renderer. The field will be @@ -97,7 +97,7 @@ public interface Encoder, OUTP * @param fkFormatter the foreign key {@code JsonFormatter} * @return a reference to a resulting JsonFormatter */ - R put(ReferenceForeignKeyField field, Encoder fkFormatter); + R put(ReferenceForeignKeyFieldImpl field, Encoder fkFormatter); /** * Adds this ComparableReferenceForeignKeyField to the output renderer. The @@ -253,6 +253,6 @@ public interface Encoder, OUTP * @param field to add to the renderer * @return a reference to a resulting JsonFormatter */ - R remove(ReferenceField field); + R remove(ReferenceFieldImpl field); } diff --git a/src/main/java/com/speedment/core/encoder/JsonEncoder.java b/src/main/java/com/speedment/core/encoder/JsonEncoder.java index 12183527d4..44ff3bc970 100644 --- a/src/main/java/com/speedment/core/encoder/JsonEncoder.java +++ b/src/main/java/com/speedment/core/encoder/JsonEncoder.java @@ -22,9 +22,9 @@ import com.speedment.core.field.doubles.DoubleField; import com.speedment.core.field.ints.IntField; import com.speedment.core.field.longs.LongField; -import com.speedment.core.field.reference.ComparableReferenceForeignKeyField; -import com.speedment.core.field.reference.ReferenceField; -import com.speedment.core.field.reference.ReferenceForeignKeyField; +import com.speedment.core.field.newimpl.ComparableReferenceForeignKeyField; +import com.speedment.core.field.ReferenceFieldImpl; +import com.speedment.core.field.ReferenceForeignKeyFieldImpl; import com.speedment.core.field.reference.string.StringReferenceForeignKeyField; import com.speedment.api.Manager; import static com.speedment.util.JavaLanguage.javaVariableName; @@ -42,6 +42,18 @@ import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.joining; /** * @@ -63,7 +75,7 @@ public JsonEncoder() { // Fields @Override - public JsonEncoder put(ReferenceField field) { + public JsonEncoder put(ReferenceFieldImpl field) { return put(jsonField(field), field::getFrom); } @@ -84,7 +96,7 @@ public JsonEncoder put(DoubleField field) { // Foreign key fields. @Override - public JsonEncoder put(ReferenceForeignKeyField field, Encoder builder) { + public JsonEncoder put(ReferenceForeignKeyFieldImpl field, Encoder builder) { return put(jsonField(field), field::findFrom, builder); } @@ -151,7 +163,7 @@ public JsonEncoder remove(String label) { } @Override - public JsonEncoder remove(ReferenceField field) { + public JsonEncoder remove(ReferenceFieldImpl field) { getters.remove(jsonField(field)); return this; } diff --git a/src/main/java/com/speedment/core/field/BaseFunction.java b/src/main/java/com/speedment/core/field/BaseFunction.java deleted file mode 100644 index 7257be45f0..0000000000 --- a/src/main/java/com/speedment/core/field/BaseFunction.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * - * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. - * - * 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.speedment.core.field; - -import java.util.function.Function; - -/** - * - * @author Emil - * @param the entity - */ -public abstract class BaseFunction implements Function { - - @Override - public Function compose(Function before) { - throw new UnsupportedOperationException("Optimized functions does not support 'compose'."); - } - - @Override - public Function andThen(Function after) { - throw new UnsupportedOperationException("Optimized functions does not support 'andThen'."); - } -} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/CombinedBaseFunction.java b/src/main/java/com/speedment/core/field/CombinedBaseFunction.java deleted file mode 100644 index 334c351f42..0000000000 --- a/src/main/java/com/speedment/core/field/CombinedBaseFunction.java +++ /dev/null @@ -1,106 +0,0 @@ -/** - * - * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. - * - * 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.speedment.core.field; - -import java.util.ArrayList; -import java.util.List; -import java.util.function.Function; -import java.util.stream.Stream; - -import static java.util.Objects.requireNonNull; - -/** - * @author Emil Forslund - * @param the entity - */ -public final class CombinedBaseFunction extends BaseFunction { - - private final List> functions; - - /** - * Initialize this class. - * - * @param first the first function to include - * @param second the second function to include - */ - public CombinedBaseFunction(Function first, Function second) { - functions = new ArrayList<>(); - add(requireNonNull(first)); - add(requireNonNull(second)); - } - - /** - * Adds the provided Function to this CombinedBaseFunction. - * - * @param function to add - * @return a reference to a CombinedFunction after the method has been applied - */ - protected final CombinedBaseFunction add(Function function) { - if (getClass().equals(function.getClass())) { - @SuppressWarnings("unchecked") - final CombinedBaseFunction cbp = getClass().cast(function); - cbp.stream().forEachOrdered(functions::add); - } else { - functions.add(function); - } - - return this; - } - - /** - * Removes the provided Function from this CombinedBaseFunction. - * - * @param function to remove - * @return a reference to a CombinedFunction after the method has been applied - */ - protected CombinedBaseFunction remove(Function function) { - functions.remove(function); - return this; - } - - /** - * Creates and returns a {link Stream} of all functions that this CombinedBaseFunction holds. - * - * @return a {link Stream} of all predicates that this CombinedBaseFunction holds - */ - public Stream> stream() { - return functions.stream(); - } - - /** - * Returns the number of functions that this CombinedBaseFunction holds - * - * @return the number of functions that this CombinedBaseFunction holds - */ - public int size() { - return functions.size(); - } - - /** - * {@inheritDoc} - */ - @Override - public ENTITY apply(ENTITY entity) { - ENTITY current = entity; - - for (Function function : functions) { - current = function.apply(current); - } - - return current; - } -} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/FunctionBuilder.java b/src/main/java/com/speedment/core/field/FunctionBuilder.java deleted file mode 100644 index 3e0c6b97a7..0000000000 --- a/src/main/java/com/speedment/core/field/FunctionBuilder.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * - * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. - * - * 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.speedment.core.field; - -import com.speedment.api.field.Field; - -/** - * - * @author Emil Forslund - * @param Entity type - */ -public interface FunctionBuilder { - - Field getField(); - -} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/Operator.java b/src/main/java/com/speedment/core/field/Operator.java deleted file mode 100644 index 3f7fef8d59..0000000000 --- a/src/main/java/com/speedment/core/field/Operator.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * - * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. - * - * 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.speedment.core.field; - -/** - * - * @author pemi - */ -public interface Operator { - -} diff --git a/src/main/java/com/speedment/core/field/reference/ComparableReferenceField.java b/src/main/java/com/speedment/core/field/ReferenceComparableFieldImpl.java similarity index 62% rename from src/main/java/com/speedment/core/field/reference/ComparableReferenceField.java rename to src/main/java/com/speedment/core/field/ReferenceComparableFieldImpl.java index ef426a9941..b4687b8b83 100644 --- a/src/main/java/com/speedment/core/field/reference/ComparableReferenceField.java +++ b/src/main/java/com/speedment/core/field/ReferenceComparableFieldImpl.java @@ -14,9 +14,15 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.speedment.core.field.reference; +package com.speedment.core.field; -import com.speedment.core.field.StandardBinaryOperator; +import com.speedment.api.field.methods.Getter; +import com.speedment.api.field.methods.Setter; +import com.speedment.api.field.operators.StandardComparableOperator; +import com.speedment.api.field.ReferenceComparableField; +import com.speedment.core.field.builders.ComparablePredicateBuilderImpl; +import java.util.Comparator; +import com.speedment.api.field.builders.ComparablePredicateBuilder; /** * This class represents a Comparable Reference Field. A Reference Field is @@ -26,9 +32,11 @@ * @param The entity type * @param The value type */ -public class ComparableReferenceField> extends ReferenceField { +public class ReferenceComparableFieldImpl> + extends ReferenceFieldImpl + implements ReferenceComparableField { - public ComparableReferenceField(String columnName, Getter getter, Setter setter) { + public ReferenceComparableFieldImpl(String columnName, Getter getter, Setter setter) { super(columnName, getter, setter); } @@ -41,8 +49,9 @@ public ComparableReferenceField(String columnName, Getter getter, Set * @return a Predicate that will evaluate to {@code true}, if and only if * this Field is equal to the given value */ - public ReferenceBinaryPredicateBuilder equal(V value) { - return newBinary(value, StandardBinaryOperator.EQUAL); + @Override + public ComparablePredicateBuilder equal(V value) { + return newBinary(value, StandardComparableOperator.EQUAL); } /** @@ -54,8 +63,9 @@ public ReferenceBinaryPredicateBuilder equal(V value) { * @return a Predicate that will evaluate to {@code true}, if and only if * this Field is not equal to the given value */ - public ReferenceBinaryPredicateBuilder notEqual(V value) { - return newBinary(value, StandardBinaryOperator.NOT_EQUAL); + @Override + public ComparablePredicateBuilder notEqual(V value) { + return newBinary(value, StandardComparableOperator.NOT_EQUAL); } /** @@ -67,8 +77,9 @@ public ReferenceBinaryPredicateBuilder notEqual(V value) { * @return a Predicate that will evaluate to {@code true}, if and only if * this Field is less than the given value */ - public ReferenceBinaryPredicateBuilder lessThan(V value) { - return newBinary(value, StandardBinaryOperator.LESS_THAN); + @Override + public ComparablePredicateBuilder lessThan(V value) { + return newBinary(value, StandardComparableOperator.LESS_THAN); } /** @@ -80,8 +91,9 @@ public ReferenceBinaryPredicateBuilder lessThan(V value) { * @return a Predicate that will evaluate to {@code true}, if and only if * this Field is less than or equal to the given value */ - public ReferenceBinaryPredicateBuilder lessOrEqual(V value) { - return newBinary(value, StandardBinaryOperator.LESS_OR_EQUAL); + @Override + public ComparablePredicateBuilder lessOrEqual(V value) { + return newBinary(value, StandardComparableOperator.LESS_OR_EQUAL); } /** @@ -93,8 +105,9 @@ public ReferenceBinaryPredicateBuilder lessOrEqual(V value) { * @return a Predicate that will evaluate to {@code true}, if and only if * this Field is greater than the given value */ - public ReferenceBinaryPredicateBuilder greaterThan(V value) { - return newBinary(value, StandardBinaryOperator.GREATER_THAN); + @Override + public ComparablePredicateBuilder greaterThan(V value) { + return newBinary(value, StandardComparableOperator.GREATER_THAN); } /** @@ -106,12 +119,12 @@ public ReferenceBinaryPredicateBuilder greaterThan(V value) { * @return a Predicate that will evaluate to {@code true}, if and only if * this Field is greater than or equal to the given value */ - public ReferenceBinaryPredicateBuilder greaterOrEqual(V value) { - return newBinary(value, StandardBinaryOperator.GREATER_OR_EQUAL); + @Override + public ComparablePredicateBuilder greaterOrEqual(V value) { + return newBinary(value, StandardComparableOperator.GREATER_OR_EQUAL); } - protected ReferenceBinaryPredicateBuilder newBinary(V value, StandardBinaryOperator binaryOperator) { - return new ReferenceBinaryPredicateBuilder<>(this, value, binaryOperator); + protected ComparablePredicateBuilder newBinary(V value, StandardComparableOperator binaryOperator) { + return new ComparablePredicateBuilderImpl<>(this, value, binaryOperator, Comparator.naturalOrder()); } - -} +} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/reference/ComparableReferenceForeignKeyField.java b/src/main/java/com/speedment/core/field/ReferenceComparableForeignKeyFieldImpl.java similarity index 50% rename from src/main/java/com/speedment/core/field/reference/ComparableReferenceForeignKeyField.java rename to src/main/java/com/speedment/core/field/ReferenceComparableForeignKeyFieldImpl.java index c784513239..b5f0012cf1 100644 --- a/src/main/java/com/speedment/core/field/reference/ComparableReferenceForeignKeyField.java +++ b/src/main/java/com/speedment/core/field/ReferenceComparableForeignKeyFieldImpl.java @@ -14,36 +14,40 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.speedment.core.field.reference; +package com.speedment.core.field; + +import com.speedment.api.field.ReferenceComparableForeignKeyField; +import com.speedment.api.field.methods.Getter; +import com.speedment.api.field.methods.Setter; +import static java.util.Objects.requireNonNull; /** + * This class represents a Reference Field that is a Foreign key to another + * table/column. A Reference Field is something that extends {@link Object}. * * @author pemi * @param The entity type * @param The value type * @param The foreign entity type */ -public class ComparableReferenceForeignKeyField, FK> extends ComparableReferenceField { +public class ReferenceComparableForeignKeyFieldImpl, FK> + extends ReferenceComparableFieldImpl + implements ReferenceComparableForeignKeyField { private final Getter finder; - - public ComparableReferenceForeignKeyField( - String columnName, - Getter getter, - Setter setter, - Getter finder) { - + + public ReferenceComparableForeignKeyFieldImpl(String columnName, Getter getter, Setter setter, Getter finder) { super(columnName, getter, setter); - this.finder = finder; + this.finder = requireNonNull(finder); } - /** - * Finds and returns the foreign key Entity using the provided Entity. - * - * @param entity to use when finding the foreign key Entity - * @return the foreign key Entity - */ + @Override public FK findFrom(ENTITY entity) { return finder.apply(entity); } -} + + @Override + public Getter finder() { + return finder; + } +} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/ReferenceComparableForeignKeyStringFieldImpl.java b/src/main/java/com/speedment/core/field/ReferenceComparableForeignKeyStringFieldImpl.java new file mode 100644 index 0000000000..200e479686 --- /dev/null +++ b/src/main/java/com/speedment/core/field/ReferenceComparableForeignKeyStringFieldImpl.java @@ -0,0 +1,33 @@ +package com.speedment.core.field; + +import com.speedment.api.field.ReferenceComparableForeignKeyStringField; +import com.speedment.api.field.methods.Getter; +import com.speedment.api.field.methods.Setter; + +/** + * + * @author pemi + * @param + * @param + */ +public class ReferenceComparableForeignKeyStringFieldImpl + extends ReferenceComparableStringFieldImpl + implements ReferenceComparableForeignKeyStringField { + + private final Getter finder; + + public ReferenceComparableForeignKeyStringFieldImpl(String columnName, Getter getter, Setter setter, Getter finder) { + super(columnName, getter, setter); + this.finder = finder; + } + + @Override + public Getter finder() { + return finder; + } + + @Override + public FK findFrom(ENTITY entity) { + return finder.apply(entity); + } +} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/ReferenceComparableStringFieldImpl.java b/src/main/java/com/speedment/core/field/ReferenceComparableStringFieldImpl.java new file mode 100644 index 0000000000..32bef30d37 --- /dev/null +++ b/src/main/java/com/speedment/core/field/ReferenceComparableStringFieldImpl.java @@ -0,0 +1,51 @@ +package com.speedment.core.field; + +import com.speedment.api.field.ReferenceComparableStringField; +import com.speedment.api.field.methods.Getter; +import com.speedment.api.field.methods.Setter; +import com.speedment.api.field.operators.StandardStringOperator; +import com.speedment.core.field.builders.StringPredicateBuilderImpl; +import com.speedment.api.field.builders.StringPredicateBuilder; + +/** + * + * @author pemi + * @param + */ +public class ReferenceComparableStringFieldImpl + extends ReferenceComparableFieldImpl + implements ReferenceComparableStringField { + + public ReferenceComparableStringFieldImpl(String columnName, Getter getter, Setter setter) { + super(columnName, getter, setter); + } + + @Override + public StringPredicateBuilder equalIgnoreCase(String value) { + return newBinary(value, StandardStringOperator.EQUAL_IGNORE_CASE); + } + + @Override + public StringPredicateBuilder notEqualIgnoreCase(String value) { + return newBinary(value, StandardStringOperator.NOT_EQUAL_IGNORE_CASE); + } + + @Override + public StringPredicateBuilder startsWith(String value) { + return newBinary(value, StandardStringOperator.STARTS_WITH); + } + + @Override + public StringPredicateBuilder endsWith(String value) { + return newBinary(value, StandardStringOperator.ENDS_WITH); + } + + @Override + public StringPredicateBuilder contains(String value) { + return newBinary(value, StandardStringOperator.CONTAINS); + } + + protected StringPredicateBuilder newBinary(String value, StandardStringOperator binaryOperator) { + return new StringPredicateBuilderImpl<>(this, value, binaryOperator); + } +} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/ReferenceFieldImpl.java b/src/main/java/com/speedment/core/field/ReferenceFieldImpl.java new file mode 100644 index 0000000000..1edad1ecc3 --- /dev/null +++ b/src/main/java/com/speedment/core/field/ReferenceFieldImpl.java @@ -0,0 +1,87 @@ +/** + * + * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. + * + * 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.speedment.core.field; + +import com.speedment.api.field.methods.Getter; +import com.speedment.api.field.methods.Setter; +import com.speedment.api.field.ReferenceField; +import com.speedment.api.field.operators.StandardUnaryOperator; + +import com.speedment.api.field.builders.UnaryPredicateBuilder; +import com.speedment.core.field.builders.SetterBuilderImpl; +import com.speedment.core.field.builders.UnaryPredicateBuilderImpl; +import static java.util.Objects.requireNonNull; +import static java.util.Objects.requireNonNull; +import com.speedment.api.field.builders.SetterBuilder; +import static java.util.Objects.requireNonNull; +import static java.util.Objects.requireNonNull; + +/** + * This class represents a Reference Field. A Reference Field is something that + * extends {@link Object}. + * + * @author pemi + * @param The entity type + * @param The value type + */ +public class ReferenceFieldImpl implements ReferenceField { + + private final String columnName; + private final Getter getter; + private final Setter setter; + + public ReferenceFieldImpl(String columnName, Getter getter, Setter setter) { + this.columnName = requireNonNull(columnName); + this.getter = requireNonNull(getter); + this.setter = requireNonNull(setter); + } + + @Override + public String getColumnName() { + return columnName; + } + + @Override + public UnaryPredicateBuilder isNull() { + return new UnaryPredicateBuilderImpl<>(this, StandardUnaryOperator.IS_NULL); + } + + @Override + public UnaryPredicateBuilder isNotNull() { + return new UnaryPredicateBuilderImpl<>(this, StandardUnaryOperator.IS_NOT_NULL); + } + + @Override + public Setter setter() { + return setter; + } + + @Override + public Getter getter() { + return getter; + } + + @Override + public SetterBuilder set(V newValue) { + return new SetterBuilderImpl<>(this, newValue); + } + + @Override + public V get(ENTITY entity) { + return getter().apply(entity); + } +} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/reference/ReferenceForeignKeyField.java b/src/main/java/com/speedment/core/field/ReferenceForeignKeyFieldImpl.java similarity index 61% rename from src/main/java/com/speedment/core/field/reference/ReferenceForeignKeyField.java rename to src/main/java/com/speedment/core/field/ReferenceForeignKeyFieldImpl.java index 1bd014ab82..a0fd47feb2 100644 --- a/src/main/java/com/speedment/core/field/reference/ReferenceForeignKeyField.java +++ b/src/main/java/com/speedment/core/field/ReferenceForeignKeyFieldImpl.java @@ -14,7 +14,12 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.speedment.core.field.reference; +package com.speedment.core.field; + +import com.speedment.api.field.methods.Getter; +import com.speedment.api.field.methods.Setter; +import com.speedment.api.field.ReferenceForeignKeyField; +import static java.util.Objects.requireNonNull; /** * This class represents a Reference Field that is a Foreign key to another @@ -25,22 +30,24 @@ * @param The value type * @param The foreign entity type */ -public class ReferenceForeignKeyField extends ReferenceField { +public class ReferenceForeignKeyFieldImpl + extends ReferenceFieldImpl + implements ReferenceForeignKeyField { private final Getter finder; - public ReferenceForeignKeyField(String columnName, Getter getter, Setter setter, Getter finder) { + public ReferenceForeignKeyFieldImpl(String columnName, Getter getter, Setter setter, Getter finder) { super(columnName, getter, setter); - this.finder = finder; + this.finder = requireNonNull(finder); } - /** - * Finds and returns the foreign key Entity using the provided Entity. - * - * @param entity to use when finding the foreign key Entity - * @return the foreign key Entity - */ + @Override public FK findFrom(ENTITY entity) { return finder.apply(entity); } -} + + @Override + public Getter finder() { + return finder; + } +} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/BasePredicate.java b/src/main/java/com/speedment/core/field/builders/AbstractBasePredicate.java similarity index 75% rename from src/main/java/com/speedment/core/field/BasePredicate.java rename to src/main/java/com/speedment/core/field/builders/AbstractBasePredicate.java index 27a9630899..329d3d1b72 100644 --- a/src/main/java/com/speedment/core/field/BasePredicate.java +++ b/src/main/java/com/speedment/core/field/builders/AbstractBasePredicate.java @@ -14,10 +14,10 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.speedment.core.field; +package com.speedment.core.field.builders; -import com.speedment.core.field.CombinedBasePredicate.AndCombinedBasePredicate; -import com.speedment.core.field.CombinedBasePredicate.OrCombinedBasePredicate; +import com.speedment.core.field.builders.AbstractCombinedBasePredicate.AndCombinedBasePredicate; +import com.speedment.core.field.builders.AbstractCombinedBasePredicate.OrCombinedBasePredicate; import java.util.function.Predicate; /** @@ -27,11 +27,11 @@ * @author pemi * @param Type */ -public abstract class BasePredicate implements Predicate { +public abstract class AbstractBasePredicate implements Predicate { private boolean negated; - public BasePredicate() { + public AbstractBasePredicate() { negated = false; } @@ -46,9 +46,8 @@ public Predicate or(Predicate other) { } @Override - public BasePredicate negate() { + public AbstractBasePredicate negate() { negated = !negated; return this; } - -} +} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/CombinedBasePredicate.java b/src/main/java/com/speedment/core/field/builders/AbstractCombinedBasePredicate.java similarity index 87% rename from src/main/java/com/speedment/core/field/CombinedBasePredicate.java rename to src/main/java/com/speedment/core/field/builders/AbstractCombinedBasePredicate.java index 8440396ebe..412659fbbb 100644 --- a/src/main/java/com/speedment/core/field/CombinedBasePredicate.java +++ b/src/main/java/com/speedment/core/field/builders/AbstractCombinedBasePredicate.java @@ -14,13 +14,12 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.speedment.core.field; +package com.speedment.core.field.builders; import java.util.ArrayList; import java.util.List; import java.util.function.Predicate; import java.util.stream.Stream; - import static java.util.Objects.requireNonNull; /** @@ -30,7 +29,7 @@ * @author pemi * @param the Entity type */ -public abstract class CombinedBasePredicate extends BasePredicate { +public abstract class AbstractCombinedBasePredicate extends AbstractBasePredicate { /** * This enum list all the different types of concrete implementation of the @@ -43,7 +42,7 @@ public enum Type { private final List> predicates; private final Type type; - private CombinedBasePredicate(Type type, Predicate first, Predicate second) { + private AbstractCombinedBasePredicate(Type type, Predicate first, Predicate second) { this.type = type; this.predicates = new ArrayList<>(); add(requireNonNull(first)); @@ -59,10 +58,10 @@ private CombinedBasePredicate(Type type, Predicate first, Predicate> R add(Predicate predicate) { + protected final > R add(Predicate predicate) { if (getClass().equals(predicate.getClass())) { @SuppressWarnings("unchecked") - final CombinedBasePredicate cbp = getClass().cast(predicate); + final AbstractCombinedBasePredicate cbp = getClass().cast(predicate); cbp.stream().forEachOrdered(predicates::add); } else { predicates.add(predicate); @@ -80,7 +79,7 @@ protected final > R add(Predicate remove(Predicate predicate) { + protected AbstractCombinedBasePredicate remove(Predicate predicate) { predicates.remove(predicate); return this; } @@ -120,7 +119,7 @@ public Type getType() { @Override public abstract OrCombinedBasePredicate or(Predicate other); - public static class AndCombinedBasePredicate extends CombinedBasePredicate { + public static class AndCombinedBasePredicate extends AbstractCombinedBasePredicate { public AndCombinedBasePredicate(Predicate first, Predicate second) { super(Type.AND, first, second); @@ -142,7 +141,7 @@ public OrCombinedBasePredicate or(Predicate other) { } } - public static class OrCombinedBasePredicate extends CombinedBasePredicate { + public static class OrCombinedBasePredicate extends AbstractCombinedBasePredicate { public OrCombinedBasePredicate(Predicate first, Predicate second) { super(Type.OR, first, second); diff --git a/src/main/java/com/speedment/core/field/builders/ComparablePredicateBuilderImpl.java b/src/main/java/com/speedment/core/field/builders/ComparablePredicateBuilderImpl.java new file mode 100644 index 0000000000..3a9a3651cb --- /dev/null +++ b/src/main/java/com/speedment/core/field/builders/ComparablePredicateBuilderImpl.java @@ -0,0 +1,76 @@ +/** + * + * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. + * + * 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.speedment.core.field.builders; + +import com.speedment.api.field.ReferenceComparableField; +import java.util.Comparator; +import java.util.Objects; +import com.speedment.api.field.builders.ComparablePredicateBuilder; +import com.speedment.api.field.operators.ComparableOperator; +import static java.util.Objects.requireNonNull; + +/** + * + * @author pemi + * @param Entity type + * @param Value type + */ +public class ComparablePredicateBuilderImpl> + extends AbstractBasePredicate + implements ComparablePredicateBuilder { + + private final ReferenceComparableField field; + private final V value; + private final ComparableOperator operator; + private final Comparator entityComparator; + + public ComparablePredicateBuilderImpl( + final ReferenceComparableField field, + final V value, + final ComparableOperator operator, + final Comparator entityComparator + ) { + this.field = requireNonNull(field); + this.value = value; + this.entityComparator = requireNonNull(entityComparator); + this.operator = requireNonNull(operator); + } + + @Override + public boolean test(final ENTITY entity) { + return test(Objects.compare(field.get(entity), getValue(), entityComparator)); + } + + public boolean test(final int compare) { + return operator.getComparator().test(compare); + } + + @Override + public ComparableOperator getComparableOperator() { + return operator; + } + + @Override + public V getValue() { + return value; + } + + @Override + public ReferenceComparableField getField() { + return field; + } +} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/reference/ReferenceFunctionBuilder.java b/src/main/java/com/speedment/core/field/builders/SetterBuilderImpl.java similarity index 74% rename from src/main/java/com/speedment/core/field/reference/ReferenceFunctionBuilder.java rename to src/main/java/com/speedment/core/field/builders/SetterBuilderImpl.java index 88042b5476..e316764f40 100644 --- a/src/main/java/com/speedment/core/field/reference/ReferenceFunctionBuilder.java +++ b/src/main/java/com/speedment/core/field/builders/SetterBuilderImpl.java @@ -14,38 +14,39 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.speedment.core.field.reference; +package com.speedment.core.field.builders; -import com.speedment.core.field.BaseFunction; import com.speedment.api.field.Field; -import com.speedment.core.field.FunctionBuilder; +import com.speedment.api.field.ReferenceField; +import com.speedment.api.field.builders.SetterBuilder; /** * @author Emil Forslund * @param the entity * @param the value type */ -public class ReferenceFunctionBuilder extends BaseFunction implements FunctionBuilder { +public class SetterBuilderImpl implements SetterBuilder { private final ReferenceField field; private final V newValue; - public ReferenceFunctionBuilder(ReferenceField field, V newValue) { + public SetterBuilderImpl(ReferenceField field, V newValue) { this.field = field; this.newValue = newValue; } - @Override - public ENTITY apply(ENTITY entity) { - return field.setIn(entity, newValue); - } - @Override public Field getField() { return field; } + @Override public V getValue() { return newValue; } + + @Override + public ENTITY apply(ENTITY entity) { + return field.setter().apply(entity, newValue); + } } \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/builders/StringPredicateBuilderImpl.java b/src/main/java/com/speedment/core/field/builders/StringPredicateBuilderImpl.java new file mode 100644 index 0000000000..42cf4b3740 --- /dev/null +++ b/src/main/java/com/speedment/core/field/builders/StringPredicateBuilderImpl.java @@ -0,0 +1,75 @@ +/** + * + * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. + * + * 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.speedment.core.field.builders; + +import com.speedment.api.field.ReferenceComparableStringField; +import java.util.Objects; +import com.speedment.api.field.builders.StringPredicateBuilder; +import com.speedment.api.field.operators.StringOperator; +import static java.util.Objects.requireNonNull; + +/** + * + * @author pemi + * @param Entity type + * + */ +public class StringPredicateBuilderImpl + extends AbstractBasePredicate + implements StringPredicateBuilder { + + private final ReferenceComparableStringField field; + private final String value; + private final StringOperator operator; + + public StringPredicateBuilderImpl( + final ReferenceComparableStringField field, + final String value, + final StringOperator operator + ) { + this.field = requireNonNull(field); + this.value = value; + this.operator = Objects.requireNonNull(operator); + } + + @Override + public boolean test(ENTITY entity) { + final String columnValue = field.get(entity); + + if (columnValue == null || value == null) { + return false; + } else { + return operator.getStringFilter().test(columnValue, value); + } + } + + @Override + public ReferenceComparableStringField getField() { + return field; + } + + @Override + public String getValue() { + return value; + } + + @Override + public StringOperator getStringOperator() { + return operator; + } + +} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/builders/UnaryPredicateBuilderImpl.java b/src/main/java/com/speedment/core/field/builders/UnaryPredicateBuilderImpl.java new file mode 100644 index 0000000000..2b66ff61ca --- /dev/null +++ b/src/main/java/com/speedment/core/field/builders/UnaryPredicateBuilderImpl.java @@ -0,0 +1,62 @@ +/** + * + * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. + * + * 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.speedment.core.field.builders; + +import com.speedment.core.field.ReferenceFieldImpl; +import com.speedment.api.field.operators.StandardUnaryOperator; +import com.speedment.api.field.builders.UnaryPredicateBuilder; +import com.speedment.api.field.operators.UnaryOperator; + +import java.util.Objects; +import static java.util.Objects.requireNonNull; + +/** + * + * @author pemi + * @param Entity type + * @param Value type + */ +public class UnaryPredicateBuilderImpl + extends AbstractBasePredicate + implements UnaryPredicateBuilder { + + private final ReferenceFieldImpl field; + private final UnaryOperator operator; + + public UnaryPredicateBuilderImpl( + final ReferenceFieldImpl field, + final UnaryOperator operator + ) { + this.field = requireNonNull(field); + this.operator = requireNonNull(operator); + } + + @Override + public boolean test(ENTITY entity) { + return operator.getUnaryFilter().test(field.get(entity)); + } + + @Override + public ReferenceFieldImpl getField() { + return field; + } + + @Override + public UnaryOperator getUnaryOperator() { + return operator; + } +} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/doubles/DoubleBinaryPredicateBuilder.java b/src/main/java/com/speedment/core/field/doubles/DoubleBinaryPredicateBuilder.java deleted file mode 100644 index 5592e16622..0000000000 --- a/src/main/java/com/speedment/core/field/doubles/DoubleBinaryPredicateBuilder.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * - * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. - * - * 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.speedment.core.field.doubles; - -import com.speedment.core.field.BasePredicate; -import com.speedment.core.field.BinaryPredicateBuilder; -import com.speedment.core.field.StandardBinaryOperator; -import java.util.Objects; -import java.util.function.Predicate; - -/** - * - * @author pemi - * @param Entity type - */ -public class DoubleBinaryPredicateBuilder extends BasePredicate implements Predicate, BinaryPredicateBuilder { - - private final DoubleField field; - private final double value; - private final StandardBinaryOperator binaryOperator; - - public DoubleBinaryPredicateBuilder( - DoubleField field, - double value, - StandardBinaryOperator binaryOperator - ) { - this.field = Objects.requireNonNull(field); - this.value = value; - this.binaryOperator = Objects.requireNonNull(binaryOperator); - } - - @Override - public boolean test(ENTITY entity) { - return test(Double.compare(field.getFrom(entity), getValue())); - } - - public boolean test(int compare) { - return binaryOperator.getComparator().test(compare); - } - - @Override - public DoubleField getField() { - return field; - } - - @Override - public StandardBinaryOperator getOperator() { - return binaryOperator; - } - - public double getValue() { - return value; - } - - @Override - public Double getValueAsObject() { - return getValue(); - } -} diff --git a/src/main/java/com/speedment/core/field/doubles/DoubleField.java b/src/main/java/com/speedment/core/field/doubles/DoubleField.java deleted file mode 100644 index 4a5d2bc4d9..0000000000 --- a/src/main/java/com/speedment/core/field/doubles/DoubleField.java +++ /dev/null @@ -1,149 +0,0 @@ -/** - * - * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. - * - * 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.speedment.core.field.doubles; - -import com.speedment.api.field.Field; -import com.speedment.core.field.StandardBinaryOperator; -import com.speedment.core.field.StandardUnaryOperator; - -/** - * This class represents a {@code double} Field. - * - * @author pemi - * @param the entity type - */ -public class DoubleField implements Field { - - private final String columnName; - private final DoubleGetter getter; - private final DoubleSetter setter; - - public DoubleField(String columnName, DoubleGetter getter, DoubleSetter setter) { - this.getter = getter; - this.setter = setter; - this.columnName = columnName; - } - - /** - * Returns a {@link java.util.function.Predicate} that will evaluate to - * {@code true}, if and only if this Field is equal to the given - * value. - * - * @param value to compare - * @return a Predicate that will evaluate to {@code true}, if and only if - * this Field is equal to the given value - */ - public DoubleBinaryPredicateBuilder equal(double value) { - return newBinary(value, StandardBinaryOperator.EQUAL); - } - - /** - * Returns a {@link java.util.function.Predicate} that will evaluate to - * {@code true}, if and only if this Field is not equal to the - * given value. - * - * @param value to compare - * @return a Predicate that will evaluate to {@code true}, if and only if - * this Field is not equal to the given value - */ - public DoubleBinaryPredicateBuilder notEqual(double value) { - return newBinary(value, StandardBinaryOperator.NOT_EQUAL); - } - - /** - * Returns a {@link java.util.function.Predicate} that will evaluate to - * {@code true}, if and only if this Field is less than the given - * value. - * - * @param value to compare - * @return a Predicate that will evaluate to {@code true}, if and only if - * this Field is less than the given value - */ - public DoubleBinaryPredicateBuilder lessThan(double value) { - return newBinary(value, StandardBinaryOperator.LESS_THAN); - } - - /** - * Returns a {@link java.util.function.Predicate} that will evaluate to - * {@code true}, if and only if this Field is less than or equal - * to the given value. - * - * @param value to compare - * @return a Predicate that will evaluate to {@code true}, if and only if - * this Field is less than or equal to the given value - */ - public DoubleBinaryPredicateBuilder lessOrEqual(double value) { - return newBinary(value, StandardBinaryOperator.LESS_OR_EQUAL); - } - - /** - * Returns a {@link java.util.function.Predicate} that will evaluate to - * {@code true}, if and only if this Field is greater than - * the given value. - * - * @param value to compare - * @return a Predicate that will evaluate to {@code true}, if and only if - * this Field is greater than the given value - */ - public DoubleBinaryPredicateBuilder greaterThan(double value) { - return newBinary(value, StandardBinaryOperator.GREATER_THAN); - } - - /** - * Returns a {@link java.util.function.Predicate} that will evaluate to - * {@code true}, if and only if this Field is greater than or equal - * to the given value. - * - * @param value to compare - * @return a Predicate that will evaluate to {@code true}, if and only if - * this Field is greater than or equal to the given value - */ - public DoubleBinaryPredicateBuilder greaterOrEqual(double value) { - return newBinary(value, StandardBinaryOperator.GREATER_OR_EQUAL); - } - - public DoubleFunctionBuilder set(double value) { - return new DoubleFunctionBuilder<>(this, value); - } - - @Override - public boolean isNullIn(ENTITY entity) { - return false; - } - - public double getFrom(ENTITY entity) { - return getter.applyAsDouble(entity); - } - - public ENTITY setIn(ENTITY entity, double value) { - return setter.applyAsDouble(entity, value); - } - - @Override - public String getColumnName() { - return columnName; - } - - protected DoubleBinaryPredicateBuilder newBinary(double value, StandardBinaryOperator binaryOperator) { - return new DoubleBinaryPredicateBuilder<>(this, value, binaryOperator); - } - - protected DoubleUnaryPredicateBuilder newUnary(StandardUnaryOperator unaryOperator) { - return new DoubleUnaryPredicateBuilder<>(this, unaryOperator); - } - -} diff --git a/src/main/java/com/speedment/core/field/doubles/DoubleFunctionBuilder.java b/src/main/java/com/speedment/core/field/doubles/DoubleFunctionBuilder.java deleted file mode 100644 index 25d788a005..0000000000 --- a/src/main/java/com/speedment/core/field/doubles/DoubleFunctionBuilder.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * - * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. - * - * 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.speedment.core.field.doubles; - -import com.speedment.core.field.BaseFunction; -import com.speedment.core.field.FunctionBuilder; -import com.speedment.core.field.ints.IntField; - -import static java.util.Objects.requireNonNull; - -/** - * - * @author pemi - * @param Entity type - */ -public class DoubleFunctionBuilder extends BaseFunction implements FunctionBuilder { - - private final DoubleField field; - private final double newValue; - - public DoubleFunctionBuilder( - final DoubleField field, - final double newValue - ) { - this.field = requireNonNull(field); - this.newValue = requireNonNull(newValue); - } - - @Override - public ENTITY apply(ENTITY entity) { - return field.setIn(entity, newValue); - } - - @Override - public DoubleField getField() { - return field; - } - - public double getValue() { - return newValue; - } -} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/doubles/DoubleGetter.java b/src/main/java/com/speedment/core/field/doubles/DoubleGetter.java deleted file mode 100644 index a65892b97d..0000000000 --- a/src/main/java/com/speedment/core/field/doubles/DoubleGetter.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * - * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. - * - * 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.speedment.core.field.doubles; - -import java.util.function.ToDoubleFunction; - -/** - * @author Emil Forslund - * @param The entity type - */ -public interface DoubleGetter extends ToDoubleFunction {} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/doubles/DoubleSetter.java b/src/main/java/com/speedment/core/field/doubles/DoubleSetter.java deleted file mode 100644 index 5d15a990c1..0000000000 --- a/src/main/java/com/speedment/core/field/doubles/DoubleSetter.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * - * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. - * - * 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.speedment.core.field.doubles; - -/** - * @author Emil Forslund - * @param The entity type - */ -public interface DoubleSetter { - ENTITY applyAsDouble(ENTITY entity, double value); -} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/doubles/DoubleUnaryPredicateBuilder.java b/src/main/java/com/speedment/core/field/doubles/DoubleUnaryPredicateBuilder.java deleted file mode 100644 index 31c1d83c81..0000000000 --- a/src/main/java/com/speedment/core/field/doubles/DoubleUnaryPredicateBuilder.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * - * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. - * - * 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.speedment.core.field.doubles; - -import com.speedment.core.field.BasePredicate; -import com.speedment.core.field.StandardUnaryOperator; -import com.speedment.core.field.UnaryPredicateBuilder; -import java.util.Objects; -import java.util.function.Predicate; - -/** - * - * @author pemi - * @param Entity type - */ -public class DoubleUnaryPredicateBuilder extends BasePredicate implements Predicate, UnaryPredicateBuilder { - - private final DoubleField field; - private final StandardUnaryOperator unaryOperator; - - public DoubleUnaryPredicateBuilder( - final DoubleField field, - final StandardUnaryOperator unaryOperator - ) { - this.field = Objects.requireNonNull(field); - this.unaryOperator = Objects.requireNonNull(unaryOperator); - } - - @Override - public boolean test(final ENTITY t) { - return unaryOperator.getComparator().test(getField().getFrom(t)); - } - - @Override - public DoubleField getField() { - return field; - } - - @Override - public StandardUnaryOperator getOperator() { - return unaryOperator; - } - -} diff --git a/src/main/java/com/speedment/core/field/ints/IntBinaryPredicateBuilder.java b/src/main/java/com/speedment/core/field/ints/IntBinaryPredicateBuilder.java deleted file mode 100644 index 62b8ab2e89..0000000000 --- a/src/main/java/com/speedment/core/field/ints/IntBinaryPredicateBuilder.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * - * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. - * - * 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.speedment.core.field.ints; - -import com.speedment.core.field.BasePredicate; -import com.speedment.core.field.BinaryPredicateBuilder; -import com.speedment.core.field.StandardBinaryOperator; -import java.util.Objects; -import java.util.function.Predicate; - -/** - * - * @author pemi - * @param Entity type - */ -public class IntBinaryPredicateBuilder extends BasePredicate implements Predicate, BinaryPredicateBuilder { - - private final IntField field; - private final int value; - private final StandardBinaryOperator binaryOperator; - - public IntBinaryPredicateBuilder( - final IntField field, - final int value, - final StandardBinaryOperator binaryOperator - ) { - this.field = Objects.requireNonNull(field); - this.value = value; - this.binaryOperator = Objects.requireNonNull(binaryOperator); - } - - @Override - public boolean test(ENTITY entity) { - return test(Integer.compare(field.getFrom(entity), getValue())); - } - - public boolean test(int compare) { - return binaryOperator.getComparator().test(compare); - } - - @Override - public IntField getField() { - return field; - } - - @Override - public StandardBinaryOperator getOperator() { - return binaryOperator; - } - - public int getValue() { - return value; - } - - @Override - public Integer getValueAsObject() { - return getValue(); - } - -} diff --git a/src/main/java/com/speedment/core/field/ints/IntField.java b/src/main/java/com/speedment/core/field/ints/IntField.java deleted file mode 100644 index a74bc5bc94..0000000000 --- a/src/main/java/com/speedment/core/field/ints/IntField.java +++ /dev/null @@ -1,151 +0,0 @@ -/** - * - * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. - * - * 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.speedment.core.field.ints; - -import com.speedment.api.field.Field; -import com.speedment.core.field.StandardBinaryOperator; -import com.speedment.core.field.StandardUnaryOperator; - -import static java.util.Objects.requireNonNull; - -/** - * This class represents an {@code int} Field. - * - * @author pemi - * @param The entity field - */ -public class IntField implements Field { - - private final String columnName; - private final IntGetter getter; - private final IntSetter setter; - - public IntField(String columnName, IntGetter getter, IntSetter setter) { - this.getter = requireNonNull(getter); - this.setter = requireNonNull(setter); - this.columnName = columnName; - } - - /** - * Returns a {@link java.util.function.Predicate} that will evaluate to - * {@code true}, if and only if this Field is equal to the given - * value. - * - * @param value to compare - * @return a Predicate that will evaluate to {@code true}, if and only if - * this Field is equal to the given value - */ - public IntBinaryPredicateBuilder equal(int value) { - return newBinary(value, StandardBinaryOperator.EQUAL); - } - - /** - * Returns a {@link java.util.function.Predicate} that will evaluate to - * {@code true}, if and only if this Field is not equal to the - * given value. - * - * @param value to compare - * @return a Predicate that will evaluate to {@code true}, if and only if - * this Field is not equal to the given value - */ - public IntBinaryPredicateBuilder notEqual(int value) { - return newBinary(value, StandardBinaryOperator.NOT_EQUAL); - } - - /** - * Returns a {@link java.util.function.Predicate} that will evaluate to - * {@code true}, if and only if this Field is less than the given - * value. - * - * @param value to compare - * @return a Predicate that will evaluate to {@code true}, if and only if - * this Field is less than the given value - */ - public IntBinaryPredicateBuilder lessThan(int value) { - return newBinary(value, StandardBinaryOperator.LESS_THAN); - } - - /** - * Returns a {@link java.util.function.Predicate} that will evaluate to - * {@code true}, if and only if this Field is less than or equal - * to the given value. - * - * @param value to compare - * @return a Predicate that will evaluate to {@code true}, if and only if - * this Field is less than or equal to the given value - */ - public IntBinaryPredicateBuilder lessOrEqual(int value) { - return newBinary(value, StandardBinaryOperator.LESS_OR_EQUAL); - } - - /** - * Returns a {@link java.util.function.Predicate} that will evaluate to - * {@code true}, if and only if this Field is greater than - * the given value. - * - * @param value to compare - * @return a Predicate that will evaluate to {@code true}, if and only if - * this Field is greater than the given value - */ - public IntBinaryPredicateBuilder greaterThan(int value) { - return newBinary(value, StandardBinaryOperator.GREATER_THAN); - } - - /** - * Returns a {@link java.util.function.Predicate} that will evaluate to - * {@code true}, if and only if this Field is greater than or equal - * to the given value. - * - * @param value to compare - * @return a Predicate that will evaluate to {@code true}, if and only if - * this Field is greater than or equal to the given value - */ - public IntBinaryPredicateBuilder greaterOrEqual(int value) { - return newBinary(value, StandardBinaryOperator.GREATER_OR_EQUAL); - } - - public IntFunctionBuilder set(int value) { - return new IntFunctionBuilder<>(this, value); - } - - @Override - public boolean isNullIn(ENTITY entity) { - return false; - } - - public int getFrom(ENTITY entity) { - return getter.applyAsInt(entity); - } - - public ENTITY setIn(ENTITY entity, int value) { - return setter.applyAsInt(entity, value); - } - - @Override - public String getColumnName() { - return columnName; - } - - protected IntBinaryPredicateBuilder newBinary(int value, StandardBinaryOperator binaryOperator) { - return new IntBinaryPredicateBuilder<>(this, value, binaryOperator); - } - - protected IntUnaryPredicateBuilder newUnary(StandardUnaryOperator unaryOperator) { - return new IntUnaryPredicateBuilder<>(this, unaryOperator); - } - -} diff --git a/src/main/java/com/speedment/core/field/ints/IntFunctionBuilder.java b/src/main/java/com/speedment/core/field/ints/IntFunctionBuilder.java deleted file mode 100644 index 75e0852c7f..0000000000 --- a/src/main/java/com/speedment/core/field/ints/IntFunctionBuilder.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * - * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. - * - * 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.speedment.core.field.ints; - -import com.speedment.core.field.BaseFunction; -import com.speedment.core.field.FunctionBuilder; - -import static java.util.Objects.requireNonNull; - -/** - * - * @author pemi - * @param Entity type - */ -public class IntFunctionBuilder extends BaseFunction implements FunctionBuilder { - - private final IntField field; - private final int newValue; - - public IntFunctionBuilder( - final IntField field, - final int newValue - ) { - this.field = requireNonNull(field); - this.newValue = requireNonNull(newValue); - } - - @Override - public ENTITY apply(ENTITY entity) { - return field.setIn(entity, newValue); - } - - @Override - public IntField getField() { - return field; - } - - public int getValue() { - return newValue; - } -} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/ints/IntGetter.java b/src/main/java/com/speedment/core/field/ints/IntGetter.java deleted file mode 100644 index df66c07727..0000000000 --- a/src/main/java/com/speedment/core/field/ints/IntGetter.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * - * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. - * - * 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.speedment.core.field.ints; - -import java.util.function.ToIntFunction; - -/** - * @author Emil Forslund - * @param The entity type - */ -public interface IntGetter extends ToIntFunction {} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/ints/IntSetter.java b/src/main/java/com/speedment/core/field/ints/IntSetter.java deleted file mode 100644 index f7af9aa833..0000000000 --- a/src/main/java/com/speedment/core/field/ints/IntSetter.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * - * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. - * - * 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.speedment.core.field.ints; - -/** - * @author Emil Forslund - * @param The entity type - */ -public interface IntSetter { - ENTITY applyAsInt(ENTITY entity, int value); -} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/ints/IntUnaryPredicateBuilder.java b/src/main/java/com/speedment/core/field/ints/IntUnaryPredicateBuilder.java deleted file mode 100644 index 0c6f8d4a1c..0000000000 --- a/src/main/java/com/speedment/core/field/ints/IntUnaryPredicateBuilder.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * - * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. - * - * 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.speedment.core.field.ints; - -import com.speedment.core.field.BasePredicate; -import com.speedment.core.field.StandardUnaryOperator; -import com.speedment.core.field.UnaryPredicateBuilder; -import java.util.Objects; -import java.util.function.Predicate; - -/** - * - * @author pemi - * @param Entity type - */ -public class IntUnaryPredicateBuilder extends BasePredicate implements Predicate, UnaryPredicateBuilder { - - private final IntField field; - private final StandardUnaryOperator unaryOperator; - - public IntUnaryPredicateBuilder( - final IntField field, - final StandardUnaryOperator unaryOperator - ) { - this.field = Objects.requireNonNull(field); - this.unaryOperator = Objects.requireNonNull(unaryOperator); - } - - @Override - public boolean test(ENTITY t) { - return unaryOperator.getComparator().test(getField().getFrom(t)); - } - - @Override - public IntField getField() { - return field; - } - - @Override - public StandardUnaryOperator getOperator() { - return unaryOperator; - } - -} diff --git a/src/main/java/com/speedment/core/field/longs/LongBinaryPredicateBuilder.java b/src/main/java/com/speedment/core/field/longs/LongBinaryPredicateBuilder.java deleted file mode 100644 index 0e9851615e..0000000000 --- a/src/main/java/com/speedment/core/field/longs/LongBinaryPredicateBuilder.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * - * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. - * - * 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.speedment.core.field.longs; - -import com.speedment.core.field.BasePredicate; -import com.speedment.core.field.BinaryPredicateBuilder; -import com.speedment.core.field.StandardBinaryOperator; -import java.util.Objects; -import java.util.function.Predicate; - -/** - * - * @author pemi - * @param Entity type - */ -public class LongBinaryPredicateBuilder extends BasePredicate implements Predicate, BinaryPredicateBuilder { - - private final LongField field; - private final long value; - private final StandardBinaryOperator binaryOperator; - - public LongBinaryPredicateBuilder( - final LongField field, - final long value, - final StandardBinaryOperator binaryOperator - ) { - this.field = Objects.requireNonNull(field); - this.value = value; - this.binaryOperator = Objects.requireNonNull(binaryOperator); - } - - @Override - public boolean test(ENTITY entity) { - return test(Long.compare(field.getFrom(entity), getValue())); - } - - public boolean test(int compare) { - return binaryOperator.getComparator().test(compare); - } - - @Override - public LongField getField() { - return field; - } - - @Override - public StandardBinaryOperator getOperator() { - return binaryOperator; - } - - public long getValue() { - return value; - } - - @Override - public Long getValueAsObject() { - return getValue(); - } - -} diff --git a/src/main/java/com/speedment/core/field/longs/LongField.java b/src/main/java/com/speedment/core/field/longs/LongField.java deleted file mode 100644 index 7f69ae05bb..0000000000 --- a/src/main/java/com/speedment/core/field/longs/LongField.java +++ /dev/null @@ -1,151 +0,0 @@ -/** - * - * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. - * - * 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.speedment.core.field.longs; - -import com.speedment.api.field.Field; -import com.speedment.core.field.StandardBinaryOperator; -import com.speedment.core.field.StandardUnaryOperator; - -import static java.util.Objects.requireNonNull; - -/** - * This class represents a {@code long} Field. - * - * @author pemi - * @param The entity type - */ -public class LongField implements Field { - - private final String columnName; - private final LongGetter getter; - private final LongSetter setter; - - public LongField(String columnName, LongGetter getter, LongSetter setter) { - this.getter = requireNonNull(getter); - this.setter = requireNonNull(setter); - this.columnName = columnName; - } - - /** - * Returns a {@link java.util.function.Predicate} that will evaluate to - * {@code true}, if and only if this Field is equal to the given - * value. - * - * @param value to compare - * @return a Predicate that will evaluate to {@code true}, if and only if - * this Field is equal to the given value - */ - public LongBinaryPredicateBuilder equal(long value) { - return newBinary(value, StandardBinaryOperator.EQUAL); - } - - /** - * Returns a {@link java.util.function.Predicate} that will evaluate to - * {@code true}, if and only if this Field is not equal to the - * given value. - * - * @param value to compare - * @return a Predicate that will evaluate to {@code true}, if and only if - * this Field is not equal to the given value - */ - public LongBinaryPredicateBuilder notEqual(long value) { - return newBinary(value, StandardBinaryOperator.NOT_EQUAL); - } - - /** - * Returns a {@link java.util.function.Predicate} that will evaluate to - * {@code true}, if and only if this Field is less than the given - * value. - * - * @param value to compare - * @return a Predicate that will evaluate to {@code true}, if and only if - * this Field is less than the given value - */ - public LongBinaryPredicateBuilder lessThan(long value) { - return newBinary(value, StandardBinaryOperator.LESS_THAN); - } - - /** - * Returns a {@link java.util.function.Predicate} that will evaluate to - * {@code true}, if and only if this Field is less than or equal - * to the given value. - * - * @param value to compare - * @return a Predicate that will evaluate to {@code true}, if and only if - * this Field is less than or equal to the given value - */ - public LongBinaryPredicateBuilder lessOrEqual(long value) { - return newBinary(value, StandardBinaryOperator.LESS_OR_EQUAL); - } - - /** - * Returns a {@link java.util.function.Predicate} that will evaluate to - * {@code true}, if and only if this Field is greater than - * the given value. - * - * @param value to compare - * @return a Predicate that will evaluate to {@code true}, if and only if - * this Field is greater than the given value - */ - public LongBinaryPredicateBuilder greaterThan(long value) { - return newBinary(value, StandardBinaryOperator.GREATER_THAN); - } - - /** - * Returns a {@link java.util.function.Predicate} that will evaluate to - * {@code true}, if and only if this Field is greater than or equal - * to the given value. - * - * @param value to compare - * @return a Predicate that will evaluate to {@code true}, if and only if - * this Field is greater than or equal to the given value - */ - public LongBinaryPredicateBuilder greaterOrEqual(long value) { - return newBinary(value, StandardBinaryOperator.GREATER_OR_EQUAL); - } - - public LongFunctionBuilder set(long value) { - return new LongFunctionBuilder<>(this, value); - } - - @Override - public boolean isNullIn(ENTITY entity) { - return false; - } - - public long getFrom(ENTITY entity) { - return getter.applyAsLong(entity); - } - - public ENTITY setIn(ENTITY entity, long value) { - return setter.applyAsLong(entity, value); - } - - @Override - public String getColumnName() { - return columnName; - } - - protected LongBinaryPredicateBuilder newBinary(long value, StandardBinaryOperator binaryOperator) { - return new LongBinaryPredicateBuilder<>(this, value, binaryOperator); - } - - protected LongUnaryPredicateBuilder newUnary(StandardUnaryOperator unaryOperator) { - return new LongUnaryPredicateBuilder<>(this, unaryOperator); - } - -} diff --git a/src/main/java/com/speedment/core/field/longs/LongFunctionBuilder.java b/src/main/java/com/speedment/core/field/longs/LongFunctionBuilder.java deleted file mode 100644 index 3258e36fea..0000000000 --- a/src/main/java/com/speedment/core/field/longs/LongFunctionBuilder.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * - * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. - * - * 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.speedment.core.field.longs; - -import com.speedment.core.field.BaseFunction; -import com.speedment.core.field.FunctionBuilder; - -import static java.util.Objects.requireNonNull; - -/** - * - * @author pemi - * @param Entity type - */ -public class LongFunctionBuilder extends BaseFunction implements FunctionBuilder { - - private final LongField field; - private final long newValue; - - public LongFunctionBuilder( - final LongField field, - final long newValue - ) { - this.field = requireNonNull(field); - this.newValue = requireNonNull(newValue); - } - - @Override - public ENTITY apply(ENTITY entity) { - return field.setIn(entity, newValue); - } - - @Override - public LongField getField() { - return field; - } - - public long getValue() { - return newValue; - } -} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/longs/LongGetter.java b/src/main/java/com/speedment/core/field/longs/LongGetter.java deleted file mode 100644 index 9d36ba5c7d..0000000000 --- a/src/main/java/com/speedment/core/field/longs/LongGetter.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * - * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. - * - * 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.speedment.core.field.longs; - -import java.util.function.ToLongFunction; - -/** - * @author Emil Forslund - * @param The entity type - */ -public interface LongGetter extends ToLongFunction {} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/longs/LongSetter.java b/src/main/java/com/speedment/core/field/longs/LongSetter.java deleted file mode 100644 index 299302a955..0000000000 --- a/src/main/java/com/speedment/core/field/longs/LongSetter.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * - * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. - * - * 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.speedment.core.field.longs; - -/** - * @author Emil Forslund - * @param The entity type - */ -public interface LongSetter { - ENTITY applyAsLong(ENTITY entity, long value); -} diff --git a/src/main/java/com/speedment/core/field/longs/LongUnaryPredicateBuilder.java b/src/main/java/com/speedment/core/field/longs/LongUnaryPredicateBuilder.java deleted file mode 100644 index 6a7c290e8d..0000000000 --- a/src/main/java/com/speedment/core/field/longs/LongUnaryPredicateBuilder.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * - * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. - * - * 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.speedment.core.field.longs; - -import com.speedment.core.field.BasePredicate; -import com.speedment.core.field.Operator; -import com.speedment.core.field.PredicateBuilder; -import com.speedment.core.field.StandardUnaryOperator; - -import java.util.Objects; - -/** - * - * @author pemi - * @param Entity type - */ -public class LongUnaryPredicateBuilder extends BasePredicate implements PredicateBuilder { - - private final LongField field; - private final StandardUnaryOperator unaryOperator; - - public LongUnaryPredicateBuilder( - final LongField field, - final StandardUnaryOperator unaryOperator - ) { - this.field = Objects.requireNonNull(field); - this.unaryOperator = Objects.requireNonNull(unaryOperator); - } - - @Override - public boolean test(ENTITY t) { - return unaryOperator.getComparator().test(getField().getFrom(t)); - } - - @Override - public LongField getField() { - return field; - } - - @Override - public Operator getOperator() { - return unaryOperator; - } - -} diff --git a/src/main/java/com/speedment/core/field/reference/ReferenceBinaryPredicateBuilder.java b/src/main/java/com/speedment/core/field/reference/ReferenceBinaryPredicateBuilder.java deleted file mode 100644 index f77642c2f5..0000000000 --- a/src/main/java/com/speedment/core/field/reference/ReferenceBinaryPredicateBuilder.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * - * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. - * - * 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.speedment.core.field.reference; - -import com.speedment.core.field.BasePredicate; -import com.speedment.core.field.BinaryPredicateBuilder; -import com.speedment.core.field.StandardBinaryOperator; -import java.util.Comparator; -import java.util.Objects; - -/** - * - * @author pemi - * @param Entity type - * @param Value type - */ -public class ReferenceBinaryPredicateBuilder> extends BasePredicate implements BinaryPredicateBuilder { - - private final ReferenceField field; - private final V value; - private final StandardBinaryOperator binaryOperator; - private final Comparator entityComparator; - - public ReferenceBinaryPredicateBuilder( - final ReferenceField field, - final V value, - final StandardBinaryOperator binaryOperator, - final Comparator entityComparator - ) { - this.field = Objects.requireNonNull(field); - this.value = value; - this.entityComparator = Objects.requireNonNull(entityComparator); - this.binaryOperator = Objects.requireNonNull(binaryOperator); - } - - public ReferenceBinaryPredicateBuilder( - final ReferenceField field, - final V value, - final StandardBinaryOperator binaryOperator - ) { - this(field, value, binaryOperator, Comparator.naturalOrder()); - } - - @Override - public boolean test(final ENTITY entity) { - return test(Objects.compare(field.getFrom(entity), getValue(), entityComparator)); - } - - public boolean test(final int compare) { - return binaryOperator.getComparator().test(compare); - } - - @Override - public ReferenceField getField() { - return field; - } - - public V getValue() { - return value; - } - - @Override - public StandardBinaryOperator getOperator() { - return binaryOperator; - } - - @Override - public V getValueAsObject() { - return getValue(); - } - -} diff --git a/src/main/java/com/speedment/core/field/reference/ReferenceField.java b/src/main/java/com/speedment/core/field/reference/ReferenceField.java deleted file mode 100644 index 5cde8cfcc7..0000000000 --- a/src/main/java/com/speedment/core/field/reference/ReferenceField.java +++ /dev/null @@ -1,92 +0,0 @@ -/** - * - * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. - * - * 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.speedment.core.field.reference; - -import com.speedment.api.field.Field; -import com.speedment.core.field.StandardUnaryOperator; - -import static java.util.Objects.requireNonNull; - -/** - * This class represents a Reference Field. A Reference Field is something that - * extends {@link Object}. - * - * @author pemi - * @param The entity type - * @param The value type - */ -public class ReferenceField implements Field { - - private final String columnName; - private final Getter getter; - private final Setter setter; - - public ReferenceField(String columnName, Getter getter, Setter setter) { - this.columnName = requireNonNull(columnName); - this.getter = requireNonNull(getter); - this.setter = requireNonNull(setter); - } - - /** - * Returns a {@link java.util.function.Predicate} that will evaluate to - * {@code true}, if and only if this Field is {@code null}. - * - * @return a Predicate that will evaluate to {@code true}, if and only if - * this Field is {@code null} - */ - public ReferenceUnaryPredicateBuilder isNull() { - return newUnary(StandardUnaryOperator.IS_NULL); - } - - /** - * Returns a {@link java.util.function.Predicate} that will evaluate to - * {@code true}, if and only if this Field is not {@code null}. - * - * @return a Predicate that will evaluate to {@code true}, if and only if - * this Field is not {@code null} - */ - public ReferenceUnaryPredicateBuilder isNotNull() { - return newUnary(StandardUnaryOperator.IS_NOT_NULL); - } - - public ReferenceFunctionBuilder set(V newValue) { - return new ReferenceFunctionBuilder<>(this, newValue); - } - - @Override - public boolean isNullIn(ENTITY entity) { - return getFrom(entity) == null; - } - - public V getFrom(ENTITY entity) { - return getter.apply(entity); - } - - public ENTITY setIn(ENTITY entity, V value) { - return setter.apply(entity, value); - } - - @Override - public String getColumnName() { - return columnName; - } - - protected ReferenceUnaryPredicateBuilder newUnary(StandardUnaryOperator unaryOperator) { - return new ReferenceUnaryPredicateBuilder<>(this, unaryOperator); - } - -} diff --git a/src/main/java/com/speedment/core/field/reference/ReferenceUnaryPredicateBuilder.java b/src/main/java/com/speedment/core/field/reference/ReferenceUnaryPredicateBuilder.java deleted file mode 100644 index 3e78be2356..0000000000 --- a/src/main/java/com/speedment/core/field/reference/ReferenceUnaryPredicateBuilder.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * - * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. - * - * 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.speedment.core.field.reference; - -import com.speedment.core.field.BasePredicate; -import com.speedment.core.field.StandardUnaryOperator; -import com.speedment.core.field.UnaryPredicateBuilder; - -import java.util.Objects; - -/** - * - * @author pemi - * @param Entity type - * @param Value type - */ -public class ReferenceUnaryPredicateBuilder extends BasePredicate implements UnaryPredicateBuilder { - - private final ReferenceField field; - private final StandardUnaryOperator unaryOperator; - - public ReferenceUnaryPredicateBuilder( - final ReferenceField field, - final StandardUnaryOperator unaryOperator - ) { - this.field = Objects.requireNonNull(field); - this.unaryOperator = Objects.requireNonNull(unaryOperator); - } - - @Override - public boolean test(ENTITY entity) { - return unaryOperator.getComparator().test(field.getFrom(entity)); - } - - @Override - public ReferenceField getField() { - return field; - } - - @Override - public StandardUnaryOperator getOperator() { - return unaryOperator; - } - -} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/field/reference/string/StringBinaryPredicateBuilder.java b/src/main/java/com/speedment/core/field/reference/string/StringBinaryPredicateBuilder.java deleted file mode 100644 index 3e13d14564..0000000000 --- a/src/main/java/com/speedment/core/field/reference/string/StringBinaryPredicateBuilder.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * - * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. - * - * 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.speedment.core.field.reference.string; - -import com.speedment.core.field.BasePredicate; -import com.speedment.core.field.BinaryPredicateBuilder; -import com.speedment.core.field.StandardStringBinaryOperator; -import java.util.Objects; - -/** - * - * @author pemi - * @param Entity type - * - */ -public class StringBinaryPredicateBuilder extends BasePredicate implements BinaryPredicateBuilder { - - private final StringReferenceField field; - private final String value; - private final StandardStringBinaryOperator binaryOperator; - - public StringBinaryPredicateBuilder( - final StringReferenceField field, - final String value, - final StandardStringBinaryOperator binaryOperator - ) { - this.field = Objects.requireNonNull(field); - this.value = value; - this.binaryOperator = Objects.requireNonNull(binaryOperator); - } - - @Override - public boolean test(ENTITY entity) { - final String columnValue = field.getFrom(entity); - if (columnValue == null || value == null) { - return false; - } - return binaryOperator.getComparator().test(columnValue, value); - } - - @Override - public StringReferenceField getField() { - return field; - } - - public String getValue() { - return value; - } - - @Override - public StandardStringBinaryOperator getOperator() { - return binaryOperator; - } - - @Override - public String getValueAsObject() { - return getValue(); - } - -} diff --git a/src/main/java/com/speedment/core/field/reference/string/StringReferenceForeignKeyField.java b/src/main/java/com/speedment/core/field/reference/string/StringReferenceForeignKeyField.java deleted file mode 100644 index 95241136e7..0000000000 --- a/src/main/java/com/speedment/core/field/reference/string/StringReferenceForeignKeyField.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * - * Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. - * - * 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.speedment.core.field.reference.string; - -import com.speedment.core.field.reference.Getter; -import com.speedment.core.field.reference.Setter; - -/** - * - * @author pemi - * @param The entity type - * @param The foreign entity type - */ -public class StringReferenceForeignKeyField extends StringReferenceField { - - private final Getter finder; - - public StringReferenceForeignKeyField( - String columnName, - Getter getter, - Setter setter, - Getter finder) { - - super(columnName, getter, setter); - this.finder = finder; - } - - public FK findFrom(ENTITY entity) { - return finder.apply(entity); - } -} \ No newline at end of file diff --git a/src/main/java/com/speedment/core/manager/sql/SqlStreamTerminator.java b/src/main/java/com/speedment/core/manager/sql/SqlStreamTerminator.java index f7bc41ff0f..1910479523 100644 --- a/src/main/java/com/speedment/core/manager/sql/SqlStreamTerminator.java +++ b/src/main/java/com/speedment/core/manager/sql/SqlStreamTerminator.java @@ -19,9 +19,8 @@ import com.speedment.codegen.base.Generator; import com.speedment.core.manager.sql.generator.SQLGenerator; import com.speedment.core.db.AsynchronousQueryResult; -import com.speedment.core.field.BinaryPredicateBuilder; -import com.speedment.core.field.CombinedBasePredicate.AndCombinedBasePredicate; -import com.speedment.core.field.PredicateBuilder; +import com.speedment.core.field.builders.AbstractCombinedBasePredicate.AndCombinedBasePredicate; +import com.speedment.api.field.builders.PredicateBuilder; import com.speedment.util.Cast; import com.speedment.core.stream.builder.action.Action; import static com.speedment.core.stream.builder.action.Property.SIZE; @@ -41,6 +40,10 @@ import java.util.function.Predicate; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; +import static java.util.stream.Collectors.joining; +import com.speedment.api.field.builders.ComparablePredicateBuilder; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.joining; /** * @@ -92,10 +95,10 @@ public void modifySource(final List> predicateBuilders, Asyn @SuppressWarnings("rawtypes") final List values = predicateBuilders.stream() - .map(pb -> Cast.cast(pb, BinaryPredicateBuilder.class)) + .map(pb -> Cast.cast(pb, ComparablePredicateBuilder.class)) .filter(Optional::isPresent) .map(Optional::get) - .map(BinaryPredicateBuilder::getValueAsObject) + .map(ComparablePredicateBuilder::getValueAsObject) .collect(toList()); qr.setSql(sql); diff --git a/src/main/java/com/speedment/core/manager/sql/generator/BinaryPredicateBuilderView.java b/src/main/java/com/speedment/core/manager/sql/generator/BinaryPredicateBuilderView.java index 703b1bd610..a140ea0c6a 100644 --- a/src/main/java/com/speedment/core/manager/sql/generator/BinaryPredicateBuilderView.java +++ b/src/main/java/com/speedment/core/manager/sql/generator/BinaryPredicateBuilderView.java @@ -18,18 +18,18 @@ import com.speedment.codegen.base.Generator; import com.speedment.codegen.base.Transform; -import com.speedment.core.field.BinaryPredicateBuilder; -import com.speedment.core.field.StandardBinaryOperator; +import com.speedment.api.field.operators.StandardComparableOperator; import java.util.Optional; +import com.speedment.api.field.builders.ComparablePredicateBuilder; /** * * @author Emil Forslund */ @SuppressWarnings("rawtypes") -public class BinaryPredicateBuilderView implements Transform { +public class BinaryPredicateBuilderView implements Transform { - protected String render(StandardBinaryOperator op) { + protected String render(StandardComparableOperator op) { switch (op) { case EQUAL: return " = "; @@ -51,11 +51,11 @@ protected String render(StandardBinaryOperator op) { } @Override - public Optional transform(Generator gen, BinaryPredicateBuilder model) { - if (model.getOperator() instanceof StandardBinaryOperator) { + public Optional transform(Generator gen, ComparablePredicateBuilder model) { + if (model.getOperator() instanceof StandardComparableOperator) { return Optional.of("(" + model.getField().getColumnName() - + render((StandardBinaryOperator) model.getOperator()) + + render((StandardComparableOperator) model.getOperator()) + "?)" ); } else { diff --git a/src/main/java/com/speedment/core/manager/sql/generator/SQLTransformFactory.java b/src/main/java/com/speedment/core/manager/sql/generator/SQLTransformFactory.java index c04d517299..1f57b2e751 100644 --- a/src/main/java/com/speedment/core/manager/sql/generator/SQLTransformFactory.java +++ b/src/main/java/com/speedment/core/manager/sql/generator/SQLTransformFactory.java @@ -17,9 +17,9 @@ package com.speedment.core.manager.sql.generator; import com.speedment.codegen.base.DefaultTransformFactory; -import com.speedment.core.field.BinaryPredicateBuilder; -import com.speedment.core.field.UnaryPredicateBuilder; +import com.speedment.api.field.builders.UnaryPredicateBuilder; import com.speedment.core.field.reference.string.StringBinaryPredicateBuilder; +import com.speedment.api.field.builders.ComparablePredicateBuilder; /** * @@ -30,7 +30,7 @@ public class SQLTransformFactory extends DefaultTransformFactory { public SQLTransformFactory() { super(SQLTransformFactory.class.getSimpleName()); install(UnaryPredicateBuilder.class, UnaryPredicateBuilderView.class); - install(BinaryPredicateBuilder.class, BinaryPredicateBuilderView.class); + install(ComparablePredicateBuilder.class, BinaryPredicateBuilderView.class); install(StringBinaryPredicateBuilder.class, StringBinaryPredicateBuilderView.class); } } diff --git a/src/main/java/com/speedment/core/manager/sql/generator/StringBinaryPredicateBuilderView.java b/src/main/java/com/speedment/core/manager/sql/generator/StringBinaryPredicateBuilderView.java index dc9323d985..894460bfec 100644 --- a/src/main/java/com/speedment/core/manager/sql/generator/StringBinaryPredicateBuilderView.java +++ b/src/main/java/com/speedment/core/manager/sql/generator/StringBinaryPredicateBuilderView.java @@ -18,7 +18,7 @@ import com.speedment.codegen.base.Generator; import com.speedment.codegen.base.Transform; -import com.speedment.core.field.StandardStringBinaryOperator; +import com.speedment.api.field.operators.StandardStringOperator; import com.speedment.core.field.reference.string.StringBinaryPredicateBuilder; import java.util.Optional; @@ -29,7 +29,7 @@ @SuppressWarnings("rawtypes") public class StringBinaryPredicateBuilderView implements Transform { - protected String render(StandardStringBinaryOperator op, String columnName) { + protected String render(StandardStringOperator op, String columnName) { switch (op) { case CONTAINS: return columnName + " LIKE BINARY CONCAT('%', ? ,'%')"; diff --git a/src/main/java/com/speedment/core/manager/sql/generator/UnaryPredicateBuilderView.java b/src/main/java/com/speedment/core/manager/sql/generator/UnaryPredicateBuilderView.java index a1ec95b791..0cb7208dae 100644 --- a/src/main/java/com/speedment/core/manager/sql/generator/UnaryPredicateBuilderView.java +++ b/src/main/java/com/speedment/core/manager/sql/generator/UnaryPredicateBuilderView.java @@ -18,10 +18,10 @@ import com.speedment.codegen.base.Generator; import com.speedment.codegen.base.Transform; -import com.speedment.core.field.StandardUnaryOperator; -import static com.speedment.core.field.StandardUnaryOperator.IS_NOT_NULL; -import static com.speedment.core.field.StandardUnaryOperator.IS_NULL; -import com.speedment.core.field.UnaryPredicateBuilder; +import com.speedment.api.field.operators.StandardUnaryOperator; +import static com.speedment.api.field.operators.StandardUnaryOperator.IS_NOT_NULL; +import static com.speedment.api.field.operators.StandardUnaryOperator.IS_NULL; +import com.speedment.api.field.builders.UnaryPredicateBuilder; import java.util.Optional;