Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add setter builders to entity fields. This will later be used to opti…
…mize update operations in like described in issue #27.
- Loading branch information
Emil Forslund
committed
Aug 24, 2015
1 parent
413f109
commit 61b938f
Showing
25 changed files
with
348 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
package com.speedment.core.field; | |||
|
|||
import java.util.function.Function; | |||
|
|||
/** | |||
* | |||
* @author Emil | |||
*/ | |||
public abstract class BaseFunction<ENTITY> implements Function<ENTITY, ENTITY> { | |||
|
|||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/com/speedment/core/field/FunctionBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,12 @@ | |||
package com.speedment.core.field; | |||
|
|||
/** | |||
* | |||
* @author Emil Forslund | |||
* @param <ENTITY> Entity type | |||
*/ | |||
public interface FunctionBuilder<ENTITY> { | |||
|
|||
Field<ENTITY> getField(); | |||
|
|||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/com/speedment/core/field/doubles/DoubleFunctionBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,56 @@ | |||
/** | |||
* | |||
* 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> Entity type | |||
*/ | |||
public class DoubleFunctionBuilder<ENTITY> extends BaseFunction<ENTITY> implements FunctionBuilder<ENTITY> { | |||
|
|||
private final DoubleField<ENTITY> field; | |||
private final double newValue; | |||
|
|||
public DoubleFunctionBuilder( | |||
final DoubleField<ENTITY> 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<ENTITY> getField() { | |||
return field; | |||
} | |||
|
|||
public double getValue() { | |||
return newValue; | |||
} | |||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/speedment/core/field/doubles/DoubleSetter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,9 @@ | |||
package com.speedment.core.field.doubles; | |||
|
|||
/** | |||
* @author Emil Forslund | |||
* @param <ENTITY> The entity type | |||
*/ | |||
public interface DoubleSetter<ENTITY> { | |||
ENTITY applyAsDouble(ENTITY entity, double value); | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/java/com/speedment/core/field/ints/IntFunctionBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,55 @@ | |||
/** | |||
* | |||
* 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> Entity type | |||
*/ | |||
public class IntFunctionBuilder<ENTITY> extends BaseFunction<ENTITY> implements FunctionBuilder<ENTITY> { | |||
|
|||
private final IntField<ENTITY> field; | |||
private final int newValue; | |||
|
|||
public IntFunctionBuilder( | |||
final IntField<ENTITY> 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<ENTITY> getField() { | |||
return field; | |||
} | |||
|
|||
public int getValue() { | |||
return newValue; | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,9 @@ | |||
package com.speedment.core.field.ints; | |||
|
|||
/** | |||
* @author Emil Forslund | |||
* @param <ENTITY> The entity type | |||
*/ | |||
public interface IntSetter<ENTITY> { | |||
ENTITY applyAsInt(ENTITY entity, int value); | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/java/com/speedment/core/field/longs/LongFunctionBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,55 @@ | |||
/** | |||
* | |||
* 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> Entity type | |||
*/ | |||
public class LongFunctionBuilder<ENTITY> extends BaseFunction<ENTITY> implements FunctionBuilder<ENTITY> { | |||
|
|||
private final LongField<ENTITY> field; | |||
private final long newValue; | |||
|
|||
public LongFunctionBuilder( | |||
final LongField<ENTITY> 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<ENTITY> getField() { | |||
return field; | |||
} | |||
|
|||
public long getValue() { | |||
return newValue; | |||
} | |||
} |
Oops, something went wrong.