BrightSide Workbench Full Report + Source Code
TimeTrackerType.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2020 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.elephant.entities.db;
20 
21 import java.util.EnumSet;
22 
27 public enum TimeTrackerType {
28 
29  TRACK_START(true),
30  TRACK_END(false),
31  TRACK_PAUSE(false),
32  TRACK_RESUME(true);
33 
34  private final boolean starts;
35 
36  private TimeTrackerType(boolean starts) {
37  this.starts = starts;
38  }
39 
40  public boolean isStarts() {
41  return starts;
42  }
43 
44  public boolean isPreviousValid(TimeTrackerType previousType) {
45  return getValidNexts(previousType).contains(this);
46  }
47 
49  if(null == previous) {
50  if(TRACK_END.equals(this)) {
51  return TRACK_START;
52  }
53  } else switch (previous.getTrackType()) {
54  case TRACK_END:
55  if(TRACK_PAUSE.equals(this) || TRACK_END.equals(this)) {
56  return TRACK_START;
57  }
58  break;
59  case TRACK_START:
60  if(TRACK_RESUME.equals(this)) {
61  return TRACK_PAUSE;
62  } else if(TRACK_START.equals(this)) {
63  return TRACK_END;
64  }
65  break;
66  case TRACK_PAUSE:
67  if(TRACK_RESUME.equals(this) || TRACK_START.equals(this)) {
68  return TRACK_END;
69  }
70  break;
71  case TRACK_RESUME:
72  break;
73  }
74  return null;
75  }
76 
77  public static EnumSet<TimeTrackerType> getValidNexts(TimeTrackerType type) {
78  if(null == type) {
79  return EnumSet.of(TRACK_START);
80  } else switch (type) {
81  case TRACK_END:
82  return EnumSet.of(TRACK_START);
83  case TRACK_START:
84  return EnumSet.of(TRACK_END, TRACK_PAUSE);
85  case TRACK_PAUSE:
86  return EnumSet.of(TRACK_RESUME);
87  case TRACK_RESUME:
88  return EnumSet.of(TRACK_END, TRACK_PAUSE);
89  default:
90  return null;
91  }
92  }
93 
94  public static EnumSet<TimeTrackerType> getActiveTypes() {
95  return EnumSet.of(TRACK_START, TRACK_PAUSE, TRACK_RESUME);
96  }
97 
98  public static EnumSet<TimeTrackerType> getInactiveTypes() {
99  return EnumSet.of(TRACK_END);
100  }
101 
102  public static EnumSet<TimeTrackerType> getStartTypes() {
103  return EnumSet.of(TRACK_START, TRACK_RESUME);
104  }
105 
106  public static EnumSet<TimeTrackerType> getEndTypes() {
107  return EnumSet.of(TRACK_PAUSE, TRACK_END);
108  }
109 
110 }
boolean isPreviousValid(TimeTrackerType previousType)
static EnumSet< TimeTrackerType > getStartTypes()
static EnumSet< TimeTrackerType > getValidNexts(TimeTrackerType type)
static EnumSet< TimeTrackerType > getEndTypes()
static EnumSet< TimeTrackerType > getInactiveTypes()
static EnumSet< TimeTrackerType > getActiveTypes()
TimeTrackerType getValidRepair(TimeTracker previous)