java - 在Java中的对象初始化期间根据构造函数变量值更改键?
问题描述
即使我做了几年程序员,我仍然总是试图找到最好的方法,
这是我的挑战之一,我想以最好的方式做到这一点,
MutableEventInstance mutableEventInstance = new MutableEventInstance(key, start, stop, value);
类定义
public class MutableEventInstance {
private int key;
private int start;
private int stop;
private double value;
/*'***************************************************************************************
* Class members
******************************************************************************************/
public MutableEventInstance(int key, int start, int stop, double value) {
this.key = key;
this.start = start;
this.stop = stop;
this.value = value;
}
/**
* @return the key
*/
public int getKey() {
return key;
}
/**
* @return the start
*/
public int getStart() {
return start;
}
/**
* @return the stop
*/
public int getStop() {
return stop;
}
/**
* @return the value
*/
public double getValue() {
return value;
}
/**
* @param key the key to set
*/
public void setKey(int key) {
this.key = key;
}
/**
* @param start the start to set
*/
public void setStart(int start) {
this.start = start;
}
/**
* @param stop the stop to set
*/
public void setStop(int stop) {
this.stop = stop;
}
/**
* @param value the value to set
*/
public void setValue(double value) {
this.value = value;
}
}
当任何开始/停止值与以前的值不同时,键值将从零开始递增。
我只能猜测,存储以前的开始和停止值,然后递增。
有什么最好的方法吗?请指教。
我需要根据 Spark 2.3 中的键聚合值
示例:当启动/停止发生变化时,键值需要增加。我该怎么做呢 ?在这些对象的初始化发生的方法上?
Key=0, Start = 3, Stop = 7, Value = -10.0
Key=0, Start = 3, Stop = 7, Value = 0.0
Key=0, Start = 3, Stop = 7, Value = 0.0
Key=0, Start = 3, Stop = 7, Value = 3.03
Key=0, Start = 3, Stop = 7, Value = 0.0
Key=0, Start = 3, Stop = 7, Value = 0.0
Key=0, Start = 3, Stop = 7, Value = 2.5
Key=1, Start = 5, Stop = 6, Value = -10.0
Key=1, Start = 5, Stop = 6, Value = 0.0
Key=1, Start = 5, Stop = 6, Value = 0.0
Key=1, Start = 5, Stop = 6, Value = 3.03
Key=1, Start = 5, Stop = 6, Value = 0.0
Key=1, Start = 5, Stop = 6, Value = 0.0
Key=1, Start = 5, Stop = 6, Value = 2.5
解决方案
推荐阅读
- javascript - 如何更改环回 4 中有关密码长度的 HTTP 错误?
- ffmpeg - 如何在 1920x1080 视频中使用“标准 PAL”标志
- python - 将 .split 与 tkinter 一起使用
- javascript - 如何在
使用 javascript 的元素 - php - Laravel PostgreSQL 分组错误:7 错误:列“table.column”必须出现在 GROUP BY
- cloudkit - iOS:Cloudkit 链接在 iOS13 中不起作用
- node.js - 函数的Nodejs可见性
- amazon-web-services - 错误:SignatureDoesNotMatch 在尝试使用预签名 URL 从邮递员上传文件时收到此错误
- laravel - 为什么输入 laravel 循环数据最多 40 行?
- php - 这个 POST 方法有什么问题?