- * Value that needs to be parsed - * @return 解析之后的单位数值对象 - *
- * Parsed Unit Value Object - */ - public static BaseValue parse(double valueNumber) { - return parse(valueNumber, null); - } - - /** - * @param valueNumber 需要被解析的数值 - *
- * Value that needs to be parsed - * @param baseNameKeyValue 单位的键值对,如果您需要指定数值的单位,您可以在这里进行指定,如果您不需要可以直接设置为 null,请注意 如果您不设置为null 此操作将不会对数值进行任何化简. - *
- * The key value pairs of units. If you need to specify the unit of a numerical value, you can specify it here. If you don't need it, you can directly set it to null. Please note that if you don't set it to null, this operation will not simplify the numerical value in any way. - * @return 解析之后的单位数值对象 - *
- * Parsed Unit Value Object
- */
- protected static BaseValue parse(double valueNumber, KeyValue
- * Value that needs to be parsed
- * @return 解析之后的单位数值对象
- *
- * Parsed Unit Value Object
- */
- public static BaseValue parse(double valueNumber) {
- return parse(valueNumber, null);
- }
-
- /**
- * @param valueNumber 需要被解析的数值
- *
- * Value that needs to be parsed
- * @param baseNameKeyValue 单位的键值对,如果您需要指定数值的单位,您可以在这里进行指定,如果您不需要可以直接设置为 null,请注意 如果您不设置为null 此操作将不会对数值进行任何化简.
- *
- * The key value pairs of units. If you need to specify the unit of a numerical value, you can specify it here. If you don't need it, you can directly set it to null. Please note that if you don't set it to null, this operation will not simplify the numerical value in any way.
- * @return 解析之后的单位数值对象
- *
- * Parsed Unit Value Object
- */
- protected static BaseValue parse(double valueNumber, KeyValue
* Annotations for base numerical units. You can set a base numerical unit and the name of each subunit here. Please ensure that the base numerical values between each subunit are a proportional sequence.
*/
@Target(ElementType.TYPE)
@@ -20,10 +20,34 @@
*/
String[] value();
+
/**
* @return 每个相邻子单位之间的进制数值。
*
- * The decimal value between each adjacent subunit.
+ * 如果只设置了一个元素,则这里代表的就是每个相邻的子单位之间的进制差,例如:["米", "分米", "厘米"] 中的每个单位的进制差都是 10 所以您可以在这里直接写 10;
+ *
+ * 如果是多个元素就代表指定位置的子单位距离它下一个单位的禁止差 例如:["h","m","s","ms"] 中 进制差为 [60, 60, 1000, 0] 代表的就是下一个单位与当前单位的倍数
+ *
+ * The decimal value between each adjacent subunit. If only one element is set, it represents the base difference between each adjacent subunit. For example, the base difference for each unit in ["meter", "decimeter", "centimeter"] is 10, so you can directly write 10 here; If there are multiple elements, it represents the forbidden difference between the subunit at the specified position and its next unit. For example, in ["h", "m", "s", "ms"], the decimal difference is [60, 60, 1000, 0], which represents the multiple of the current unit for the next unit
+ */
+ double[] baseValue() default 10;
+
+ /**
+ * @return 在数学中,乘法运算需要注意两个方面:数字和单位。
+ *
+ * 当数字相乘时,可以直接进行乘法运算。例如,2升乘以2升,数字部分是2乘以2,结果是4。
+ *
+ * 当单位相乘时,需要先统一单位,然后再进行乘法运算。例如,2米乘以2米,单位是米,可以直接相乘得到4平方米。但如果单位不同,比如2米乘以2厘米,需要先统一单位,把2厘米转换为米(即0.01米),然后再相乘得到0.04平方米。
+ *
+ * 因此,在进行乘法运算时,需要先判断数字和单位是否一致,如果单位不一致需要先统一单位再进行计算。
+ *
+ * In mathematics, multiplication operations require attention to two aspects: numbers and units.
+ *
+ * When multiplying numbers, multiplication can be performed directly. For example, multiplying 2 liters by 2 liters, the numerical part is 2 times 2, and the result is 4.
+ *
+ * When multiplying units, it is necessary to first unify the units before performing multiplication operations. For example, multiplying 2 meters by 2 meters in meters can directly yield 4 square meters. But if the units are different, such as multiplying 2 meters by 2 centimeters, it is necessary to first unify the units, convert 2 centimeters to meters (i.e. 0.01 meters), and then multiply them to obtain 0.04 square meters.
+ *
+ * Therefore, when performing multiplication operations, it is necessary to first check whether the numbers and units are consistent. If the units are not consistent, it is necessary to first unify the units before calculating.
*/
- double baseValue() default 10;
+ boolean needUnifiedUnit() default true;
}
diff --git a/src_code/src/main/java/zhao/algorithmMagic/operands/unit/BaseUnitObj.java b/src_code/src/main/java/zhao/algorithmMagic/operands/unit/BaseUnitObj.java
index 3259233..f5b5368 100644
--- a/src_code/src/main/java/zhao/algorithmMagic/operands/unit/BaseUnitObj.java
+++ b/src_code/src/main/java/zhao/algorithmMagic/operands/unit/BaseUnitObj.java
@@ -35,7 +35,7 @@ static TempBaseData parse(BaseUnit baseUnit) {
return tempBaseData;
}
final double[] doubles = new double[value.length];
- double number = 1, base = baseUnit.baseValue();
+ double number = 1, base = baseUnit.baseValue()[0];
HashMap
+ * The bit weight of each subunit in the current unit object. Bit weight is iterated in ascending order.
+ * 例如:["h","m","s","ms"] 中 进制差为 [60, 60, 1000, 0] 代表的就是下一个单位举例当前单位的倍数
+ */
+ double[] getBaseDiff();
+
+ /**
+ * 如果需要设置为 true;Set to true if necessary
+ *
+ * @return 在数学中,乘法运算需要注意两个方面:数字和单位。
+ *
+ * 当数字相乘时,可以直接进行乘法运算。例如,2升乘以2升,数字部分是2乘以2,结果是4。
+ *
+ * 当单位相乘时,需要先统一单位,然后再进行乘法运算。例如,2米乘以2米,单位是米,可以直接相乘得到4平方米。但如果单位不同,比如2米乘以2厘米,需要先统一单位,把2厘米转换为米(即0.01米),然后再相乘得到0.04平方米。
+ *
+ * 因此,在进行乘法运算时,需要先判断数字和单位是否一致,如果单位不一致需要先统一单位再进行计算。
+ *
+ * In mathematics, multiplication operations require attention to two aspects: numbers and units.
+ *
+ * When multiplying numbers, multiplication can be performed directly. For example, multiplying 2 liters by 2 liters, the numerical part is 2 times 2, and the result is 4.
+ *
+ * When multiplying units, it is necessary to first unify the units before performing multiplication operations. For example, multiplying 2 meters by 2 meters in meters can directly yield 4 square meters. But if the units are different, such as multiplying 2 meters by 2 centimeters, it is necessary to first unify the units, convert 2 centimeters to meters (i.e. 0.01 meters), and then multiply them to obtain 0.04 square meters.
+ *
+ * Therefore, when performing multiplication operations, it is necessary to first check whether the numbers and units are consistent. If the units are not consistent, it is necessary to first unify the units before calculating.
+ */
+ boolean isNeedUnifiedUnit();
+
/**
* 位权单位元数据存储类
*/
final class TempBaseData {
private final HashMap
+ * Value that needs to be parsed
+ * @param baseValueFactoryClass 单位数值构造工厂类
+ *
+ * Unit Value Construction Factory Class
* @return 解析之后的单位数值对象
*
* Parsed Unit Value Object
*/
- public static BaseValue parse(double valueNumber) {
- return parse(valueNumber, null);
+ public static BaseValue parse(double valueNumber, BaseValueFactory baseValueFactoryClass) {
+ return parse(valueNumber, null, baseValueFactoryClass);
}
/**
- * @param valueNumber 需要被解析的数值
- *
- * Value that needs to be parsed
- * @param baseNameKeyValue 单位的键值对,如果您需要指定数值的单位,您可以在这里进行指定,如果您不需要可以直接设置为 null,请注意 如果您不设置为null 此操作将不会对数值进行任何化简.
- *
- * The key value pairs of units. If you need to specify the unit of a numerical value, you can specify it here. If you don't need it, you can directly set it to null. Please note that if you don't set it to null, this operation will not simplify the numerical value in any way.
+ * @param valueNumber 需要被解析的数值
+ *
+ * Value that needs to be parsed
+ * @param baseNameKeyValue 单位的键值对,如果您需要指定数值的单位,您可以在这里进行指定,如果您不需要可以直接设置为 null,请注意 如果您不设置为null 此操作将不会对数值进行任何化简.
+ *
+ * The key value pairs of units. If you need to specify the unit of a numerical value, you can specify it here. If you don't need it, you can directly set it to null. Please note that if you don't set it to null, this operation will not simplify the numerical value in any way.
+ * @param baseValueFactoryClass 单位数值构造工厂类
+ *
+ * Unit Value Construction Factory Class
* @return 解析之后的单位数值对象
*
* Parsed Unit Value Object
*/
- protected static BaseValue parse(double valueNumber, KeyValue
+ * The value corresponding to the lowest weighted unit obtained is also the original value, which has not been simplified.
+ */
+ public double getSrcValue() {
+ return srcValue;
}
/**
@@ -196,7 +232,7 @@ public BaseValue divide(BaseValue value) {
* The calculation result will return a new unit value object.
*/
public BaseValue multiply(Number value) {
- return new BaseValue(this.doubleValue() * value.doubleValue(), this.getBaseUnitObj(), this.getNowBase());
+ return new BaseValue(this.doubleValue() * value.doubleValue(), baseValueFactoryClass, this.getBaseUnitObj(), this.getNowBase());
}
/**
@@ -212,7 +248,7 @@ public BaseValue multiply(Number value) {
* The calculation result will return a new unit value object.
*/
public BaseValue divide(Number value) {
- return new BaseValue(this.doubleValue() / value.doubleValue(), this.getBaseUnitObj(), this.getNowBase());
+ return new BaseValue(this.doubleValue() / value.doubleValue(), baseValueFactoryClass, this.getBaseUnitObj(), this.getNowBase());
}
/**
@@ -231,6 +267,19 @@ public BaseValue switchUnits(KeyValue
+ * Do not change the numerical value, only change the unit measurement.
+ *
+ * @param targetUnit 需要被切换到的目标单位
+ *
+ * The target unit that needs to be switched to
+ */
+ public void switchUnitsNotChange(KeyValue
@@ -241,7 +290,7 @@ public BaseValue switchUnits(KeyValue
+ * Whether to unify units
+ */
+ public boolean isNeedUnifiedUnit() {
+ return this.baseUnitObj.isNeedUnifiedUnit();
+ }
+
/**
* @return The string representation of the object.
*/
@@ -329,4 +387,13 @@ public double doubleValue() {
public String toString() {
return this.doubleValue() + this.getNowBase().getValue();
}
+
+ /**
+ * @return 本单位数值对象对应的工厂类
+ *
+ * The factory class corresponding to the numerical object of this unit
+ */
+ public BaseValueFactory getBaseValueFactoryClass() {
+ return baseValueFactoryClass;
+ }
}
diff --git a/src_code/src/main/java/zhao/algorithmMagic/operands/unit/DataValue.java b/src_code/src/main/java/zhao/algorithmMagic/operands/unit/DataValue.java
index 7c8f91e..bcb8658 100644
--- a/src_code/src/main/java/zhao/algorithmMagic/operands/unit/DataValue.java
+++ b/src_code/src/main/java/zhao/algorithmMagic/operands/unit/DataValue.java
@@ -1,45 +1,55 @@
package zhao.algorithmMagic.operands.unit;
+import zhao.algorithmMagic.core.BaseValueFactory;
import zhao.algorithmMagic.utils.dataContainer.KeyValue;
/**
* 数据进制单位,可以实现数据单位相关的计算
- *
+ *
* Data unit, which can achieve calculations related to data units
+ *
* @author zhao
*/
@BaseUnit(value = {
- "YB" ,"ZB" ,"EB" ,"TB", "GB", "MB", "KB", "B"
+ "YB", "ZB", "EB", "TB", "GB", "MB", "KB", "B"
}, baseValue = 1024)
-public class DataValue extends BaseValue{
- public DataValue(double valueNumber, Class extends BaseValue> c, KeyValue
- * Value that needs to be parsed
+ * @param valueNumber 需要被解析的数值
+ *
+ * Value that needs to be parsed
+ * @param baseValueFactoryClass 单位数值构造工厂类
+ *
+ * Unit Value Construction Factory Class
* @return 解析之后的单位数值对象
*
* Parsed Unit Value Object
*/
- public static BaseValue parse(double valueNumber) {
- return parse(valueNumber, null);
+ public static BaseValue parse(double valueNumber, BaseValueFactory baseValueFactoryClass) {
+ return parse(valueNumber, null, baseValueFactoryClass);
}
/**
- * @param valueNumber 需要被解析的数值
- *
- * Value that needs to be parsed
- * @param baseNameKeyValue 单位的键值对,如果您需要指定数值的单位,您可以在这里进行指定,如果您不需要可以直接设置为 null,请注意 如果您不设置为null 此操作将不会对数值进行任何化简.
- *
- * The key value pairs of units. If you need to specify the unit of a numerical value, you can specify it here. If you don't need it, you can directly set it to null. Please note that if you don't set it to null, this operation will not simplify the numerical value in any way.
+ * @param valueNumber 需要被解析的数值
+ *
+ * Value that needs to be parsed
+ * @param baseNameKeyValue 单位的键值对,如果您需要指定数值的单位,您可以在这里进行指定,如果您不需要可以直接设置为 null,请注意 如果您不设置为null 此操作将不会对数值进行任何化简.
+ *
+ * The key value pairs of units. If you need to specify the unit of a numerical value, you can specify it here. If you don't need it, you can directly set it to null. Please note that if you don't set it to null, this operation will not simplify the numerical value in any way.
+ * @param baseValueFactoryClass 单位数值构造工厂类
+ *
+ * Unit Value Construction Factory Class
* @return 解析之后的单位数值对象
*
* Parsed Unit Value Object
*/
- protected static BaseValue parse(double valueNumber, KeyValue
* Time unit numerical class, supporting operations of hours, minutes, and seconds
*/
@BaseUnit(value = {
- "时", "分", "秒"
-}, baseValue = 60)
-public class DateValue extends BaseValue{
+ "天", "时", "分", "秒", "毫秒"
+}, baseValue = {24, 60, 60, 1000, 1})
+public class DateValue extends BaseValue {
- public DateValue(double valueNumber, Class extends BaseValue> c, KeyValue
- * Value that needs to be parsed
+ * @param valueNumber 需要被解析的数值
+ *
+ * Value that needs to be parsed
+ * @param baseValueFactoryClass 单位数值构造工厂类
+ *
+ * Unit Value Construction Factory Class
* @return 解析之后的单位数值对象
*
* Parsed Unit Value Object
*/
- public static BaseValue parse(double valueNumber) {
- return parse(valueNumber, null);
+ public static BaseValue parse(double valueNumber, BaseValueFactory baseValueFactoryClass) {
+ return parse(valueNumber, null, baseValueFactoryClass);
}
/**
- * @param valueNumber 需要被解析的数值
- *
- * Value that needs to be parsed
- * @param baseNameKeyValue 单位的键值对,如果您需要指定数值的单位,您可以在这里进行指定,如果您不需要可以直接设置为 null,请注意 如果您不设置为null 此操作将不会对数值进行任何化简.
- *
- * The key value pairs of units. If you need to specify the unit of a numerical value, you can specify it here. If you don't need it, you can directly set it to null. Please note that if you don't set it to null, this operation will not simplify the numerical value in any way.
+ * @param valueNumber 需要被解析的数值
+ *
+ * Value that needs to be parsed
+ * @param baseNameKeyValue 单位的键值对,如果您需要指定数值的单位,您可以在这里进行指定,如果您不需要可以直接设置为 null,请注意 如果您不设置为null 此操作将不会对数值进行任何化简.
+ *
+ * The key value pairs of units. If you need to specify the unit of a numerical value, you can specify it here. If you don't need it, you can directly set it to null. Please note that if you don't set it to null, this operation will not simplify the numerical value in any way.
+ * @param baseValueFactoryClass 单位数值构造工厂类
+ *
+ * Unit Value Construction Factory Class
* @return 解析之后的单位数值对象
*
* Parsed Unit Value Object
*/
- protected static BaseValue parse(double valueNumber, KeyValue
+ * Matching unit classes, which can automatically generate appropriate class objects based on annotations in a class.
+ *
+ * @author zhao
+ */
+public class MatchBaseGroupUnit extends MatchBaseUnit {
+
+ protected final double[] baseDiff;
+
+
+ protected MatchBaseGroupUnit(TempBaseData tempBaseData, double[] baseDiff) {
+ super(tempBaseData);
+ final int length = super.tempBaseData.getBaseNames().length;
+ if (length != baseDiff.length) {
+ throw new UnsupportedOperationException("The length of the base difference array you provided is [" + baseDiff.length + "]. It is expected to be [" + length + "] because each element in the array corresponds to a base digit");
+ }
+ this.baseDiff = baseDiff;
+ }
+
+
+ /**
+ * 根据单位注解创建出一个单位对象。
+ *
+ * The decimal value between each adjacent subunit. Create a unit object based on the unit annotation.
+ *
+ * @param baseUnit 需要被解析的单位注解。
+ *
+ * Unit annotations that need to be parsed.
+ * @return 创建出来的单位对象。
+ *
+ * The unit object created.
+ */
+ static TempBaseData parse(BaseUnit baseUnit) {
+ final String[] value = baseUnit.value();
+ final TempBaseData tempBaseData = TEMP_BASE_DATA_HASH_MAP.get(baseUnit);
+ if (tempBaseData != null) {
+ return tempBaseData;
+ }
+ final double[] doubles = new double[value.length];
+ double number = 1;
+ final double[] doubles1 = baseUnit.baseValue();
+ HashMap
+ * The bit weight of each subunit in the current unit object. Bit weight is iterated in ascending order.
+ * 例如:["h","m","s","ms"] 中 进制差为 [60, 60, 1000, 0] 代表的就是下一个单位举例当前单位的倍数
+ */
+ @Override
+ public double[] getBaseDiff() {
+ return this.baseDiff.clone();
+ }
+
+ /**
+ * 将一个具有指定单位的数值转换为另一个具有指定单位的数值
+ *
+ * Convert a numerical value with a specified unit to another numerical value with a specified unit
+ *
+ * @param baseValue 需要被转换的数值对象
+ *
+ * Numerical objects that need to be converted
+ * @param targetUnit 期望切换到的目标单位
+ *
+ *
+ * Expected target unit to switch to
+ * @return 计算出能够容纳此数值的单位名称
+ *
+ * Calculate the unit name that can accommodate this value
+ */
+ @Override
+ public BaseValue switchBaseName(BaseValue baseValue, KeyValue
+ * The bit weight of each subunit in the current unit object. Bit weight is iterated in ascending order.
+ * 例如:["h","m","s","ms"] 中 进制差为 [60, 60, 1000, 0] 代表的就是下一个单位举例当前单位的倍数
+ */
+ @Override
+ public double[] getBaseDiff() {
+ final double[] doubles = new double[this.tempBaseData.getBaseNames().length];
+ Arrays.fill(doubles, this.getBaseValue());
+ doubles[doubles.length - 1] = 1;
+ return doubles;
+ }
+
+ /**
+ * 如果需要设置为 true;Set to true if necessary
+ *
+ * @return 在数学中,乘法运算需要注意两个方面:数字和单位。
+ *
+ * 当数字相乘时,可以直接进行乘法运算。例如,2升乘以2升,数字部分是2乘以2,结果是4。
+ *
+ * 当单位相乘时,需要先统一单位,然后再进行乘法运算。例如,2米乘以2米,单位是米,可以直接相乘得到4平方米。但如果单位不同,比如2米乘以2厘米,需要先统一单位,把2厘米转换为米(即0.01米),然后再相乘得到0.04平方米。
+ *
+ * 因此,在进行乘法运算时,需要先判断数字和单位是否一致,如果单位不一致需要先统一单位再进行计算。
+ *
+ * In mathematics, multiplication operations require attention to two aspects: numbers and units.
+ *
+ * When multiplying numbers, multiplication can be performed directly. For example, multiplying 2 liters by 2 liters, the numerical part is 2 times 2, and the result is 4.
+ *
+ * When multiplying units, it is necessary to first unify the units before performing multiplication operations. For example, multiplying 2 meters by 2 meters in meters can directly yield 4 square meters. But if the units are different, such as multiplying 2 meters by 2 centimeters, it is necessary to first unify the units, convert 2 centimeters to meters (i.e. 0.01 meters), and then multiply them to obtain 0.04 square meters.
+ *
+ * Therefore, when performing multiplication operations, it is necessary to first check whether the numbers and units are consistent. If the units are not consistent, it is necessary to first unify the units before calculating.
+ */
+ @Override
+ public boolean isNeedUnifiedUnit() {
+ return this.tempBaseData.isNeedUnifiedUnit();
+ }
+
/**
* 将一个具有指定单位的数值转换为另一个具有指定单位的数值
*
@@ -140,7 +187,7 @@ public BaseValue switchBaseName(BaseValue baseValue, KeyValue
* Volume unit numerical class, which stores volume related units and numerical management mechanisms
+ *
* @author zhao
*/
@BaseUnit(value = {
"m³(立方米)", "dm³(立方分米 or 升)", "cm³(立方厘米 or 毫升)", "mm³(立方毫米)"
}, baseValue = 1000)
-public class VolumeValue extends BaseValue{
+public class VolumeValue extends BaseValue {
+
- public VolumeValue(double valueNumber, Class extends BaseValue> c, KeyValue
- * Value that needs to be parsed
+ * @param valueNumber 需要被解析的数值
+ *
+ * Value that needs to be parsed
+ * @param baseValueFactoryClass 单位数值构造工厂类
+ *
+ * Unit Value Construction Factory Class
* @return 解析之后的单位数值对象
*
* Parsed Unit Value Object
*/
- public static BaseValue parse(double valueNumber) {
- return parse(valueNumber, null);
+ public static BaseValue parse(double valueNumber, BaseValueFactory baseValueFactoryClass) {
+ return parse(valueNumber, null, baseValueFactoryClass);
}
/**
- * @param valueNumber 需要被解析的数值
- *
- * Value that needs to be parsed
- * @param baseNameKeyValue 单位的键值对,如果您需要指定数值的单位,您可以在这里进行指定,如果您不需要可以直接设置为 null,请注意 如果您不设置为null 此操作将不会对数值进行任何化简.
- *
- * The key value pairs of units. If you need to specify the unit of a numerical value, you can specify it here. If you don't need it, you can directly set it to null. Please note that if you don't set it to null, this operation will not simplify the numerical value in any way.
+ * @param valueNumber 需要被解析的数值
+ *
+ * Value that needs to be parsed
+ * @param baseNameKeyValue 单位的键值对,如果您需要指定数值的单位,您可以在这里进行指定,如果您不需要可以直接设置为 null,请注意 如果您不设置为null 此操作将不会对数值进行任何化简.
+ *
+ * The key value pairs of units. If you need to specify the unit of a numerical value, you can specify it here. If you don't need it, you can directly set it to null. Please note that if you don't set it to null, this operation will not simplify the numerical value in any way.
+ * @param baseValueFactoryClass 单位数值构造工厂类
+ *
+ * Unit Value Construction Factory Class
* @return 解析之后的单位数值对象
*
* Parsed Unit Value Object
*/
- protected static BaseValue parse(double valueNumber, KeyValue
- * Value that needs to be parsed
+ * @param valueNumber 需要被解析的数值
+ *
+ * Value that needs to be parsed
+ * @param baseValueFactoryClass 单位数值构造工厂类
+ *
+ * Unit Value Construction Factory Class
* @return 解析之后的单位数值对象
*
* Parsed Unit Value Object
*/
- public static BaseValue parse(double valueNumber) {
- return parse(valueNumber, null);
+ public static BaseValue parse(double valueNumber, BaseValueFactory baseValueFactoryClass) {
+ return parse(valueNumber, null, baseValueFactoryClass);
}
/**
- * @param valueNumber 需要被解析的数值
- *
- * Value that needs to be parsed
- * @param baseNameKeyValue 单位的键值对,如果您需要指定数值的单位,您可以在这里进行指定,如果您不需要可以直接设置为 null,请注意 如果您不设置为null 此操作将不会对数值进行任何化简.
- *
- * The key value pairs of units. If you need to specify the unit of a numerical value, you can specify it here. If you don't need it, you can directly set it to null. Please note that if you don't set it to null, this operation will not simplify the numerical value in any way.
+ * @param valueNumber 需要被解析的数值
+ *
+ * Value that needs to be parsed
+ * @param baseNameKeyValue 单位的键值对,如果您需要指定数值的单位,您可以在这里进行指定,如果您不需要可以直接设置为 null,请注意 如果您不设置为null 此操作将不会对数值进行任何化简.
+ *
+ * The key value pairs of units. If you need to specify the unit of a numerical value, you can specify it here. If you don't need it, you can directly set it to null. Please note that if you don't set it to null, this operation will not simplify the numerical value in any way.
+ * @param baseValueFactoryClass 单位数值构造工厂类
+ *
+ * Unit Value Construction Factory Class
* @return 解析之后的单位数值对象
*
* Parsed Unit Value Object
*/
- protected static BaseValue parse(double valueNumber, KeyValue
- * the number of dimensions contained in the vector
- */
- override def getNumberOfDimensions: Int = size
-
/**
* 在两个操作数之间做差的方法,具体用法请参阅API说明。
*
@@ -142,21 +127,6 @@ final class SparkVector(sparkContext: SparkContext, vector: org.apache.spark.mll
else throw new OperatorOperationException("'DoubleVector1 diff DoubleVector2' 时,两个'DoubleVector'的向量所包含的数量不同,DoubleVector1=[" + numberOfDimensions1 + "],DoubleVector2=[" + numberOfDimensions2 + "]\n" + "When 'DoubleVector1 diff DoubleVector2', the two vectors of 'DoubleVector' contain different quantities, DoubleVector1=[" + numberOfDimensions1 + "], DoubleVector2=[" + numberOfDimensions2 + "]")
}
- /**
- * @return 向量中包含的维度数量
- *
- * the number of dimensions contained in the vector
- */
- override def getNumberOfDimensions: Int = size
-
- /**
- *
- * @return 将本对象中存储的向量序列数组拷贝到一个新数组并将新数组返回,这里返回的是一个新数组,支持修改等操作。
- *
- * Copy the vector sequence array stored in this object to a new array and return the new array. Here, a new array is returned, which supports modification and other operations.
- */
- override def copyToNewArray(): Array[Double] = vector.toArray
-
/**
* 将本对象中的所有数据进行洗牌打乱,随机分布数据行的排列。
*
@@ -191,6 +161,21 @@ final class SparkVector(sparkContext: SparkContext, vector: org.apache.spark.mll
SparkVector.parse(sparkContext, doubles)
}
+ /**
+ *
+ * @return 将本对象中存储的向量序列数组拷贝到一个新数组并将新数组返回,这里返回的是一个新数组,支持修改等操作。
+ *
+ * Copy the vector sequence array stored in this object to a new array and return the new array. Here, a new array is returned, which supports modification and other operations.
+ */
+ override def copyToNewArray(): Array[Double] = vector.toArray
+
+ /**
+ * @return 向量中包含的维度数量
+ *
+ * the number of dimensions contained in the vector
+ */
+ override def getNumberOfDimensions: Int = size
+
/**
* 在两个操作数之间做差的方法,具体用法请参阅API说明。
*
diff --git a/src_code/update/1.29-1.30-Chinese.md b/src_code/update/1.29-1.30-Chinese.md
new file mode 100644
index 0000000..a11d0f5
--- /dev/null
+++ b/src_code/update/1.29-1.30-Chinese.md
@@ -0,0 +1,158 @@
+#  算法之星-机器大脑
+
+- Switch to [English Document](https://github.com/BeardedManZhao/algorithmStar/blob/Zhao-develop/src_code/README.md)
+- knowledge base
+
+
+ * Value that needs to be parsed
+ * @return 解析之后的单位数值对象
+ *
+ * Parsed Unit Value Object
+ */
+ public static BaseValue parse(double valueNumber) {
+ return parse(valueNumber, null);
+ }
+
+ /**
+ * @param valueNumber 需要被解析的数值
+ *
+ * Value that needs to be parsed
+ * @param baseNameKeyValue 单位的键值对,如果您需要指定数值的单位,您可以在这里进行指定,如果您不需要可以直接设置为 null,请注意 如果您不设置为null 此操作将不会对数值进行任何化简.
+ *
+ * The key value pairs of units. If you need to specify the unit of a numerical value, you can specify it here. If you don't need it, you can directly set it to null. Please note that if you don't set it to null, this operation will not simplify the numerical value in any way.
+ * @return 解析之后的单位数值对象
+ *
+ * Parsed Unit Value Object
+ */
+ protected static BaseValue parse(double valueNumber, KeyValue
+ * Value that needs to be parsed
+ * @return 解析之后的单位数值对象
+ *
+ * Parsed Unit Value Object
+ */
+ public static BaseValue parse(double valueNumber) {
+ return parse(valueNumber, null);
+ }
+
+ /**
+ * @param valueNumber 需要被解析的数值
+ *
+ * Value that needs to be parsed
+ * @param baseNameKeyValue 单位的键值对,如果您需要指定数值的单位,您可以在这里进行指定,如果您不需要可以直接设置为 null,请注意 如果您不设置为null 此操作将不会对数值进行任何化简.
+ *
+ * The key value pairs of units. If you need to specify the unit of a numerical value, you can specify it here. If you don't need it, you can directly set it to null. Please note that if you don't set it to null, this operation will not simplify the numerical value in any way.
+ * @return 解析之后的单位数值对象
+ *
+ * Parsed Unit Value Object
+ */
+ protected static BaseValue parse(double valueNumber, KeyValue
+
+
+### 更新日志
+
+* 框架版本:1.29 - 1.30
+* 新增单位数值类操作数,此操作数可以实现基本计算,同时还可以实现带有单位的计算效果,其还具有单位转换操作,且允许自定义单位!!!
+ * 内置了 BaseValue 类,其可以实现加减乘除运算,同时还支持单位数值的转换,可以直接使用
+
+```java
+package zhao.algorithmMagic;
+
+import zhao.algorithmMagic.core.AlgorithmStar;
+import zhao.algorithmMagic.core.BaseValueFactory;
+import zhao.algorithmMagic.operands.unit.BaseValue;
+
+import java.net.MalformedURLException;
+
+public class MAIN1 {
+ public static void main(String[] args) {
+ // 构建一个用来创建 BaseValue.class 的工厂类 TODO 这里的类型可以是其它的 但是要确保是 BaseValue 的子类
+ final BaseValueFactory baseValueFactory = AlgorithmStar.baseValueFactory(BaseValue.class);
+ // 获取到数值
+ final BaseValue number_1 = baseValueFactory.parse(200);
+ System.out.println("number_1 = " + number_1);
+ final BaseValue number_2 = baseValueFactory.parse(1024);
+ System.out.println("number_2 = " + number_2);
+
+ // 基本的运算演示
+ System.out.println("============");
+ System.out.println(number_2 + " + " + number_1 + " = " + number_1.add(number_2));
+ System.out.println(number_2 + " + " + 2 + number_2.getNowBase().getValue() + " = " + number_2.add(2));
+
+ System.out.println("============");
+ System.out.println(number_2 + " - " + number_1 + " = " + number_1.diff(number_2));
+ System.out.println(number_2 + " - " + 2 + number_2.getNowBase().getValue() + " = " + number_2.diff(2));
+
+ System.out.println("============");
+ System.out.println(number_2 + " * " + number_1 + " = " + number_1.multiply(number_2));
+ System.out.println(number_2 + " * " + 2 + number_2.getNowBase().getValue() + " = " + number_2.multiply(2));
+
+ System.out.println("============");
+ System.out.println(number_2 + " / " + number_1 + " = " + number_1.divide(number_2));
+ System.out.println(number_2 + " / " + 2 + number_2.getNowBase().getValue() + " = " + number_2.divide(2));
+
+ // 将 1.024千 转换为 10.24百 和 0.1024 万
+ System.out.println("============");
+ System.out.println(number_2.switchUnits("百"));
+ System.out.println(number_2.switchUnits("万"));
+ }
+}
+
+```
+
+* 如果需要自定义单位,可以直接继承 BaseValue 类,然后标注 BaseUnit 注解即可,下面是一个基本的实例(下面的类也已经加入到了AS库)
+ * 继承 BaseValue 并重写静态的 parse 函数
+ * 标注 BaseUnit 注解 在其中设置单位 与 进制值
+
+```java
+package zhao.algorithmMagic.operands.unit;
+
+import zhao.algorithmMagic.utils.dataContainer.KeyValue;
+
+/**
+ * 重量单位数值,在这里可以直接使用重量相关的单位!
+ *
+ * Weight unit value, weight related units can be directly used here!
+ * @author zhao
+ */
+@BaseUnit(value = {
+ "t(吨)", "kg(千克)", "g(克)", "mg(毫克)", "ug(微克)", "ng(纳克)", "pg(皮克)", "fg(飞克)"
+}, baseValue = 1000)
+public class WeightValue extends BaseValue {
+
+ protected WeightValue(double valueNumber, Class extends BaseValue> c, KeyValue
+
+
+### Update log:
+
+* Framework version: 1.29 - 1.30
+* Add unit value operands, which can achieve basic calculations and also achieve calculation effects with units. They
+ also have unit conversion operations and allow custom units!!!
+ * Built in BaseValue class, it can implement addition, subtraction, multiplication, and division operations, and
+ also supports conversion of unit values, which can be directly used
+
+```java
+package zhao.algorithmMagic;
+
+import zhao.algorithmMagic.core.AlgorithmStar;
+import zhao.algorithmMagic.core.BaseValueFactory;
+import zhao.algorithmMagic.operands.unit.BaseValue;
+
+import java.net.MalformedURLException;
+
+public class MAIN1 {
+ public static void main(String[] args) {
+ // 构建一个用来创建 BaseValue.class 的工厂类 TODO 这里的类型可以是其它的 但是要确保是 BaseValue 的子类
+ final BaseValueFactory baseValueFactory = AlgorithmStar.baseValueFactory(BaseValue.class);
+ // 获取到数值
+ final BaseValue number_1 = baseValueFactory.parse(200);
+ System.out.println("number_1 = " + number_1);
+ final BaseValue number_2 = baseValueFactory.parse(1024);
+ System.out.println("number_2 = " + number_2);
+
+ // 基本的运算演示
+ System.out.println("============");
+ System.out.println(number_2 + " + " + number_1 + " = " + number_1.add(number_2));
+ System.out.println(number_2 + " + " + 2 + number_2.getNowBase().getValue() + " = " + number_2.add(2));
+
+ System.out.println("============");
+ System.out.println(number_2 + " - " + number_1 + " = " + number_1.diff(number_2));
+ System.out.println(number_2 + " - " + 2 + number_2.getNowBase().getValue() + " = " + number_2.diff(2));
+
+ System.out.println("============");
+ System.out.println(number_2 + " * " + number_1 + " = " + number_1.multiply(number_2));
+ System.out.println(number_2 + " * " + 2 + number_2.getNowBase().getValue() + " = " + number_2.multiply(2));
+
+ System.out.println("============");
+ System.out.println(number_2 + " / " + number_1 + " = " + number_1.divide(number_2));
+ System.out.println(number_2 + " / " + 2 + number_2.getNowBase().getValue() + " = " + number_2.divide(2));
+
+ // 将 1.024千 转换为 10.24百 和 0.1024 万
+ System.out.println("============");
+ System.out.println(number_2.switchUnits("百"));
+ System.out.println(number_2.switchUnits("万"));
+ }
+}
+
+```
+
+* If you need to customize the unit, you can directly inherit the BaseValue class and annotate it with BaseUnit
+ annotation. Below is a basic instance (the following class has also been added to the AS library)
+ * Inherit BaseValue and rewrite the static parse function
+ * Annotate BaseUnit to set units and base values in it
+
+```java
+package zhao.algorithmMagic.operands.unit;
+
+import zhao.algorithmMagic.utils.dataContainer.KeyValue;
+
+/**
+ * 重量单位数值,在这里可以直接使用重量相关的单位!
+ *
+ * Weight unit value, weight related units can be directly used here!
+ * @author zhao
+ */
+@BaseUnit(value = {
+ "t(吨)", "kg(千克)", "g(克)", "mg(毫克)", "ug(微克)", "ng(纳克)", "pg(皮克)", "fg(飞克)"
+}, baseValue = 1000)
+public class WeightValue extends BaseValue {
+
+ protected WeightValue(double valueNumber, Class extends BaseValue> c, KeyValue