Skip to content

Commit 08ab79c

Browse files
committed
incorporated files from tensorics-expressions project. Solved warnings
1 parent c5a7833 commit 08ab79c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+441
-70
lines changed

src/java/org/tensorics/core/commons/options/Environment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import org.tensorics.core.math.ExtendedField;
2626

2727
/**
28-
* Encapsulates a field (on which alll calculations are based) and a set of options, since the two are very commonly
28+
* Encapsulates a field (on which all calculations are based) and a set of options, since the two are very commonly
2929
* used together and have to be passed on on many occasions.
3030
*
3131
* @author kfuchsbe

src/java/org/tensorics/core/commons/options/ImmutableOptionRegistry.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public final class ImmutableOptionRegistry<T extends Option<T>> implements Optio
5050
* @param processingOptions the options that will be contained in the registry
5151
* @return a new instance of a registry, containing the options
5252
*/
53-
@SuppressWarnings("PMD.ShortMethodName")
5453
public static <T extends Option<T>> ImmutableOptionRegistry<T> of(Collection<T> processingOptions) {
5554
return new ImmutableOptionRegistry<T>(processingOptions);
5655
}

src/java/org/tensorics/core/commons/util/AbstractPair.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
* @param <T> the type of the elements of the pair
3636
* @author kfuchsbe
3737
*/
38-
@SuppressWarnings("PMD.CyclomaticComplexity")
3938
public class AbstractPair<T> {
4039

4140
private final T leftElement;
@@ -68,7 +67,6 @@ public final int hashCode() {
6867
}
6968

7069
@Override
71-
@SuppressWarnings("PMD.CyclomaticComplexity")
7270
public final boolean equals(Object obj) {
7371
if (this == obj) {
7472
return true;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright (c) 2016 European Organisation for Nuclear Research (CERN), All Rights Reserved.
3+
*/
4+
5+
package org.tensorics.core.expressions;
6+
7+
import org.tensorics.core.commons.operations.Conversion;
8+
import org.tensorics.core.tree.domain.Expression;
9+
10+
/**
11+
* This expression reduces an {@link Expression} of {@link Iterable} of boolean to an {@link Expression} of a
12+
* {@link Boolean}. The conversion represents the reduction strategy that will be applied on the iterable.
13+
*
14+
* @author acalia, caguiler, kfuchsberger
15+
*/
16+
public class CombinedBooleanExpression extends ConversionOperationExpression<Iterable<Boolean>, Boolean> {
17+
18+
public CombinedBooleanExpression(Conversion<Iterable<Boolean>, Boolean> operation,
19+
Expression<Iterable<Boolean>> source) {
20+
super(operation, source);
21+
}
22+
23+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Copyright (c) 2016 European Organisation for Nuclear Research (CERN), All Rights Reserved.
3+
*/
4+
5+
package org.tensorics.core.expressions;
6+
7+
public enum EvaluationStatus {
8+
EVALUATED,
9+
NOT_EVALUATED;
10+
11+
public static EvaluationStatus fromBoolean(boolean isExecuted) {
12+
return isExecuted ? EVALUATED : NOT_EVALUATED;
13+
}
14+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright (c) 2016 European Organisation for Nuclear Research (CERN), All Rights Reserved.
3+
*/
4+
5+
package org.tensorics.core.expressions;
6+
7+
import static java.lang.String.format;
8+
9+
import org.tensorics.core.math.predicates.IsEqualTo;
10+
import org.tensorics.core.tree.domain.Expression;
11+
12+
public class IsEqualToExpression<T> extends BinaryPredicateExpression<T> {
13+
14+
public IsEqualToExpression(Expression<T> left, Expression<T> right) {
15+
super(new IsEqualTo<T>(), left, right);
16+
}
17+
18+
@Override
19+
public String toString() {
20+
return format("%s is equal to %s", getLeft(), getRight());
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright (c) 2016 European Organisation for Nuclear Research (CERN), All Rights Reserved.
3+
*/
4+
5+
package org.tensorics.core.expressions;
6+
7+
import static java.lang.String.format;
8+
9+
import org.tensorics.core.math.predicates.IsNotEqualTo;
10+
import org.tensorics.core.tree.domain.Expression;
11+
12+
public class IsNotEqualExpression<T> extends BinaryPredicateExpression<T> {
13+
14+
public IsNotEqualExpression(Expression<T> left, Expression<T> right) {
15+
super(new IsNotEqualTo<>(), left, right);
16+
}
17+
18+
@Override
19+
public String toString() {
20+
return format("%s is not equal to %s", getLeft(), getRight());
21+
}
22+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* Copyright (c) 2016 European Organisation for Nuclear Research (CERN), All Rights Reserved.
3+
*/
4+
5+
package org.tensorics.core.expressions;
6+
7+
import java.util.List;
8+
9+
import org.tensorics.core.resolve.resolvers.IterableResolvingExpressionResolver;
10+
import org.tensorics.core.tree.domain.AbstractDeferredExpression;
11+
import org.tensorics.core.tree.domain.Expression;
12+
import org.tensorics.core.tree.domain.Node;
13+
14+
import com.google.common.collect.ImmutableList;
15+
16+
/**
17+
* Expression that given an {@link Iterable} of {@link Expression} of T, resolves to an {@link Iterable} of T. In other
18+
* words, it resolves the inner {@link Expression} of the {@link Iterable}.
19+
*
20+
* @see IterableResolvingExpressionResolver
21+
* @author acalia, caguiler, kfuchsberger
22+
* @param <T> type of the elements of the iterable
23+
*/
24+
public class IterableResolvingExpression<T> extends AbstractDeferredExpression<Iterable<T>> {
25+
26+
private final List<Expression<T>> expressions;
27+
28+
public IterableResolvingExpression(Iterable<Expression<T>> iterable) {
29+
this.expressions = ImmutableList.copyOf(iterable);
30+
}
31+
32+
@Override
33+
public List<? extends Node> getChildren() {
34+
return expressions;
35+
}
36+
37+
public List<? extends Expression<T>> expressions() {
38+
return expressions;
39+
}
40+
41+
@Override
42+
public int hashCode() {
43+
final int prime = 31;
44+
int result = 1;
45+
result = prime * result + ((expressions == null) ? 0 : expressions.hashCode());
46+
return result;
47+
}
48+
49+
@Override
50+
public boolean equals(Object obj) {
51+
if (this == obj) {
52+
return true;
53+
}
54+
if (obj == null) {
55+
return false;
56+
}
57+
if (getClass() != obj.getClass()) {
58+
return false;
59+
}
60+
IterableResolvingExpression<?> other = (IterableResolvingExpression<?>) obj;
61+
if (expressions == null) {
62+
if (other.expressions != null) {
63+
return false;
64+
}
65+
} else if (!expressions.equals(other.expressions)) {
66+
return false;
67+
}
68+
return true;
69+
}
70+
71+
@Override
72+
public String toString() {
73+
return "IterableResolvingExpression [expressions=" + expressions + "]";
74+
}
75+
76+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/**
2+
* Copyright (c) 2016 European Organisation for Nuclear Research (CERN), All Rights Reserved.
3+
*/
4+
5+
package org.tensorics.core.expressions;
6+
7+
import java.util.List;
8+
import java.util.function.Predicate;
9+
10+
import org.tensorics.core.tree.domain.AbstractDeferredExpression;
11+
import org.tensorics.core.tree.domain.Expression;
12+
13+
import com.google.common.collect.ImmutableList;
14+
15+
public class PredicateExpression<T> extends AbstractDeferredExpression<Boolean> {
16+
17+
private final Expression<T> source;
18+
private final Expression<Predicate<T>> predicate;
19+
20+
private PredicateExpression(Expression<T> source, Expression<Predicate<T>> predicate) {
21+
super();
22+
this.source = source;
23+
this.predicate = predicate;
24+
}
25+
26+
public static <T> PredicateExpression<T> ofSourceAndPredicate(Expression<T> source,
27+
Expression<Predicate<T>> predicate) {
28+
return new PredicateExpression<>(source, predicate);
29+
}
30+
31+
@Override
32+
public List<Expression<?>> getChildren() {
33+
return ImmutableList.of(source, predicate);
34+
}
35+
36+
public Expression<T> source() {
37+
return source;
38+
}
39+
40+
public Expression<Predicate<T>> predicate() {
41+
return predicate;
42+
}
43+
44+
@Override
45+
public int hashCode() {
46+
final int prime = 31;
47+
int result = 1;
48+
result = prime * result + ((predicate == null) ? 0 : predicate.hashCode());
49+
result = prime * result + ((source == null) ? 0 : source.hashCode());
50+
return result;
51+
}
52+
53+
@Override
54+
public boolean equals(Object obj) {
55+
if (this == obj) {
56+
return true;
57+
}
58+
if (obj == null) {
59+
return false;
60+
}
61+
if (getClass() != obj.getClass()) {
62+
return false;
63+
}
64+
PredicateExpression<?> other = (PredicateExpression<?>) obj;
65+
if (predicate == null) {
66+
if (other.predicate != null) {
67+
return false;
68+
}
69+
} else if (!predicate.equals(other.predicate)) {
70+
return false;
71+
}
72+
if (source == null) {
73+
if (other.source != null) {
74+
return false;
75+
}
76+
} else if (!source.equals(other.source)) {
77+
return false;
78+
}
79+
return true;
80+
}
81+
82+
@Override
83+
public String toString() {
84+
return "PredicateCondition [source=" + source + ", predicate=" + predicate + "]";
85+
}
86+
87+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/**
2+
* Copyright (c) 2016 European Organisation for Nuclear Research (CERN), All Rights Reserved.
3+
*/
4+
5+
package org.tensorics.core.expressions;
6+
7+
import java.util.Arrays;
8+
import java.util.List;
9+
10+
import org.tensorics.core.resolve.resolvers.WindowedExpressionResolver;
11+
import org.tensorics.core.tree.domain.AbstractDeferredExpression;
12+
import org.tensorics.core.tree.domain.Expression;
13+
14+
/**
15+
* Expression that evaluates the targetExpression given the result of the enabling expression. The enabling
16+
* expression is an {@link Expression} of {@link Boolean} that decides if the targetExpression is
17+
* resolved or not. This expression resolves into an {@link EvaluationStatus}.
18+
*
19+
* @see WindowedExpressionResolver
20+
* @param T the type of the target expression
21+
* @author acalia, caguiler
22+
*/
23+
public class WindowedExpression<T extends Expression<?>> extends AbstractDeferredExpression<EvaluationStatus> {
24+
25+
private final T targetExpression;
26+
private final Expression<Boolean> enablingExpression;
27+
28+
public WindowedExpression(T targetExpression, Expression<Boolean> enablingExpression) {
29+
this.targetExpression = targetExpression;
30+
this.enablingExpression = enablingExpression;
31+
}
32+
33+
@Override
34+
public List<Expression<?>> getChildren() {
35+
return Arrays.asList(targetExpression, enablingExpression);
36+
}
37+
38+
public T targetExpression() {
39+
return targetExpression;
40+
}
41+
42+
public Expression<Boolean> enablingExpression() {
43+
return enablingExpression;
44+
}
45+
46+
@Override
47+
public int hashCode() {
48+
final int prime = 31;
49+
int result = 1;
50+
result = prime * result + ((enablingExpression == null) ? 0 : enablingExpression.hashCode());
51+
result = prime * result + ((targetExpression == null) ? 0 : targetExpression.hashCode());
52+
return result;
53+
}
54+
55+
@Override
56+
public boolean equals(Object obj) {
57+
if (this == obj) {
58+
return true;
59+
}
60+
if (obj == null) {
61+
return false;
62+
}
63+
if (getClass() != obj.getClass()) {
64+
return false;
65+
}
66+
WindowedExpression<?> other = (WindowedExpression<?>) obj;
67+
if (enablingExpression == null) {
68+
if (other.enablingExpression != null) {
69+
return false;
70+
}
71+
} else if (!enablingExpression.equals(other.enablingExpression)) {
72+
return false;
73+
}
74+
if (targetExpression == null) {
75+
if (other.targetExpression != null) {
76+
return false;
77+
}
78+
} else if (!targetExpression.equals(other.targetExpression)) {
79+
return false;
80+
}
81+
return true;
82+
}
83+
84+
@Override
85+
public String toString() {
86+
return this.getClass().getSimpleName() + " [targetExpression=" + targetExpression + ", enablingExpression="
87+
+ enablingExpression + "]";
88+
}
89+
}

0 commit comments

Comments
 (0)