Skip to content

Commit 07de5f4

Browse files
committedNov 6, 2017
binary predicate expressions for equals (and not equals)
1 parent f10c04e commit 07de5f4

13 files changed

+157
-12
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Copyright (c) 2017 European Organisation for Nuclear Research (CERN), All Rights Reserved.
3+
*/
4+
5+
package org.tensorics.core.examples.meteo.icalepcs17;
6+
7+
public class City {
8+
9+
public static City ofName(String name) {
10+
return null;
11+
}
12+
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Copyright (c) 2017 European Organisation for Nuclear Research (CERN), All Rights Reserved.
3+
*/
4+
5+
package org.tensorics.core.examples.meteo.icalepcs17;
6+
7+
public class Constants {
8+
9+
public static final City SF = City.ofName("San Francisco");
10+
public static final City LA = City.ofName("Los Angeles");
11+
12+
public static final Time T1 = Time.of("2017-01-01 15:00");
13+
public static final Time T2 = Time.of("2017-01-02 15:00");
14+
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Copyright (c) 2017 European Organisation for Nuclear Research (CERN), All Rights Reserved.
3+
*/
4+
5+
package org.tensorics.core.examples.meteo.icalepcs17;
6+
7+
public class Time {
8+
9+
public static Time of(String time) {
10+
return null;
11+
}
12+
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Copyright (c) 2017 European Organisation for Nuclear Research (CERN), All Rights Reserved.
3+
*/
4+
5+
package org.tensorics.core.lang;
6+
7+
import org.tensorics.core.expressions.BinaryPredicateExpression;
8+
import org.tensorics.core.math.predicates.IsEqualTo;
9+
import org.tensorics.core.math.predicates.IsNotEqualTo;
10+
import org.tensorics.core.tree.domain.Expression;
11+
import org.tensorics.core.tree.domain.ResolvedExpression;
12+
13+
public class OngoingBasicDeferredBinaryPredicate<T> {
14+
15+
private final Expression<T> left;
16+
17+
public OngoingBasicDeferredBinaryPredicate(Expression<T> left) {
18+
this.left = left;
19+
}
20+
21+
public Expression<Boolean> isEqualTo(Expression<T> right) {
22+
return new BinaryPredicateExpression<>(IsEqualTo.isEqualTo(), left, right);
23+
}
24+
25+
public Expression<Boolean> isEqualTo(T right) {
26+
return isEqualTo(ResolvedExpression.of(right));
27+
}
28+
29+
public Expression<Boolean> isNotEqualTo(Expression<T> right) {
30+
return new BinaryPredicateExpression<>(IsNotEqualTo.isNotEqualTo(), left, right);
31+
}
32+
33+
public Expression<Boolean> isNotEqualTo(T right) {
34+
return isNotEqualTo(ResolvedExpression.of(right));
35+
}
36+
37+
}

‎src/java/org/tensorics/core/lang/TensoricExpressions.java

+9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.tensorics.core.functional.FuncN;
2323
import org.tensorics.core.functional.expressions.FunctionalExpression;
2424
import org.tensorics.core.tree.domain.Expression;
25+
import org.tensorics.core.tree.domain.ResolvedExpression;
2526

2627
import com.google.common.collect.ImmutableList;
2728

@@ -106,4 +107,12 @@ public static <T> Expression<T> lastOf(Expression<? extends Iterable<T>> source)
106107
return LatestOfExpression.latestOf(source);
107108
}
108109

110+
public static <T> OngoingBasicDeferredBinaryPredicate<T> testIf(Expression<T> left) {
111+
return new OngoingBasicDeferredBinaryPredicate<>(left);
112+
}
113+
114+
public static <T> OngoingBasicDeferredBinaryPredicate<T> testIf(T left) {
115+
return testIf(ResolvedExpression.of(left));
116+
}
117+
109118
}

‎src/java/org/tensorics/core/math/predicates/IsEqualTo.java

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
public final class IsEqualTo<T> implements BinaryPredicate<T> {
88

9+
private static final IsEqualTo<?> INSTANCE = new IsEqualTo<>();
10+
911
@Override
1012
public Boolean perform(T left, T right) {
1113
return test(left, right);
@@ -16,4 +18,9 @@ public boolean test(T left, T right) {
1618
return left.equals(right);
1719
}
1820

21+
@SuppressWarnings("unchecked")
22+
public static final <T> IsEqualTo<T> isEqualTo() {
23+
return (IsEqualTo<T>) INSTANCE;
24+
}
25+
1926
}

‎src/java/org/tensorics/core/math/predicates/IsNotEqualTo.java

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
public class IsNotEqualTo<T> implements BinaryPredicate<T> {
88

9+
private static final IsNotEqualTo<?> INSTANCE = new IsNotEqualTo<>();
10+
911
@Override
1012
public Boolean perform(T left, T right) {
1113
return test(left, right);
@@ -15,4 +17,9 @@ public Boolean perform(T left, T right) {
1517
public boolean test(T left, T right) {
1618
return !left.equals(right);
1719
}
20+
21+
@SuppressWarnings("unchecked")
22+
public static final <T> IsNotEqualTo<T> isNotEqualTo() {
23+
return (IsNotEqualTo<T>) INSTANCE;
24+
}
1825
}

‎src/java/org/tensorics/core/tensor/lang/OngoingDimensionReduction.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*******************************************************************************
33
*
44
* This file is part of tensorics.
5-
*
5+
*
66
* Copyright (c) 2008-2011, CERN. All rights reserved.
77
*
88
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,7 +16,7 @@
1616
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1717
* See the License for the specific language governing permissions and
1818
* limitations under the License.
19-
*
19+
*
2020
******************************************************************************/
2121
// @formatter:on
2222

@@ -30,11 +30,12 @@
3030
/**
3131
* Part of the tensorics fluent API, that allows to further describe how a tensor dimesion shall be reduced (where the
3232
* field was not yet known in the previous expression part)
33-
*
33+
*
3434
* @author kfuchsbe
3535
* @param <C> the type of the dimension in which the tensor shall be reduced
3636
* @param <S> the type of the scalars (elements of the field on which all the operations are based on)
3737
*/
38+
@Deprecated
3839
public final class OngoingDimensionReduction<C, S> extends OngoingStructuralReduction<C, S> {
3940

4041
public OngoingDimensionReduction(Tensor<S> tensor, Class<C> dimension) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright (c) 2017 European Organisation for Nuclear Research (CERN), All Rights Reserved.
3+
*/
4+
5+
package org.tensorics.core.tensor.lang;
6+
7+
import static java.util.Objects.requireNonNull;
8+
9+
import org.tensorics.core.commons.options.Environment;
10+
11+
public class OngoingFieldAwareTensorReduction<V> extends OngoingTensorReduction<V> {
12+
13+
private final Environment<V> environment;
14+
15+
public OngoingFieldAwareTensorReduction(Environment<V> environment) {
16+
this.environment = requireNonNull(environment, "environment must not be null");
17+
}
18+
19+
}

‎src/java/org/tensorics/core/tensor/lang/OngoingStructuralReduction.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*******************************************************************************
33
*
44
* This file is part of tensorics.
5-
*
5+
*
66
* Copyright (c) 2008-2011, CERN. All rights reserved.
77
*
88
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,7 +16,7 @@
1616
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1717
* See the License for the specific language governing permissions and
1818
* limitations under the License.
19-
*
19+
*
2020
******************************************************************************/
2121
// @formatter:on
2222

@@ -30,12 +30,13 @@
3030
/**
3131
* Part of the tensoric fluent API, which provides methods to specify concretely how a given dimension should be
3232
* reduced.
33-
*
33+
*
3434
* @author kfuchsbe
3535
* @param <C> the type of coordinate (aka 'the dimension') which is going to be reduced (by calling methods of this
3636
* class)
3737
* @param <E> the type of the elements of the tensor to be reduced.
3838
*/
39+
@Deprecated
3940
public class OngoingStructuralReduction<C, E> {
4041

4142
private final Tensor<E> tensor;

‎src/java/org/tensorics/core/tensor/lang/OngoingStructuralReductionOptions.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* @param <E>
1616
* @param <C>
1717
*/
18+
@Deprecated
1819
public class OngoingStructuralReductionOptions<E, C> {
1920

2021
private final Tensor<E> tensor;
@@ -30,7 +31,7 @@ public OngoingStructuralReductionOptions(C slicePosition, Tensor<E> tensor, Clas
3031
/**
3132
* Defines the interpolation strategy. <br>
3233
* See {@link AbstractInterpolationStrategy} and its extension.
33-
*
34+
*
3435
* @param strategy to use
3536
* @return slicing result with interpolation between the missing comparable coordinates.
3637
*/

‎src/java/org/tensorics/core/tensor/lang/OngoingTensorManipulation.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*******************************************************************************
33
*
44
* This file is part of tensorics.
5-
*
5+
*
66
* Copyright (c) 2008-2011, CERN. All rights reserved.
77
*
88
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,7 +16,7 @@
1616
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1717
* See the License for the specific language governing permissions and
1818
* limitations under the License.
19-
*
19+
*
2020
******************************************************************************/
2121
// @formatter:on
2222

@@ -38,7 +38,7 @@
3838

3939
/**
4040
* Part of the tensoric fluent API which provides methods to describe misc manipulations on a given tensor.
41-
*
41+
*
4242
* @author kfuchsbe
4343
* @param <V> the type of the values of the tensor
4444
*/
@@ -55,7 +55,7 @@ public class OngoingTensorManipulation<V> {
5555
* Extracts from the tensor only those elements where the values in the given mask is {@code true}. The resulting
5656
* tensors will then have the same dimensionality as the original tensor, but will only have that many elements as
5757
* there are {@code true} elements in the mask tensor.
58-
*
58+
*
5959
* @param mask the mask which determines which elements shall be present in the new tensor.
6060
* @return A tensor which will contain only those elements which have {@code true} flags in the mask
6161
*/
@@ -71,7 +71,7 @@ public Tensor<V> extractWhereTrue(Tensor<Boolean> mask) {
7171

7272
/**
7373
* Retrieves all the unique coordinates of the given type.
74-
*
74+
*
7575
* @param coordinateType the type of the coordinate to extract
7676
* @return a set of extracted coordinates
7777
*/
@@ -130,6 +130,7 @@ private static final <C, E> Tensor<E> slice(Tensor<E> tensor, C coordinate) {
130130
return TensorStructurals.from(tensor).reduce(correctDimension).bySlicingAt(coordinate);
131131
}
132132

133+
@Deprecated
133134
public <C> OngoingDimensionReduction<C, V> reduce(Class<C> dimension) {
134135
return new OngoingDimensionReduction<>(tensor, dimension);
135136
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Copyright (c) 2017 European Organisation for Nuclear Research (CERN), All Rights Reserved.
3+
*/
4+
5+
package org.tensorics.core.tensor.lang;
6+
7+
import org.tensorics.core.reduction.ReductionStrategy;
8+
import org.tensorics.core.tensor.Tensor;
9+
import org.tensorics.core.tensor.operations.TensorReduction;
10+
11+
public class OngoingTensorReduction<V> {
12+
13+
public <C, R> Tensor<R> by(ReductionStrategy<C, V, R> strategy) {
14+
return reduceBy(strategy);
15+
}
16+
17+
protected <C, R> Tensor<R> reduceBy(ReductionStrategy<C, V, R> strategy) {
18+
return null;// return new TensorReduction<>(dimension, strategy).apply(tensor);
19+
}
20+
21+
}

0 commit comments

Comments
 (0)
Please sign in to comment.