Skip to content

Commit cdfb95c

Browse files
committed
JAVAMONEY-89: Removed timestamp methods.
1 parent 8b184f5 commit cdfb95c

File tree

8 files changed

+65
-224
lines changed

8 files changed

+65
-224
lines changed

src/main/java/javax/money/AbstractContext.java

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
package javax.money;
1212

1313
import java.io.Serializable;
14-
import java.time.Instant;
15-
import java.time.temporal.ChronoField;
16-
import java.time.temporal.TemporalAccessor;
1714
import java.util.HashMap;
1815
import java.util.Map;
1916
import java.util.Objects;
@@ -34,12 +31,8 @@ public abstract class AbstractContext implements Serializable {
3431
/**
3532
* Key for storing the target providers to be queried
3633
*/
37-
public static final String KEY_PROVIDER = "provider";
34+
protected static final String KEY_PROVIDER = "provider";
3835

39-
/**
40-
* Key name for the timestamp attribute.
41-
*/
42-
public static final String KEY_TIMESTAMP = "timestamp";
4336

4437
/**
4538
* The data map containing all values.
@@ -175,43 +168,6 @@ public String getProviderName() {
175168
return getText(KEY_PROVIDER);
176169
}
177170

178-
/**
179-
* Get the current target timestamp of the query in UTC milliseconds. If not set it tries to of an
180-
* UTC timestamp from #getTimestamp(). This allows to select historical roundings that were valid in the
181-
* past. Its implementation specific, to what extend historical roundings are available. By default if this
182-
* property is not set always current {@link javax.money.MonetaryRounding} instances are provided.
183-
*
184-
* @return the timestamp in millis, or null.
185-
*/
186-
public Long getTimestampMillis() {
187-
Long value = get(KEY_TIMESTAMP, Long.class);
188-
if (Objects.isNull(value)) {
189-
TemporalAccessor acc = getTimestamp();
190-
if (Objects.nonNull(acc)) {
191-
return (acc.getLong(ChronoField.INSTANT_SECONDS) * 1000L) + acc.getLong(ChronoField.MILLI_OF_SECOND);
192-
}
193-
}
194-
return value;
195-
}
196-
197-
/**
198-
* Get the current target timestamp of the query. If not set it tries to of an Instant from
199-
* #getTimestampMillis(). This allows to select historical roundings that were valid in the
200-
* past. Its implementation specific, to what extend historical roundings are available. By default if this
201-
* property is not set always current {@link javax.money.MonetaryRounding} instances are provided.
202-
*
203-
* @return the current timestamp, or null.
204-
*/
205-
public TemporalAccessor getTimestamp() {
206-
TemporalAccessor acc = get(KEY_TIMESTAMP, TemporalAccessor.class);
207-
if (Objects.isNull(acc)) {
208-
Long value = get(KEY_TIMESTAMP, Long.class);
209-
if (Objects.nonNull(value)) {
210-
acc = Instant.ofEpochMilli(value);
211-
}
212-
}
213-
return acc;
214-
}
215171

216172
/**
217173
* Checks if the current instance has no attributes set. This is often the cases, when used in default cases.
@@ -232,19 +188,6 @@ public int hashCode() {
232188
return Objects.hash(data);
233189
}
234190

235-
/**
236-
* Access all the key/values present, filtered by the values that are assignable to the given type.
237-
*
238-
* @param type the value type, not null.
239-
* @return return all key/values with values assignable to a given value type.
240-
*/
241-
public <T> Map<String, T> getValues(Class<T> type) {
242-
Map<String, T> result = new HashMap<>();
243-
data.entrySet().stream().filter(en -> type.isAssignableFrom(en.getValue().getClass())).forEach(
244-
en -> result.put(en.getKey(), type.cast(en.getValue())));
245-
return result;
246-
}
247-
248191
/*
249192
* (non-Javadoc)
250193
*

src/main/java/javax/money/AbstractContextBuilder.java

Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
*/
99
package javax.money;
1010

11-
import java.time.LocalDateTime;
12-
import java.time.temporal.TemporalAccessor;
1311
import java.util.HashMap;
1412
import java.util.Map;
1513
import java.util.Objects;
@@ -191,35 +189,35 @@ public B setProviderName(String provider) {
191189
set(AbstractContext.KEY_PROVIDER, provider);
192190
return (B) this;
193191
}
194-
195-
/**
196-
* Set the target timestamp in UTC millis. This allows to select historical roundings that were valid in the
197-
* past. Its implementation specific, to what extend historical roundings are available. By default if this
198-
* property is not set always current {@link javax.money.MonetaryRounding} instances are provided.
199-
*
200-
* @param timestamp the target timestamp
201-
* @return this instance for chaining
202-
* @see #setTimestamp(java.time.temporal.TemporalAccessor)
203-
*/
204-
public B setTimestampMillis(long timestamp){
205-
set(AbstractContext.KEY_TIMESTAMP, timestamp);
206-
return (B) this;
207-
}
208-
209-
/**
210-
* Set the target timestamp as {@link java.time.temporal.TemporalAccessor}. This allows to select historical
211-
* roundings that were valid in the past. Its implementation specific, to what extend historical roundings
212-
* are available. By default if this property is not set always current {@link javax.money.MonetaryRounding}
213-
* instances are provided.
214-
*
215-
* @param timestamp the target timestamp
216-
* @return this instance for chaining
217-
* @see #setTimestampMillis(long)
218-
*/
219-
public B setTimestamp(LocalDateTime timestamp) {
220-
set(AbstractContext.KEY_TIMESTAMP, Objects.requireNonNull(timestamp));
221-
return (B) this;
222-
}
192+
//
193+
// /**
194+
// * Set the target timestamp in UTC millis. This allows to select historical roundings that were valid in the
195+
// * past. Its implementation specific, to what extend historical roundings are available. By default if this
196+
// * property is not set always current {@link javax.money.MonetaryRounding} instances are provided.
197+
// *
198+
// * @param timestamp the target timestamp
199+
// * @return this instance for chaining
200+
// * @see #setTimestamp(java.time.temporal.TemporalAccessor)
201+
// */
202+
// public B setTimestampMillis(long timestamp){
203+
// set(AbstractContext.KEY_TIMESTAMP, timestamp);
204+
// return (B) this;
205+
// }
206+
//
207+
// /**
208+
// * Set the target timestamp as {@link java.time.temporal.TemporalAccessor}. This allows to select historical
209+
// * roundings that were valid in the past. Its implementation specific, to what extend historical roundings
210+
// * are available. By default if this property is not set always current {@link javax.money.MonetaryRounding}
211+
// * instances are provided.
212+
// *
213+
// * @param timestamp the target timestamp
214+
// * @return this instance for chaining
215+
// * @see #setTimestampMillis(long)
216+
// */
217+
// public B setTimestamp(LocalDateTime timestamp) {
218+
// set(AbstractContext.KEY_TIMESTAMP, Objects.requireNonNull(timestamp));
219+
// return (B) this;
220+
// }
223221

224222
/**
225223
* Removes an entry of a certain keys. This can be useful, when a context is initialized with another
@@ -236,16 +234,6 @@ public B removeAttributes(String... keys) {
236234
return (B) this;
237235
}
238236

239-
/**
240-
* Removes all entries.
241-
*
242-
* @return this Builder, for chaining
243-
*/
244-
public B removeAll() {
245-
this.data.clear();
246-
return (B) this;
247-
}
248-
249237
/**
250238
* Creates a new {@link AbstractContext} with the data from this Builder
251239
* instance.

src/main/java/javax/money/AbstractQuery.java

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,8 @@
1010
*/
1111
package javax.money;
1212

13-
import java.time.Instant;
14-
import java.time.LocalDateTime;
15-
import java.time.ZoneId;
16-
import java.time.temporal.ChronoField;
17-
import java.time.temporal.TemporalAccessor;
1813
import java.util.Collections;
19-
import java.util.Date;
2014
import java.util.List;
21-
import java.util.Objects;
2215

2316
/**
2417
* Represents a general context of data targeting an item of type {@code Q}. Contexts are used to add arbitrary
@@ -80,29 +73,4 @@ public Class<?> getTargetType() {
8073
return get(KEY_QUERY_TARGET_TYPE, Class.class);
8174
}
8275

83-
/**
84-
* Get the current timestamp of the context in UTC milliseconds. If not set it tries to of an
85-
* UTC timestamp from #getTimestamp().
86-
*
87-
* @return the timestamp in millis, or null.
88-
*/
89-
@Override
90-
public Long getTimestampMillis() {
91-
LocalDateTime value = getTimestamp();
92-
if (Objects.nonNull(value)) {
93-
return Date.from(value.atZone(ZoneId.systemDefault()).toInstant())
94-
.getTime();
95-
}
96-
return null;
97-
}
98-
99-
/**
100-
* Get the current timestamp. If not set it tries to of an Instant from #getTimestampMillis().
101-
* @return the current timestamp, or null.
102-
*/
103-
@Override
104-
public LocalDateTime getTimestamp() {
105-
return get(KEY_QUERY_TIMESTAMP, LocalDateTime.class);
106-
}
107-
10876
}

src/main/java/javax/money/AbstractQueryBuilder.java

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@
88
*/
99
package javax.money;
1010

11-
import java.time.LocalDate;
12-
import java.time.LocalDateTime;
13-
import java.time.LocalTime;
14-
import java.time.ZoneId;
1511
import java.util.Arrays;
16-
import java.util.Date;
1712
import java.util.List;
1813
import java.util.Objects;
1914

@@ -59,30 +54,6 @@ public B setProviderNames(List<String> providers) {
5954
return set(AbstractQuery.KEY_QUERY_PROVIDERS, providers);
6055
}
6156

62-
/**
63-
* Set the target timestamp as {@link java.time.temporal.TemporalAccessor}. This allows to select historical
64-
* roundings that were valid in the past. Its implementation specific, to what extend historical roundings
65-
* are available. By default if this property is not set always current {@link javax.money.MonetaryRounding}
66-
* instances are provided.
67-
*
68-
* @param timestamp the target timestamp
69-
* @return this instance for chaining
70-
* @see #setTimestampMillis(long)
71-
*/
72-
@Override
73-
public B setTimestamp(LocalDateTime timestamp) {
74-
set(AbstractQuery.KEY_QUERY_TIMESTAMP,
75-
Objects.requireNonNull(timestamp));
76-
return (B) this;
77-
}
78-
79-
public B setTimestamp(LocalDate timestamp) {
80-
return setTimestamp(timestamp.atTime(LocalTime.now()));
81-
}
82-
83-
public B setTimestamp(LocalTime timestamp) {
84-
return setTimestamp(LocalDate.now().atTime(timestamp));
85-
}
8657
/**
8758
* Set the providers to be considered. If not set explicitly the <i>default</i> providers and the corresponding
8859
* default ordering are used.
@@ -105,19 +76,6 @@ public B setProviderName(String provider) {
10576
return setProviderNames(provider);
10677
}
10778

108-
/**
109-
* Sets the target timestamp as UTC millisesonds.
110-
*
111-
* @param timestamp the target timestamp
112-
* @return the query builder for chaining.
113-
*/
114-
@Override
115-
public B setTimestampMillis(long timestamp) {
116-
Date date = new Date(timestamp);
117-
LocalDateTime localDateTime = LocalDateTime.ofInstant(date.toInstant(),
118-
ZoneId.systemDefault());
119-
return set(AbstractQuery.KEY_QUERY_TIMESTAMP, localDateTime);
120-
}
12179

12280
/**
12381
* Sets the target implementation type required. This can be used to explicitly acquire a specific
@@ -140,6 +98,6 @@ public B setTargetType(Class<?> type) {
14098
* @return a new {@link AbstractQuery}. never {@code null}.
14199
*/
142100
@Override
143-
public abstract C build();
101+
public abstract C build();
144102

145103
}

src/test/java/javax/money/AbstractContextBuilderTest.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,6 @@ public void testRemoveAttributes() throws Exception {
188188
assertEquals(ctx.getText("myKey"), null);
189189
}
190190

191-
@Test
192-
public void testRemoveAll() throws Exception {
193-
AbstractContextBuilder b = createBuilder();
194-
Set<Number> set = new HashSet<>();
195-
set.add(BigDecimal.ONE);
196-
b.set("myKey", "test");
197-
AbstractContext ctx = b.build();
198-
assertEquals(ctx.getText("myKey"), "test");
199-
b.removeAll();
200-
ctx = b.build();
201-
assertEquals(ctx.getText("myKey"), null);
202-
}
203-
204191
@Test
205192
public void testToString() throws Exception {
206193
AbstractContextBuilder b = createBuilder();

src/test/java/javax/money/AbstractContextTest.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import static org.testng.Assert.assertNull;
1717
import static org.testng.Assert.assertTrue;
1818

19-
import java.time.LocalDateTime;
2019
import java.util.ArrayList;
2120
import java.util.HashSet;
2221
import java.util.List;
@@ -127,19 +126,19 @@ public void testGetType() {
127126
assertEquals(Integer.class, ctx.getType("a"));
128127
assertEquals(Integer.class, ctx.getType("b"));
129128
}
130-
131-
@Test
132-
public void testGetTimestampMillis() {
133-
TestContext ctx = new TestContext.Builder().setTimestampMillis(2000L).build();
134-
assertEquals(Long.valueOf(2000L), ctx.getTimestampMillis());
135-
}
136-
137-
@Test
138-
public void testGetTimestamp() {
139-
LocalDateTime now = LocalDateTime.now();
140-
TestContext ctx = new TestContext.Builder().setTimestamp(now).build();
141-
assertEquals(now, ctx.getTimestamp());
142-
}
129+
//
130+
// @Test
131+
// public void testGetTimestampMillis() {
132+
// TestContext ctx = new TestContext.Builder().setTimestampMillis(2000L).build();
133+
// assertEquals(Long.valueOf(2000L), ctx.getTimestampMillis());
134+
// }
135+
//
136+
// @Test
137+
// public void testGetTimestamp() {
138+
// LocalDateTime now = LocalDateTime.now();
139+
// TestContext ctx = new TestContext.Builder().setTimestamp(now).build();
140+
// assertEquals(now, ctx.getTimestamp());
141+
// }
143142

144143
private static class TestContext extends AbstractContext {
145144

0 commit comments

Comments
 (0)