Skip to content

Commit 7bbad68

Browse files
authored
Merge branch 'main' into add-result-of-optional
2 parents a6e4b86 + 2ed984c commit 7bbad68

File tree

18 files changed

+69
-19
lines changed

18 files changed

+69
-19
lines changed

examples/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111
<groupId>com.opengamma.strata</groupId>
1212
<artifactId>strata-examples</artifactId>
13-
<version>2.12.39-SNAPSHOT</version>
13+
<version>2.12.40-SNAPSHOT</version>
1414
<packaging>jar</packaging>
1515
<name>Strata-Examples</name>
1616
<description>Example code to demonstrate use of Strata</description>

modules/basics/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.opengamma.strata</groupId>
77
<artifactId>strata-parent</artifactId>
8-
<version>2.12.39-SNAPSHOT</version>
8+
<version>2.12.40-SNAPSHOT</version>
99
<relativePath>..</relativePath>
1010
</parent>
1111
<artifactId>strata-basics</artifactId>

modules/basics/src/main/java/com/opengamma/strata/basics/value/ValueStepSequence.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,18 @@ private void validate() {
120120
List<ValueStep> resolve(List<ValueStep> existingSteps, RollConvention rollConv) {
121121
ImmutableList.Builder<ValueStep> steps = ImmutableList.builder();
122122
steps.addAll(existingSteps);
123-
LocalDate prev = firstStepDate;
124-
LocalDate date = firstStepDate;
125-
while (!date.isAfter(lastStepDate)) {
123+
LocalDate prev = rollConv.adjust(firstStepDate);
124+
LocalDate date = rollConv.adjust(firstStepDate);
125+
LocalDate adjustedLastStepDate = rollConv.adjust(lastStepDate);
126+
while (!date.isAfter(adjustedLastStepDate)) {
126127
steps.add(ValueStep.of(date, adjustment));
127128
prev = date;
128129
date = rollConv.next(date, frequency);
129130
}
130-
if (!prev.equals(lastStepDate)) {
131+
if (!prev.equals(adjustedLastStepDate)) {
131132
throw new IllegalArgumentException(Messages.format(
132133
"ValueStepSequence lastStepDate did not match frequency '{}' using roll convention '{}', {} != {}",
133-
frequency, rollConv, lastStepDate, prev));
134+
frequency, rollConv, adjustedLastStepDate, prev));
134135
}
135136
return steps.build();
136137
}

modules/basics/src/test/java/com/opengamma/strata/basics/value/ValueStepSequenceTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ public void test_resolve() {
5959
assertThat(steps.get(3)).isEqualTo(ValueStep.of(date(2016, 10, 20), ADJ));
6060
}
6161

62+
@Test
63+
public void test_resolve_with_roll_convention() {
64+
ValueStepSequence test = ValueStepSequence.of(date(2022, 9, 21), date(2026, 9, 21), Frequency.P12M, ADJ);
65+
List<ValueStep> steps = test.resolve(ImmutableList.of(), RollConventions.IMM);
66+
assertThat(steps.size()).isEqualTo(5);
67+
assertThat(steps.get(0)).isEqualTo(ValueStep.of(date(2022, 9, 21), ADJ));
68+
assertThat(steps.get(1)).isEqualTo(ValueStep.of(date(2023, 9, 20), ADJ));
69+
assertThat(steps.get(2)).isEqualTo(ValueStep.of(date(2024, 9, 18), ADJ));
70+
assertThat(steps.get(3)).isEqualTo(ValueStep.of(date(2025, 9, 17), ADJ));
71+
assertThat(steps.get(4)).isEqualTo(ValueStep.of(date(2026, 9, 16), ADJ));
72+
}
73+
6274
@Test
6375
public void test_resolve_invalid() {
6476
ValueStepSequence test = ValueStepSequence.of(date(2016, 4, 20), date(2016, 10, 20), Frequency.P12M, ADJ);

modules/calc/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.opengamma.strata</groupId>
77
<artifactId>strata-parent</artifactId>
8-
<version>2.12.39-SNAPSHOT</version>
8+
<version>2.12.40-SNAPSHOT</version>
99
<relativePath>..</relativePath>
1010
</parent>
1111
<artifactId>strata-calc</artifactId>

modules/collect/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.opengamma.strata</groupId>
77
<artifactId>strata-parent</artifactId>
8-
<version>2.12.39-SNAPSHOT</version>
8+
<version>2.12.40-SNAPSHOT</version>
99
<relativePath>..</relativePath>
1010
</parent>
1111
<artifactId>strata-collect</artifactId>

modules/collect/src/main/java/com/opengamma/strata/collect/Guavate.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ public static <R> Predicate<R> not(Predicate<R> predicate) {
682682
*
683683
* @param <T> the type of element in the stream
684684
* @return the operator
685+
* @throws IllegalArgumentException if more than one element is present
685686
*/
686687
public static <T> BinaryOperator<T> ensureOnlyOne() {
687688
return (a, b) -> {
@@ -690,6 +691,31 @@ public static <T> BinaryOperator<T> ensureOnlyOne() {
690691
};
691692
}
692693

694+
/**
695+
* Reducer used in a stream to ensure there is no more than one matching element.
696+
* <p>
697+
* This method returns an operator that can be used with {@link Stream#reduce(BinaryOperator)}
698+
* that returns either zero or one elements from the stream. Unlike {@link Stream#findFirst()}
699+
* or {@link Stream#findAny()}, this approach ensures an exception is thrown if there
700+
* is more than one element in the stream.
701+
* <p>
702+
* This would be used as follows (with a static import):
703+
* <pre>
704+
* stream.filter(...).reduce(ensureOnlyOne()).get();
705+
* </pre>
706+
*
707+
* @param <T> the type of element in the stream
708+
* @param message the message template for the {@link IllegalArgumentException} with "{}" placeholders
709+
* @param args the arguments for the message
710+
* @return the operator
711+
* @throws IllegalArgumentException if more than one element is present
712+
*/
713+
public static <T> BinaryOperator<T> ensureOnlyOne(String message, Object... args) {
714+
return (a, b) -> {
715+
throw new IllegalArgumentException(Messages.format(message, args));
716+
};
717+
}
718+
693719
//-------------------------------------------------------------------------
694720
/**
695721
* Function used in a stream to cast instances to a particular type without filtering.

modules/collect/src/test/java/com/opengamma/strata/collect/GuavateTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,17 @@ public void test_ensureOnlyOne() {
424424
assertThatIllegalArgumentException().isThrownBy(() -> Stream.of("a", "b").reduce(Guavate.ensureOnlyOne()));
425425
}
426426

427+
@Test
428+
public void test_ensureOnlyOne_withCustomMessage() {
429+
String message = "Expected one letter but found multiple for date {}";
430+
LocalDate arg = LocalDate.of(2024, 4, 24);
431+
assertThat(Stream.empty().reduce(Guavate.ensureOnlyOne(message, arg))).isEqualTo(Optional.empty());
432+
assertThat(Stream.of("a").reduce(Guavate.ensureOnlyOne(message, arg))).isEqualTo(Optional.of("a"));
433+
assertThatIllegalArgumentException().isThrownBy(() -> Stream.of("a", "b")
434+
.reduce(Guavate.ensureOnlyOne(message, arg)))
435+
.withMessage(Messages.format(message, arg));
436+
}
437+
427438
//-------------------------------------------------------------------------
428439
@Test
429440
public void test_casting() {

modules/data/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.opengamma.strata</groupId>
77
<artifactId>strata-parent</artifactId>
8-
<version>2.12.39-SNAPSHOT</version>
8+
<version>2.12.40-SNAPSHOT</version>
99
<relativePath>..</relativePath>
1010
</parent>
1111
<artifactId>strata-data</artifactId>

modules/loader/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.opengamma.strata</groupId>
77
<artifactId>strata-parent</artifactId>
8-
<version>2.12.39-SNAPSHOT</version>
8+
<version>2.12.40-SNAPSHOT</version>
99
<relativePath>..</relativePath>
1010
</parent>
1111
<artifactId>strata-loader</artifactId>

modules/market/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.opengamma.strata</groupId>
77
<artifactId>strata-parent</artifactId>
8-
<version>2.12.39-SNAPSHOT</version>
8+
<version>2.12.40-SNAPSHOT</version>
99
<relativePath>..</relativePath>
1010
</parent>
1111
<artifactId>strata-market</artifactId>

modules/math/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.opengamma.strata</groupId>
77
<artifactId>strata-parent</artifactId>
8-
<version>2.12.39-SNAPSHOT</version>
8+
<version>2.12.40-SNAPSHOT</version>
99
<relativePath>..</relativePath>
1010
</parent>
1111
<artifactId>strata-math</artifactId>

modules/measure/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.opengamma.strata</groupId>
77
<artifactId>strata-parent</artifactId>
8-
<version>2.12.39-SNAPSHOT</version>
8+
<version>2.12.40-SNAPSHOT</version>
99
<relativePath>..</relativePath>
1010
</parent>
1111
<artifactId>strata-measure</artifactId>

modules/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111
<groupId>com.opengamma.strata</groupId>
1212
<artifactId>strata-parent</artifactId>
13-
<version>2.12.39-SNAPSHOT</version>
13+
<version>2.12.40-SNAPSHOT</version>
1414
<packaging>pom</packaging>
1515
<name>Strata-Parent</name>
1616
<description>OpenGamma Strata Parent</description>

modules/pricer/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.opengamma.strata</groupId>
77
<artifactId>strata-parent</artifactId>
8-
<version>2.12.39-SNAPSHOT</version>
8+
<version>2.12.40-SNAPSHOT</version>
99
<relativePath>..</relativePath>
1010
</parent>
1111
<artifactId>strata-pricer</artifactId>

modules/product/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.opengamma.strata</groupId>
77
<artifactId>strata-parent</artifactId>
8-
<version>2.12.39-SNAPSHOT</version>
8+
<version>2.12.40-SNAPSHOT</version>
99
<relativePath>..</relativePath>
1010
</parent>
1111
<artifactId>strata-product</artifactId>

modules/report/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.opengamma.strata</groupId>
77
<artifactId>strata-parent</artifactId>
8-
<version>2.12.39-SNAPSHOT</version>
8+
<version>2.12.40-SNAPSHOT</version>
99
<relativePath>..</relativePath>
1010
</parent>
1111
<artifactId>strata-report</artifactId>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111
<groupId>com.opengamma.strata</groupId>
1212
<artifactId>strata-root</artifactId>
13-
<version>2.12.39-SNAPSHOT</version>
13+
<version>2.12.40-SNAPSHOT</version>
1414
<packaging>pom</packaging>
1515
<name>Strata-Root</name>
1616
<description>OpenGamma Strata root</description>

0 commit comments

Comments
 (0)