forked from rico-projects/rico
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jörg Hälker
committed
Jan 17, 2019
1 parent
87b80ee
commit b3fe164
Showing
5 changed files
with
178 additions
and
23 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
...g-common/src/main/java/dev/rico/internal/remoting/converters/InstantConverterFactory.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,82 @@ | ||
/* | ||
* Copyright 2015-2016 Canoo Engineering AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package dev.rico.internal.remoting.converters; | ||
|
||
|
||
import dev.rico.remoting.converter.Converter; | ||
import dev.rico.remoting.converter.ValueConverterException; | ||
|
||
import java.time.Instant; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by hendrikebbers on 25.10.16. | ||
*/ | ||
public class InstantConverterFactory extends AbstractConverterFactory { | ||
|
||
@SuppressWarnings("rawtypes") | ||
private final static Converter CONVERTER = new InstantConverter(); | ||
|
||
@Override | ||
public boolean supportsType(Class<?> cls) { | ||
return Instant.class.isAssignableFrom(cls); | ||
} | ||
|
||
@Override | ||
public List<Class> getSupportedTypes() { | ||
return Collections.singletonList(Instant.class); | ||
} | ||
|
||
@Override | ||
public int getTypeIdentifier() { | ||
return 1000; | ||
} | ||
|
||
@Override | ||
public Converter getConverterForType(Class<?> cls) { | ||
return CONVERTER; | ||
} | ||
|
||
private static class InstantConverter extends AbstractStringConverter<Instant> { | ||
|
||
@Override | ||
public Instant convertFromRemoting(String value) throws ValueConverterException { | ||
if (value == null) { | ||
return null; | ||
} | ||
try { | ||
return Instant.from(DateTimeFormatter.ISO_INSTANT.parse(value)); | ||
} catch (Exception e) { | ||
throw new ValueConverterException("Can not convert to Instant", e); | ||
} | ||
} | ||
|
||
@Override | ||
public String convertToRemoting(Instant value) throws ValueConverterException { | ||
if (value == null) { | ||
return null; | ||
} | ||
try { | ||
return value.toString(); | ||
} catch (Exception e) { | ||
throw new ValueConverterException("Can not convert from Instant", e); | ||
} | ||
} | ||
} | ||
|
||
} |
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
82 changes: 82 additions & 0 deletions
82
...common/src/main/java/dev/rico/internal/remoting/converters/LocalTimeConverterFactory.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,82 @@ | ||
/* | ||
* Copyright 2015-2016 Canoo Engineering AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package dev.rico.internal.remoting.converters; | ||
|
||
|
||
import dev.rico.remoting.converter.Converter; | ||
import dev.rico.remoting.converter.ValueConverterException; | ||
|
||
import java.time.LocalTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by hendrikebbers on 25.10.16. | ||
*/ | ||
public class LocalTimeConverterFactory extends AbstractConverterFactory { | ||
|
||
@SuppressWarnings("rawtypes") | ||
private final static Converter CONVERTER = new LocalTimeConverter(); | ||
|
||
@Override | ||
public boolean supportsType(Class<?> cls) { | ||
return LocalTime.class.isAssignableFrom(cls); | ||
} | ||
|
||
@Override | ||
public List<Class> getSupportedTypes() { | ||
return Collections.singletonList(LocalTime.class); | ||
} | ||
|
||
@Override | ||
public int getTypeIdentifier() { | ||
return 1200; | ||
} | ||
|
||
@Override | ||
public Converter getConverterForType(Class<?> cls) { | ||
return CONVERTER; | ||
} | ||
|
||
private static class LocalTimeConverter extends AbstractStringConverter<LocalTime> { | ||
|
||
@Override | ||
public LocalTime convertFromRemoting(String value) throws ValueConverterException { | ||
if (value == null) { | ||
return null; | ||
} | ||
try { | ||
return LocalTime.from(DateTimeFormatter.ISO_TIME.parse(value)); | ||
} catch (Exception e) { | ||
throw new ValueConverterException("Can not convert to LocalTime", e); | ||
} | ||
} | ||
|
||
@Override | ||
public String convertToRemoting(LocalTime value) throws ValueConverterException { | ||
if (value == null) { | ||
return null; | ||
} | ||
try { | ||
return value.toString(); | ||
} catch (Exception e) { | ||
throw new ValueConverterException("Can not convert from LocalTime", e); | ||
} | ||
} | ||
} | ||
|
||
} |
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