Skip to content

Commit

Permalink
Refactor API third step (fields).
Browse files Browse the repository at this point in the history
  • Loading branch information
minborg committed Aug 28, 2015
1 parent d890286 commit 94511aa
Show file tree
Hide file tree
Showing 67 changed files with 903 additions and 1,930 deletions.
10 changes: 1 addition & 9 deletions src/main/java/com/speedment/api/field/Field.java
Expand Up @@ -29,19 +29,11 @@
@Api(version = "2.1") @Api(version = "2.1")
public interface Field<ENTITY> { public interface Field<ENTITY> {


/**
* 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. * Returns the column name that corresponds to this Field.
* *
* @return the name * @return the name
*/ */
String getColumnName(); String getColumnName();


} }
@@ -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 <ENTITY>
* @param <V>
*/
@Api(version = "2.1")
public interface ReferenceComparableField<ENTITY, V extends Comparable<? super V>> extends ReferenceField<ENTITY, V> {

/**
* Returns a {@link java.util.function.Predicate} that will evaluate to
* {@code true}, if and only if this Field is <em>equal</em> to the given
* value.
*
* @param value to compare
* @return a Predicate that will evaluate to {@code true}, if and only if
* this Field is <em>equal</em> to the given value
*/
ComparablePredicateBuilder<ENTITY, V> equal(V value);

/**
* Returns a {@link java.util.function.Predicate} that will evaluate to
* {@code true}, if and only if this Field is <em>not equal</em> to the
* given value.
*
* @param value to compare
* @return a Predicate that will evaluate to {@code true}, if and only if
* this Field is <em>not equal</em> to the given value
*/
ComparablePredicateBuilder<ENTITY, V> notEqual(V value);

/**
* Returns a {@link java.util.function.Predicate} that will evaluate to
* {@code true}, if and only if this Field is <em>less than</em> the given
* value.
*
* @param value to compare
* @return a Predicate that will evaluate to {@code true}, if and only if
* this Field is <em>less than</em> the given value
*/
ComparablePredicateBuilder<ENTITY, V> lessThan(V value);

/**
* Returns a {@link java.util.function.Predicate} that will evaluate to
* {@code true}, if and only if this Field is <em>less than or equal</em>
* to the given value.
*
* @param value to compare
* @return a Predicate that will evaluate to {@code true}, if and only if
* this Field is <em>less than or equal</em> to the given value
*/
ComparablePredicateBuilder<ENTITY, V> lessOrEqual(V value);

/**
* Returns a {@link java.util.function.Predicate} that will evaluate to
* {@code true}, if and only if this Field is <em>greater than</em>
* the given value.
*
* @param value to compare
* @return a Predicate that will evaluate to {@code true}, if and only if
* this Field is <em>greater than</em> the given value
*/
ComparablePredicateBuilder<ENTITY, V> greaterThan(V value);

/**
* Returns a {@link java.util.function.Predicate} that will evaluate to
* {@code true}, if and only if this Field is <em>greater than or equal</em>
* to the given value.
*
* @param value to compare
* @return a Predicate that will evaluate to {@code true}, if and only if
* this Field is <em>greater than or equal</em> to the given value
*/
ComparablePredicateBuilder<ENTITY, V> greaterOrEqual(V value);
}
@@ -0,0 +1,14 @@
package com.speedment.api.field;

import com.speedment.api.annotation.Api;

/**
*
* @author pemi
* @param <ENTITY>
* @param <V>
* @param <FK>
*/
@Api(version = "2.1")
public interface ReferenceComparableForeignKeyField<ENTITY, V extends Comparable<? super V>, FK> extends
ReferenceComparableField<ENTITY, V>, ReferenceForeignKeyField<ENTITY, V, FK> {}
@@ -0,0 +1,15 @@
package com.speedment.api.field;

import com.speedment.api.annotation.Api;

/**
*
* @author pemi
* @param <ENTITY>
* @param <FK>
*/
@Api(version = "2.1")
public interface ReferenceComparableForeignKeyStringField<ENTITY, FK> extends
ReferenceComparableField<ENTITY, String>,
ReferenceForeignKeyField<ENTITY, String, FK>,
ReferenceComparableStringField<ENTITY> {}
@@ -1,39 +1,16 @@
/** package com.speedment.api.field;
*
* 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.StandardStringBinaryOperator; import com.speedment.api.annotation.Api;
import com.speedment.core.field.reference.ComparableReferenceField; import com.speedment.api.field.builders.StringPredicateBuilder;
import com.speedment.core.field.reference.Getter;
import com.speedment.core.field.reference.Setter;


/** /**
* This class represents a String Reference Field. A String Field maps to a
* {@link String} Column.
* *
* @author pemi * @author pemi
* @param <ENTITY> The entity type * @param <ENTITY>
*/ */
public class StringReferenceField<ENTITY> extends ComparableReferenceField<ENTITY, String> { @Api(version = "2.1")

public interface ReferenceComparableStringField<ENTITY> extends ReferenceComparableField<ENTITY, String> {
public StringReferenceField(String columnName, Getter<ENTITY, String> getter, Setter<ENTITY, String> setter) {
super(columnName, getter, setter);
}

/** /**
* Returns a {@link java.util.function.Predicate} that will evaluate to * Returns a {@link java.util.function.Predicate} that will evaluate to
* {@code true}, if and only if this Field is <em>equal</em> to the given * {@code true}, if and only if this Field is <em>equal</em> to the given
Expand All @@ -46,9 +23,7 @@ public StringReferenceField(String columnName, Getter<ENTITY, String> getter, Se
* *
* @see String#compareToIgnoreCase(java.lang.String) * @see String#compareToIgnoreCase(java.lang.String)
*/ */
public StringBinaryPredicateBuilder<ENTITY> equalIgnoreCase(String value) { StringPredicateBuilder<ENTITY> equalIgnoreCase(String value);
return newBinary(value, StandardStringBinaryOperator.EQUAL_IGNORE_CASE);
}


/** /**
* Returns a {@link java.util.function.Predicate} that will evaluate to * Returns a {@link java.util.function.Predicate} that will evaluate to
Expand All @@ -62,9 +37,7 @@ public StringBinaryPredicateBuilder<ENTITY> equalIgnoreCase(String value) {
* *
* @see String#compareToIgnoreCase(java.lang.String) * @see String#compareToIgnoreCase(java.lang.String)
*/ */
public StringBinaryPredicateBuilder<ENTITY> notEqualIgnoreCase(String value) { StringPredicateBuilder<ENTITY> notEqualIgnoreCase(String value);
return newBinary(value, StandardStringBinaryOperator.NOT_EQUAL_IGNORE_CASE);
}


/** /**
* Returns a {@link java.util.function.Predicate} that will evaluate to * Returns a {@link java.util.function.Predicate} that will evaluate to
Expand All @@ -77,9 +50,7 @@ public StringBinaryPredicateBuilder<ENTITY> notEqualIgnoreCase(String value) {
* *
* @see String#startsWith(java.lang.String) * @see String#startsWith(java.lang.String)
*/ */
public StringBinaryPredicateBuilder<ENTITY> startsWith(String value) { StringPredicateBuilder<ENTITY> startsWith(String value);
return newBinary(value, StandardStringBinaryOperator.STARTS_WITH);
}


/** /**
* Returns a {@link java.util.function.Predicate} that will evaluate to * Returns a {@link java.util.function.Predicate} that will evaluate to
Expand All @@ -92,9 +63,7 @@ public StringBinaryPredicateBuilder<ENTITY> startsWith(String value) {
* *
* @see String#endsWith(java.lang.String) * @see String#endsWith(java.lang.String)
*/ */
public StringBinaryPredicateBuilder<ENTITY> endsWith(String value) { StringPredicateBuilder<ENTITY> endsWith(String value);
return newBinary(value, StandardStringBinaryOperator.ENDS_WITH);
}


/** /**
* Returns a {@link java.util.function.Predicate} that will evaluate to * Returns a {@link java.util.function.Predicate} that will evaluate to
Expand All @@ -107,12 +76,5 @@ public StringBinaryPredicateBuilder<ENTITY> endsWith(String value) {
* *
* @see String#endsWith(java.lang.String) * @see String#endsWith(java.lang.String)
*/ */
public StringBinaryPredicateBuilder<ENTITY> contains(String value) { StringPredicateBuilder<ENTITY> contains(String value);
return newBinary(value, StandardStringBinaryOperator.CONTAINS); }
}

protected StringBinaryPredicateBuilder<ENTITY> newBinary(String value, StandardStringBinaryOperator binaryOperator) {
return new StringBinaryPredicateBuilder<>(this, value, binaryOperator);
}

}
86 changes: 86 additions & 0 deletions 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 <ENTITY>
* @param <V>
*/
@Api(version = "2.1")
public interface ReferenceField<ENTITY, V> extends Field<ENTITY> {

/**
* Returns a reference to the setter for this field.
*
* @return the setter
*/
Setter<ENTITY, V> setter();

/**
* Returns a reference to the getter of this field.
*
* @return the getter
*/
Getter<ENTITY, V> 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<ENTITY, V> 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<ENTITY> 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 <em>not</em> {@code null}.
*
* @return a Predicate that will evaluate to {@code true}, if and
* only if this Field is <em>not</em> {@code null}
*/
UnaryPredicateBuilder<ENTITY> isNotNull();

/**
* Returns if this Field is <b>not</b> {@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);
}
}
@@ -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 <ENTITY>
* @param <V>
* @param <FK>
*/
@Api(version = "2.1")
public interface ReferenceForeignKeyField<ENTITY, V, FK> extends ReferenceField<ENTITY, V> {
/**
* Returns a function that can find a foreign entity pointed out by this
* field.
*
* @return the finder
*/
Getter<ENTITY, FK> 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);
}
Expand Up @@ -14,18 +14,22 @@
* License for the specific language governing permissions and limitations under * License for the specific language governing permissions and limitations under
* the License. * 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;


/** /**
* *
* @author pemi * @author pemi
* @param <ENTITY> The entity type * @param <ENTITY> The entity type
* @param <V> the value type * @param <V> the value type
*/ */
public interface BinaryPredicateBuilder<ENTITY, V> extends PredicateBuilder<ENTITY> { @Api(version = "2.1")

public interface ComparablePredicateBuilder<ENTITY, V extends Comparable<? super V>> extends PredicateBuilder<ENTITY>, Predicate<ENTITY> {
V getValueAsObject();
ComparableOperator getComparableOperator();


@Override V getValue();
BinaryOperator getOperator();
} }

0 comments on commit 94511aa

Please sign in to comment.