Unverified Commit 405c77d1 authored by Kay Kasemir's avatar Kay Kasemir Committed by GitHub
Browse files

Merge pull request #2149 from ControlSystemStudio/pva_cvt_2145

PVA: Allow setting all array types from double[]
parents fb023c8d 97cbe31b
Pipeline #106862 passed with stage
in 11 minutes and 33 seconds
/*******************************************************************************
* Copyright (c) 2022 Oak Ridge National Laboratory.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
******************************************************************************/
package org.epics.pva.data;
/** Array converters
* @author Kay Kasemir
*/
public class Convert
{
public static float[] toFloat(final double[] array)
{
final float[] cvt = new float[array.length];
for (int i=0; i<cvt.length; ++i)
cvt[i] = (float) array[i];
return cvt;
}
public static long[] toLong(final double[] array)
{
final long[] cvt = new long[array.length];
for (int i=0; i<cvt.length; ++i)
cvt[i] = (long) array[i];
return cvt;
}
public static int[] toInt(final double[] array)
{
final int[] cvt = new int[array.length];
for (int i=0; i<cvt.length; ++i)
cvt[i] = (int) array[i];
return cvt;
}
public static short[] toShort(final double[] array)
{
final short[] cvt = new short[array.length];
for (int i=0; i<cvt.length; ++i)
cvt[i] = (short) array[i];
return cvt;
}
public static byte[] toByte(final double[] array)
{
final byte[] cvt = new byte[array.length];
for (int i=0; i<cvt.length; ++i)
cvt[i] = (byte) array[i];
return cvt;
}
}
/*******************************************************************************
* Copyright (c) 2019-2020 Oak Ridge National Laboratory.
* Copyright (c) 2019-2022 Oak Ridge National Laboratory.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
......@@ -61,6 +61,10 @@ public class PVAByteArray extends PVAData implements PVAArray
final byte[] other = ((PVAByteArray) new_value).value;
value = Arrays.copyOf(other, other.length);
}
else if (new_value instanceof PVADoubleArray)
set(Convert.toByte(((PVADoubleArray) new_value).get()));
else if (new_value instanceof double[])
set(Convert.toByte((double[]) new_value));
else if (new_value instanceof byte[])
set(((byte[]) new_value));
else if (new_value instanceof List)
......
/*******************************************************************************
* Copyright (c) 2019 Oak Ridge National Laboratory.
* Copyright (c) 2019-2022 Oak Ridge National Laboratory.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
......@@ -41,6 +41,10 @@ public abstract class PVAData
* This method allows setting the value from
* generic {@link Object}.
*
* <p>Not all types are supported,
* but the matching type as well as double and String
* generally are.
*
* @param new_value New value for this data item
* @throws Exception on error, including incompatible data type
*/
......
/*******************************************************************************
* Copyright (c) 2019-2020 Oak Ridge National Laboratory.
* Copyright (c) 2019-2022 Oak Ridge National Laboratory.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
......@@ -49,9 +49,13 @@ public class PVAFloatArray extends PVAData implements PVAArray
{
if (new_value instanceof PVAFloatArray)
{
final float[] other = ((PVAFloatArray) new_value).value;
final float[] other = ((PVAFloatArray) new_value).get();
value = Arrays.copyOf(other, other.length);
}
else if (new_value instanceof PVADoubleArray)
set(Convert.toFloat(((PVADoubleArray) new_value).get()));
else if (new_value instanceof double[])
set(Convert.toFloat((double[]) new_value));
else if (new_value instanceof float[])
set(((float[]) new_value));
else if (new_value instanceof List)
......
/*******************************************************************************
* Copyright (c) 2019-2020 Oak Ridge National Laboratory.
* Copyright (c) 2019-2022 Oak Ridge National Laboratory.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
......@@ -61,6 +61,10 @@ public class PVAIntArray extends PVAData implements PVAArray
final int[] other = ((PVAIntArray) new_value).value;
value = Arrays.copyOf(other, other.length);
}
else if (new_value instanceof PVADoubleArray)
set(Convert.toInt(((PVADoubleArray) new_value).get()));
else if (new_value instanceof double[])
set(Convert.toInt((double[]) new_value));
else if (new_value instanceof int[])
set(((int[]) new_value));
else if (new_value instanceof List)
......
/*******************************************************************************
* Copyright (c) 2019-2020 Oak Ridge National Laboratory.
* Copyright (c) 2019-2022 Oak Ridge National Laboratory.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
......@@ -61,6 +61,10 @@ public class PVALongArray extends PVAData implements PVAArray
final long[] other = ((PVALongArray) new_value).value;
value = Arrays.copyOf(other, other.length);
}
else if (new_value instanceof PVADoubleArray)
set(Convert.toLong(((PVADoubleArray) new_value).get()));
else if (new_value instanceof double[])
set(Convert.toLong((double[]) new_value));
else if (new_value instanceof long[])
set(((long[]) new_value));
else if (new_value instanceof List)
......
/*******************************************************************************
* Copyright (c) 2019-2020 Oak Ridge National Laboratory.
* Copyright (c) 2019-2022 Oak Ridge National Laboratory.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
......@@ -61,6 +61,10 @@ public class PVAShortArray extends PVAData implements PVAArray
final short[] other = ((PVAShortArray) new_value).value;
value = Arrays.copyOf(other, other.length);
}
else if (new_value instanceof PVADoubleArray)
set(Convert.toShort(((PVADoubleArray) new_value).get()));
else if (new_value instanceof double[])
set(Convert.toShort((double[]) new_value));
else if (new_value instanceof short[])
set(((short[]) new_value));
else if (new_value instanceof List)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment