Skip to content

Commit 0f76316

Browse files
committed
wip
1 parent 7c3195c commit 0f76316

11 files changed

Lines changed: 113 additions & 374 deletions

File tree

ShiftSharp/Break.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public class Break : TimePeriod
3434
{
3535
public Break(string name, string description, LocalTime start, Duration duration) : base(name, description, start, duration)
3636
{
37-
3837
}
3938

4039
public override bool IsWorkingPeriod()

ShiftSharp/Named.cs

Lines changed: 8 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ namespace Point85.ShiftSharp.Schedule
3333
public abstract class Named
3434
{
3535
// name
36-
private string name;
36+
public string Name { get; set; }
3737

3838
// description
39-
private string description;
39+
public string Description { get; set; }
4040

4141
protected Named()
4242
{
@@ -45,48 +45,8 @@ protected Named()
4545

4646
protected Named(string name, string description)
4747
{
48-
SetName(name);
49-
SetDescription(description);
50-
}
51-
52-
/// <summary>
53-
/// Get name
54-
/// </summary>
55-
/// <returns>Name</returns>
56-
public string GetName()
57-
{
58-
return name;
59-
}
60-
61-
/// <summary>
62-
/// Set name
63-
/// </summary>
64-
/// <param name="name">Name</param>
65-
public void SetName(string name)
66-
{
67-
if (name == null)
68-
{
69-
throw new Exception(WorkSchedule.GetMessage("name.not.defined"));
70-
}
71-
this.name = name;
72-
}
73-
74-
/// <summary>
75-
/// Get description
76-
/// </summary>
77-
/// <returns>Description</returns>
78-
public string GetDescription()
79-
{
80-
return description;
81-
}
82-
83-
/// <summary>
84-
/// Set description
85-
/// </summary>
86-
/// <param name="description"> Description</param>
87-
public void SetDescription(string description)
88-
{
89-
this.description = description;
48+
Name = name ?? throw new Exception(WorkSchedule.GetMessage("name.not.defined"));
49+
Description = description;
9050
}
9151

9252
/// <summary>
@@ -96,13 +56,12 @@ public void SetDescription(string description)
9656
/// <returns>True if equal</returns>
9757
public override bool Equals(Object other)
9858
{
99-
100-
if (other == null || GetType() != other.GetType())
59+
if (Name == null || other == null || GetType() != other.GetType())
10160
{
10261
return false;
10362
}
10463

105-
return GetName().Equals(((Named)other).GetName());
64+
return Name.Equals(((Named)other).Name);
10665
}
10766

10867
/// <summary>
@@ -111,7 +70,7 @@ public override bool Equals(Object other)
11170
/// <returns>Hash code</returns>
11271
public override int GetHashCode()
11372
{
114-
return GetName().GetHashCode();
73+
return Name.GetHashCode();
11574
}
11675

11776
/// <summary>
@@ -120,7 +79,7 @@ public override int GetHashCode()
12079
/// <returns>String value</returns>
12180
public override string ToString()
12281
{
123-
return GetName() + " (" + GetDescription() + ")";
82+
return Name + " (" + Description + ")";
12483
}
12584
}
12685
}

ShiftSharp/NonWorkingPeriod.cs

Lines changed: 14 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -34,45 +34,32 @@ namespace Point85.ShiftSharp.Schedule
3434
public class NonWorkingPeriod : Named, IComparable<NonWorkingPeriod>
3535
{
3636
// owning work schedule
37-
private WorkSchedule workSchedule;
37+
public WorkSchedule WorkSchedule { get; internal set; }
3838

3939
// starting date and time of day
40-
private LocalDateTime startDateTime;
40+
public LocalDateTime StartDateTime { get; set; }
4141

4242
// duration of period
43-
private Duration duration;
43+
public Duration Duration;
4444

4545
public NonWorkingPeriod() : base()
4646
{
4747
}
4848

4949
internal NonWorkingPeriod(string name, string description, LocalDateTime startDateTime, Duration duration) : base(name, description)
50-
{
51-
SetStartDateTime(startDateTime);
52-
SetDuration(duration);
53-
}
54-
55-
/// <summary>
56-
/// Get period start date and time
57-
/// </summary>
58-
/// <returns>Start date and time</returns>
59-
public LocalDateTime GetStartDateTime()
60-
{
61-
return startDateTime;
62-
}
63-
64-
/// <summary>
65-
/// Set period start date and time
66-
/// </summary>
67-
/// <param name="startDateTime">Period start</param>
68-
public void SetStartDateTime(LocalDateTime startDateTime)
6950
{
7051
if (startDateTime == null)
7152
{
7253
throw new Exception(WorkSchedule.GetMessage("start.not.defined"));
7354
}
7455

75-
this.startDateTime = startDateTime;
56+
if (duration == null || duration.TotalSeconds == 0)
57+
{
58+
throw new Exception(WorkSchedule.GetMessage("duration.not.defined"));
59+
}
60+
61+
StartDateTime = startDateTime;
62+
Duration = duration;
7663
}
7764

7865
/// <summary>
@@ -81,30 +68,7 @@ public void SetStartDateTime(LocalDateTime startDateTime)
8168
/// <returns>Period end</returns>
8269
public LocalDateTime GetEndDateTime()
8370
{
84-
return startDateTime.PlusSeconds((long)duration.TotalSeconds);
85-
}
86-
87-
/// <summary>
88-
/// Get period duration
89-
/// </summary>
90-
/// <returns>Duration</returns>
91-
public Duration GetDuration()
92-
{
93-
return duration;
94-
}
95-
96-
/// <summary>
97-
/// Set duration
98-
/// </summary>
99-
/// <param name="duration">Duration</param>
100-
public void SetDuration(Duration duration)
101-
{
102-
if (duration == null || duration.TotalSeconds == 0)
103-
{
104-
throw new Exception(WorkSchedule.GetMessage("duration.not.defined"));
105-
}
106-
107-
this.duration = duration;
71+
return StartDateTime.PlusSeconds((long)Duration.TotalSeconds);
10872
}
10973

11074
/// <summary>
@@ -119,7 +83,7 @@ public override string ToString()
11983

12084
try
12185
{
122-
text = base.ToString() + ", " + start + ": " + GetStartDateTime() + " (" + GetDuration() + ")" + ", " + end
86+
text = base.ToString() + ", " + start + ": " + StartDateTime + " (" + Duration + ")" + ", " + end
12387
+ ": " + GetEndDateTime();
12488
}
12589
catch (Exception)
@@ -136,21 +100,7 @@ public override string ToString()
136100
/// <returns>negative if less than, 0 if equal and positive if greater than</returns>
137101
public int CompareTo(NonWorkingPeriod other)
138102
{
139-
return GetStartDateTime().CompareTo(other.GetStartDateTime());
140-
}
141-
142-
/// <summary>
143-
/// Get the work schedule that owns this non-working period
144-
/// </summary>
145-
/// <returns></returns>
146-
public WorkSchedule GetWorkSchedule()
147-
{
148-
return workSchedule;
149-
}
150-
151-
internal void SetWorkSchedule(WorkSchedule workSchedule)
152-
{
153-
this.workSchedule = workSchedule;
103+
return StartDateTime.CompareTo(other.StartDateTime);
154104
}
155105

156106
/// <summary>
@@ -162,7 +112,7 @@ public bool IsInPeriod(LocalDate day)
162112
{
163113
bool isInPeriod = false;
164114

165-
LocalDate periodStart = GetStartDateTime().Date;
115+
LocalDate periodStart = StartDateTime.Date;
166116
LocalDate periodEnd = GetEndDateTime().Date;
167117

168118
if (day.CompareTo(periodStart) >= 0 && day.CompareTo(periodEnd) <= 0)

ShiftSharp/Rotation.cs

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace Point85.ShiftSharp.Schedule
3535
public class Rotation : Named, IComparable<Rotation>
3636
{
3737
// working periods in the rotation
38-
private List<RotationSegment> rotationSegments = new List<RotationSegment>();
38+
public List<RotationSegment> RotationSegments { get; private set; } = new List<RotationSegment>();
3939

4040
// list of working and non-working days
4141
private List<TimePeriod> periods;
@@ -44,7 +44,7 @@ public class Rotation : Named, IComparable<Rotation>
4444
private const string DAY_OFF_NAME = "DAY_OFF";
4545

4646
// 24-hour day off period
47-
private static DayOff DAY_OFF;// = InitializeDayOff();
47+
private static DayOff DAY_OFF;
4848

4949
static Rotation()
5050
{
@@ -94,21 +94,21 @@ public List<TimePeriod> GetPeriods()
9494
periods = new List<TimePeriod>();
9595

9696
// sort by sequence number
97-
rotationSegments.Sort();
97+
RotationSegments.Sort();
9898

99-
foreach (RotationSegment segment in rotationSegments)
99+
foreach (RotationSegment segment in RotationSegments)
100100
{
101101
// add the on days
102-
if (segment.GetStartingShift() != null)
102+
if (segment.StartingShift != null)
103103
{
104-
for (int i = 0; i < segment.GetDaysOn(); i++)
104+
for (int i = 0; i < segment.DaysOn; i++)
105105
{
106-
periods.Add(segment.GetStartingShift());
106+
periods.Add(segment.StartingShift);
107107
}
108108
}
109109

110110
// add the off days
111-
for (int i = 0; i < segment.GetDaysOff(); i++)
111+
for (int i = 0; i < segment.DaysOff; i++)
112112
{
113113
periods.Add(Rotation.DAY_OFF);
114114
}
@@ -158,16 +158,6 @@ public Duration GetWorkingTime()
158158
return sum;
159159
}
160160

161-
/**
162-
* Get the rotation's working periods
163-
*
164-
* @return List of {@link RotationSegment}
165-
*/
166-
public List<RotationSegment> GetRotationSegments()
167-
{
168-
return rotationSegments;
169-
}
170-
171161
/**
172162
* Add a working period to this rotation. A working period starts with a
173163
* shift and specifies the number of days on and days off
@@ -189,14 +179,14 @@ public RotationSegment AddSegment(Shift startingShift, int daysOn, int daysOff)
189179
throw new Exception("The starting shift must be specified.");
190180
}
191181
RotationSegment segment = new RotationSegment(startingShift, daysOn, daysOff, this);
192-
rotationSegments.Add(segment);
193-
segment.SetSequence(rotationSegments.Count);
182+
RotationSegments.Add(segment);
183+
segment.Sequence = RotationSegments.Count;
194184
return segment;
195185
}
196186

197187
public int CompareTo(Rotation other)
198188
{
199-
return GetName().CompareTo(other.GetName());
189+
return Name.CompareTo(other.Name);
200190
}
201191

202192
/**
@@ -222,7 +212,7 @@ public override string ToString()
222212
}
223213

224214
string onOff = period.IsWorkingPeriod() ? on : off;
225-
periodsString += period.GetName() + " (" + onOff + ")";
215+
periodsString += period.Name + " (" + onOff + ")";
226216
}
227217

228218
string text = named + "\n" + rper + ": [" + periodsString + "], " + rd + ": " + GetDuration() + ", " + rda

0 commit comments

Comments
 (0)