added calendar features

This commit is contained in:
shaggy3007 2023-10-23 23:03:10 +02:00
parent 2fe42dc224
commit 7c45335ce8
13 changed files with 369 additions and 2 deletions

View File

@ -0,0 +1,5 @@
package Calendar;
public class Activity {
}

View File

@ -0,0 +1,19 @@
package Calendar;
import java.util.TreeSet;
public enum ActivityType {
Retrieve,
FirstRelease,
Renew,
Shipment,
Lost,
Ruined;
public TreeSet<String> Names () {
TreeSet<String> TMP = new TreeSet<>();
for (var name: ActivityType.values()) {
TMP.add(name.toString());
}
return TMP;
}
}

View File

@ -0,0 +1,5 @@
package Calendar;
public class Calendar {
}

View File

@ -0,0 +1,88 @@
package Calendar;
import java.util.Iterator;
public class Date implements Comparable<Date> , Iterable<Date>{
private int day;
private int month;
private int year;
private static int[] DaysInMonth = {31,28,31,30,31,30,31,30,30,31,30,31};
public Date (int day, int month, int year) {
if (isValid(day, month, year)) {
this.day = day;
this.month = month;
this.year = year;
} else {
this.day = 1;
this.month = 1;
this.year = 2023;
}
}
public Date (Date O) {
this.day = O.day;
this.month = O.month;
this.year = O.year;
}
private boolean isValid(int day, int month, int year) {
if (month > 0 && month < 13) {
if (day > 0 && day <= DaysInMonth[month-1]) {
return true;
}
}
return false;
}
@Override
public int compareTo(Date o) {
if (year == o.year) {
if (month == o.month) {
if (day == o.day) {
return 0;
} else if (day > o.day) {
return 1;
} else return -1;
} else if (month > o.month) {
return 1;
} else return -1;
} else if (year > o.year) {
return 1;
} else return -1;
}
@Override
public Iterator<Date> iterator() {
// TODO Auto-generated method stub
return new Iterator<Date>() {
int nextDay = day+1;
@Override
public boolean hasNext() {
// TODO Auto-generated method stub
return true;
} //there's always the next day :P
@Override
public Date next() {
if (isValid(nextDay,month,year)) {
return new Date(nextDay,month,year);
} else if (month < 12) {
return new Date(1,++month,year);
} else return new Date(1,1,year+1);
}
};
}
public int getDay() {
return day;
}
public int getMonth() {
return month;
}
public int getYear() {
return year;
}
public String toString() {
return day + "/" + month + "/" + year;
}
}

View File

@ -0,0 +1,58 @@
package Calendar;
import java.util.Iterator;
public class Day implements Iterable<Day>,Comparable<Day> {
private Days Name;
private int ordinal;
private Date date;
public Day (Date date, int ordinal) {
this.ordinal = ordinal;
this.Name = Days.values()[ordinal-1];
this.date = date;
}
@Override
public Iterator<Day> iterator() {
return new Iterator<Day>() {
@Override
public boolean hasNext() {
// There' s always a next day
return true;
}
@Override
public Day next() {
if (ordinal == 7) {
return new Day(date.iterator().next(),1);
} else {
return new Day(date.iterator().next(),ordinal+1);
}
}
};
}
@Override
public int compareTo(Day o) {
return this.date.compareTo(o.date);
}
public Days getName() {
return Name;
}
public Date getDate() {
return date;
}
public int getOrdinal() {
return ordinal;
}
public String toString() {
return Name.toString() + ": " + date.toString();
}
}

View File

@ -0,0 +1,11 @@
package Calendar;
public enum Days {
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
Sunday;
}

View File

@ -0,0 +1,11 @@
package Calendar;
public class MainTest {
public static void main(String[] args) {
Month M = new Month(2023,10,Days.Sunday);
System.out.println(M.toString());
}
}

View File

@ -0,0 +1,73 @@
package Calendar;
import java.util.Iterator;
import java.util.TreeSet;
public class Month implements Iterable<Month>,Comparable<Month>{
private Months name;
private int ordinal;
private Date First;
private TreeSet<Week> Weeks = new TreeSet<>();
private static int[] DaysInMonth = {31,28,31,30,31,30,31,30,30,31,30,31};
public Month (int year, int ordinal, Days firstDay) {
this.First = new Date(1,ordinal,year);
name = Months.values()[ordinal-1];
Date tmpDate = new Date(First);
Week tmpWeek = new Week(tmpDate,firstDay.ordinal()+1);
Weeks.add(tmpWeek);
do {
tmpWeek = tmpWeek.iterator().next();
tmpDate = tmpWeek.getWeekDays().last().getDate();
Weeks.add(tmpWeek);
}while(tmpDate.getDay()<DaysInMonth[ordinal-1]);
}
@Override
public int compareTo(Month o) {
// TODO Auto-generated method stub
return First.compareTo(o.First);
}
@Override
public Iterator<Month> iterator() {
// TODO Auto-generated method stub
return new Iterator<Month>() {
@Override
public boolean hasNext() {
// There's always a next month
return true;
}
@Override
public Month next() {
if (ordinal == 12) {
return new Month(First.getYear()+1,1,Weeks.last().getWeekDays().last().getName());
} else {
return new Month(First.getYear(),ordinal+1,Weeks.last().getWeekDays().last().getName());
}
}
};
}
public Months getName() {
return name;
}
public String toString() {
String out = name.toString()+":\n";
for (Week W: Weeks) {
out += W.toString()+ "\n";
}
return out;
}
}

View File

@ -0,0 +1,16 @@
package Calendar;
public enum Months {
January,
February,
March,
April,
May,
June,
July,
August,
September,
October,
November,
December;
}

View File

@ -0,0 +1,61 @@
package Calendar;
import java.util.Iterator;
import java.util.TreeSet;
public class Week implements Iterable<Week>, Comparable<Week> {
private TreeSet<Day> WeekDays = new TreeSet<>();
private static int[] DaysInMonth = {31,28,31,30,31,30,31,30,30,31,30,31};
public Week (Date date,int ordinal) {
Day WeekDay = new Day(date,ordinal);
WeekDays.add(WeekDay);
do{
if (!WeekDay.getName().toString().equals(Days.Sunday.toString())) {
WeekDay = WeekDay.iterator().next();
WeekDays.add(WeekDay);
}
//System.out.println(WeekDay.toString()+" "+DaysInMonth[WeekDay.getDate().getMonth()-1]);
}while(!(WeekDay.getName().toString().equals(Days.Sunday.toString())) && WeekDay.getDate().getDay()<DaysInMonth[WeekDay.getDate().getMonth()-1]);
}
@Override
public Iterator<Week> iterator() {
return new Iterator<Week>() {
@Override
public boolean hasNext() {
// There's always a next week
return true;
}
@Override
public Week next() {
if (WeekDays.last().getOrdinal() == 7) {
return new Week(WeekDays.last().iterator().next().getDate(),1);
} else {
return new Week(WeekDays.last().iterator().next().getDate(),WeekDays.last().getOrdinal() + 1);
}
}
};
}
@Override
public int compareTo(Week o) {
// TODO Auto-generated method stub
return WeekDays.first().compareTo(o.WeekDays.first());
}
public TreeSet<Day> getWeekDays () {
return WeekDays;
}
public String toString() {
String out = "\t";
for (Day D: WeekDays) {
out += " - " + D.toString();
}
out += "\n";
return out;
}
}

View File

@ -0,0 +1,5 @@
package ClientApp;
public class ActivitySelectorPane {
}

View File

@ -0,0 +1,17 @@
package ClientApp;
public class LoginPage extends AbstractAppPane {
@Override
public void gridSetup() {
// TODO Auto-generated method stub
}
@Override
public void textFill() {
// TODO Auto-generated method stub
}
}

View File

@ -5,8 +5,6 @@ import java.util.ArrayList;
public enum UserDataTypes {
Nome,
Cognome,
Città,
Provincia,
Luogo,
Cittàl,
Data,