Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#638 default and derived encoding, virtual and derived fields
should be a lot better now
- Loading branch information
Showing
17 changed files
with
380 additions
and
130 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
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
24 changes: 24 additions & 0 deletions
24
value-fixture/src/org/immutables/fixture/encoding/defs/CompactDate.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,24 @@ | |||
package org.immutables.fixture.encoding.defs; | |||
|
|||
import java.util.Date; | |||
import org.immutables.encode.Encoding; | |||
|
|||
@Encoding | |||
public class CompactDate { | |||
@Encoding.Impl | |||
private long time; | |||
|
|||
@Encoding.Expose | |||
Date get() { | |||
return toDate(time); | |||
} | |||
|
|||
@Encoding.Of | |||
static long fromDate(Date date) { | |||
return date == null ? 0L : date.getTime(); | |||
} | |||
|
|||
private static Date toDate(long time) { | |||
return time == 0L ? null : new Date(time); | |||
} | |||
} |
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
25 changes: 25 additions & 0 deletions
25
value-fixture/test/org/immutables/fixture/encoding/UseCompactLocalDateTime.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,25 @@ | |||
package org.immutables.fixture.encoding; | |||
|
|||
import java.util.Date; | |||
import org.immutables.fixture.encoding.defs.CompactDateEnabled; | |||
import org.immutables.value.Value; | |||
|
|||
@CompactDateEnabled | |||
public abstract class UseCompactLocalDateTime { | |||
public abstract static class Base { | |||
@Value.Default | |||
public Date firstSeen() { | |||
return new Date(); | |||
} | |||
|
|||
@Value.Default | |||
public Date lastSeen() { | |||
return firstSeen(); | |||
} | |||
} | |||
|
|||
@Value.Immutable | |||
public abstract static class SomeSubclass extends Base { | |||
public abstract String name(); | |||
} | |||
} |
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
Oops, something went wrong.