mirror of
https://github.com/meteoinfo/MeteoInfo.git
synced 2025-12-08 20:36:05 +00:00
update array's astype function
This commit is contained in:
parent
4de1cef0ac
commit
ee78df31cc
@ -1624,31 +1624,27 @@ public class Axis extends Artist implements Cloneable {
|
|||||||
}
|
}
|
||||||
//Time label - left
|
//Time label - left
|
||||||
if (this.drawTickLabel) {
|
if (this.drawTickLabel) {
|
||||||
DateTimeFormatter format;
|
|
||||||
if (this instanceof TimeAxis) {
|
if (this instanceof TimeAxis) {
|
||||||
TimeAxis tAxis = (TimeAxis) this;
|
TimeAxis tAxis = (TimeAxis) this;
|
||||||
if (tAxis.isVarFormat()) {
|
if (tAxis.isVarFormat()) {
|
||||||
drawStr = null;
|
int idx = this.inverse ? this.getTickValues().length - 1 : 0;
|
||||||
|
LocalDateTime cDate = JDateUtil.fromOADate(this.getTickValues()[idx]);
|
||||||
|
DateTimeFormatter format = null;
|
||||||
switch (tAxis.getTimeUnit()) {
|
switch (tAxis.getTimeUnit()) {
|
||||||
case MONTH:
|
case MONTH:
|
||||||
format = DateTimeFormatter.ofPattern("yyyy");
|
format = DateTimeFormatter.ofPattern("yyyy");
|
||||||
LocalDateTime cdate = JDateUtil.fromOADate(this.getTickValues()[0]);
|
|
||||||
drawStr = format.format(cdate);
|
|
||||||
break;
|
break;
|
||||||
case DAY:
|
case DAY:
|
||||||
format = DateTimeFormatter.ofPattern("yyyy-MM");
|
format = DateTimeFormatter.ofPattern("yyyy-MM");
|
||||||
cdate = JDateUtil.fromOADate(this.getTickValues()[0]);
|
|
||||||
drawStr = format.format(cdate);
|
|
||||||
break;
|
break;
|
||||||
case HOUR:
|
case HOUR:
|
||||||
case MINUTE:
|
case MINUTE:
|
||||||
case SECOND:
|
case SECOND:
|
||||||
format = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
format = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||||
cdate = JDateUtil.fromOADate(this.getTickValues()[0]);
|
|
||||||
drawStr = format.format(cdate);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (drawStr != null) {
|
if (format != null) {
|
||||||
|
drawStr = format.format(cDate);
|
||||||
labx = (float) minx;
|
labx = (float) minx;
|
||||||
laby = laby + this.tickSpace;
|
laby = laby + this.tickSpace;
|
||||||
Draw.drawString(g, labx, laby, drawStr, XAlign.LEFT, YAlign.TOP, true);
|
Draw.drawString(g, labx, laby, drawStr, XAlign.LEFT, YAlign.TOP, true);
|
||||||
|
|||||||
@ -1,14 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<MeteoInfo File="milconfig.xml" Type="configurefile">
|
<MeteoInfo File="milconfig.xml" Type="configurefile">
|
||||||
<Path OpenPath="D:\Working\MIScript\Jython\mis\plot_types\contour">
|
<Path OpenPath="D:\Working\MIScript\Jython\mis\traj">
|
||||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\chart\axis"/>
|
|
||||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map\topology"/>
|
|
||||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo\eof"/>
|
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo\eof"/>
|
||||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo\calc"/>
|
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo\calc"/>
|
||||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo"/>
|
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo"/>
|
||||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math"/>
|
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math"/>
|
||||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\stats"/>
|
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\stats"/>
|
||||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
|
|
||||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\chart"/>
|
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\chart"/>
|
||||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\chart\subplot"/>
|
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\chart\subplot"/>
|
||||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\scatter"/>
|
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\scatter"/>
|
||||||
@ -16,17 +13,20 @@
|
|||||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map\projection"/>
|
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map\projection"/>
|
||||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
|
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
|
||||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\contour"/>
|
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\contour"/>
|
||||||
|
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\array"/>
|
||||||
|
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
|
||||||
|
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\traj"/>
|
||||||
</Path>
|
</Path>
|
||||||
<File>
|
<File>
|
||||||
<OpenedFiles>
|
<OpenedFiles>
|
||||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\plot\plot_cdata_3.py"/>
|
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\plot\plot_cdata_3.py"/>
|
||||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\contour\conout_negtive_value.py"/>
|
<OpenedFile File="D:\Working\MIScript\Jython\mis\array\astype_1.py"/>
|
||||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\contour\conoutm_clabel_1.py"/>
|
<OpenedFile File="D:\Working\MIScript\Jython\mis\traj\plot_traj_bd.py"/>
|
||||||
</OpenedFiles>
|
</OpenedFiles>
|
||||||
<RecentFiles>
|
<RecentFiles>
|
||||||
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\plot\plot_cdata_3.py"/>
|
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\plot\plot_cdata_3.py"/>
|
||||||
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\contour\conout_negtive_value.py"/>
|
<RecentFile File="D:\Working\MIScript\Jython\mis\array\astype_1.py"/>
|
||||||
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\contour\conoutm_clabel_1.py"/>
|
<RecentFile File="D:\Working\MIScript\Jython\mis\traj\plot_traj_bd.py"/>
|
||||||
</RecentFiles>
|
</RecentFiles>
|
||||||
</File>
|
</File>
|
||||||
<Font>
|
<Font>
|
||||||
|
|||||||
Binary file not shown.
@ -7,16 +7,25 @@ __all__ = [
|
|||||||
|
|
||||||
_dtype_dict = dict(byte = JDataType.BYTE,
|
_dtype_dict = dict(byte = JDataType.BYTE,
|
||||||
char = JDataType.CHAR,
|
char = JDataType.CHAR,
|
||||||
|
bool = JDataType.BOOLEAN,
|
||||||
boolean = JDataType.BOOLEAN,
|
boolean = JDataType.BOOLEAN,
|
||||||
int = JDataType.INT,
|
int = JDataType.INT,
|
||||||
|
int32 = JDataType.INT,
|
||||||
|
integer = JDataType.INT,
|
||||||
uint = JDataType.UINT,
|
uint = JDataType.UINT,
|
||||||
short = JDataType.SHORT,
|
short = JDataType.SHORT,
|
||||||
|
int16 = JDataType.SHORT,
|
||||||
long = JDataType.LONG,
|
long = JDataType.LONG,
|
||||||
|
int64 = JDataType.LONG,
|
||||||
float = JDataType.FLOAT,
|
float = JDataType.FLOAT,
|
||||||
|
float32 = JDataType.FLOAT,
|
||||||
double = JDataType.DOUBLE,
|
double = JDataType.DOUBLE,
|
||||||
|
float64 = JDataType.DOUBLE,
|
||||||
|
str = JDataType.STRING,
|
||||||
string = JDataType.STRING,
|
string = JDataType.STRING,
|
||||||
complex = JDataType.COMPLEX,
|
complex = JDataType.COMPLEX,
|
||||||
date = JDataType.DATE,
|
date = JDataType.DATE,
|
||||||
|
datetime = JDataType.DATE,
|
||||||
object = JDataType.OBJECT)
|
object = JDataType.OBJECT)
|
||||||
|
|
||||||
class DataType(object):
|
class DataType(object):
|
||||||
|
|||||||
@ -717,17 +717,18 @@ class NDArray(object):
|
|||||||
if self.dtype == dtype:
|
if self.dtype == dtype:
|
||||||
return self.copy()
|
return self.copy()
|
||||||
|
|
||||||
if dtype.kind == 'i':
|
# if dtype.kind == 'i':
|
||||||
r = NDArray(ArrayUtil.toInteger(self._array))
|
# r = NDArray(ArrayUtil.toInteger(self._array))
|
||||||
elif dtype.kind == 'f':
|
# elif dtype.kind == 'f':
|
||||||
if dtype.name == 'float':
|
# if dtype.name == 'float':
|
||||||
r = NDArray(ArrayUtil.toFloat(self._array))
|
# r = NDArray(ArrayUtil.toFloat(self._array))
|
||||||
else:
|
# else:
|
||||||
r = NDArray(ArrayUtil.toDouble(self._array))
|
# r = NDArray(ArrayUtil.toDouble(self._array))
|
||||||
elif dtype.kind == 'b':
|
# elif dtype.kind == 'b':
|
||||||
r = NDArray(ArrayUtil.toBoolean(self._array))
|
# r = NDArray(ArrayUtil.toBoolean(self._array))
|
||||||
else:
|
# else:
|
||||||
r = self
|
# r = self
|
||||||
|
r = NDArray(ArrayUtil.convertToDataType(self._array, dtype._dtype))
|
||||||
return r
|
return r
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
@ -32,6 +32,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.meteoinfo.ndarray;
|
package org.meteoinfo.ndarray;
|
||||||
|
|
||||||
|
import org.meteoinfo.common.util.JDateUtil;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.DoubleBuffer;
|
import java.nio.DoubleBuffer;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@ -266,9 +268,13 @@ public class ArrayDouble extends Array {
|
|||||||
throw new ForbiddenConversionException();
|
throw new ForbiddenConversionException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalDateTime getDate(Index i) { throw new ForbiddenConversionException(); }
|
public LocalDateTime getDate(Index i) {
|
||||||
|
return JDateUtil.fromOADate(storageD[i.currentElement()]);
|
||||||
|
}
|
||||||
|
|
||||||
public void setDate(Index i, LocalDateTime value) { throw new ForbiddenConversionException(); }
|
public void setDate(Index i, LocalDateTime value) {
|
||||||
|
storageD[i.currentElement()] = JDateUtil.toOADate(value);
|
||||||
|
}
|
||||||
|
|
||||||
public Object getObject(Index i) {
|
public Object getObject(Index i) {
|
||||||
return storageD[i.currentElement()];
|
return storageD[i.currentElement()];
|
||||||
@ -363,9 +369,13 @@ public class ArrayDouble extends Array {
|
|||||||
throw new ForbiddenConversionException();
|
throw new ForbiddenConversionException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalDateTime getDate(int index) { throw new ForbiddenConversionException(); }
|
public LocalDateTime getDate(int index) {
|
||||||
|
return JDateUtil.fromOADate(storageD[index]);
|
||||||
|
}
|
||||||
|
|
||||||
public void setDate(int index, LocalDateTime value) { throw new ForbiddenConversionException(); }
|
public void setDate(int index, LocalDateTime value) {
|
||||||
|
storageD[index] = JDateUtil.toOADate(value);
|
||||||
|
}
|
||||||
|
|
||||||
public Object getObject(int index) {
|
public Object getObject(int index) {
|
||||||
return getDouble(index);
|
return getDouble(index);
|
||||||
|
|||||||
@ -191,122 +191,122 @@ public class ArrayString extends Array {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set the value at the sepcified index.
|
* set the value at the specified index.
|
||||||
*/
|
*/
|
||||||
public void set(Index i, String value) {
|
public void set(Index i, String value) {
|
||||||
storage[i.currentElement()] = value;
|
storage[i.currentElement()] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* not legal, throw ForbiddenConversionException
|
* get the double value at the specified index.
|
||||||
*/
|
*/
|
||||||
public double getDouble(Index i) {
|
public double getDouble(Index i) {
|
||||||
throw new ForbiddenConversionException();
|
return Double.parseDouble(storage[i.currentElement()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* not legal, throw ForbiddenConversionException
|
* set the value at the specified index.
|
||||||
*/
|
*/
|
||||||
public void setDouble(Index i, double value) {
|
public void setDouble(Index i, double value) {
|
||||||
throw new ForbiddenConversionException();
|
storage[i.currentElement()] = String.valueOf(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* not legal, throw ForbiddenConversionException
|
* get the float value at the specified index.
|
||||||
*/
|
*/
|
||||||
public float getFloat(Index i) {
|
public float getFloat(Index i) {
|
||||||
throw new ForbiddenConversionException();
|
return Float.parseFloat(storage[i.currentElement()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* not legal, throw ForbiddenConversionException
|
* set the value at the specified index.
|
||||||
*/
|
*/
|
||||||
public void setFloat(Index i, float value) {
|
public void setFloat(Index i, float value) {
|
||||||
throw new ForbiddenConversionException();
|
storage[i.currentElement()] = String.valueOf(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* not legal, throw ForbiddenConversionException
|
* get the long value at the specified index.
|
||||||
*/
|
*/
|
||||||
public long getLong(Index i) {
|
public long getLong(Index i) {
|
||||||
throw new ForbiddenConversionException();
|
return Long.parseLong(storage[i.currentElement()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* not legal, throw ForbiddenConversionException
|
* set the value at the specified index.
|
||||||
*/
|
*/
|
||||||
public void setLong(Index i, long value) {
|
public void setLong(Index i, long value) {
|
||||||
throw new ForbiddenConversionException();
|
storage[i.currentElement()] = String.valueOf(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* not legal, throw ForbiddenConversionException
|
* get the integer value at the specified index.
|
||||||
*/
|
*/
|
||||||
public int getInt(Index i) {
|
public int getInt(Index i) {
|
||||||
throw new ForbiddenConversionException();
|
return Integer.parseInt(storage[i.currentElement()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* not legal, throw ForbiddenConversionException
|
* set the value at the specified index.
|
||||||
*/
|
*/
|
||||||
public void setInt(Index i, int value) {
|
public void setInt(Index i, int value) {
|
||||||
throw new ForbiddenConversionException();
|
storage[i.currentElement()] = String.valueOf(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* not legal, throw ForbiddenConversionException
|
* get the short value at the specified index.
|
||||||
*/
|
*/
|
||||||
public short getShort(Index i) {
|
public short getShort(Index i) {
|
||||||
throw new ForbiddenConversionException();
|
return Short.parseShort(storage[i.currentElement()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* not legal, throw ForbiddenConversionException
|
* set the value at the specified index.
|
||||||
*/
|
*/
|
||||||
public void setShort(Index i, short value) {
|
public void setShort(Index i, short value) {
|
||||||
throw new ForbiddenConversionException();
|
storage[i.currentElement()] = String.valueOf(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* not legal, throw ForbiddenConversionException
|
* get the byte value at the specified index.
|
||||||
*/
|
*/
|
||||||
public byte getByte(Index i) {
|
public byte getByte(Index i) {
|
||||||
throw new ForbiddenConversionException();
|
return Byte.parseByte(storage[i.currentElement()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* not legal, throw ForbiddenConversionException
|
* set the value at the specified index.
|
||||||
*/
|
*/
|
||||||
public void setByte(Index i, byte value) {
|
public void setByte(Index i, byte value) {
|
||||||
throw new ForbiddenConversionException();
|
storage[i.currentElement()] = String.valueOf(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* not legal, throw ForbiddenConversionException
|
* get the boolean value at the specified index.
|
||||||
*/
|
*/
|
||||||
public boolean getBoolean(Index i) {
|
public boolean getBoolean(Index i) {
|
||||||
throw new ForbiddenConversionException();
|
return Boolean.parseBoolean(storage[i.currentElement()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* not legal, throw ForbiddenConversionException
|
* set the value at the specified index.
|
||||||
*/
|
*/
|
||||||
public void setBoolean(Index i, boolean value) {
|
public void setBoolean(Index i, boolean value) {
|
||||||
throw new ForbiddenConversionException();
|
storage[i.currentElement()] = String.valueOf(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* not legal, throw ForbiddenConversionException
|
* get the char value at the specified index.
|
||||||
*/
|
*/
|
||||||
public char getChar(Index i) {
|
public char getChar(Index i) {
|
||||||
throw new ForbiddenConversionException();
|
return storage[i.currentElement()].charAt(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* not legal, throw ForbiddenConversionException
|
* set the value at the specified index.
|
||||||
*/
|
*/
|
||||||
public void setChar(Index i, char value) {
|
public void setChar(Index i, char value) {
|
||||||
throw new ForbiddenConversionException();
|
storage[i.currentElement()] = String.valueOf(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getString(Index i) {
|
public String getString(Index i) {
|
||||||
@ -339,67 +339,67 @@ public class ArrayString extends Array {
|
|||||||
|
|
||||||
// package private : mostly for iterators
|
// package private : mostly for iterators
|
||||||
public double getDouble(int index) {
|
public double getDouble(int index) {
|
||||||
throw new ForbiddenConversionException();
|
return Double.parseDouble(storage[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDouble(int index, double value) {
|
public void setDouble(int index, double value) {
|
||||||
throw new ForbiddenConversionException();
|
storage[index] = String.valueOf(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getFloat(int index) {
|
public float getFloat(int index) {
|
||||||
throw new ForbiddenConversionException();
|
return Float.parseFloat(storage[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFloat(int index, float value) {
|
public void setFloat(int index, float value) {
|
||||||
throw new ForbiddenConversionException();
|
storage[index] = String.valueOf(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getLong(int index) {
|
public long getLong(int index) {
|
||||||
throw new ForbiddenConversionException();
|
return Long.parseLong(storage[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLong(int index, long value) {
|
public void setLong(int index, long value) {
|
||||||
throw new ForbiddenConversionException();
|
storage[index] = String.valueOf(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getInt(int index) {
|
public int getInt(int index) {
|
||||||
throw new ForbiddenConversionException();
|
return Integer.parseInt(storage[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInt(int index, int value) {
|
public void setInt(int index, int value) {
|
||||||
throw new ForbiddenConversionException();
|
storage[index] = String.valueOf(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public short getShort(int index) {
|
public short getShort(int index) {
|
||||||
throw new ForbiddenConversionException();
|
return Short.parseShort(storage[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setShort(int index, short value) {
|
public void setShort(int index, short value) {
|
||||||
throw new ForbiddenConversionException();
|
storage[index] = String.valueOf(value);;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte getByte(int index) {
|
public byte getByte(int index) {
|
||||||
throw new ForbiddenConversionException();
|
return Byte.parseByte(storage[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setByte(int index, byte value) {
|
public void setByte(int index, byte value) {
|
||||||
throw new ForbiddenConversionException();
|
storage[index] = String.valueOf(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public char getChar(int index) {
|
public char getChar(int index) {
|
||||||
throw new ForbiddenConversionException();
|
return storage[index].charAt(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setChar(int index, char value) {
|
public void setChar(int index, char value) {
|
||||||
throw new ForbiddenConversionException();
|
storage[index] = String.valueOf(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getBoolean(int index) {
|
public boolean getBoolean(int index) {
|
||||||
throw new ForbiddenConversionException();
|
return Boolean.parseBoolean(storage[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBoolean(int index, boolean value) {
|
public void setBoolean(int index, boolean value) {
|
||||||
throw new ForbiddenConversionException();
|
storage[index] = String.valueOf(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getString(int index) {
|
public String getString(int index) {
|
||||||
@ -411,11 +411,11 @@ public class ArrayString extends Array {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Complex getComplex(int index) {
|
public Complex getComplex(int index) {
|
||||||
throw new ForbiddenConversionException();
|
return Complex.parse(storage[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setComplex(int index, Complex value) {
|
public void setComplex(int index, Complex value) {
|
||||||
throw new ForbiddenConversionException();
|
storage[index] = value.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalDateTime getDate(int index) { throw new ForbiddenConversionException(); }
|
public LocalDateTime getDate(int index) { throw new ForbiddenConversionException(); }
|
||||||
|
|||||||
@ -1900,6 +1900,76 @@ public class ArrayUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert array to another data type
|
||||||
|
* @param a The input array
|
||||||
|
* @param dataType The data type to be converted
|
||||||
|
* @return Converted array
|
||||||
|
*/
|
||||||
|
public static Array convertToDataType(Array a, DataType dataType) {
|
||||||
|
if (a.getDataType() == dataType) {
|
||||||
|
return a;
|
||||||
|
} else {
|
||||||
|
Array r = Array.factory(dataType, a.getShape());
|
||||||
|
IndexIterator iterA = a.getIndexIterator();
|
||||||
|
IndexIterator iterR = r.getIndexIterator();
|
||||||
|
switch (dataType) {
|
||||||
|
case BYTE:
|
||||||
|
while (iterR.hasNext()) {
|
||||||
|
iterR.setByteNext(iterA.getByteNext());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case BOOLEAN:
|
||||||
|
while (iterR.hasNext()) {
|
||||||
|
iterR.setBooleanNext(iterA.getBooleanNext());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SHORT:
|
||||||
|
while (iterR.hasNext()) {
|
||||||
|
iterR.setShortNext(iterA.getShortNext());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case INT:
|
||||||
|
while (iterR.hasNext()) {
|
||||||
|
iterR.setIntNext(iterA.getIntNext());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case LONG:
|
||||||
|
while (iterR.hasNext()) {
|
||||||
|
iterR.setLongNext(iterA.getLongNext());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case FLOAT:
|
||||||
|
while (iterR.hasNext()) {
|
||||||
|
iterR.setFloatNext(iterA.getFloatNext());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case DOUBLE:
|
||||||
|
while (iterR.hasNext()) {
|
||||||
|
iterR.setDoubleNext(iterA.getDoubleNext());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case COMPLEX:
|
||||||
|
while (iterR.hasNext()) {
|
||||||
|
iterR.setComplexNext(iterA.getComplexNext());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case STRING:
|
||||||
|
while (iterR.hasNext()) {
|
||||||
|
iterR.setStringNext(iterA.getStringNext());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case DATE:
|
||||||
|
while (iterR.hasNext()) {
|
||||||
|
iterR.setDateNext(iterA.getDateNext());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert array to integer type
|
* Convert array to integer type
|
||||||
*
|
*
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user