You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by jf...@apache.org on 2018/11/01 20:18:04 UTC
[incubator-plc4x] 34/35: [plc4j-ads] fixed small problems with time
api and added a todo
This is an automated email from the ASF dual-hosted git repository.
jfeinauer pushed a commit to branch add-simple-mock-driver
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git
commit 3fe63781c707ac8a02c1227f500bca93d7a0d226
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Nov 1 16:26:15 2018 +0100
[plc4j-ads] fixed small problems with time api and added a todo
---
.../plc4x/java/ads/model/AdsPlcFieldHandler.java | 26 +++++++++++++++++-----
1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/AdsPlcFieldHandler.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/AdsPlcFieldHandler.java
index 9732634..ef05777 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/AdsPlcFieldHandler.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/AdsPlcFieldHandler.java
@@ -982,20 +982,34 @@ public class AdsPlcFieldHandler extends DefaultPlcFieldHandler {
private BaseDefaultFieldItem internalDateTimeTemporal(PlcField field, Object[] values) {
AdsField adsField = (AdsField) field;
+ Class<? extends BaseDefaultFieldItem> fieldType;
switch (adsField.getAdsDataType()) {
case TIME:
+ fieldType = DefaultLocalTimeFieldItem.class;
+ break;
case DATE:
+ fieldType = DefaultLocalDateFieldItem.class;
+ break;
case DATE_AND_TIME:
+ fieldType = DefaultLocalDateTimeFieldItem.class;
break;
default:
throw new IllegalArgumentException(
"Cannot assign temporal values to " + adsField.getAdsDataType().name() + " fields.");
}
- // TODO: support other types
- List<LocalDateTime> localDateTimeValues = Arrays.stream(values)
- .filter(LocalDateTime.class::isInstance)
- .map(LocalDateTime.class::cast)
- .collect(Collectors.toList());
- return new DefaultLocalDateTimeFieldItem(localDateTimeValues.toArray(new LocalDateTime[0]));
+ // TODO: add type conversion
+ if (fieldType == DefaultLocalDateTimeFieldItem.class) {
+ return new DefaultLocalDateTimeFieldItem(Arrays.stream(values)
+ .filter(LocalDateTime.class::isInstance)
+ .map(LocalDateTime.class::cast).toArray(LocalDateTime[]::new));
+ } else if (fieldType == DefaultLocalDateFieldItem.class) {
+ return new DefaultLocalDateFieldItem(Arrays.stream(values)
+ .filter(LocalDate.class::isInstance)
+ .map(LocalDate.class::cast).toArray(LocalDate[]::new));
+ } else {
+ return new DefaultLocalTimeFieldItem(Arrays.stream(values)
+ .filter(LocalTime.class::isInstance)
+ .map(LocalTime.class::cast).toArray(LocalTime[]::new));
+ }
}
}