Skip to content

Commit 07de5f4

Browse files
committed
binary predicate expressions for equals (and not equals)
1 parent f10c04e commit 07de5f4

File tree

13 files changed

+157
-12
lines changed

13 files changed

+157
-12
lines changed
Lines changed: 13 additions & 0 deletions
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+
}
Lines changed: 15 additions & 0 deletions
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+
}
Lines changed: 13 additions & 0 deletions
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+
}
Lines changed: 37 additions & 0 deletions
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

Lines changed: 9 additions & 0 deletions
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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 4 additions & 3 deletions
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) {
Lines changed: 19 additions & 0 deletions
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

Lines changed: 4 additions & 3 deletions
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;

0 commit comments

Comments
 (0)