-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IPROTO-146 Adapters for java.time classes
- Loading branch information
1 parent
c430dfe
commit c2978ba
Showing
22 changed files
with
682 additions
and
232 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
* An annotation-based generated proto schema file. This is just a more specific flavour of | ||
* {@link SerializationContextInitializer} that also exposes the generated Protobuf schema, which consists of the file | ||
* name and the file contents. Users will never implement this interface directly. Implementations are always generated | ||
* by the annotation processor based on the {@link org.infinispan.protostream.annotations.AutoProtoSchemaBuilder} | ||
* by the annotation processor based on the {@link org.infinispan.protostream.annotations.ProtoSchema} | ||
* annotation, identically as for {@link SerializationContextInitializer}. | ||
* | ||
* @author [email protected] | ||
|
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
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package org.infinispan.protostream.types.java; | ||
|
||
import org.infinispan.protostream.GeneratedSchema; | ||
import org.infinispan.protostream.annotations.AutoProtoSchemaBuilder; | ||
import org.infinispan.protostream.annotations.ProtoSchema; | ||
import org.infinispan.protostream.types.java.arrays.BooleanArrayAdapter; | ||
import org.infinispan.protostream.types.java.arrays.BoxedBooleanArrayAdapter; | ||
import org.infinispan.protostream.types.java.arrays.BoxedByteArrayAdapter; | ||
|
@@ -29,7 +29,7 @@ | |
* @author [email protected] | ||
* @since 4.4 | ||
*/ | ||
@AutoProtoSchemaBuilder( | ||
@ProtoSchema( | ||
className = "CommonContainerTypesSchema", | ||
schemaFileName = "common-java-container-types.proto", | ||
schemaFilePath = "/protostream", | ||
|
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
21 changes: 21 additions & 0 deletions
21
types/src/main/java/org/infinispan/protostream/types/java/time/LocalDateAdapter.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,21 @@ | ||
package org.infinispan.protostream.types.java.time; | ||
|
||
import java.time.LocalDate; | ||
|
||
import org.infinispan.protostream.annotations.ProtoAdapter; | ||
import org.infinispan.protostream.annotations.ProtoFactory; | ||
import org.infinispan.protostream.annotations.ProtoField; | ||
import org.infinispan.protostream.descriptors.Type; | ||
|
||
@ProtoAdapter(LocalDate.class) | ||
public class LocalDateAdapter { | ||
@ProtoFactory | ||
LocalDate create(Long epochDay) { | ||
return LocalDate.ofEpochDay(epochDay); | ||
} | ||
|
||
@ProtoField(number = 1, type = Type.UINT64) | ||
Long getEpochDay(LocalDate localDate) { | ||
return localDate.toEpochDay(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
types/src/main/java/org/infinispan/protostream/types/java/time/LocalDateTimeAdapter.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,28 @@ | ||
package org.infinispan.protostream.types.java.time; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.LocalTime; | ||
|
||
import org.infinispan.protostream.annotations.ProtoAdapter; | ||
import org.infinispan.protostream.annotations.ProtoFactory; | ||
import org.infinispan.protostream.annotations.ProtoField; | ||
import org.infinispan.protostream.descriptors.Type; | ||
|
||
@ProtoAdapter(LocalDateTime.class) | ||
public class LocalDateTimeAdapter { | ||
@ProtoFactory | ||
LocalDateTime create(LocalDate localDate, LocalTime localTime) { | ||
return LocalDateTime.of(localDate, localTime); | ||
} | ||
|
||
@ProtoField(number = 1, type = Type.MESSAGE) | ||
LocalDate getLocalDate(LocalDateTime localDateTime) { | ||
return localDateTime.toLocalDate(); | ||
} | ||
|
||
@ProtoField(number = 2, type = Type.MESSAGE) | ||
LocalTime getLocalTime(LocalDateTime localDateTime) { | ||
return localDateTime.toLocalTime() ; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
types/src/main/java/org/infinispan/protostream/types/java/time/LocalTimeAdapter.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.infinispan.protostream.types.java.time; | ||
|
||
import java.time.LocalTime; | ||
|
||
import org.infinispan.protostream.annotations.ProtoAdapter; | ||
import org.infinispan.protostream.annotations.ProtoFactory; | ||
import org.infinispan.protostream.annotations.ProtoField; | ||
import org.infinispan.protostream.descriptors.Type; | ||
|
||
@ProtoAdapter(LocalTime.class) | ||
public class LocalTimeAdapter { | ||
@ProtoFactory | ||
LocalTime create(Long nanoOfDay) { | ||
return LocalTime.ofNanoOfDay(nanoOfDay); | ||
} | ||
@ProtoField(number = 1, type = Type.UINT64) | ||
Long getNanoOfDay(LocalTime localTime) { | ||
return localTime.toNanoOfDay(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
types/src/main/java/org/infinispan/protostream/types/java/time/MonthAdapter.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,36 @@ | ||
package org.infinispan.protostream.types.java.time; | ||
|
||
import java.time.Month; | ||
|
||
import org.infinispan.protostream.annotations.ProtoAdapter; | ||
import org.infinispan.protostream.annotations.ProtoEnumValue; | ||
import org.infinispan.protostream.annotations.ProtoName; | ||
|
||
@ProtoAdapter(Month.class) | ||
@ProtoName("Month") | ||
public enum MonthAdapter { | ||
@ProtoEnumValue | ||
JANUARY, | ||
@ProtoEnumValue(value = 1) | ||
FEBRUARY, | ||
@ProtoEnumValue(value = 2) | ||
MARCH, | ||
@ProtoEnumValue(value = 3) | ||
APRIL, | ||
@ProtoEnumValue(value = 4) | ||
MAY, | ||
@ProtoEnumValue(value = 5) | ||
JUNE, | ||
@ProtoEnumValue(value = 6) | ||
JULY, | ||
@ProtoEnumValue(value = 7) | ||
AUGUST, | ||
@ProtoEnumValue(value = 8) | ||
SEPTEMBER, | ||
@ProtoEnumValue(value = 9) | ||
OCTOBER, | ||
@ProtoEnumValue(value = 10) | ||
NOVEMBER, | ||
@ProtoEnumValue(value = 11) | ||
DECEMBER; | ||
} |
25 changes: 25 additions & 0 deletions
25
types/src/main/java/org/infinispan/protostream/types/java/time/MonthDayAdapter.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,25 @@ | ||
package org.infinispan.protostream.types.java.time; | ||
|
||
import java.time.MonthDay; | ||
|
||
import org.infinispan.protostream.annotations.ProtoAdapter; | ||
import org.infinispan.protostream.annotations.ProtoFactory; | ||
import org.infinispan.protostream.annotations.ProtoField; | ||
import org.infinispan.protostream.descriptors.Type; | ||
|
||
@ProtoAdapter(MonthDay.class) | ||
public class MonthDayAdapter { | ||
@ProtoFactory | ||
MonthDay create(Integer month, Integer dayOfMonth) { | ||
return MonthDay.of(month, dayOfMonth); | ||
} | ||
@ProtoField(number = 1, type = Type.INT32) | ||
Integer getMonth(MonthDay monthDay) { | ||
return monthDay.getMonthValue(); | ||
} | ||
|
||
@ProtoField(number = 2, type = Type.INT32) | ||
Integer getDayOfMonth(MonthDay monthDay) { | ||
return monthDay.getDayOfMonth(); | ||
} | ||
} |
Oops, something went wrong.