-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1409 from immutables/1408-with-unary-operator
#1408 withUnaryOperator style flag/naming template
- Loading branch information
Showing
9 changed files
with
203 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
value-fixture/src/org/immutables/fixture/with/WithMapUnary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.immutables.fixture.with; | ||
|
||
import org.immutables.value.Value; | ||
|
||
@Value.Immutable | ||
@Value.Style(withUnaryOperator = "map*") | ||
public interface WithMapUnary extends WithUnaryOperator, WithWithMapUnary { | ||
// inherit all attributes from WithUnaryOperator and generate With-interface | ||
class Builder extends ImmutableWithMapUnary.Builder {} | ||
|
||
default void compiledAndUsable() { | ||
WithMapUnary u = new Builder() | ||
.a(1) | ||
.b("B") | ||
.build(); | ||
|
||
// signatures exist after code generation and compilation | ||
u = u.mapA(a -> a + 2).mapL(l -> l + "!!!").mapO(o -> o + "???"); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
value-fixture/src/org/immutables/fixture/with/WithUnaryOperator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.immutables.fixture.with; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.OptionalDouble; | ||
import java.util.OptionalInt; | ||
import org.immutables.value.Value; | ||
|
||
@Value.Immutable | ||
@Value.Style(withUnaryOperator = "map*") | ||
interface WithUnaryOperator { | ||
int a(); | ||
String b(); | ||
Optional<String> o(); | ||
List<String> l(); | ||
OptionalInt i(); | ||
OptionalDouble d(); | ||
com.google.common.base.Optional<Integer> oi(); | ||
} |
43 changes: 43 additions & 0 deletions
43
value-fixture/test/org/immutables/fixture/with/WithUnaryOperatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.immutables.fixture.with; | ||
|
||
import java.util.Optional; | ||
import org.junit.jupiter.api.Test; | ||
import static org.immutables.check.Checkers.check; | ||
|
||
public class WithUnaryOperatorTest { | ||
@Test | ||
public void mapAttributes() { | ||
ImmutableWithUnaryOperator m = ImmutableWithUnaryOperator.builder() | ||
.a(1) | ||
.b("b") | ||
.addL("x", "y", "z") | ||
.o("**") | ||
.build(); | ||
|
||
ImmutableWithUnaryOperator t = m.mapA(a -> a + 1) | ||
.mapB(b -> "[" + b + "]") | ||
.mapL(String::toUpperCase) | ||
.mapO(o -> o.replace('*', '_')); | ||
|
||
check(t.a()).is(2); | ||
check(t.b()).is("[b]"); | ||
check(t.l()).isOf("X", "Y", "Z"); | ||
check(t.o()).is(Optional.of("__")); | ||
} | ||
|
||
@Test | ||
public void mapEmptyReturningThis() { | ||
ImmutableWithUnaryOperator m = ImmutableWithUnaryOperator.builder() | ||
.a(1) | ||
.b("b") | ||
.build(); | ||
|
||
ImmutableWithUnaryOperator t = m.mapO(o -> o + "!!!") | ||
.mapL(l -> l + "???") | ||
.mapI(i -> ++i) | ||
.mapD(d -> d + 0.1) | ||
.mapOi(oi -> oi * 10); | ||
|
||
check(t).same(m); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters