doublearrayproperty.java

来自「JAVA 数学程序库 提供常规的数值计算程序包」· Java 代码 · 共 71 行

JAVA
71
字号
package jmathlib.core.graphics.properties;


import java.text.DecimalFormat;
import jmathlib.core.graphics.*;

public class DoubleArrayProperty extends Property
{
	private int maxCount;
	private double[][] array;

	public DoubleArrayProperty(PropertySet parent, String name, double[][] value, int maxCount)
	{
		super(parent, name);
		this.array = value;
		this.maxCount = maxCount;
	}

	public Object get()
	{
		return getArray();
	}

	public void set(Object value) throws PropertyException
	{
		try
		{
			double[][] v = (value == null ? new double[0][0] : (double[][])value);
			if (maxCount != -1 && v.length != maxCount)
				throw new PropertyException("incorrect array length - " + value.toString());
			setArrayInternal(v);
		}
		catch (ClassCastException e)
		{
			throw new PropertyException("invalid array value - " + value.toString());
		}
	}

	public double[][] getArray()
	{
		return array;
	}

	public void setArray(double[][] a)
	{
		try { set(a); }
		catch (PropertyException e) { }
	}

	private void setArrayInternal(double[][] v)
	{
		array = v;
		valueChanged();
	}

	public String toString()
	{
		if (array.length > 4)
			return ("[ 1 x " + array.length + " array ]");
		else
		{
			String s = "[ ";
			DecimalFormat fmt = new DecimalFormat("0.0000 ");
			for (int i=0; i<array.length; i++)
				s += fmt.format(array[i]);
			s += "]";
			return s;
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?