diff --git a/epics-util/pom.xml b/epics-util/pom.xml index 51340c06d..2483ff136 100644 --- a/epics-util/pom.xml +++ b/epics-util/pom.xml @@ -1,83 +1,83 @@ - - - 4.0.0 - 1.0.0-SNAPSHOT - org.epics - epics-util - org.epics.util - Basic Java utility classes to be shared across projects until - suitable replacements are available in the JDK. - - UTF-8 - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.6.2 - - 1.8 - 1.8 - - - - org.apache.maven.plugins - maven-source-plugin - 3.0.1 - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.10.4 - - - attach-javadocs - - jar - - - - - - com.mycila - license-maven-plugin - 3.0 - -
HEADER.TXT
- - **/*.java - -
-
-
-
- - - junit - junit - 4.12 - test - - - org.mockito - mockito-all - 1.10.19 - test - - - org.hamcrest - hamcrest-all - 1.3 - test - - -
+ + + 4.0.0 + 1.0.0-SNAPSHOT + epics-util + org.epics.util + Basic Java utility classes to be shared across projects until + suitable replacements are available in the JDK. + + UTF-8 + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.2 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-source-plugin + 3.0.1 + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.4 + + + attach-javadocs + + jar + + + + + + com.mycila + license-maven-plugin + 3.0 + +
HEADER.TXT
+ + **/*.java + +
+
+
+
+ + + junit + junit + 4.12 + test + + + org.mockito + mockito-all + 1.10.19 + test + + + org.hamcrest + hamcrest-all + 1.3 + test + + + org.epics +
diff --git a/epics-vtype/pom.xml b/epics-vtype/pom.xml index d3ec416eb..30b58566d 100644 --- a/epics-vtype/pom.xml +++ b/epics-vtype/pom.xml @@ -1,92 +1,92 @@ - - - 4.0.0 - org.epics - epics-vtype-all - epics-vtype - 1.0.0-SNAPSHOT - pom - A set of standard types for value processing. - - UTF-8 - - - vtype - vtype-json - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.6.2 - - 1.8 - 1.8 - - - - org.apache.maven.plugins - maven-source-plugin - 3.0.1 - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.10.4 - - - attach-javadocs - - jar - - - - - - com.mycila - license-maven-plugin - 3.0 - -
HEADER.TXT
- - **/*.java - -
-
-
-
- - - ${project.groupId} - epics-util - ${project.version} - - - junit - junit - 4.12 - test - - - org.mockito - mockito-all - 1.10.19 - test - - - org.hamcrest - hamcrest-all - 1.3 - test - - -
+ + + 4.0.0 + epics-vtype-all + epics-vtype + 1.0.0-SNAPSHOT + pom + A set of standard types for value processing. + + UTF-8 + + + vtype + vtype-json + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.2 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-source-plugin + 3.0.1 + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.4 + + + attach-javadocs + + jar + + + + + + com.mycila + license-maven-plugin + 3.0 + +
HEADER.TXT
+ + **/*.java + +
+
+
+
+ + + ${project.groupId} + epics-util + ${project.version} + + + junit + junit + 4.12 + test + + + org.mockito + mockito-all + 1.10.19 + test + + + org.hamcrest + hamcrest-all + 1.3 + test + + + org.epics +
diff --git a/epics-vtype/vtype/src/main/java/org/epics/vtype/IVImage.java b/epics-vtype/vtype/src/main/java/org/epics/vtype/IVImage.java new file mode 100644 index 000000000..ecbc6d281 --- /dev/null +++ b/epics-vtype/vtype/src/main/java/org/epics/vtype/IVImage.java @@ -0,0 +1,68 @@ +package org.epics.vtype; + +import org.epics.util.array.ListNumber; + +/** + * An immutable implementation of the {@link VImage} + * + * @author Kunal Shroff + * + */ +public class IVImage extends VImage { + + private final Alarm alarm; + private final Time time; + + private final int height; + private final int width; + private final ListNumber data; + private final VImageDataType imageDataType; + private final VImageType imageType; + + IVImage(int height, int width, ListNumber data, VImageDataType imageDataType, VImageType imageType, Alarm alarm, + Time time) { + super(); + VType.argumentNotNull("alarm", alarm); + VType.argumentNotNull("time", time); + this.alarm = alarm; + this.time = time; + this.height = height; + this.width = width; + this.data = data; + this.imageDataType = imageDataType; + this.imageType = imageType; + } + + public int getHeight() { + return height; + } + + public int getWidth() { + return width; + } + + public ListNumber getData() { + return data; + } + + @Override + public Alarm getAlarm() { + return alarm; + } + + @Override + public Time getTime() { + return time; + } + + @Override + public VImageDataType getDataType() { + return imageDataType; + } + + @Override + public VImageType getVImageType() { + return imageType; + } + +} diff --git a/epics-vtype/vtype/src/main/java/org/epics/vtype/IVTable.java b/epics-vtype/vtype/src/main/java/org/epics/vtype/IVTable.java new file mode 100644 index 000000000..adb67b3fa --- /dev/null +++ b/epics-vtype/vtype/src/main/java/org/epics/vtype/IVTable.java @@ -0,0 +1,68 @@ +/** + * Copyright (C) 2010-18 diirt developers. See COPYRIGHT.TXT + * All rights reserved. Use is subject to license terms. See LICENSE.TXT + */ +package org.epics.vtype; + +import java.util.List; +import org.epics.util.array.ListNumber; + +/** + * An immutable table that extends {@link VTable} + * + * @author carcassi, shroff + */ +class IVTable extends VTable { + + private final List> types; + private final List names; + private final List values; + private final int rowCount; + + IVTable(List> types, List names, List values) { + this.types = types; + this.names = names; + this.values = values; + int maxCount = 0; + for (Object array : values) { + maxCount = Math.max(maxCount, getDataSize(array)); + } + this.rowCount = maxCount; + } + + private static int getDataSize(Object data) { + if (data instanceof List) { + return ((List) data).size(); + } else if (data instanceof ListNumber) { + return ((ListNumber) data).size(); + } + + throw new IllegalArgumentException("Object " + data + " is not supported"); + } + + @Override + public int getColumnCount() { + return names.size(); + } + + @Override + public int getRowCount() { + return rowCount; + } + + @Override + public Class getColumnType(int column) { + return types.get(column); + } + + @Override + public String getColumnName(int column) { + return names.get(column); + } + + @Override + public Object getColumnData(int column) { + return values.get(column); + } + +} diff --git a/epics-vtype/vtype/src/main/java/org/epics/vtype/VImage.java b/epics-vtype/vtype/src/main/java/org/epics/vtype/VImage.java new file mode 100644 index 000000000..c6e4c345c --- /dev/null +++ b/epics-vtype/vtype/src/main/java/org/epics/vtype/VImage.java @@ -0,0 +1,106 @@ +/** + * Copyright (C) 2010-18 diirt developers. See COPYRIGHT.TXT + * All rights reserved. Use is subject to license terms. See LICENSE.TXT + */ +package org.epics.vtype; + +import java.util.Objects; + +import org.epics.util.array.ListNumber; + +/** + * VImage represents an image. + * + * @author carcassi, shroff + */ +public abstract class VImage extends VType implements AlarmProvider, TimeProvider { + + /** + * Height of the image in pixels. + * + * @return image height + */ + public abstract int getHeight(); + + /** + * Width of the image in pixels. + * + * @return image width + */ + public abstract int getWidth(); + + /** + * Image data; + * + * @return ListNumber image data + */ + public abstract ListNumber getData(); + + /** + * Describes the type in which the data is stored {@link VImageDataType} + * + * @return image data type + */ + public abstract VImageDataType getDataType(); + + /** + * Returns the image type, The image type describes the mechanism in which the + * data is encoded and how it can be converted to something that can be + * rendered. + * + * @return the image type {@link VImageType} + */ + public abstract VImageType getVImageType(); + + /** + * Creates a new VImage. + * + * @param height image height + * @param width image width + * @param data image data + * @param imageDataType image data type + * @param vImageType image type + * @param alarm alarm information + * @param time timestamp + * @return + */ + public static VImage of(int height, int width, final ListNumber data, VImageDataType imageDataType, VImageType vImageType, Alarm alarm, Time time) { + return new IVImage(height, width, data, imageDataType, vImageType, alarm, time); + } + + @Override + public final boolean equals(Object obj) { + if (this == obj) { + return true; + } + + if (obj instanceof VImage) { + VImage other = (VImage) obj; + + return getClass().equals(other.getClass()) + && getHeight() == other.getHeight() + && getWidth() == other.getWidth() + && getData().equals(other.getData()) + && getDataType().equals(other.getDataType()) + && getVImageType().equals(other.getVImageType()) + && getAlarm().equals(other.getAlarm()) + && getTime().equals(other.getTime()); + } + + return false; + } + + @Override + public final int hashCode() { + int hash = 7; + hash = 23 * hash + Objects.hashCode(getHeight()); + hash = 23 * hash + Objects.hashCode(getWidth()); + hash = 23 * hash + Objects.hashCode(getData()); + hash = 23 * hash + Objects.hashCode(getDataType()); + hash = 23 * hash + Objects.hashCode(getVImageType()); + hash = 23 * hash + Objects.hashCode(getAlarm()); + hash = 23 * hash + Objects.hashCode(getTime()); + return hash; + } + +} diff --git a/epics-vtype/vtype/src/main/java/org/epics/vtype/VImageDataType.java b/epics-vtype/vtype/src/main/java/org/epics/vtype/VImageDataType.java new file mode 100644 index 000000000..ccca6735f --- /dev/null +++ b/epics-vtype/vtype/src/main/java/org/epics/vtype/VImageDataType.java @@ -0,0 +1,150 @@ +/** + * Copyright (C) 2010-18 diirt developers. See COPYRIGHT.TXT + * All rights reserved. Use is subject to license terms. See LICENSE.TXT + */ +package org.epics.vtype; +/** + * + * Data type description for {@link VImage} data. + * + * based on the the VImageDataType from org.epics.pvdata.pv + * @author mrk + * + */ +public enum VImageDataType { + /** + * Value has type boolean. + */ + pvBoolean, + /** + * Value has type byte. + */ + pvByte, + /** + * Value has type short. + */ + pvShort, + /** + * Value has type int. + */ + pvInt, + /** + * Value has type long. + */ + pvLong, + /** + * Value has type ubyte. + */ + pvUByte, + /** + * Value has type ushort. + */ + pvUShort, + /** + * Value has type uint. + */ + pvUInt, + /** + * Value has type ulong. + */ + pvULong, + /** + * value has type float. + */ + pvFloat, + /** + * Value has type double. + */ + pvDouble, + /** + * Value has type string. + */ + pvString; + + /** + * Is this an integer (signed or unsigned). true if byte, short, int, long, ubyte, ushort, uint, or ulong. + * @return true if it is an integer type + */ + public boolean isInteger() { + if( (ordinal() >= VImageDataType.pvByte.ordinal()) && (ordinal() <= VImageDataType.pvULong.ordinal()) ) { + return true; + } + return false; + } + + /** + * Is this an unsigned integer. true if ubyte, ushort, uint, or ulong. + * + * @return true if it is an unsigned integer type + */ + public boolean isUInteger() { + if( (ordinal() >= VImageDataType.pvUByte.ordinal()) && (ordinal() <= VImageDataType.pvULong.ordinal()) ) { + return true; + } + return false; + } + + /** + * Is this a Java numeric type? + * + * @return true if the type is a Java numeric type. + * The numeric types are byte, short, int, long, float, and double. + */ + public boolean isNumeric() { + if( (ordinal() >= VImageDataType.pvByte.ordinal()) && (ordinal() <= VImageDataType.pvDouble.ordinal()) ) { + return true; + } + return false; + } + + /** + * Is this a Java primitive type? + * + * @return true if the type is a Java primitive type. + * The numeric types and boolean are primitive types. + */ + public boolean isPrimitive() { + if(isNumeric()) return true; + if(ordinal() == VImageDataType.pvBoolean.ordinal()) return true; + return false; + } + + /** + * Get the VImageDataType for a string defining the type. + * + * @param type a character string defining the type + * @return the VImageDataType or null if an illegal type + */ + public static VImageDataType getVImageDataType(String type) { + if(type.equals("boolean")) return VImageDataType.pvBoolean; + if(type.equals("byte")) return VImageDataType.pvByte; + if(type.equals("short")) return VImageDataType.pvShort; + if(type.equals("int")) return VImageDataType.pvInt; + if(type.equals("long")) return VImageDataType.pvLong; + if(type.equals("ubyte")) return VImageDataType.pvUByte; + if(type.equals("ushort")) return VImageDataType.pvUShort; + if(type.equals("uint")) return VImageDataType.pvUInt; + if(type.equals("ulong")) return VImageDataType.pvULong; + if(type.equals("float")) return VImageDataType.pvFloat; + if(type.equals("double")) return VImageDataType.pvDouble; + if(type.equals("string")) return VImageDataType.pvString; + return null; + } + public String toString() { + switch(this) { + case pvBoolean: return "boolean"; + case pvByte: return "byte"; + case pvShort: return "short"; + case pvInt: return "int"; + case pvLong: return "long"; + case pvUByte: return "ubyte"; + case pvUShort: return "ushort"; + case pvUInt: return "uint"; + case pvULong: return "ulong"; + case pvFloat: return "float"; + case pvDouble: return "double"; + case pvString: return "string"; + } + throw new IllegalArgumentException("Unknown VImageDataType"); + } +} \ No newline at end of file diff --git a/epics-vtype/vtype/src/main/java/org/epics/vtype/VImageType.java b/epics-vtype/vtype/src/main/java/org/epics/vtype/VImageType.java new file mode 100644 index 000000000..190b34252 --- /dev/null +++ b/epics-vtype/vtype/src/main/java/org/epics/vtype/VImageType.java @@ -0,0 +1,122 @@ +/** + * Copyright (C) 2010-18 diirt developers. See COPYRIGHT.TXT + * All rights reserved. Use is subject to license terms. See LICENSE.TXT + */ + +package org.epics.vtype; + +/** + * Description of the the Image Type represented by the {@link VImage} + * + * @author Kunal Shroff + * + */ +public enum VImageType { + /** + * Image type constants + */ + TYPE_CUSTOM, + /** + * Monochromatic image + */ + TYPE_MONO, + /** + * Bayer pattern image, 1 value per pixel but with color filter on + * detector + */ + TYPE_BAYER, + /** + * RGB image with pixel color interleave, data array is [3, NX, NY] + */ + TYPE_RGB1, + /** + * RGB image with row color interleave, data array is [NX, 3, NY] + */ + TYPE_RGB2, + /** + * RGB image with plane color interleave, data array is [NX, NY, 3] + */ + TYPE_RGB3, + /** + * YUV image, 3 bytes encodes 1 RGB pixel + */ + TYPE_YUV444, + /** + * YUV image, 4 bytes encodes 2 RGB pixel + */ + TYPE_YUV422, + /** + * YUV image, 6 bytes encodes 4 RGB pixels + */ + TYPE_YUV411, + /** + * An image with 8-bit RGB color components, corresponding to a + * Windows-style BGR color model with the colors Blue, Green, and Red + * stored in 3 bytes. + */ + TYPE_3BYTE_BGR, + /** + * Represents an image with 8-bit RGBA color components with the colors + * Blue, Green, and Red stored in 3 bytes and 1 byte of alpha. + */ + TYPE_4BYTE_ABGR, + /** + * Represents an image with 8-bit RGBA color components with the colors + * Blue, Green, and Red stored in 3 bytes and 1 byte of alpha. + */ + TYPE_4BYTE_ABGR_PRE, + /** + * Represents an opaque byte-packed 1, 2, or 4 bit image. + */ + TYPE_BYTE_BINARY, + /** + * Represents a unsigned byte grayscale image, non-indexed. + */ + TYPE_BYTE_GRAY, + /** + * Represents an indexed byte image. + */ + TYPE_BYTE_INDEXED, + /** + * Represents an image with 8-bit RGBA color components packed into + * integer pixels. + * + */ + TYPE_INT_ARGB, + /** + * Represents an image with 8-bit RGBA color components packed into + * integer pixels. + * + */ + TYPE_INT_ARGB_PRE, + /** + * Represents an image with 8-bit RGB color components, corresponding to + * a Windows- or Solaris- style BGR color model, with the colors Blue, + * Green, and Red packed into integer pixels. + * + */ + TYPE_INT_BGR, + /** + * Represents an image with 8-bit RGB color components packed into + * integer pixels. + * + */ + TYPE_INT_RGB, + /** + * Represents an image with 5-5-5 RGB color components (5-bits red, + * 5-bits green, 5-bits blue) with no alpha. + * + */ + TYPE_USHORT_555_RGB, + /** + * Represents an image with 5-6-5 RGB color components (5-bits red, + * 6-bits green, 5-bits blue) with no alpha. + * + */ + TYPE_USHORT_565_RGB, + /** + * Represents an unsigned short grayscale image, non-indexed). + * + */ + TYPE_USHORT_GRAY +} \ No newline at end of file diff --git a/epics-vtype/vtype/src/main/java/org/epics/vtype/VTable.java b/epics-vtype/vtype/src/main/java/org/epics/vtype/VTable.java new file mode 100644 index 000000000..a29869211 --- /dev/null +++ b/epics-vtype/vtype/src/main/java/org/epics/vtype/VTable.java @@ -0,0 +1,79 @@ +/** + * Copyright (C) 2010-18 diirt developers. See COPYRIGHT.TXT + * All rights reserved. Use is subject to license terms. See LICENSE.TXT + */ +package org.epics.vtype; + +import java.util.List; +import org.epics.util.array.ListNumber; + +/** + * A table. Tables are collections of columns, each of which is composed of a + * String representing the name of the column and a list of a particular type + * (all elements of the same column must be of the same type). + * + * @author carcassi, shroff + */ +public abstract class VTable extends VType { + + /** + * The number of columns in the table. + * + * @return the number of columns + */ + abstract int getColumnCount(); + + /** + * The number of rows in the table. + *

+ * Currently, it is not clear whether all columns actually have the same number + * of rows, that is if all arrays have the same length. In the case of variable + * row, this will return the maximum row count, that is the length of the + * longest array/column. + * + * @return the number of rows + */ + abstract int getRowCount(); + + /** + * The type of the elements in the column. The column array will be an array of + * the given type. For primitive types, this function will return the TYPE class + * (such as {@link Double#TYPE}, while {@link #getColumnData(int) } will return + * a {@link ListNumber}. + * + * @param column the column index + * @return the type of this column + */ + abstract Class getColumnType(int column); + + /** + * The name of the given column. + * + * @param column the column index + * @return the name of the column + */ + abstract String getColumnName(int column); + + /** + * The data for the given column. + *

+ * The data is going to be a {@link List} in case of objects or a + * {@link ListNumber} in case of a numeric primitive. + * + * @param column the column index + * @return the data of the column + */ + abstract Object getColumnData(int column); + + /** + * Create a new VTable + * + * @param types the types of each column + * @param names the name of each column + * @param values the values of each column + * @return an immutable instance of the VTable + */ + public static VTable of(List> types, List names, List values) { + return new IVTable(types, names, values); + } +} diff --git a/epics-vtype/vtype/src/main/java/org/epics/vtype/VType.java b/epics-vtype/vtype/src/main/java/org/epics/vtype/VType.java index a4dc0569c..bc5c21fc5 100644 --- a/epics-vtype/vtype/src/main/java/org/epics/vtype/VType.java +++ b/epics-vtype/vtype/src/main/java/org/epics/vtype/VType.java @@ -1,188 +1,190 @@ -/** - * Copyright information and license terms for this software can be - * found in the file LICENSE.TXT included with the distribution. - */ -package org.epics.vtype; - -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import org.epics.util.array.CollectionNumbers; -import org.epics.util.array.ListNumber; - -/** - * Tag interface to mark all the members of the value classes. - * - * @author carcassi - */ -public abstract class VType { - - private static final Collection> TYPES = Arrays.>asList( - VDouble.class, - VFloat.class, - VULong.class, - VLong.class, - VUInt.class, - VInt.class, - VUShort.class, - VShort.class, - VUByte.class, - VByte.class, - VEnum.class, - VBoolean.class, - VString.class, - VDoubleArray.class, - VFloatArray.class, - VULongArray.class, - VLongArray.class, - VUIntArray.class, - VIntArray.class, - VUShortArray.class, - VShortArray.class, - VUByteArray.class, - VByteArray.class); - - /** - * Returns the type of the object by returning the class object of one - * of the VXxx interfaces. The getClass() methods returns the - * concrete implementation type, which is of little use. If no - * super-interface is found, Object.class is used. - * - * @param obj an object implementing a standard type - * @return the type is implementing - */ - public static Class typeOf(Object obj) { - if (obj == null) - return null; - - for (Class type : TYPES) { - if (type.isInstance(obj)) { - return type; - } - } - - return Object.class; - } - - /** - * As {@link #toVType(java.lang.Object)} but throws an exception - * if conversion not possible. - * - * @param javaObject the value to wrap - * @return the new VType value - */ - public static VType toVTypeChecked(Object javaObject) { - VType value = toVType(javaObject); - if (value == null) { - throw new IllegalArgumentException("Value " + value + " cannot be converted to VType."); - } - return value; - } - - /** - * As {@link #toVType(java.lang.Object, org.epics.vtype.Alarm, org.epics.vtype.Time, org.epics.vtype.Display)} but throws an exception - * if conversion not possible. - * - * @param javaObject the value to wrap - * @param alarm the alarm - * @param time the time - * @param display the display - * @return the new VType value - */ - public static VType toVTypeChecked(Object javaObject, Alarm alarm, Time time, Display display) { - VType value = toVType(javaObject, alarm, time, display); - if (value == null) { - throw new IllegalArgumentException("Value " + value + " cannot be converted to VType."); - } - return value; - } - - /** - * Converts a standard java type to VTypes. Returns null if no conversion - * is possible. Calls {@link #toVType(java.lang.Object, org.epics.vtype.Alarm, org.epics.vtype.Time, org.epics.vtype.Display) } - * with no alarm, time now and no display. - * - * @param javaObject the value to wrap - * @return the new VType value - */ - public static VType toVType(Object javaObject) { - return toVType(javaObject, Alarm.none(), Time.now(), Display.none()); - } - - /** - * Converts a standard java type to VTypes. Returns null if no conversion - * is possible. Calls {@link #toVType(java.lang.Object, org.epics.vtype.Alarm, org.epics.vtype.Time, org.epics.vtype.Display) } - * with the given alarm, time now and no display. - * - * @param javaObject the value to wrap - * @param alarm the alarm - * @return the new VType value - */ - public static VType toVType(Object javaObject, Alarm alarm) { - return toVType(javaObject, alarm, Time.now(), Display.none()); - } - - /** - * Converts a standard java type to VTypes. Returns null if no conversion - * is possible. - *

- * Types are converted as follow: - *

    - *
  • Boolean -> VBoolean
  • - *
  • Number -> corresponding VNumber
  • - *
  • String -> VString
  • - *
  • number array -> corresponding VNumberArray
  • - *
  • ListNumber -> corresponding VNumberArray
  • - *
  • List -> if all elements are String, VStringArray
  • - *
- * - * @param javaObject the value to wrap - * @param alarm the alarm - * @param time the time - * @param display the display - * @return the new VType value - */ - public static VType toVType(Object javaObject, Alarm alarm, Time time, Display display) { - if (javaObject instanceof Number) { - return VNumber.of((Number) javaObject, alarm, time, display); - } else if (javaObject instanceof String) { - return VString.of((String) javaObject, alarm, time); - } else if (javaObject instanceof Boolean) { - return VBoolean.of((Boolean) javaObject, alarm, time); - } else if (javaObject instanceof byte[] - || javaObject instanceof short[] - || javaObject instanceof int[] - || javaObject instanceof long[] - || javaObject instanceof float[] - || javaObject instanceof double[]) { - return VNumberArray.of(CollectionNumbers.toList(javaObject), alarm, time, display); - } else if (javaObject instanceof ListNumber) { - return VNumberArray.of((ListNumber) javaObject, alarm, time, display); - } else if (javaObject instanceof String[]) { - return null;//newVStringArray(Arrays.asList((String[]) javaObject), alarm, time); - } else if (javaObject instanceof List) { - boolean matches = true; - List list = (List) javaObject; - for (Object object : list) { - if (!(object instanceof String)) { - matches = false; - } - } - if (matches) { - @SuppressWarnings("unchecked") - List newList = (List) list; - return null;//newVStringArray(Collections.unmodifiableList(newList), alarm, time); - } else { - return null; - } - } else { - return null; - } - } - - static void argumentNotNull(String argName, Object value) { - if (value == null) { - throw new NullPointerException(argName + " can't be null"); - } - } -} +/** + * Copyright information and license terms for this software can be + * found in the file LICENSE.TXT included with the distribution. + */ +package org.epics.vtype; + +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import org.epics.util.array.CollectionNumbers; +import org.epics.util.array.ListNumber; + +/** + * Tag interface to mark all the members of the value classes. + * + * @author carcassi + */ +public abstract class VType { + + private static final Collection> TYPES = Arrays.>asList( + VDouble.class, + VFloat.class, + VULong.class, + VLong.class, + VUInt.class, + VInt.class, + VUShort.class, + VShort.class, + VUByte.class, + VByte.class, + VEnum.class, + VBoolean.class, + VString.class, + VDoubleArray.class, + VFloatArray.class, + VULongArray.class, + VLongArray.class, + VUIntArray.class, + VIntArray.class, + VUShortArray.class, + VShortArray.class, + VUByteArray.class, + VByteArray.class, + VImage.class, + VTable.class); + + /** + * Returns the type of the object by returning the class object of one + * of the VXxx interfaces. The getClass() methods returns the + * concrete implementation type, which is of little use. If no + * super-interface is found, Object.class is used. + * + * @param obj an object implementing a standard type + * @return the type is implementing + */ + public static Class typeOf(Object obj) { + if (obj == null) + return null; + + for (Class type : TYPES) { + if (type.isInstance(obj)) { + return type; + } + } + + return Object.class; + } + + /** + * As {@link #toVType(java.lang.Object)} but throws an exception + * if conversion not possible. + * + * @param javaObject the value to wrap + * @return the new VType value + */ + public static VType toVTypeChecked(Object javaObject) { + VType value = toVType(javaObject); + if (value == null) { + throw new IllegalArgumentException("Value " + value + " cannot be converted to VType."); + } + return value; + } + + /** + * As {@link #toVType(java.lang.Object, org.epics.vtype.Alarm, org.epics.vtype.Time, org.epics.vtype.Display)} but throws an exception + * if conversion not possible. + * + * @param javaObject the value to wrap + * @param alarm the alarm + * @param time the time + * @param display the display + * @return the new VType value + */ + public static VType toVTypeChecked(Object javaObject, Alarm alarm, Time time, Display display) { + VType value = toVType(javaObject, alarm, time, display); + if (value == null) { + throw new IllegalArgumentException("Value " + value + " cannot be converted to VType."); + } + return value; + } + + /** + * Converts a standard java type to VTypes. Returns null if no conversion + * is possible. Calls {@link #toVType(java.lang.Object, org.epics.vtype.Alarm, org.epics.vtype.Time, org.epics.vtype.Display) } + * with no alarm, time now and no display. + * + * @param javaObject the value to wrap + * @return the new VType value + */ + public static VType toVType(Object javaObject) { + return toVType(javaObject, Alarm.none(), Time.now(), Display.none()); + } + + /** + * Converts a standard java type to VTypes. Returns null if no conversion + * is possible. Calls {@link #toVType(java.lang.Object, org.epics.vtype.Alarm, org.epics.vtype.Time, org.epics.vtype.Display) } + * with the given alarm, time now and no display. + * + * @param javaObject the value to wrap + * @param alarm the alarm + * @return the new VType value + */ + public static VType toVType(Object javaObject, Alarm alarm) { + return toVType(javaObject, alarm, Time.now(), Display.none()); + } + + /** + * Converts a standard java type to VTypes. Returns null if no conversion + * is possible. + *

+ * Types are converted as follow: + *

    + *
  • Boolean -> VBoolean
  • + *
  • Number -> corresponding VNumber
  • + *
  • String -> VString
  • + *
  • number array -> corresponding VNumberArray
  • + *
  • ListNumber -> corresponding VNumberArray
  • + *
  • List -> if all elements are String, VStringArray
  • + *
+ * + * @param javaObject the value to wrap + * @param alarm the alarm + * @param time the time + * @param display the display + * @return the new VType value + */ + public static VType toVType(Object javaObject, Alarm alarm, Time time, Display display) { + if (javaObject instanceof Number) { + return VNumber.of((Number) javaObject, alarm, time, display); + } else if (javaObject instanceof String) { + return VString.of((String) javaObject, alarm, time); + } else if (javaObject instanceof Boolean) { + return VBoolean.of((Boolean) javaObject, alarm, time); + } else if (javaObject instanceof byte[] + || javaObject instanceof short[] + || javaObject instanceof int[] + || javaObject instanceof long[] + || javaObject instanceof float[] + || javaObject instanceof double[]) { + return VNumberArray.of(CollectionNumbers.toList(javaObject), alarm, time, display); + } else if (javaObject instanceof ListNumber) { + return VNumberArray.of((ListNumber) javaObject, alarm, time, display); + } else if (javaObject instanceof String[]) { + return null;//newVStringArray(Arrays.asList((String[]) javaObject), alarm, time); + } else if (javaObject instanceof List) { + boolean matches = true; + List list = (List) javaObject; + for (Object object : list) { + if (!(object instanceof String)) { + matches = false; + } + } + if (matches) { + @SuppressWarnings("unchecked") + List newList = (List) list; + return null;//newVStringArray(Collections.unmodifiableList(newList), alarm, time); + } else { + return null; + } + } else { + return null; + } + } + + static void argumentNotNull(String argName, Object value) { + if (value == null) { + throw new NullPointerException(argName + " can't be null"); + } + } +} diff --git a/epics-vtype/vtype/src/test/java/org/epics/vtype/VImageTest.java b/epics-vtype/vtype/src/test/java/org/epics/vtype/VImageTest.java new file mode 100644 index 000000000..5ced6de40 --- /dev/null +++ b/epics-vtype/vtype/src/test/java/org/epics/vtype/VImageTest.java @@ -0,0 +1,64 @@ +package org.epics.vtype; + +import static org.junit.Assert.assertEquals; + +import java.awt.image.BufferedImage; +import java.awt.image.DataBufferByte; +import java.io.File; +import java.io.IOException; + +import javax.imageio.ImageIO; + +import org.epics.util.array.ArrayByte; +import org.epics.util.array.ListNumber; +import org.junit.Test; + +public class VImageTest { + + /** + * A test for the creation of a {@link VImage} data structure using an example image + */ + @Test + public void of() { + BufferedImage img = null; + VImage vImage = null; + boolean done = false; + try { + img = ImageIO.read(VType.class.getResource("Tulips.jpg")); + vImage = VImage.of(img.getHeight(), img.getWidth(), + ArrayByte.of(((DataBufferByte) img.getRaster().getDataBuffer()).getData()), VImageDataType.pvByte, + VImageType.TYPE_3BYTE_BGR, + Alarm.none(), Time.now()); + BufferedImage vImg = toImage(vImage); + for (int x = 0; x < vImage.getWidth(); x++) { + for (int y = 0; y < vImage.getHeight(); y++) { + assertEquals(img.getRGB(x, y), vImg.getRGB(x, y)); + } + } + done = true; + } catch (IOException e) { + } finally { + if (!done) { + BufferedImage bf = toImage(vImage); + try { + ImageIO.write(bf, "png", new File("src/test/resources/org/diirt/vtype/Tuplips-failed.jpg")); + } catch (IOException e) { + } + } + } + } + + private static BufferedImage toImage(VImage vImage) { + if (vImage.getVImageType() == VImageType.TYPE_3BYTE_BGR) { + BufferedImage image = new BufferedImage(vImage.getWidth(), vImage.getHeight(), BufferedImage.TYPE_3BYTE_BGR); + ListNumber data = vImage.getData(); + for (int i = 0; i < data.size(); i++) { + ((DataBufferByte) image.getRaster().getDataBuffer()).getData()[i] = data.getByte(i); + } + return image; + } else { + throw new UnsupportedOperationException( + "No support for creating a BufferedImage from Image Type: " + vImage.getVImageType()); + } + } +} diff --git a/epics-vtype/vtype/src/test/resources/org/epics/vtype/Tulips.jpg b/epics-vtype/vtype/src/test/resources/org/epics/vtype/Tulips.jpg new file mode 100644 index 000000000..54c51eb6a Binary files /dev/null and b/epics-vtype/vtype/src/test/resources/org/epics/vtype/Tulips.jpg differ diff --git a/pom.xml b/pom.xml index 0ef054900..bdb5e5708 100644 --- a/pom.xml +++ b/pom.xml @@ -34,6 +34,9 @@ pvDatabaseJava epics-core epics-deploy + epics-util + epics-vtype + gpclient diff --git a/pvDataJava/pom.xml b/pvDataJava/pom.xml index 8b40bdc94..4f0f2118e 100644 --- a/pvDataJava/pom.xml +++ b/pvDataJava/pom.xml @@ -42,4 +42,17 @@ https://github.com/epics-base/pvDataJava https://github.com/epics-base/pvDataJava + + + ${project.groupId} + epics-util + 1.0.0-SNAPSHOT + + + org.hamcrest + hamcrest-all + 1.3 + test + + diff --git a/pvDataJava/src/org/epics/pvdata/copy/package.html b/pvDataJava/src/org/epics/pvdata/copy/package.html index ebb177af4..4399d065a 100644 --- a/pvDataJava/src/org/epics/pvdata/copy/package.html +++ b/pvDataJava/src/org/epics/pvdata/copy/package.html @@ -18,5 +18,7 @@ + +

diff --git a/pvDataJava/src/org/epics/pvdata/factory/AbstractPVArray.java b/pvDataJava/src/org/epics/pvdata/factory/AbstractPVArray.java index af0ddd310..210a9c4b8 100644 --- a/pvDataJava/src/org/epics/pvdata/factory/AbstractPVArray.java +++ b/pvDataJava/src/org/epics/pvdata/factory/AbstractPVArray.java @@ -10,6 +10,8 @@ import org.epics.pvdata.pv.ArrayData; import org.epics.pvdata.pv.PVArray; import org.epics.pvdata.pv.SerializableControl; +import org.epics.util.array.CollectionNumbers; +import org.epics.util.array.ListNumber; /** * Abstract base class for any PVArray field. @@ -116,6 +118,22 @@ protected int internalPut(int offset, int len, Object from, int fromOffset) { return len; } + public void put(int offset, ListNumber list) { + if (super.isImmutable()) + throw new IllegalStateException("field is immutable"); + + int newLength = offset + list.size(); + if (newLength > length) + { + checkLength(newLength); + setCapacity(newLength); + length = newLength; + } + + CollectionNumbers.toList(getValue()).setAll(offset, list); + super.postPut(); + } + private void checkLength(int len) { Array.ArraySizeType type = getArray().getArraySizeType(); diff --git a/pvDataJava/src/org/epics/pvdata/factory/BasePVByteArray.java b/pvDataJava/src/org/epics/pvdata/factory/BasePVByteArray.java index d2c62bac7..a3d0f5273 100644 --- a/pvDataJava/src/org/epics/pvdata/factory/BasePVByteArray.java +++ b/pvDataJava/src/org/epics/pvdata/factory/BasePVByteArray.java @@ -12,6 +12,8 @@ import org.epics.pvdata.pv.PVByteArray; import org.epics.pvdata.pv.ScalarArray; import org.epics.pvdata.pv.SerializableControl; +import org.epics.util.array.ArrayByte; +import org.epics.util.array.CollectionNumbers; /** @@ -71,6 +73,11 @@ protected int getFromBuffer(ByteBuffer buffer, DeserializableControl control, in public int get(int offset, int len, ByteArrayData data) { return internalGet(offset, len, data); } + + @Override + public ArrayByte get() { + return CollectionNumbers.unmodifiableListByte(value); + } /* (non-Javadoc) * @see org.epics.pvdata.pv.PVByteArray#put(int, int, byte[], int) diff --git a/pvDataJava/src/org/epics/pvdata/factory/BasePVDoubleArray.java b/pvDataJava/src/org/epics/pvdata/factory/BasePVDoubleArray.java index e5788e6ee..b40626a39 100644 --- a/pvDataJava/src/org/epics/pvdata/factory/BasePVDoubleArray.java +++ b/pvDataJava/src/org/epics/pvdata/factory/BasePVDoubleArray.java @@ -12,6 +12,9 @@ import org.epics.pvdata.pv.PVDoubleArray; import org.epics.pvdata.pv.ScalarArray; import org.epics.pvdata.pv.SerializableControl; +import org.epics.util.array.ArrayDouble; +import org.epics.util.array.CollectionNumbers; +import org.epics.util.array.ListNumber; /** @@ -73,6 +76,11 @@ protected int getFromBuffer(ByteBuffer buffer, DeserializableControl control, in public int get(int offset, int len, DoubleArrayData data) { return internalGet(offset, len, data); } + + @Override + public ArrayDouble get() { + return CollectionNumbers.unmodifiableListDouble(value); + } /* (non-Javadoc) * @see org.epics.pvdata.pv.PVDoubleArray#put(int, int, double[], int) @@ -82,7 +90,6 @@ public int put(int offset, int len, double[] from, int fromOffset) { return internalPut(offset, len, from, fromOffset); } - /* (non-Javadoc) * @see org.epics.pvdata.pv.PVDoubleArray#shareData(double[]) */ diff --git a/pvDataJava/src/org/epics/pvdata/factory/BasePVFloatArray.java b/pvDataJava/src/org/epics/pvdata/factory/BasePVFloatArray.java index 8102c3d96..3e61b49f3 100644 --- a/pvDataJava/src/org/epics/pvdata/factory/BasePVFloatArray.java +++ b/pvDataJava/src/org/epics/pvdata/factory/BasePVFloatArray.java @@ -12,6 +12,8 @@ import org.epics.pvdata.pv.PVFloatArray; import org.epics.pvdata.pv.ScalarArray; import org.epics.pvdata.pv.SerializableControl; +import org.epics.util.array.ArrayFloat; +import org.epics.util.array.CollectionNumbers; /** @@ -73,6 +75,11 @@ protected int getFromBuffer(ByteBuffer buffer, DeserializableControl control, in public int get(int offset, int len, FloatArrayData data) { return internalGet(offset, len, data); } + + @Override + public ArrayFloat get() { + return CollectionNumbers.unmodifiableListFloat(value); + } /* (non-Javadoc) * @see org.epics.pvdata.pv.PVFloatArray#put(int, int, float[], int) diff --git a/pvDataJava/src/org/epics/pvdata/factory/BasePVIntArray.java b/pvDataJava/src/org/epics/pvdata/factory/BasePVIntArray.java index 23ae3d694..818745e03 100644 --- a/pvDataJava/src/org/epics/pvdata/factory/BasePVIntArray.java +++ b/pvDataJava/src/org/epics/pvdata/factory/BasePVIntArray.java @@ -12,6 +12,8 @@ import org.epics.pvdata.pv.PVIntArray; import org.epics.pvdata.pv.ScalarArray; import org.epics.pvdata.pv.SerializableControl; +import org.epics.util.array.ArrayInteger; +import org.epics.util.array.CollectionNumbers; /** @@ -73,6 +75,11 @@ protected int getFromBuffer(ByteBuffer buffer, DeserializableControl control, in public int get(int offset, int len, IntArrayData data) { return internalGet(offset, len, data); } + + @Override + public ArrayInteger get() { + return CollectionNumbers.unmodifiableListInt(value); + } /* (non-Javadoc) * @see org.epics.pvdata.pv.PVIntArray#put(int, int, int[], int) diff --git a/pvDataJava/src/org/epics/pvdata/factory/BasePVLongArray.java b/pvDataJava/src/org/epics/pvdata/factory/BasePVLongArray.java index 039e6169e..790874640 100644 --- a/pvDataJava/src/org/epics/pvdata/factory/BasePVLongArray.java +++ b/pvDataJava/src/org/epics/pvdata/factory/BasePVLongArray.java @@ -12,6 +12,8 @@ import org.epics.pvdata.pv.PVLongArray; import org.epics.pvdata.pv.ScalarArray; import org.epics.pvdata.pv.SerializableControl; +import org.epics.util.array.ArrayLong; +import org.epics.util.array.CollectionNumbers; /** @@ -73,6 +75,11 @@ protected int getFromBuffer(ByteBuffer buffer, DeserializableControl control, in public int get(int offset, int len, LongArrayData data) { return internalGet(offset, len, data); } + + @Override + public ArrayLong get() { + return CollectionNumbers.unmodifiableListLong(value); + } /* (non-Javadoc) * @see org.epics.pvdata.pv.PVLongArray#put(int, int, long[], int) diff --git a/pvDataJava/src/org/epics/pvdata/factory/BasePVShortArray.java b/pvDataJava/src/org/epics/pvdata/factory/BasePVShortArray.java index 3a4c983f9..65acbe714 100644 --- a/pvDataJava/src/org/epics/pvdata/factory/BasePVShortArray.java +++ b/pvDataJava/src/org/epics/pvdata/factory/BasePVShortArray.java @@ -12,6 +12,8 @@ import org.epics.pvdata.pv.ScalarArray; import org.epics.pvdata.pv.SerializableControl; import org.epics.pvdata.pv.ShortArrayData; +import org.epics.util.array.ArrayShort; +import org.epics.util.array.CollectionNumbers; /** @@ -73,6 +75,11 @@ protected int getFromBuffer(ByteBuffer buffer, DeserializableControl control, in public int get(int offset, int len, ShortArrayData data) { return internalGet(offset, len, data); } + + @Override + public ArrayShort get() { + return CollectionNumbers.unmodifiableListShort(value); + } /* (non-Javadoc) * @see org.epics.pvdata.pv.PVShortArray#put(int, int, short[], int) diff --git a/pvDataJava/src/org/epics/pvdata/factory/BasePVUByteArray.java b/pvDataJava/src/org/epics/pvdata/factory/BasePVUByteArray.java index 81f3df76b..9e83c7b48 100644 --- a/pvDataJava/src/org/epics/pvdata/factory/BasePVUByteArray.java +++ b/pvDataJava/src/org/epics/pvdata/factory/BasePVUByteArray.java @@ -12,6 +12,8 @@ import org.epics.pvdata.pv.PVUByteArray; import org.epics.pvdata.pv.ScalarArray; import org.epics.pvdata.pv.SerializableControl; +import org.epics.util.array.ArrayUByte; +import org.epics.util.array.CollectionNumbers; /** @@ -71,6 +73,11 @@ protected int getFromBuffer(ByteBuffer buffer, DeserializableControl control, in public int get(int offset, int len, ByteArrayData data) { return internalGet(offset, len, data); } + + @Override + public ArrayUByte get() { + return CollectionNumbers.unmodifiableListUByte(value); + } /* (non-Javadoc) * @see org.epics.pvdata.pv.PVUByteArray#put(int, int, byte[], int) diff --git a/pvDataJava/src/org/epics/pvdata/factory/BasePVUIntArray.java b/pvDataJava/src/org/epics/pvdata/factory/BasePVUIntArray.java index 02a90a8c7..08757b29f 100644 --- a/pvDataJava/src/org/epics/pvdata/factory/BasePVUIntArray.java +++ b/pvDataJava/src/org/epics/pvdata/factory/BasePVUIntArray.java @@ -12,6 +12,8 @@ import org.epics.pvdata.pv.PVUIntArray; import org.epics.pvdata.pv.ScalarArray; import org.epics.pvdata.pv.SerializableControl; +import org.epics.util.array.ArrayUInteger; +import org.epics.util.array.CollectionNumbers; /** @@ -73,6 +75,11 @@ protected int getFromBuffer(ByteBuffer buffer, DeserializableControl control, in public int get(int offset, int len, IntArrayData data) { return internalGet(offset, len, data); } + + @Override + public ArrayUInteger get() { + return CollectionNumbers.unmodifiableListUInt(value); + } /* (non-Javadoc) * @see org.epics.pvdata.pv.PVUIntArray#put(int, int, int[], int) diff --git a/pvDataJava/src/org/epics/pvdata/factory/BasePVULongArray.java b/pvDataJava/src/org/epics/pvdata/factory/BasePVULongArray.java index 257b898c4..82678dff6 100644 --- a/pvDataJava/src/org/epics/pvdata/factory/BasePVULongArray.java +++ b/pvDataJava/src/org/epics/pvdata/factory/BasePVULongArray.java @@ -12,6 +12,8 @@ import org.epics.pvdata.pv.PVULongArray; import org.epics.pvdata.pv.ScalarArray; import org.epics.pvdata.pv.SerializableControl; +import org.epics.util.array.ArrayULong; +import org.epics.util.array.CollectionNumbers; /** @@ -73,6 +75,11 @@ protected int getFromBuffer(ByteBuffer buffer, DeserializableControl control, in public int get(int offset, int len, LongArrayData data) { return internalGet(offset, len, data); } + + @Override + public ArrayULong get() { + return CollectionNumbers.unmodifiableListULong(value); + } /* (non-Javadoc) * @see org.epics.pvdata.pv.PVULongArray#put(int, int, long[], int) diff --git a/pvDataJava/src/org/epics/pvdata/factory/BasePVUShortArray.java b/pvDataJava/src/org/epics/pvdata/factory/BasePVUShortArray.java index 755a8ef97..ce0892998 100644 --- a/pvDataJava/src/org/epics/pvdata/factory/BasePVUShortArray.java +++ b/pvDataJava/src/org/epics/pvdata/factory/BasePVUShortArray.java @@ -12,6 +12,8 @@ import org.epics.pvdata.pv.ScalarArray; import org.epics.pvdata.pv.SerializableControl; import org.epics.pvdata.pv.ShortArrayData; +import org.epics.util.array.ArrayUShort; +import org.epics.util.array.CollectionNumbers; /** @@ -73,6 +75,11 @@ protected int getFromBuffer(ByteBuffer buffer, DeserializableControl control, in public int get(int offset, int len, ShortArrayData data) { return internalGet(offset, len, data); } + + @Override + public ArrayUShort get() { + return CollectionNumbers.unmodifiableListUShort(value); + } /* (non-Javadoc) * @see org.epics.pvdata.pv.PVUShortArray#put(int, int, short[], int) diff --git a/pvDataJava/src/org/epics/pvdata/misc/BitSet.java b/pvDataJava/src/org/epics/pvdata/misc/BitSet.java index 81b22aefc..ef5c203b8 100644 --- a/pvDataJava/src/org/epics/pvdata/misc/BitSet.java +++ b/pvDataJava/src/org/epics/pvdata/misc/BitSet.java @@ -214,6 +214,7 @@ public static BitSet valueOf(long[] longs) { * @param lb a long buffer containing a little-endian representation * of a sequence of bits between its position and limit, to be * used as the initial bits of the new bit set + * @return the new bit set * @return a new bit set containing all the bits in the given long buffer between its position and limit * @since 1.7 */ @@ -461,11 +462,11 @@ public boolean getAndSet(int bitIndex) { final int wordIndex = wordIndex(bitIndex); final long mask = 1L << bitIndex; final boolean retVal = (wordIndex < wordsInUse) && ((words[wordIndex] & mask) != 0); - + expandTo(wordIndex); words[wordIndex] |= mask; // Restores invariants - + return retVal; } @@ -477,11 +478,11 @@ public void set(BitSet src) { // we ensure that words array size is adequate (and not wordsInUse to ensure capacity to the future) if (src.words.length > this.words.length) this.words = new long[src.words.length]; - + System.arraycopy(src.words, 0, this.words, 0, src.wordsInUse); this.wordsInUse = src.wordsInUse; } - + /** * Sets the bit at the specified index to the specified value. * @@ -949,12 +950,12 @@ public void or_and(BitSet set1, BitSet set2) { words = Arrays.copyOf(words, inUse); wordsInUse = inUse; } - + // Perform logical AND on words in common for (int i = 0; i < inUse; i++) words[i] |= (set1.words[i] & set2.words[i]); } - + /** * Performs a logical OR of this bit set with the bit set * argument. This bit set is modified so that a bit in it has the @@ -1218,7 +1219,7 @@ public String toString() { b.append('}'); return b.toString(); } - + /** * Get long[] that represents this BitSet. * @return long[] that represts this BitSet. @@ -1227,9 +1228,9 @@ public long[] getBitArray() { return words; } - + /** - * NOTE: word is atomic unit here; some bytes might be saved, but it's not worth it. + * NOTE: word is atomic unit here; some bytes might be saved, but it's not worth it. * @see org.epics.pvdata.pv.Serializable#serialize(java.nio.ByteBuffer, org.epics.pvdata.pv.SerializableControl) */ @Override @@ -1243,12 +1244,12 @@ public void serialize(ByteBuffer buffer, SerializableControl flusher) { final int maxIndex = Math.min(wordsInUse, i + spaceLeft); for (; i < maxIndex; i++) buffer.putLong(words[i]); - + if (i < wordsInUse) flusher.flushSerializeBuffer(); } */ - + int n = wordsInUse; if (n == 0) { SerializeHelper.writeSize(0, buffer, flusher); @@ -1257,14 +1258,14 @@ public void serialize(ByteBuffer buffer, SerializableControl flusher) { int len = 8 * (n-1); for (long x = words[n - 1]; x != 0; x >>>= 8) len++; - + SerializeHelper.writeSize(len, buffer, flusher); flusher.ensureBuffer(len); n = len / 8; for (int i = 0; i < n; i++) buffer.putLong(words[i]); - + if (n < wordsInUse) for (long x = words[wordsInUse - 1]; x != 0; x >>>= 8) buffer.put((byte) (x & 0xff)); @@ -1277,29 +1278,29 @@ public void serialize(ByteBuffer buffer, SerializableControl flusher) { public void deserialize(ByteBuffer buffer, DeserializableControl control) { final int bytes = SerializeHelper.readSize(buffer, control); // in bytes - + wordsInUse = (bytes + 7) / 8; if (wordsInUse > words.length) words = new long[wordsInUse]; if (wordsInUse == 0) return; - + control.ensureData(bytes); - + int i = 0; final int longs = bytes / 8; while (i < longs) words[i++] = buffer.getLong(); - + for (int j = i; j < wordsInUse; j++) words[j] = 0; - + for (int remaining = (bytes - longs * 8), j = 0; j < remaining; j++) words[i] |= (buffer.get() & 0xffL) << (8 * j); - + /* - + wordsInUse = SerializeHelper.readSize(buffer, control); if (wordsInUse > words.length) words = new long[wordsInUse]; diff --git a/pvDataJava/src/org/epics/pvdata/property/package.html b/pvDataJava/src/org/epics/pvdata/property/package.html index 091715ea8..454c38ff7 100644 --- a/pvDataJava/src/org/epics/pvdata/property/package.html +++ b/pvDataJava/src/org/epics/pvdata/property/package.html @@ -14,6 +14,6 @@
Provides support for setting limits for scalar double values.
display
Provides support for for displaying scalar double values.
- +
diff --git a/pvDataJava/src/org/epics/pvdata/pv/PVByteArray.java b/pvDataJava/src/org/epics/pvdata/pv/PVByteArray.java index 4f6e9ff5b..decc6893a 100644 --- a/pvDataJava/src/org/epics/pvdata/pv/PVByteArray.java +++ b/pvDataJava/src/org/epics/pvdata/pv/PVByteArray.java @@ -4,6 +4,8 @@ */ package org.epics.pvdata.pv; +import org.epics.util.array.ArrayByte; + /** * Get/put a byte array. * The caller must be prepared to get/put the array in chunks. @@ -12,7 +14,7 @@ * @author mrk * */ -public interface PVByteArray extends PVScalarArray { +public interface PVByteArray extends PVNumberArray { /** * Get values from a PVByteArray and put them into byte[]from. * @@ -28,6 +30,14 @@ public interface PVByteArray extends PVScalarArray { * array. */ int get(int offset, int length, ByteArrayData data); + + /** + * Returns an unmodifiable view of the data. + * + * @return an unmodifiable view of the data + */ + @Override + ArrayByte get(); /** * Put values into a PVByteArray from byte[]to. diff --git a/pvDataJava/src/org/epics/pvdata/pv/PVDoubleArray.java b/pvDataJava/src/org/epics/pvdata/pv/PVDoubleArray.java index d1edabf8b..96b10a616 100644 --- a/pvDataJava/src/org/epics/pvdata/pv/PVDoubleArray.java +++ b/pvDataJava/src/org/epics/pvdata/pv/PVDoubleArray.java @@ -4,6 +4,9 @@ */ package org.epics.pvdata.pv; +import org.epics.util.array.ArrayDouble; +import org.epics.util.array.ListNumber; + /** * Get/put a double array. * The caller must be prepared to get/put the array in chunks. @@ -12,7 +15,7 @@ * @author mrk * */ -public interface PVDoubleArray extends PVScalarArray{ +public interface PVDoubleArray extends PVNumberArray{ /** * Get values from a PVDoubleArray * and put them into double[]to @@ -29,6 +32,14 @@ public interface PVDoubleArray extends PVScalarArray{ * array. */ int get(int offset, int length, DoubleArrayData data); + + /** + * Returns an unmodifiable view of the data. + * + * @return an unmodifiable view of the data + */ + @Override + ArrayDouble get(); /** * Put values into a PVDoubleArray from double[]from diff --git a/pvDataJava/src/org/epics/pvdata/pv/PVFloatArray.java b/pvDataJava/src/org/epics/pvdata/pv/PVFloatArray.java index 5da12c572..cb66fde25 100644 --- a/pvDataJava/src/org/epics/pvdata/pv/PVFloatArray.java +++ b/pvDataJava/src/org/epics/pvdata/pv/PVFloatArray.java @@ -4,6 +4,8 @@ */ package org.epics.pvdata.pv; +import org.epics.util.array.ArrayFloat; + /** * Get/put a float array. * The caller must be prepared to get/put the array in chunks. @@ -12,7 +14,7 @@ * @author mrk * */ -public interface PVFloatArray extends PVScalarArray{ +public interface PVFloatArray extends PVNumberArray{ /** * Get values from a PVFloatArray * and put them into float[]to. @@ -29,6 +31,14 @@ public interface PVFloatArray extends PVScalarArray{ * array. */ int get(int offset, int length, FloatArrayData data); + + /** + * Returns an unmodifiable view of the data. + * + * @return an unmodifiable view of the data + */ + @Override + ArrayFloat get(); /** * Put values into a PVFloatArray from float[]from. diff --git a/pvDataJava/src/org/epics/pvdata/pv/PVIntArray.java b/pvDataJava/src/org/epics/pvdata/pv/PVIntArray.java index d5a5ac5b1..8f6bb6280 100644 --- a/pvDataJava/src/org/epics/pvdata/pv/PVIntArray.java +++ b/pvDataJava/src/org/epics/pvdata/pv/PVIntArray.java @@ -4,6 +4,9 @@ */ package org.epics.pvdata.pv; +import org.epics.util.array.ArrayInteger; +import org.epics.util.array.ListNumber; + /** * Get/put a int array. * The caller must be prepared to get/put the array in chunks. @@ -12,7 +15,7 @@ * @author mrk * */ -public interface PVIntArray extends PVScalarArray{ +public interface PVIntArray extends PVNumberArray{ /** * Get values from a PVIntArray and put them into int[]to. * @@ -28,6 +31,14 @@ public interface PVIntArray extends PVScalarArray{ * array. */ int get(int offset, int length, IntArrayData data); + + /** + * Returns an unmodifiable view of the data. + * + * @return an unmodifiable view of the data + */ + @Override + ArrayInteger get(); /** * Put values into a PVIntArray from int[]from. diff --git a/pvDataJava/src/org/epics/pvdata/pv/PVLongArray.java b/pvDataJava/src/org/epics/pvdata/pv/PVLongArray.java index b35e30991..40f1803a6 100644 --- a/pvDataJava/src/org/epics/pvdata/pv/PVLongArray.java +++ b/pvDataJava/src/org/epics/pvdata/pv/PVLongArray.java @@ -4,6 +4,8 @@ */ package org.epics.pvdata.pv; +import org.epics.util.array.ArrayLong; + /** * Get/put a long array. * The caller must be prepared to get/put the array in chunks. @@ -12,7 +14,7 @@ * @author mrk * */ -public interface PVLongArray extends PVScalarArray{ +public interface PVLongArray extends PVNumberArray{ /** * Get values from a PVLongArray and put them into long[]to. * @@ -28,6 +30,14 @@ public interface PVLongArray extends PVScalarArray{ * array. */ int get(int offset, int length, LongArrayData data); + + /** + * Returns an unmodifiable view of the data. + * + * @return an unmodifiable view of the data + */ + @Override + ArrayLong get(); /** * Put values into a PVLongArray from long[]from. diff --git a/pvDataJava/src/org/epics/pvdata/pv/PVNumberArray.java b/pvDataJava/src/org/epics/pvdata/pv/PVNumberArray.java new file mode 100644 index 000000000..c087a237d --- /dev/null +++ b/pvDataJava/src/org/epics/pvdata/pv/PVNumberArray.java @@ -0,0 +1,32 @@ +/* + * Copyright information and license terms for this software can be + * found in the file LICENSE that is included with the distribution + */ +package org.epics.pvdata.pv; + +import org.epics.util.array.ListNumber; + +/** + * Get/put a numeric array array. + * The caller must be prepared to get/put the array in chunks. + * The return argument is always the number of elements that were transfered. + * It may be less than the number requested. + * + */ +public interface PVNumberArray extends PVScalarArray { + + /** + * Returns an unmodifiable view of the data. + * + * @return an unmodifiable view of the data + */ + ListNumber get(); + + /** + * Puts the new value contained in the list starting from the offset. + * + * @param offset the first element to be changed + * @param list the values to be copied + */ + void put(int offset, ListNumber list); +} diff --git a/pvDataJava/src/org/epics/pvdata/pv/PVShortArray.java b/pvDataJava/src/org/epics/pvdata/pv/PVShortArray.java index 52f765f43..2753d5811 100644 --- a/pvDataJava/src/org/epics/pvdata/pv/PVShortArray.java +++ b/pvDataJava/src/org/epics/pvdata/pv/PVShortArray.java @@ -4,6 +4,8 @@ */ package org.epics.pvdata.pv; +import org.epics.util.array.ArrayShort; + /** * Get/put a short array. * The caller must be prepared to get/put the array in chunks. @@ -12,7 +14,7 @@ * @author mrk * */ -public interface PVShortArray extends PVScalarArray{ +public interface PVShortArray extends PVNumberArray{ /** * Get values from a PVShortArray and put them into short[]to. * @@ -28,6 +30,14 @@ public interface PVShortArray extends PVScalarArray{ * array. */ int get(int offset, int length, ShortArrayData data); + + /** + * Returns an unmodifiable view of the data. + * + * @return an unmodifiable view of the data + */ + @Override + ArrayShort get(); /** * Put values into a PVShortArray from short[]from. diff --git a/pvDataJava/src/org/epics/pvdata/pv/PVUByteArray.java b/pvDataJava/src/org/epics/pvdata/pv/PVUByteArray.java index 459b33523..9efd5b791 100644 --- a/pvDataJava/src/org/epics/pvdata/pv/PVUByteArray.java +++ b/pvDataJava/src/org/epics/pvdata/pv/PVUByteArray.java @@ -4,6 +4,8 @@ */ package org.epics.pvdata.pv; +import org.epics.util.array.ArrayUByte; + /** * Get/put a byte array. * Since Java does not support unsigned the actual arguments are signed. @@ -14,7 +16,7 @@ * @author mrk * */ -public interface PVUByteArray extends PVScalarArray{ +public interface PVUByteArray extends PVNumberArray{ /** * Get values from a PVByteArray and put them into byte[]from. * @@ -30,6 +32,14 @@ public interface PVUByteArray extends PVScalarArray{ * array. */ int get(int offset, int length, ByteArrayData data); + + /** + * Returns an unmodifiable view of the data. + * + * @return an unmodifiable view of the data + */ + @Override + ArrayUByte get(); /** * Put values into a PVByteArray from byte[]to. diff --git a/pvDataJava/src/org/epics/pvdata/pv/PVUIntArray.java b/pvDataJava/src/org/epics/pvdata/pv/PVUIntArray.java index fb42d848a..1e90913ce 100644 --- a/pvDataJava/src/org/epics/pvdata/pv/PVUIntArray.java +++ b/pvDataJava/src/org/epics/pvdata/pv/PVUIntArray.java @@ -4,6 +4,8 @@ */ package org.epics.pvdata.pv; +import org.epics.util.array.ArrayUInteger; + /** * Get/put a int array. * Since Java does not support unsigned the actual arguments are signed. @@ -14,7 +16,7 @@ * @author mrk * */ -public interface PVUIntArray extends PVScalarArray{ +public interface PVUIntArray extends PVNumberArray{ /** * Get values from a PVIntArray and put them into int[]to. * @@ -30,6 +32,14 @@ public interface PVUIntArray extends PVScalarArray{ * array. */ int get(int offset, int length, IntArrayData data); + + /** + * Returns an unmodifiable view of the data. + * + * @return an unmodifiable view of the data + */ + @Override + ArrayUInteger get(); /** * Put values into a PVIntArray from int[]from. diff --git a/pvDataJava/src/org/epics/pvdata/pv/PVULongArray.java b/pvDataJava/src/org/epics/pvdata/pv/PVULongArray.java index 3a1b09b38..8ee57a495 100644 --- a/pvDataJava/src/org/epics/pvdata/pv/PVULongArray.java +++ b/pvDataJava/src/org/epics/pvdata/pv/PVULongArray.java @@ -4,6 +4,8 @@ */ package org.epics.pvdata.pv; +import org.epics.util.array.ArrayULong; + /** * Get/put a long array. * Since Java does not support unsigned the actual arguments are signed. @@ -14,7 +16,7 @@ * @author mrk * */ -public interface PVULongArray extends PVScalarArray{ +public interface PVULongArray extends PVNumberArray{ /** * Get values from a PVLongArray and put them into long[]to. * @@ -30,6 +32,14 @@ public interface PVULongArray extends PVScalarArray{ * array. */ int get(int offset, int length, LongArrayData data); + + /** + * Returns an unmodifiable view of the data. + * + * @return an unmodifiable view of the data + */ + @Override + ArrayULong get(); /** * Put values into a PVLongArray from long[]from. diff --git a/pvDataJava/src/org/epics/pvdata/pv/PVUShortArray.java b/pvDataJava/src/org/epics/pvdata/pv/PVUShortArray.java index f1fbddbba..59bf23239 100644 --- a/pvDataJava/src/org/epics/pvdata/pv/PVUShortArray.java +++ b/pvDataJava/src/org/epics/pvdata/pv/PVUShortArray.java @@ -4,6 +4,8 @@ */ package org.epics.pvdata.pv; +import org.epics.util.array.ArrayUShort; + /** * Get/put a short array. * Since Java does not support unsigned the actual arguments are signed. @@ -14,7 +16,7 @@ * @author mrk * */ -public interface PVUShortArray extends PVScalarArray{ +public interface PVUShortArray extends PVNumberArray{ /** * Get values from a PVShortArray and put them into short[]to. * @@ -30,6 +32,14 @@ public interface PVUShortArray extends PVScalarArray{ * array. */ int get(int offset, int length, ShortArrayData data); + + /** + * Returns an unmodifiable view of the data. + * + * @return an unmodifiable view of the data + */ + @Override + ArrayUShort get(); /** * Put values into a PVShortArray from short[]from. diff --git a/pvDataJava/src/org/epics/pvdata/pv/StandardPVField.java b/pvDataJava/src/org/epics/pvdata/pv/StandardPVField.java index 2288eaf84..6d523584f 100644 --- a/pvDataJava/src/org/epics/pvdata/pv/StandardPVField.java +++ b/pvDataJava/src/org/epics/pvdata/pv/StandardPVField.java @@ -12,7 +12,7 @@ public interface StandardPVField { /** * Create a PVStructure with a scalar value field. - * + * * @param type The scalarType * @param properties the list of additional properties, which is some * combination of the strings alarm, timeStamp, display, @@ -23,7 +23,7 @@ public interface StandardPVField { /** * Create a PVStructure with a scalarArray value field. - * + * * @param elementType the scalarType for each element. * @param properties the list of additional properties, which is some * combination of the strings alarm, timeStamp, display, @@ -35,6 +35,7 @@ public interface StandardPVField { /** * Create a PVStructure with a structureArray value field. * + * @param properties Some combination of alarm,timeStamp * @param properties the list of additional properties, which is some * combination of the strings alarm and timeStamp * separated by commas @@ -45,7 +46,7 @@ public interface StandardPVField { /** * Create a PVStructure with an enumerated value field - * + * * @param choices the array of choices. * @return the PVStructure with field value and choices field containing * the supplied choices @@ -54,7 +55,7 @@ public interface StandardPVField { /** * Create a PVStructure with an enumerated value field - * + * * @param choices the array of choices. * @param properties the list of additional properties, which is some * combination of the strings alarm and timeStamp diff --git a/pvDataJava/src/org/epics/pvdata/pv/package.html b/pvDataJava/src/org/epics/pvdata/pv/package.html index 352f35e33..7d678e71b 100644 --- a/pvDataJava/src/org/epics/pvdata/pv/package.html +++ b/pvDataJava/src/org/epics/pvdata/pv/package.html @@ -1,18 +1,19 @@ -

This package contains the interface definitions for the Java implementation of pvData.

This package has the enum, interface, and class definitions that define pvData. This -section provides a complete definition of what pvData is and how data is accessed.

+section provides a complete definition of what pvData is and how data is accessed.

This package defines the following:

ScalarType
One of: pvBoolean, pvByte, pvShort, pvInt, pvLong, pvUByte, pvUShort, pvUInt, pvULong, - pvFloat, pvDouble, pvString
+ pvFloat, pvDouble, pvString +
Type
-
One of scalar, union, structure, scalarArray, unionArray, structureArray
-
Introspection Interfaces
+
One of scalar, union, structure, scalarArray, unionArray, structureArray +
+
Introspection Interfaces
Field
@@ -31,7 +32,7 @@
Introspection interface for type structureArray.
-
Data Interfaces
+
Data Interfaces
PVField
@@ -64,7 +65,6 @@
PVString
Data interface for scalar of type pvString.
-
PVUnion
Data interface for type pvUnion.
PVStructure
@@ -105,6 +105,7 @@
+

diff --git a/pvDataJava/test/org/epics/pvdata/NumberFormatTest.java b/pvDataJava/test/org/epics/pvdata/NumberFormatTest.java new file mode 100644 index 000000000..20e0c6432 --- /dev/null +++ b/pvDataJava/test/org/epics/pvdata/NumberFormatTest.java @@ -0,0 +1,52 @@ +/* + * Copyright information and license terms for this software can be + * found in the file LICENSE that is included with the distribution + */ +package org.epics.pvdata; + +import java.text.FieldPosition; +import java.text.NumberFormat; +import java.text.ParsePosition; + +import junit.framework.TestCase; + +/** + * JUnit test for BitSet. + * NOTE not complete. + * @author mse + * + */ +public class NumberFormatTest extends TestCase { + + public void testNumberFormat() { + NumberFormat nf = new NumberFormatDouble("%12.2f"); + StringBuffer sb = new StringBuffer(); + FieldPosition fp = new FieldPosition(0); + sb = nf.format(1.12, sb, fp); + System.out.println(sb.toString()); + ParsePosition pp = new ParsePosition(0); + double xxx = (nf.parse(sb.toString(),pp)).doubleValue(); + System.out.println("parse is "+ xxx); + } + + static class NumberFormatDouble extends NumberFormat { + private static final long serialVersionUID = -609491739577318372L; + private final String format; + + private NumberFormatDouble (String format) { + this.format = format; + } + @Override + public StringBuffer format(double arg0, StringBuffer arg1,FieldPosition arg2) { + return arg1.append(String.format(format, arg0)); + } + @Override + public StringBuffer format(long arg0, StringBuffer arg1,FieldPosition arg2) { + throw new IllegalArgumentException("long not supported"); + } + @Override + public Number parse(String arg0, ParsePosition arg1) { + return Double.parseDouble(arg0.substring(arg1.getIndex())); + } + } +} diff --git a/pvDataJava/test/org/epics/pvdata/NumericArrayTest.java b/pvDataJava/test/org/epics/pvdata/NumericArrayTest.java new file mode 100644 index 000000000..f703db3e1 --- /dev/null +++ b/pvDataJava/test/org/epics/pvdata/NumericArrayTest.java @@ -0,0 +1,150 @@ +/* + * Copyright information and license terms for this software can be + * found in the file LICENSE that is included with the distribution + */ +package org.epics.pvdata; + + +import junit.framework.TestCase; + +import org.epics.pvdata.factory.PVDataFactory; +import org.epics.pvdata.pv.PVByteArray; +import org.epics.pvdata.pv.PVDataCreate; +import org.epics.pvdata.pv.PVDoubleArray; +import org.epics.pvdata.pv.PVFloatArray; +import org.epics.pvdata.pv.PVIntArray; +import org.epics.pvdata.pv.PVLongArray; +import org.epics.pvdata.pv.PVNumberArray; +import org.epics.pvdata.pv.PVShortArray; +import org.epics.pvdata.pv.PVUByteArray; +import org.epics.pvdata.pv.PVUIntArray; +import org.epics.pvdata.pv.PVULongArray; +import org.epics.pvdata.pv.PVUShortArray; +import org.epics.pvdata.pv.ScalarType; +import org.epics.util.array.ArrayByte; +import org.epics.util.array.ArrayDouble; +import org.epics.util.array.ArrayFloat; +import org.epics.util.array.ArrayInteger; +import org.epics.util.array.ArrayLong; +import org.epics.util.array.ArrayShort; +import org.epics.util.array.ArrayUByte; +import org.epics.util.array.ArrayUInteger; +import org.epics.util.array.ArrayULong; +import org.epics.util.array.ArrayUShort; +import org.epics.util.array.CollectionNumbers; +import org.epics.util.array.ListNumber; +import static org.junit.Assert.*; +import static org.hamcrest.Matchers.*; + +public class NumericArrayTest extends TestCase { + + public void testPutDoubleArray1() { + PVDataCreate factory = PVDataFactory.getPVDataCreate(); + PVDoubleArray pvArray = (PVDoubleArray) factory.createPVScalarArray(ScalarType.pvDouble); + assertThat(pvArray.get(), instanceOf(ArrayDouble.class)); + pvArray.put(0, CollectionNumbers.toListDouble(0,1,2,3,4,5,6,7,8,9)); + assertThat(pvArray.get(), equalTo(CollectionNumbers.toListDouble(0,1,2,3,4,5,6,7,8,9))); + pvArray.put(2, CollectionNumbers.toListFloat(3,2)); + assertThat(pvArray.get(), equalTo(CollectionNumbers.toListDouble(0,1,3,2,4,5,6,7,8,9))); + } + + public void testPutFloatArray1() { + PVDataCreate factory = PVDataFactory.getPVDataCreate(); + PVFloatArray pvArray = (PVFloatArray) factory.createPVScalarArray(ScalarType.pvFloat); + assertThat(pvArray.get(), instanceOf(ArrayFloat.class)); + pvArray.put(0, CollectionNumbers.toListFloat(0,1,2,3,4,5,6,7,8,9)); + assertThat(pvArray.get(), equalTo(CollectionNumbers.toListFloat(0,1,2,3,4,5,6,7,8,9))); + pvArray.put(2, CollectionNumbers.toListDouble(3,2)); + assertThat(pvArray.get(), equalTo(CollectionNumbers.toListFloat(0,1,3,2,4,5,6,7,8,9))); + } + + public void testPutLongArray1() { + PVDataCreate factory = PVDataFactory.getPVDataCreate(); + PVLongArray pvArray = (PVLongArray) factory.createPVScalarArray(ScalarType.pvLong); + assertThat(pvArray.get(), instanceOf(ArrayLong.class)); + pvArray.put(0, CollectionNumbers.toListLong(0,1,2,3,4,5,6,7,8,9)); + assertThat(pvArray.get(), equalTo(CollectionNumbers.toListLong(0,1,2,3,4,5,6,7,8,9))); + pvArray.put(2, CollectionNumbers.toListInt(3,2)); + assertThat(pvArray.get(), equalTo(CollectionNumbers.toListLong(0,1,3,2,4,5,6,7,8,9))); + } + + public void testPutULongArray1() { + PVDataCreate factory = PVDataFactory.getPVDataCreate(); + PVULongArray pvArray = (PVULongArray) factory.createPVScalarArray(ScalarType.pvULong); + assertThat(pvArray.get(), instanceOf(ArrayULong.class)); + pvArray.put(0, CollectionNumbers.toListULong(0,1,2,3,4,5,6,7,8,9)); + assertThat(pvArray.get(), equalTo(CollectionNumbers.toListULong(0,1,2,3,4,5,6,7,8,9))); + pvArray.put(2, CollectionNumbers.toListInt(3,2)); + assertThat(pvArray.get(), equalTo(CollectionNumbers.toListULong(0,1,3,2,4,5,6,7,8,9))); + } + + public void testPutIntArray1() { + PVDataCreate factory = PVDataFactory.getPVDataCreate(); + PVIntArray pvArray = (PVIntArray) factory.createPVScalarArray(ScalarType.pvInt); + assertThat(pvArray.get(), instanceOf(ArrayInteger.class)); + pvArray.put(0, CollectionNumbers.toListInt(0,1,2,3,4,5,6,7,8,9)); + assertThat(pvArray.get(), equalTo(CollectionNumbers.toListInt(0,1,2,3,4,5,6,7,8,9))); + pvArray.put(2, CollectionNumbers.toListLong(3,2)); + assertThat(pvArray.get(), equalTo(CollectionNumbers.toListInt(0,1,3,2,4,5,6,7,8,9))); + } + + public void testPutUIntArray1() { + PVDataCreate factory = PVDataFactory.getPVDataCreate(); + PVUIntArray pvArray = (PVUIntArray) factory.createPVScalarArray(ScalarType.pvUInt); + assertThat(pvArray.get(), instanceOf(ArrayUInteger.class)); + pvArray.put(0, CollectionNumbers.toListUInt(0,1,2,3,4,5,6,7,8,9)); + assertThat(pvArray.get(), equalTo(CollectionNumbers.toListUInt(0,1,2,3,4,5,6,7,8,9))); + pvArray.put(2, CollectionNumbers.toListLong(3,2)); + assertThat(pvArray.get(), equalTo(CollectionNumbers.toListUInt(0,1,3,2,4,5,6,7,8,9))); + } + + public void testPutShortArray1() { + PVDataCreate factory = PVDataFactory.getPVDataCreate(); + PVShortArray pvArray = (PVShortArray) factory.createPVScalarArray(ScalarType.pvShort); + assertThat(pvArray.get(), instanceOf(ArrayShort.class)); + pvArray.put(0, CollectionNumbers.toListShort(new short[] {0,1,2,3,4,5,6,7,8,9})); + assertThat(pvArray.get(), equalTo(CollectionNumbers.toListShort(new short[] {0,1,2,3,4,5,6,7,8,9}))); + pvArray.put(2, CollectionNumbers.toListInt(3,2)); + assertThat(pvArray.get(), equalTo(CollectionNumbers.toListShort(new short[] {0,1,3,2,4,5,6,7,8,9}))); + } + + public void testPutUShortArray1() { + PVDataCreate factory = PVDataFactory.getPVDataCreate(); + PVUShortArray pvArray = (PVUShortArray) factory.createPVScalarArray(ScalarType.pvUShort); + assertThat(pvArray.get(), instanceOf(ArrayUShort.class)); + pvArray.put(0, CollectionNumbers.toListUShort(new short[] {0,1,2,3,4,5,6,7,8,9})); + assertThat(pvArray.get(), equalTo(CollectionNumbers.toListUShort(new short[] {0,1,2,3,4,5,6,7,8,9}))); + pvArray.put(2, CollectionNumbers.toListInt(3,2)); + assertThat(pvArray.get(), equalTo(CollectionNumbers.toListUShort(new short[] {0,1,3,2,4,5,6,7,8,9}))); + } + + public void testPutByteArray1() { + PVDataCreate factory = PVDataFactory.getPVDataCreate(); + PVByteArray pvArray = (PVByteArray) factory.createPVScalarArray(ScalarType.pvByte); + assertThat(pvArray.get(), instanceOf(ArrayByte.class)); + pvArray.put(0, CollectionNumbers.toListByte(new byte[] {0,1,2,3,4,5,6,7,8,9})); + assertThat(pvArray.get(), equalTo(CollectionNumbers.toListByte(new byte[] {0,1,2,3,4,5,6,7,8,9}))); + pvArray.put(2, CollectionNumbers.toListInt(3,2)); + assertThat(pvArray.get(), equalTo(CollectionNumbers.toListByte(new byte[] {0,1,3,2,4,5,6,7,8,9}))); + } + + public void testPutUByteArray1() { + PVDataCreate factory = PVDataFactory.getPVDataCreate(); + PVUByteArray pvArray = (PVUByteArray) factory.createPVScalarArray(ScalarType.pvUByte); + assertThat(pvArray.get(), instanceOf(ArrayUByte.class)); + pvArray.put(0, CollectionNumbers.toListUByte(new byte[] {0,1,2,3,4,5,6,7,8,9})); + assertThat(pvArray.get(), equalTo(CollectionNumbers.toListUByte(new byte[] {0,1,2,3,4,5,6,7,8,9}))); + pvArray.put(2, CollectionNumbers.toListInt(3,2)); + assertThat(pvArray.get(), equalTo(CollectionNumbers.toListUByte(new byte[] {0,1,3,2,4,5,6,7,8,9}))); + } + + public void testPutNumericArray1() { + PVDataCreate factory = PVDataFactory.getPVDataCreate(); + PVNumberArray pvArray = (PVNumberArray) factory.createPVScalarArray(ScalarType.pvInt); + assertThat(pvArray.get(), instanceOf(ArrayInteger.class)); + pvArray.put(0, CollectionNumbers.toListInt(0,1,2,3,4,5,6,7,8,9)); + assertThat(pvArray.get(), equalTo((ListNumber) CollectionNumbers.toListInt(0,1,2,3,4,5,6,7,8,9))); + pvArray.put(2, CollectionNumbers.toListInt(3,2)); + assertThat(pvArray.get(), equalTo((ListNumber) CollectionNumbers.toListInt(0,1,3,2,4,5,6,7,8,9))); + } +}