Skip to content

Commit 65c0c71

Browse files
committed
Merge branch 'master' of git@github.com:tensorics/tensorics-core.git
2 parents 6fca9b0 + 26b6513 commit 65c0c71

27 files changed

+821
-792
lines changed

src/asciidoc/tensorics-quickstart.ad

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ the respective tensor. The ++dimensions++ of a tensor are uniquely defined by th
2525
*_This might have sound complicated - however, an example should make it obvious. Give it a chance and keep on reading ;-)_*
2626

2727
=== The weather example
28-
Lets take a (very simplistic ;-) example: Assume that we are are analyzing weather data.
28+
Lets take a (very simplistic ;-) example: Assume that we are analyzing weather data.
2929
We have recorded temperature values for several cities and several days, for example:
3030

3131
.Example Temperatures (random data!)

src/examples/org/tensorics/core/examples/BooleanStepFunctionExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void testCalculations() {
4646
Tensor<Boolean> tensor = stepFunctionTensor;
4747
Tensor<Boolean> slicedTensor = TensorStructurals.from(tensor).reduce(Signal.class).bySlicingAt(AMPLIFIER);
4848
assertFalse(slicedTensor.get(ORIGIN));
49-
assertEquals(Position.of(AMPLIFIER), slicedTensor.context().getPosition());
49+
assertEquals(Position.of(AMPLIFIER), slicedTensor.context());
5050

5151
TensorBuilder<Boolean> builder = Tensorics.builderFrom(tensor);
5252
builder.putAt(false, Position.of(new Date(5L), AMPLIFIER));

src/examples/org/tensorics/core/examples/meteo/externaldata/FakeMeteoDataImporter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.tensorics.core.examples.meteo.domain.coordinates.Time;
1212
import org.tensorics.core.quantity.ImmutableQuantifiedValue;
1313
import org.tensorics.core.quantity.QuantifiedValue;
14-
import org.tensorics.core.tensor.Context;
1514
import org.tensorics.core.tensor.ImmutableTensor;
1615
import org.tensorics.core.tensor.ImmutableTensor.Builder;
1716
import org.tensorics.core.tensor.Position;
@@ -34,7 +33,7 @@ private FakeMeteoDataImporter() {
3433
public static Tensor<QuantifiedValue<Double>> importFromNow() {
3534
Set<Class<?>> dimensions = ImmutableSet.of(Longitude.class, Latitude.class);
3635
Builder<QuantifiedValue<Double>> tensorBuilder = ImmutableTensor.<QuantifiedValue<Double>> builder(dimensions);
37-
tensorBuilder.setTensorContext(Context.of(ImmutableSet.<MeteoCoordinate> of(new Time())));
36+
tensorBuilder.context(Position.of(ImmutableSet.<MeteoCoordinate> of(new Time())));
3837
Random rand = new Random();
3938
for (int x = 0; x < 10; x++) {
4039
for (int y = 0; y < 10; y++) {

src/examples/org/tensorics/core/examples/sprint/SprintExample.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.junit.Test;
1515
import org.tensorics.core.lang.TensoricDoubleSupport;
1616
import org.tensorics.core.lang.Tensorics;
17-
import org.tensorics.core.tensor.Context;
1817
import org.tensorics.core.tensor.Position;
1918
import org.tensorics.core.tensor.Tensor;
2019
import org.tensorics.core.tensor.TensorBuilder;
@@ -90,12 +89,12 @@ public void testIfMergedTensorHasCorrectSize() {
9089

9190
@Test
9291
public void testContext() {
93-
Context team1Context = team1Velocity.context();
94-
assertEquals(1, team1Context.getPosition().coordinates().size());
92+
Position team1Context = team1Velocity.context();
93+
assertEquals(1, team1Context.coordinates().size());
9594

9695
Tensor<Double> sliceAtOneDay = from(team1Velocity).extract(new NumberOfDay(1));
97-
Context oneDayContext = sliceAtOneDay.context();
98-
assertEquals(2, oneDayContext.getPosition().coordinates().size());
96+
Position oneDayContext = sliceAtOneDay.context();
97+
assertEquals(2, oneDayContext.coordinates().size());
9998
}
10099

101100
}

src/java/org/tensorics/core/lang/Tensorics.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,14 +383,14 @@ public static <V, TB extends Tensorbacked<V>> OngoingTensorbackedFiltering<V, TB
383383
/**
384384
* @see TensorStructurals#setContext(Tensor, Context)
385385
*/
386-
public static <S> Tensor<S> setContext(Tensor<S> tensor, Context context) {
386+
public static <S> Tensor<S> setContext(Tensor<S> tensor, Position context) {
387387
return TensorStructurals.setContext(tensor, context);
388388
}
389389

390390
/**
391391
* @see Tensorbackeds#setContext(Tensorbacked, Context)
392392
*/
393-
public static <V, TB extends Tensorbacked<V>> TB setContext(TB tensorbacked, Context context) {
393+
public static <V, TB extends Tensorbacked<V>> TB setContext(TB tensorbacked, Position context) {
394394
return Tensorbackeds.setContext(tensorbacked, context);
395395
}
396396

src/java/org/tensorics/core/tensor/AbstractTensorBuilder.java

Lines changed: 111 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -32,118 +32,119 @@
3232

3333
/**
3434
* @author kfuchsbe
35-
* @param <E> the type of the elements of the tensor to build
35+
* @param <E>
36+
* the type of the elements of the tensor to build
3637
*/
3738
@SuppressWarnings("PMD.TooManyMethods")
3839
public abstract class AbstractTensorBuilder<E> implements TensorBuilder<E> {
3940

40-
private final Set<Class<?>> dimensions;
41-
private final VerificationCallback<E> callback;
42-
private Context context = Context.empty();
43-
44-
public AbstractTensorBuilder(Set<Class<?>> dimensions, VerificationCallback<E> callback) {
45-
Preconditions.checkArgument(dimensions != null, "Argument '" + "dimensions" + "' must not be null!");
46-
Preconditions.checkArgument(callback != null, "Argument '" + "callback" + "' must not be null!");
47-
Coordinates.checkClassesRelations(dimensions);
48-
this.dimensions = ImmutableSet.copyOf(dimensions);
49-
this.callback = callback;
50-
}
51-
52-
public AbstractTensorBuilder(Set<Class<?>> dimensions) {
53-
this(dimensions, new VerificationCallback<E>() {
54-
55-
@Override
56-
public void verify(E scalar) {
57-
/* Nothing to do */
58-
}
59-
});
60-
}
61-
62-
/**
63-
* Prepares to set a value at given position (a combined set of coordinates)
64-
*
65-
* @param entryPosition on which future value will be placed.
66-
* @return builder object to be able to put Value in.
67-
*/
68-
@SuppressWarnings("PMD.ShortMethodName")
69-
public final OngoingPut<E> at(Position entryPosition) {
70-
return new OngoingPut<E>(entryPosition, this);
71-
}
72-
73-
@Override
74-
public final void putAt(E value, Position position) {
75-
Preconditions.checkNotNull(value, "value must not be null!");
76-
Preconditions.checkNotNull(position, "position must not be null");
77-
Positions.assertConsistentDimensions(position, getDimensions());
78-
this.callback.verify(value);
79-
this.putItAt(value, position);
80-
}
81-
82-
protected abstract void putItAt(E value, Position position);
83-
84-
@Override
85-
public final void putAt(E value, Object... coordinates) {
86-
this.putAt(value, Position.of(coordinates));
87-
}
88-
89-
@Override
90-
public void putAt(E value, Set<?> coordinates) {
91-
putAt(value, Position.of(coordinates));
92-
}
93-
94-
@Override
95-
public void putAllAt(Tensor<E> tensor, Set<?> coordinates) {
96-
putAllAt(tensor, Position.of(coordinates));
97-
}
98-
99-
@Override
100-
public final void setTensorContext(Context context) {
101-
Preconditions.checkNotNull(context, "context must not be null");
102-
checkIfContextValid(context);
103-
this.context = context;
104-
}
105-
106-
private void checkIfContextValid(Context context2) {
107-
Position contextPosition = context2.getPosition();
108-
for (Class<?> oneDimensionClass : contextPosition.dimensionSet()) {
109-
if (dimensions.contains(oneDimensionClass)) {
110-
throw new IllegalStateException("Inconsistent state: " + oneDimensionClass
111-
+ " you are trying to put in to context is a BASE dimension of the tensor!");
112-
}
113-
}
114-
}
115-
116-
@SuppressWarnings("PMD.ShortMethodName")
117-
public final OngoingPut<E> at(Set<?> coordinates) {
118-
return this.at(Position.of(coordinates));
119-
}
120-
121-
@SafeVarargs
122-
@SuppressWarnings("PMD.ShortMethodName")
123-
public final OngoingPut<E> at(Object... coordinates) {
124-
return this.at(Position.of(coordinates));
125-
}
126-
127-
@Override
128-
public final void putAllAt(Tensor<E> tensor, Position position) {
129-
checkNotNull(tensor, "The tensor must not be null!");
130-
checkNotNull(position, "The position must not be null!");
131-
for (Entry<Position, E> entry : tensor.asMap().entrySet()) {
132-
putAt(entry.getValue(), Positions.union(position, entry.getKey()));
133-
}
134-
}
135-
136-
@Override
137-
@SafeVarargs
138-
public final void putAllAt(Tensor<E> tensor, Object... coordinates) {
139-
putAllAt(tensor, Position.of(coordinates));
140-
}
141-
142-
public Set<Class<?>> getDimensions() {
143-
return dimensions;
144-
}
145-
146-
public Context getContext() {
147-
return context;
148-
}
41+
private final Set<Class<?>> dimensions;
42+
private final VerificationCallback<E> callback;
43+
private Position context = Position.empty();
44+
45+
public AbstractTensorBuilder(Set<Class<?>> dimensions, VerificationCallback<E> callback) {
46+
Preconditions.checkArgument(dimensions != null, "Argument '" + "dimensions" + "' must not be null!");
47+
Preconditions.checkArgument(callback != null, "Argument '" + "callback" + "' must not be null!");
48+
Coordinates.checkClassesRelations(dimensions);
49+
this.dimensions = ImmutableSet.copyOf(dimensions);
50+
this.callback = callback;
51+
}
52+
53+
public AbstractTensorBuilder(Set<Class<?>> dimensions) {
54+
this(dimensions, new VerificationCallback<E>() {
55+
56+
@Override
57+
public void verify(E scalar) {
58+
/* Nothing to do */
59+
}
60+
});
61+
}
62+
63+
/**
64+
* Prepares to set a value at given position (a combined set of coordinates)
65+
*
66+
* @param entryPosition
67+
* on which future value will be placed.
68+
* @return builder object to be able to put Value in.
69+
*/
70+
@SuppressWarnings("PMD.ShortMethodName")
71+
public final OngoingPut<E> at(Position entryPosition) {
72+
return new OngoingPut<E>(entryPosition, this);
73+
}
74+
75+
@Override
76+
public final void putAt(E value, Position position) {
77+
Preconditions.checkNotNull(value, "value must not be null!");
78+
Preconditions.checkNotNull(position, "position must not be null");
79+
Positions.assertConsistentDimensions(position, this.dimensions);
80+
this.callback.verify(value);
81+
this.putItAt(value, position);
82+
}
83+
84+
protected abstract void putItAt(E value, Position position);
85+
86+
@Override
87+
public final void putAt(E value, Object... coordinates) {
88+
this.putAt(value, Position.of(coordinates));
89+
}
90+
91+
@Override
92+
public void putAt(E value, Set<?> coordinates) {
93+
putAt(value, Position.of(coordinates));
94+
}
95+
96+
@Override
97+
public void putAllAt(Tensor<E> tensor, Set<?> coordinates) {
98+
putAllAt(tensor, Position.of(coordinates));
99+
}
100+
101+
@Override
102+
public void context(Position context) {
103+
Preconditions.checkNotNull(context, "context must not be null");
104+
checkIfContextValid(context);
105+
this.context = context;
106+
}
107+
108+
private void checkIfContextValid(Position context2) {
109+
for (Class<?> oneDimensionClass : context2.dimensionSet()) {
110+
if (dimensions.contains(oneDimensionClass)) {
111+
throw new IllegalStateException("Inconsistent state: " + oneDimensionClass
112+
+ " you are trying to put in to context is a BASE dimension of the tensor!");
113+
}
114+
}
115+
}
116+
117+
@SuppressWarnings("PMD.ShortMethodName")
118+
public final OngoingPut<E> at(Set<?> coordinates) {
119+
return this.at(Position.of(coordinates));
120+
}
121+
122+
@SafeVarargs
123+
@SuppressWarnings("PMD.ShortMethodName")
124+
public final OngoingPut<E> at(Object... coordinates) {
125+
return this.at(Position.of(coordinates));
126+
}
127+
128+
@Override
129+
public final void putAllAt(Tensor<E> tensor, Position position) {
130+
checkNotNull(tensor, "The tensor must not be null!");
131+
checkNotNull(position, "The position must not be null!");
132+
for (Entry<Position, E> entry : tensor.asMap().entrySet()) {
133+
putAt(entry.getValue(), Positions.union(position, entry.getKey()));
134+
}
135+
}
136+
137+
@Override
138+
@SafeVarargs
139+
public final void putAllAt(Tensor<E> tensor, Object... coordinates) {
140+
putAllAt(tensor, Position.of(coordinates));
141+
}
142+
143+
public Set<Class<?>> dimensions() {
144+
return dimensions;
145+
}
146+
147+
public Position context() {
148+
return this.context;
149+
}
149150
}

0 commit comments

Comments
 (0)