65 lines
1.1 KiB
Java
65 lines
1.1 KiB
Java
package org.hwo.pulscounter;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
|
|
import org.hwo.csv.CSV;
|
|
|
|
public class TimeBarrier {
|
|
|
|
Integer timeOfDay;
|
|
List<Integer> values;
|
|
|
|
public TimeBarrier(Integer timeOfDay)
|
|
{
|
|
this.timeOfDay = timeOfDay;
|
|
values = new ArrayList<Integer>();
|
|
load();
|
|
}
|
|
|
|
public TimeBarrier(Integer HourOfDay,Integer MinuteOfDay)
|
|
{
|
|
this.timeOfDay = (HourOfDay * 60) + MinuteOfDay;
|
|
values = new ArrayList<Integer>();
|
|
load();
|
|
}
|
|
|
|
|
|
|
|
public void update(List<Integer> values)
|
|
{
|
|
Date date = new Date();
|
|
int now = (date.getHours() * 60) + date.getMinutes();
|
|
|
|
if (now < timeOfDay)
|
|
{
|
|
this.values.clear();
|
|
for (Integer v: values)
|
|
this.values.add(v);
|
|
}
|
|
}
|
|
|
|
public void save()
|
|
{
|
|
CSV csv = new CSV();
|
|
for (Integer i:values)
|
|
csv.getCells().add(new String[]{i.toString()});
|
|
|
|
|
|
csv.saveToFile(String.format("day-%d.csv", timeOfDay));
|
|
}
|
|
|
|
public void load()
|
|
{
|
|
CSV csv = new CSV();
|
|
csv.readFromFile(String.format("day-%d.csv", timeOfDay));
|
|
|
|
for (String[] row: csv.getCells())
|
|
this.values.add(Integer.parseInt(row[0]));
|
|
|
|
}
|
|
|
|
|
|
}
|