Automation/app/src/main/java/com/jens/automation2/TimeFrame.java

95 lines
2.3 KiB
Java
Raw Normal View History

2021-02-16 13:42:49 +01:00
package com.jens.automation2;
import java.sql.Time;
import java.util.ArrayList;
public class TimeFrame
{
// Defines a timeframe
2021-11-07 17:29:00 +01:00
protected Time triggerTimeStart;
protected Time triggerTimeStop;
protected long repetition;
2021-02-16 13:42:49 +01:00
2021-11-07 17:29:00 +01:00
protected final static String separator = "/";
private ArrayList<Integer> dayList = new ArrayList<Integer>();
public ArrayList<Integer> getDayList()
{
return dayList;
}
public void setDayList(ArrayList<Integer> dayList)
{
this.dayList = dayList;
}
public void setDayListFromString(String dayListString)
{
// Log.i("Parsing", "Full string: " + dayListString);
char[] dayListCharArray = dayListString.toCharArray();
dayList = new ArrayList<Integer>();
for(char item : dayListCharArray)
2021-02-16 13:42:49 +01:00
{
// Log.i("Parsing", String.valueOf(item));
2021-11-07 17:29:00 +01:00
dayList.add(Integer.parseInt(String.valueOf(item)));
2021-02-16 13:42:49 +01:00
}
2021-11-07 17:29:00 +01:00
}
2021-02-16 13:42:49 +01:00
2021-11-07 17:29:00 +01:00
public Time getTriggerTimeStart()
{
return triggerTimeStart;
}
public void setTriggerTimeStart(Time triggerTimeStart)
{
this.triggerTimeStart = triggerTimeStart;
}
public Time getTriggerTimeStop()
{
return triggerTimeStop;
}
public void setTriggerTimeStop(Time triggerTimeStop)
{
this.triggerTimeStop = triggerTimeStop;
}
public long getRepetition()
{
return repetition;
}
public void setRepetition(long repetition)
{
this.repetition = repetition;
}
public TimeFrame (Time timeStart, Time timeEnd, ArrayList<Integer> dayList2, long repetition)
{
this.setTriggerTimeStart(timeStart);
this.setTriggerTimeStop(timeEnd);
this.setDayList(dayList2);
this.setRepetition(repetition);
}
2021-11-08 20:13:11 +01:00
public TimeFrame (String fileContent)
2021-11-07 17:29:00 +01:00
{
String[] dateArray = fileContent.split(separator); // example: timestart/timestop/days[int]/repetition
this.setTriggerTimeStart(Time.valueOf(dateArray[0]));
this.setTriggerTimeStop(Time.valueOf(dateArray[1]));
this.setDayListFromString(dateArray[2]);
2021-11-13 02:32:39 +01:00
if(dateArray.length > 3) // may not exist in old config files
this.setRepetition(Long.parseLong(dateArray[3]));
2021-11-07 17:29:00 +01:00
}
@Override
public String toString()
{
String returnString = this.getTriggerTimeStart().toString() + separator + this.getTriggerTimeStop().toString() + separator;
for(Integer oneDay : this.getDayList())
returnString += String.valueOf(oneDay);
returnString += separator + String.valueOf(repetition);
return returnString;
}
}