📄 timeperiodvalues.java
字号:
long minMiddle = s + (e - s) / 2;
if (middle < minMiddle) {
this.minMiddleIndex = index;
}
}
else {
this.minMiddleIndex = index;
}
if (this.maxMiddleIndex >= 0) {
long s = getDataItem(this.minMiddleIndex).getPeriod().getStart()
.getTime();
long e = getDataItem(this.minMiddleIndex).getPeriod().getEnd()
.getTime();
long maxMiddle = s + (e - s) / 2;
if (middle > maxMiddle) {
this.maxMiddleIndex = index;
}
}
else {
this.maxMiddleIndex = index;
}
if (this.minEndIndex >= 0) {
long minEnd = getDataItem(this.minEndIndex).getPeriod().getEnd()
.getTime();
if (end < minEnd) {
this.minEndIndex = index;
}
}
else {
this.minEndIndex = index;
}
if (this.maxEndIndex >= 0) {
long maxEnd = getDataItem(this.maxEndIndex).getPeriod().getEnd()
.getTime();
if (end > maxEnd) {
this.maxEndIndex = index;
}
}
else {
this.maxEndIndex = index;
}
}
/**
* Recalculates the bounds for the collection of items.
*/
private void recalculateBounds() {
this.minStartIndex = -1;
this.minMiddleIndex = -1;
this.minEndIndex = -1;
this.maxStartIndex = -1;
this.maxMiddleIndex = -1;
this.maxEndIndex = -1;
for (int i = 0; i < this.data.size(); i++) {
TimePeriodValue tpv = (TimePeriodValue) this.data.get(i);
updateBounds(tpv.getPeriod(), i);
}
}
/**
* Adds a new data item to the series and sends a {@link SeriesChangeEvent}
* to all registered listeners.
*
* @param period the time period (<code>null</code> not permitted).
* @param value the value.
*
* @see #add(TimePeriod, Number)
*/
public void add(TimePeriod period, double value) {
TimePeriodValue item = new TimePeriodValue(period, value);
add(item);
}
/**
* Adds a new data item to the series and sends a {@link SeriesChangeEvent}
* to all registered listeners.
*
* @param period the time period (<code>null</code> not permitted).
* @param value the value (<code>null</code> permitted).
*/
public void add(TimePeriod period, Number value) {
TimePeriodValue item = new TimePeriodValue(period, value);
add(item);
}
/**
* Updates (changes) the value of a data item and sends a
* {@link SeriesChangeEvent} to all registered listeners.
*
* @param index the index of the data item to update.
* @param value the new value (<code>null</code> not permitted).
*/
public void update(int index, Number value) {
TimePeriodValue item = getDataItem(index);
item.setValue(value);
fireSeriesChanged();
}
/**
* Deletes data from start until end index (end inclusive) and sends a
* {@link SeriesChangeEvent} to all registered listeners.
*
* @param start the index of the first period to delete.
* @param end the index of the last period to delete.
*/
public void delete(int start, int end) {
for (int i = 0; i <= (end - start); i++) {
this.data.remove(start);
}
recalculateBounds();
fireSeriesChanged();
}
/**
* Tests the series for equality with another object.
*
* @param obj the object (<code>null</code> permitted).
*
* @return <code>true</code> or <code>false</code>.
*/
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof TimePeriodValues)) {
return false;
}
if (!super.equals(obj)) {
return false;
}
TimePeriodValues that = (TimePeriodValues) obj;
if (!ObjectUtilities.equal(this.getDomainDescription(),
that.getDomainDescription())) {
return false;
}
if (!ObjectUtilities.equal(this.getRangeDescription(),
that.getRangeDescription())) {
return false;
}
int count = getItemCount();
if (count != that.getItemCount()) {
return false;
}
for (int i = 0; i < count; i++) {
if (!getDataItem(i).equals(that.getDataItem(i))) {
return false;
}
}
return true;
}
/**
* Returns a hash code value for the object.
*
* @return The hashcode
*/
public int hashCode() {
int result;
result = (this.domain != null ? this.domain.hashCode() : 0);
result = 29 * result + (this.range != null ? this.range.hashCode() : 0);
result = 29 * result + this.data.hashCode();
result = 29 * result + this.minStartIndex;
result = 29 * result + this.maxStartIndex;
result = 29 * result + this.minMiddleIndex;
result = 29 * result + this.maxMiddleIndex;
result = 29 * result + this.minEndIndex;
result = 29 * result + this.maxEndIndex;
return result;
}
/**
* Returns a clone of the collection.
* <P>
* Notes:
* <ul>
* <li>no need to clone the domain and range descriptions, since String
* object is immutable;</li>
* <li>we pass over to the more general method createCopy(start, end).
* </li>
* </ul>
*
* @return A clone of the time series.
*
* @throws CloneNotSupportedException if there is a cloning problem.
*/
public Object clone() throws CloneNotSupportedException {
Object clone = createCopy(0, getItemCount() - 1);
return clone;
}
/**
* Creates a new instance by copying a subset of the data in this
* collection.
*
* @param start the index of the first item to copy.
* @param end the index of the last item to copy.
*
* @return A copy of a subset of the items.
*
* @throws CloneNotSupportedException if there is a cloning problem.
*/
public TimePeriodValues createCopy(int start, int end)
throws CloneNotSupportedException {
TimePeriodValues copy = (TimePeriodValues) super.clone();
copy.data = new ArrayList();
if (this.data.size() > 0) {
for (int index = start; index <= end; index++) {
TimePeriodValue item = (TimePeriodValue) this.data.get(index);
TimePeriodValue clone = (TimePeriodValue) item.clone();
try {
copy.add(clone);
}
catch (SeriesException e) {
System.err.println("Failed to add cloned item.");
}
}
}
return copy;
}
/**
* Returns the index of the time period with the minimum start milliseconds.
*
* @return The index.
*/
public int getMinStartIndex() {
return this.minStartIndex;
}
/**
* Returns the index of the time period with the maximum start milliseconds.
*
* @return The index.
*/
public int getMaxStartIndex() {
return this.maxStartIndex;
}
/**
* Returns the index of the time period with the minimum middle
* milliseconds.
*
* @return The index.
*/
public int getMinMiddleIndex() {
return this.minMiddleIndex;
}
/**
* Returns the index of the time period with the maximum middle
* milliseconds.
*
* @return The index.
*/
public int getMaxMiddleIndex() {
return this.maxMiddleIndex;
}
/**
* Returns the index of the time period with the minimum end milliseconds.
*
* @return The index.
*/
public int getMinEndIndex() {
return this.minEndIndex;
}
/**
* Returns the index of the time period with the maximum end milliseconds.
*
* @return The index.
*/
public int getMaxEndIndex() {
return this.maxEndIndex;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -