You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2018/02/17 00:08:45 UTC
[incubator-plc4x] branch master updated: tested the of bytes
methods of simple types
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git
The following commit(s) were added to refs/heads/master by this push:
new d9ea5af tested the of bytes methods of simple types
d9ea5af is described below
commit d9ea5afd5d41a1ceb6fb364e1d185eac0c3aaf14
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Sat Feb 17 01:08:40 2018 +0100
tested the of bytes methods of simple types
---
.../org/apache/plc4x/java/ads/api/commands/types/Device.java | 6 +++---
.../plc4x/java/ads/api/commands/types/MajorVersion.java | 4 ++--
.../plc4x/java/ads/api/commands/types/MinorVersion.java | 4 ++--
.../apache/plc4x/java/ads/api/commands/types/TimeStamp.java | 8 ++++----
.../org/apache/plc4x/java/ads/api/commands/types/Version.java | 2 +-
.../org/apache/plc4x/java/ads/api/generic/types/AMSError.java | 2 +-
.../org/apache/plc4x/java/ads/api/generic/types/AMSNetId.java | 4 ++--
.../org/apache/plc4x/java/ads/api/generic/types/AMSPort.java | 2 +-
.../org/apache/plc4x/java/ads/api/generic/types/Command.java | 2 +-
.../org/apache/plc4x/java/ads/api/generic/types/State.java | 4 ++--
.../ads/api/commands/types/CommandTypesFactoryMethodTest.java | 11 +++++++++++
.../ads/api/generic/types/GenericTypesFactoryMethodTest.java | 9 +++++++++
12 files changed, 39 insertions(+), 19 deletions(-)
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Device.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Device.java
index 77f14f4..109df81 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Device.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Device.java
@@ -28,7 +28,7 @@ import static java.util.Objects.requireNonNull;
public class Device extends ByteValue {
- private static final int NUM_BYTES = 16;
+ public static final int NUM_BYTES = 16;
private Device(byte... values) {
super(values);
@@ -47,12 +47,12 @@ public class Device extends ByteValue {
public static Device of(String value) {
requireNonNull(value);
- return new Device(StringUtils.leftPad(value,NUM_BYTES).getBytes());
+ return new Device(StringUtils.leftPad(value, NUM_BYTES).getBytes());
}
public static Device of(String value, Charset charset) {
requireNonNull(value);
- return new Device(StringUtils.leftPad(value,NUM_BYTES).getBytes(charset));
+ return new Device(StringUtils.leftPad(value, NUM_BYTES).getBytes(charset));
}
@Override
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/MajorVersion.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/MajorVersion.java
index 5ada248..dfa5b8a 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/MajorVersion.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/MajorVersion.java
@@ -25,14 +25,14 @@ import java.util.Arrays;
public class MajorVersion extends ByteValue {
- private static final int NUM_BYTES = 1;
+ public static final int NUM_BYTES = 1;
private MajorVersion(byte... values) {
super(values);
assertLength(NUM_BYTES);
}
- private static MajorVersion of(byte... values) {
+ public static MajorVersion of(byte... values) {
return new MajorVersion(values);
}
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/MinorVersion.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/MinorVersion.java
index 54b55ce..1264f43 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/MinorVersion.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/MinorVersion.java
@@ -25,14 +25,14 @@ import java.util.Arrays;
public class MinorVersion extends ByteValue {
- private static final int NUM_BYTES = 1;
+ public static final int NUM_BYTES = 1;
private MinorVersion(byte... values) {
super(values);
assertLength(NUM_BYTES);
}
- private static MinorVersion of(byte... values) {
+ public static MinorVersion of(byte... values) {
return new MinorVersion(values);
}
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/TimeStamp.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/TimeStamp.java
index c7a1e63..df4b079 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/TimeStamp.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/TimeStamp.java
@@ -30,9 +30,9 @@ public class TimeStamp extends ByteValue {
/**
* @see <a href="https://github.com/java-native-access/jna/blob/master/contrib/platform/src/com/sun/jna/platform/win32/WinBase.java">java-native-access WinBase</a>
*/
- private final static BigInteger EPOCH_DIFF_IN_MILLIS = BigInteger.valueOf((369L * 365L + 89L) * 86400L * 1000L);
+ public final static BigInteger EPOCH_DIFF_IN_MILLIS = BigInteger.valueOf((369L * 365L + 89L) * 86400L * 1000L);
- private static final int NUM_BYTES = 8;
+ public static final int NUM_BYTES = 8;
private final BigInteger bigIntegerValue;
@@ -77,7 +77,7 @@ public class TimeStamp extends ByteValue {
.array();
}
- private static TimeStamp of(BigInteger value) {
+ public static TimeStamp of(BigInteger value) {
return new TimeStamp(javaToWinTime(value));
}
@@ -101,7 +101,7 @@ public class TimeStamp extends ByteValue {
return of(Long.valueOf(value));
}
- private static TimeStamp of(byte... values) {
+ public static TimeStamp of(byte... values) {
return new TimeStamp(values);
}
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Version.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Version.java
index 09582fb..37bd85c 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Version.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Version.java
@@ -23,7 +23,7 @@ import org.apache.plc4x.java.ads.api.util.UnsignedShortLEByteValue;
public class Version extends UnsignedShortLEByteValue {
- private static final int NUM_BYTES = UnsignedShortLEByteValue.NUM_BYTES;
+ public static final int NUM_BYTES = UnsignedShortLEByteValue.NUM_BYTES;
private Version(byte... values) {
super(values);
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AMSError.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AMSError.java
index 2a658e5..1710915 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AMSError.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AMSError.java
@@ -24,7 +24,7 @@ import org.apache.plc4x.java.ads.api.util.UnsignedIntLEByteValue;
public class AMSError extends UnsignedIntLEByteValue {
- private static final int NUM_BYTES = UnsignedIntLEByteValue.NUM_BYTES;
+ public static final int NUM_BYTES = UnsignedIntLEByteValue.NUM_BYTES;
public static final AMSError NONE = of(0);
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AMSNetId.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AMSNetId.java
index 87f5256..c39a356 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AMSNetId.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AMSNetId.java
@@ -41,14 +41,14 @@ public class AMSNetId extends ByteValue {
public static final Pattern AMS_NET_ID_PATTERN =
Pattern.compile("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}");
- private static final int NUM_BYTES = 6;
+ public static final int NUM_BYTES = 6;
private AMSNetId(byte... values) {
super(values);
assertLength(NUM_BYTES);
}
- private static AMSNetId of(byte... values) {
+ public static AMSNetId of(byte... values) {
return new AMSNetId(values);
}
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AMSPort.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AMSPort.java
index fd7f775..80d0af7 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AMSPort.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AMSPort.java
@@ -28,7 +28,7 @@ public class AMSPort extends ByteValue {
public static final Pattern AMS_PORT_PATTERN = Pattern.compile("\\d+");
- private static final int NUM_BYTES = 2;
+ public static final int NUM_BYTES = 2;
private AMSPort(byte... value) {
super(value);
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Command.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Command.java
index de536f6..e239158 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Command.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Command.java
@@ -44,7 +44,7 @@ public enum Command implements ByteReadable {
*/
UNKNOWN();
- private static final int NUM_BYTES = 2;
+ public static final int NUM_BYTES = 2;
final byte[] value;
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/State.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/State.java
index 30c974e..00f9e65 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/State.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/State.java
@@ -86,7 +86,7 @@ public class State extends UnsignedShortLEByteValue {
public static final State DEFAULT_RESPONSE = State.of(ADS_COMMAND, RESPONSE);
- private static final int NUM_BYTES = UnsignedShortLEByteValue.NUM_BYTES;
+ public static final int NUM_BYTES = UnsignedShortLEByteValue.NUM_BYTES;
private State(byte... values) {
super(values);
@@ -108,7 +108,7 @@ public class State extends UnsignedShortLEByteValue {
return new State(values);
}
- private static State of(int value) {
+ public static State of(int value) {
return new State(value);
}
diff --git a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/types/CommandTypesFactoryMethodTest.java b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/types/CommandTypesFactoryMethodTest.java
index 1f9dd8a..9b71709 100644
--- a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/types/CommandTypesFactoryMethodTest.java
+++ b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/types/CommandTypesFactoryMethodTest.java
@@ -24,12 +24,14 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
+import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.not;
import static org.junit.Assume.assumeThat;
@RunWith(Parameterized.class)
@@ -84,4 +86,13 @@ public class CommandTypesFactoryMethodTest {
Method ofMethod = clazz.getDeclaredMethod("of", String.class);
ofMethod.invoke(null, "1");
}
+
+ @Test
+ public void testOfBytes() throws Exception {
+ assumeThat(clazz, not(Data.class));
+ Field num_bytes_field = clazz.getDeclaredField("NUM_BYTES");
+ Integer numberOfBytes = (Integer) num_bytes_field.get(null);
+ Method ofMethod = clazz.getDeclaredMethod("of", byte[].class);
+ ofMethod.invoke(null, (Object) new byte[numberOfBytes]);
+ }
}
diff --git a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/GenericTypesFactoryMethodTest.java b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/GenericTypesFactoryMethodTest.java
index 275bace..d72e79a 100644
--- a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/GenericTypesFactoryMethodTest.java
+++ b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/GenericTypesFactoryMethodTest.java
@@ -24,6 +24,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
+import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.stream.Collectors;
@@ -77,4 +78,12 @@ public class GenericTypesFactoryMethodTest {
}
ofMethod.invoke(null, testString);
}
+
+ @Test
+ public void testOfBytes() throws Exception {
+ Field num_bytes_field = clazz.getDeclaredField("NUM_BYTES");
+ Integer numberOfBytes = (Integer) num_bytes_field.get(null);
+ Method ofMethod = clazz.getDeclaredMethod("of", byte[].class);
+ ofMethod.invoke(null, (Object) new byte[numberOfBytes]);
+ }
}
--
To stop receiving notification emails like this one, please contact
sruehl@apache.org.