Skip to content

Commit

Permalink
Runtime field: Add specific override, Fix #385
Browse files Browse the repository at this point in the history
  • Loading branch information
minborg committed May 3, 2017
1 parent 29fa6c0 commit 8ce3efe
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 35 deletions.
@@ -1,13 +1,13 @@
/** /**
* *
* Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); You may not * 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 * use this file except in compliance with the License. You may obtain a copy of
* the License at: * the License at:
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
Expand All @@ -18,38 +18,44 @@


import com.speedment.common.annotation.GeneratedCode; import com.speedment.common.annotation.GeneratedCode;
import com.speedment.common.function.ToBooleanFunction; import com.speedment.common.function.ToBooleanFunction;
import java.util.function.Function;


/** /**
* A short-cut functional reference to the {@code getXXX(value)} method for a * A short-cut functional reference to the {@code getXXX(value)} method for a
* particular field in an entity. * particular field in an entity.
* <p> * <p>
* A {@code BooleanGetter<ENTITY>} has the following signature: * A {@code BooleanGetter<ENTITY>} has the following signature: {@code
* {@code
* interface ENTITY { * interface ENTITY {
* boolean getXXX(); * boolean getXXX();
* }
* } * }
* * }
*
* @param <ENTITY> the entity * @param <ENTITY> the entity
* *
* @author Emil Forslund * @author Emil Forslund
* @since 3.0.0 * @since 3.0.0
*/ */
@GeneratedCode(value = "Speedment") @GeneratedCode(value = "Speedment")
@FunctionalInterface @FunctionalInterface
public interface BooleanGetter<ENTITY> extends Getter<ENTITY>, ToBooleanFunction<ENTITY> { public interface BooleanGetter<ENTITY> extends Getter<ENTITY>, ToBooleanFunction<ENTITY> {

/** /**
* Returns the member represented by this getter in the specified instance. * Returns the member represented by this getter in the specified instance.
* *
* @param instance the instance to get from * @param instance the instance to get from
* @return the value * @return the value
*/ */
@Override @Override
boolean applyAsBoolean(ENTITY instance); boolean applyAsBoolean(ENTITY instance);

@Override @Override
default Boolean apply(ENTITY instance) { default Boolean apply(ENTITY instance) {
return applyAsBoolean(instance); return applyAsBoolean(instance);
} }
}
@Override
default Function<ENTITY, Boolean> asFunction() {
return this::apply;
}

}
Expand Up @@ -17,6 +17,7 @@
package com.speedment.runtime.field.method; package com.speedment.runtime.field.method;


import com.speedment.common.annotation.GeneratedCode; import com.speedment.common.annotation.GeneratedCode;
import java.util.function.Function;


/** /**
* A short-cut functional reference to the {@code getXXX(value)} method for a * A short-cut functional reference to the {@code getXXX(value)} method for a
Expand Down Expand Up @@ -50,4 +51,10 @@ public interface ByteGetter<ENTITY> extends Getter<ENTITY> {
default Byte apply(ENTITY instance) { default Byte apply(ENTITY instance) {
return applyAsByte(instance); return applyAsByte(instance);
} }

@Override
default Function<ENTITY,Byte> asFunction() {
return this::apply;
}

} }
@@ -1,13 +1,13 @@
/** /**
* *
* Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); You may not * 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 * use this file except in compliance with the License. You may obtain a copy of
* the License at: * the License at:
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
Expand All @@ -17,37 +17,43 @@
package com.speedment.runtime.field.method; package com.speedment.runtime.field.method;


import com.speedment.common.annotation.GeneratedCode; import com.speedment.common.annotation.GeneratedCode;
import java.util.function.Function;


/** /**
* A short-cut functional reference to the {@code getXXX(value)} method for a * A short-cut functional reference to the {@code getXXX(value)} method for a
* particular field in an entity. * particular field in an entity.
* <p> * <p>
* A {@code CharacterGetter<ENTITY>} has the following signature: * A {@code CharacterGetter<ENTITY>} has the following signature: {@code
* {@code
* interface ENTITY { * interface ENTITY {
* char getXXX(); * char getXXX();
* }
* } * }
* * }
*
* @param <ENTITY> the entity * @param <ENTITY> the entity
* *
* @author Emil Forslund * @author Emil Forslund
* @since 3.0.0 * @since 3.0.0
*/ */
@GeneratedCode(value = "Speedment") @GeneratedCode(value = "Speedment")
@FunctionalInterface @FunctionalInterface
public interface CharGetter<ENTITY> extends Getter<ENTITY> { public interface CharGetter<ENTITY> extends Getter<ENTITY> {

/** /**
* Returns the member represented by this getter in the specified instance. * Returns the member represented by this getter in the specified instance.
* *
* @param instance the instance to get from * @param instance the instance to get from
* @return the value * @return the value
*/ */
char applyAsChar(ENTITY instance); char applyAsChar(ENTITY instance);

@Override @Override
default Character apply(ENTITY instance) { default Character apply(ENTITY instance) {
return applyAsChar(instance); return applyAsChar(instance);
} }
}
@Override
default Function<ENTITY, Character> asFunction() {
return this::apply;
}

}
Expand Up @@ -17,6 +17,7 @@
package com.speedment.runtime.field.method; package com.speedment.runtime.field.method;


import com.speedment.common.annotation.GeneratedCode; import com.speedment.common.annotation.GeneratedCode;
import java.util.function.Function;
import java.util.function.ToDoubleFunction; import java.util.function.ToDoubleFunction;


/** /**
Expand Down Expand Up @@ -52,4 +53,10 @@ public interface DoubleGetter<ENTITY> extends Getter<ENTITY>, ToDoubleFunction<E
default Double apply(ENTITY instance) { default Double apply(ENTITY instance) {
return applyAsDouble(instance); return applyAsDouble(instance);
} }

@Override
default Function<ENTITY, Double> asFunction() {
return this::apply;
}

} }
Expand Up @@ -17,6 +17,7 @@
package com.speedment.runtime.field.method; package com.speedment.runtime.field.method;


import com.speedment.common.annotation.GeneratedCode; import com.speedment.common.annotation.GeneratedCode;
import java.util.function.Function;


/** /**
* A short-cut functional reference to the {@code getXXX(value)} method for a * A short-cut functional reference to the {@code getXXX(value)} method for a
Expand Down Expand Up @@ -50,4 +51,10 @@ public interface FloatGetter<ENTITY> extends Getter<ENTITY> {
default Float apply(ENTITY instance) { default Float apply(ENTITY instance) {
return applyAsFloat(instance); return applyAsFloat(instance);
} }

@Override
default Function<ENTITY, Float> asFunction() {
return this::apply;
}

} }
Expand Up @@ -40,7 +40,7 @@ public interface Getter<ENTITY> {
* *
* @return this object as a function * @return this object as a function
*/ */
default Function<ENTITY, Object> asFunction() { default Function<ENTITY, ? extends Object> asFunction() {
return this::apply; return this::apply;
} }
} }
Expand Up @@ -17,6 +17,7 @@
package com.speedment.runtime.field.method; package com.speedment.runtime.field.method;


import com.speedment.common.annotation.GeneratedCode; import com.speedment.common.annotation.GeneratedCode;
import java.util.function.Function;
import java.util.function.ToIntFunction; import java.util.function.ToIntFunction;


/** /**
Expand All @@ -38,7 +39,7 @@
@GeneratedCode(value = "Speedment") @GeneratedCode(value = "Speedment")
@FunctionalInterface @FunctionalInterface
public interface IntGetter<ENTITY> extends Getter<ENTITY>, ToIntFunction<ENTITY> { public interface IntGetter<ENTITY> extends Getter<ENTITY>, ToIntFunction<ENTITY> {

/** /**
* Returns the member represented by this getter in the specified instance. * Returns the member represented by this getter in the specified instance.
* *
Expand All @@ -52,4 +53,10 @@ public interface IntGetter<ENTITY> extends Getter<ENTITY>, ToIntFunction<ENTITY>
default Integer apply(ENTITY instance) { default Integer apply(ENTITY instance) {
return applyAsInt(instance); return applyAsInt(instance);
} }

@Override
default Function<ENTITY, Integer> asFunction() {
return this::apply;
}

} }
Expand Up @@ -17,6 +17,7 @@
package com.speedment.runtime.field.method; package com.speedment.runtime.field.method;


import com.speedment.common.annotation.GeneratedCode; import com.speedment.common.annotation.GeneratedCode;
import java.util.function.Function;
import java.util.function.ToLongFunction; import java.util.function.ToLongFunction;


/** /**
Expand Down Expand Up @@ -52,4 +53,10 @@ public interface LongGetter<ENTITY> extends Getter<ENTITY>, ToLongFunction<ENTIT
default Long apply(ENTITY instance) { default Long apply(ENTITY instance) {
return applyAsLong(instance); return applyAsLong(instance);
} }

@Override
default Function<ENTITY, Long> asFunction() {
return this::apply;
}

} }
Expand Up @@ -40,4 +40,11 @@


@FunctionalInterface @FunctionalInterface
public interface ReferenceGetter<ENTITY, V> public interface ReferenceGetter<ENTITY, V>
extends Getter<ENTITY>, Function<ENTITY, V> {} extends Getter<ENTITY>, Function<ENTITY, V> {

@Override
default Function<ENTITY, V> asFunction() {
return this;
}

}
Expand Up @@ -17,6 +17,7 @@
package com.speedment.runtime.field.method; package com.speedment.runtime.field.method;


import com.speedment.common.annotation.GeneratedCode; import com.speedment.common.annotation.GeneratedCode;
import java.util.function.Function;


/** /**
* A short-cut functional reference to the {@code getXXX(value)} method for a * A short-cut functional reference to the {@code getXXX(value)} method for a
Expand Down Expand Up @@ -50,4 +51,10 @@ public interface ShortGetter<ENTITY> extends Getter<ENTITY> {
default Short apply(ENTITY instance) { default Short apply(ENTITY instance) {
return applyAsShort(instance); return applyAsShort(instance);
} }

@Override
default Function<ENTITY, Short> asFunction() {
return this::apply;
}

} }

0 comments on commit 8ce3efe

Please sign in to comment.