I need to get the count of records for the current day, from the database. The entries in the Firebase Realtime are in timestamp, I parse them using SimpleDateFormat.
But I could not get the count of records, for example, for today's date. Tell me what to do? Thanks
IMAGE RECORDS IN FIREBASE REALTIME
private void fetchDataWaterCount() {
currDate = null;
String uid = firebaseAuth.getUid();
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
currDate = LocalDate.now().toString();
}
waterRef = FirebaseDatabase.getInstance().getReference("Users").child(uid).child("body").child("water");
waterRef.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot snapshot) {
if (snapshot.exists()) {
for (DataSnapshot ds : snapshot.getChildren()) {
waterModel = ds.getValue(WaterModel.class);
waterArray.add(waterModel);
waterModel.setWaterModelList(waterArray);
ArrayList listDate = new ArrayList();
for (int i = 0; i < waterModel.getWaterModelList().size(); i++) {
long dateList = waterModel.getWaterModelList().get(i).getDate();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
String dateFormat = formatter.format(new Date(dateList));
listDate.add(dateFormat);
if(listDate.contains(currDate)){
int water_count = (int) listDate.size();
drawable = getActivity().getDrawable(R.drawable.circut_progress_bar);
progressBar.setProgress(water_count);
progressBar.setMax(12);
progressBar.setSecondaryProgress(water_count);
progressBar.setProgressDrawable(drawable);
textViewWaterCount.setText(String.valueOf(water_count));
if (water_count >= 12) {
textViewWaterCount.setText("Done");
textViewWaterCount.setTextColor(getResources().getColor(R.color.colorGreen_900));
drawable = getActivity().getDrawable(R.drawable.circut_progressbar_green);
progressBar.setProgressDrawable(drawable);
}
}
}
}
}
}
#Override
public void onCancelled(#NonNull DatabaseError error) {
}
});
}
If you want to know the amount of WaterModels that match a specific date then you need to count them as they appear.
You are currently adding every date to the list regardless if it matches the currDate, so your count is the total dates not the specific amount of specific dates.
//Add this
int dateCount = 0;
for (int i = 0; i < waterModel.getWaterModelList().size(); i++) {
long dateList = waterModel.getWaterModelList().get(i).getDate();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
String dateFormat = formatter.format(new Date(dateList));
listDate.add(dateFormat);
//Add this
if(dateFormat == currDate){
dateCount++;
}
//I don't know what your doing here but this will return true
//if there is at least 1 match. You can't use this to track how many dates
//match
if (listDate.contains(currDate)) {
int water_count = (int) listDate.size();
drawable = getActivity().getDrawable(R.drawable.circut_progress_bar);
progressBar.setProgress(water_count);
progressBar.setMax(12);
progressBar.setSecondaryProgress(water_count);
progressBar.setProgressDrawable(drawable);
textViewWaterCount.setText(String.valueOf(water_count));
if (water_count >= 12) {
textViewWaterCount.setText("Done");
textViewWaterCount.setTextColor(getResources().getColor(R.color.colorGreen_900));
drawable = getActivity().getDrawable(R.drawable.circut_progressbar_green);
progressBar.setProgressDrawable(drawable);
}
}
}
dateCount will contain the total amount of Dates that match the currDate.
Related
There are multiples dates and data (Course and Scale) for each date. Each date and data store under a unique key. The dates are inserted by Date picker.
"Data":{
"K2ngvpioRUYF4bRM07Da5cbAjE53":{ //UID
"-M3jNjCuGdMCwt1Czpwz":{ //unique key
"Date":"2020-3-30",
"Course":"A",
"Scale":"3"
},
"-M5hxnQrCJdCUvRcMZJu":{
"Date":"2020-4-24",
"Course":"A",
"Scale":"3"
}
"-M3jQWxm7z0EQYgkVenX":{
"Date":"2020-4-29",
"Course":"B",
"Scale":"4"
},
"-M5hxn-rCJICUvRcMZJu":{
"Date":"2020-4-24",
"Course":"B",
"Scale":"2"
}
}
}
I would like to calculate the total number of scales based on Course monthly. For scale, if the number is 3, it means 0.6. If the number is 2, it means 0.4. If the number is 4, it means 0.8. So, for the Course A, the total number is 1.2(0.6+0.6). For Course B, the total number is 1.2 (0.8+0.4).
Calendar mCalendar = Calendar.getInstance();
int year = mCalendar.get(Calendar.YEAR);
int month = mCalendar.get(Calendar.MONTH);
final int[] Currmonth = {month + 1}; //this is array because there are other method using this but unnecessary for this question
int lastDay = mCalendar.getActualMaximum(Calendar.DAY_OF_MONTH);
int firstDay=1;
String start=year+"-"+Currmonth[0]+"-"+firstDay;
String end=year+"-"+Currmonth[0]+"-"+lastDay;
DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("Users Mood");
Query range = ref.child(user.getUid()).orderByChild("Date").startAt(start).endAt(end);
range.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
ArrayList<String> courses=new ArrayList<>();
Map<String, Double> hm = new HashMap<>();
for(DataSnapshot ds : dataSnapshot.getChildren()) {
String course=ds.child("Course").getValue(String.class);
courses.add(course);
String scale=ds.child("Scale").getValue(String.class);
for(String i :courses) {
double num=0;
if (hm.get(i).equals("1")) {
num=0.2;
}else if(hm.get(i).equals("2")){
num=0.4;
}else if(hm.get(i).equals("3")){
num=0.6;
}else if(hm.get(i).equals("4")){
num=0.8;
}else if(hm.get(i).equals("5")){
num=1;
}
double total = hm.containsKey(course) ? hm.get(course) : 0;
total += num;
hm.put(course, total);
}
}
for(String key:hm.keySet()) {
Log.d("tag", key+hm.get(key));
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
});
In this case, the query is from the start date of month to end date of the month. The logic for mapping two children is incorrect. I don't think hashmap is suitable for this case because there might be few data with the same course with same scale (For example, there are two same data, Course A with scale 3 or num 0.6). Please help me to correct my logic.
The way you are using your date is not very efficient. Because that would mean 2020-4-12 comes before 2020-4-4. I suggest
//year is integer year
String monthStr = month; //month is integer month
if(month<=9)monthStr="0"+monthStr;
String dateStr = date; //date is integer date
if(date<=9)dateStr="0"+dateStr;
String finalStr = year+"-"+monthStr+"-"+dateStr;
Now that being said, You are using an ArrayList unnecessarily. On contrary to what you said the HashMap can be used here.
Also hm.get(i) would return Double and I dont know why you are comparing it to a string, when you should actually be comparing the string scale. Anyway, Look at this modification I made to your loop body. I hope you know parseDouble which converts a String to its Double equivalent.
for(DataSnapshot ds : dataSnapshot.getChildren()) {
String course=ds.child("Course").getValue(String.class);
String scale=ds.child("Scale").getValue(String.class);
double num= Double.parseDouble(scale)/5.0;
double total = hm.containsKey(course) ? hm.get(course) : 0;
total += num;
hm.put(course, total);
}
for(String key:hm.keySet()) {
Log.d("tag", key+hm.get(key));
}
If you have any doubts fell free to comment.
I have a problem when i set value from sqlite to x-axis label.
this is the picture
And my code of X-axis forrmated is
Axis.setValueFormatter(new IAxisValueFormatter() {
#Override
public String getFormattedValue(float value, AxisBase axis) {
String selectQueryz = "SELECT * FROM table_palembang";
db = new DBHelper(getApplicationContext());
SQLiteDatabase dbz = db.getWritableDatabase();
Cursor cursorz = dbz.rawQuery(selectQueryz, null);
countz = cursorz.getCount();
String[] datez = new String[countz];
ArrayList<String> arral = new ArrayList<>();
for (int k = 0; k < countz; k++) {
cursorz.moveToNext();
datez[k] = cursorz.getString(2);
arral.add(datez[k]);
}
return datez[countz % arral.size()];
}
});
can anyone help me?
thanks ...
ValueFormatter is used to format your data which you set with chart.setData() not to set data itself.
Here is sample code how to format dates
xAxis.setValueFormatter(new IAxisValueFormatter() {
private final SimpleDateFormat mFormat = new SimpleDateFormat("dd MMM HH:mm", Locale.ENGLISH);
#Override
public String getFormattedValue(float value, AxisBase axis) {
long millis = TimeUnit.HOURS.toMillis((long) value);
return mFormat.format(new Date(millis));
}
});
EDIT
I just took a look that you store indices of date array to chart data. If so, you just need to return date from dates array.
String[] datez;
String selectQueryz = "SELECT * FROM table_palembang";
db = new DBHelper(getApplicationContext());
SQLiteDatabase dbz = db.getWritableDatabase();
Cursor cursorz = dbz.rawQuery(selectQueryz, null);
countz = cursorz.getCount();
datez = new String[countz];
for (int k = 0; k < countz; k++) {
cursorz.moveToNext();
datez[k] = cursorz.getString(2);
}
xAxis.setValueFormatter(new IAxisValueFormatter() {
#Override
public String getFormattedValue(float value, AxisBase axis) {
return datez[(int) value];
}
});
P.S. DataBase calls should be in background thread.
This question already has answers here:
Determine Whether Two Date Ranges Overlap
(39 answers)
Closed 5 years ago.
I have set of date ranges, I need to get the combined date range if any of the dates overlap in Java.
Given three sets of date ranges, if any of the dates overlap with another range of dates need to be combined.
Example:
20170101-20170331
20170101-20170430
20170430-20170501
Expected result is:
20170101-20170430
20170430-20170501
I have all the dates in String Variable. Can please any one help me to how to write the code for that. I have pasted below my code.
I want to achieve the expected results. I couldn't find out how I need to modify this code. I am a beginner, please help me to do that. I have got this sample program from StackOverflow.
package com.kkkkk.Combine;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
public class Ideone {
public static void main(String[] args) throws java.lang.Exception {
ArrayList<Interval> x = new ArrayList<>();
x.add(new Interval("20170430", "20170501")); // "20170101", "20170430"
x.add(new Interval("20170101", "20170430"));// 20170101-20170430
x.add(new Interval("20170101", "20170331"));
x = merge(x);
for (Interval i1 : x) {
System.out.println(i1.getStartDate() + " " + i1.getEndDate());
}
}
public static ArrayList<Interval> merge(ArrayList<Interval> intervals) {
if (intervals.size() == 0 || intervals.size() == 1)
return intervals;
ArrayList<Interval> result = new ArrayList<Interval>();
Collections.sort(intervals, new IntervalComparator());
System.out.println("intervals ggggg\n" + intervals + "\n");
Interval first = intervals.get(0);
String start = first.getStartDate();
String end = first.getEndDate();
Date startDateF = null;
Date endDateF = null;
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
startDateF = sdf.parse(start);
endDateF = sdf.parse(end);
// ArrayList<Interval> result = new ArrayList<Interval>();
for (int i = 1; i < intervals.size(); i++) {
Interval current = intervals.get(i);
Date currentEndDate = sdf.parse(current.getEndDate());
Date currentStartDate = sdf.parse(current.getStartDate());
// if ((current.getStartDate().after(endDateF)) ||
Date d1 = minDate(endDateF, currentStartDate);
if ((currentStartDate).compareTo(endDateF) <= 0) {
endDateF = maxDate(currentEndDate, endDateF);
} else {
result.add(new Interval(start, (sdf.format(endDateF))));
// start = current.start;
// end = current.end;
start = sdf.format(currentStartDate);
endDateF = (currentEndDate);
enter code here
}
}
result.add(new Interval(start, end));
// result.add(new Interval(start, (sdf.format(endDateF))));
}
catch (ParseException ex) {
ex.printStackTrace();
}
// result.add(new Interval(start, end));
return result;
// return intervals;
}
public static Date minDate(Date date1, Date date2) {
// if date1 before date2 then return date1 else return date2
return date1.before(date2) ? date1 : date2;
}
/**
* find Max Dates
*
* #param date1
* #param date2
* #return
*/
public static Date maxDate(Date date1, Date date2) {
// if date1 after date2 then return date1 else return date2
System.out.println("date max");
return date1.after(date2) ? date1 : date2;
}
}
ISO 8601
Use standard ISO 8601 formats when serializing date-time values to text. Your format complies with the “basic” version of the standard, but better to use the full format when possible:
YYYY-MM-DD
Use the standard format for a date range, using a slash character as separator:
YYYY-MM-DD/YYYY-MM-DD
If you cannot alter the input strings, split the string on the hyphen. Parse each piece as a LocalDate. Use those objects to instantiate a LocalDateRange.
LocalDate ld = LocalDate.parse( "20170101" , DateTimeFormatter.BASIC_ISO_DATE ) ;
LocalDateRange
Use the LocalDateRange class from the ThreeTen-Extra project which extends java.time class functionality. Uses the standard format when parsing and generating text.
LocalDateRange range = LocalDateRange.parse( "2017-01-01/2017-03-31" ) ;
Collect in a List<LocalDateRange>.
To sort, write a comparator that calls LocalDateRange::getStart.
Compare to another range to see if they overlap. If so, combine with a call to union.
if ( range.overlaps( otherRange ) ) {
range = range.union( otherRange ) ;
}
If they do not overlap, you have finished that round. Store this result in another List<LocalDateRange>. Start another round with the next range.
Lather, rinse, repeat.
I assume your Interval is something like this:
private static class Interval {
private String begin;
private String end;
public Interval(String begin, String end) {
this.begin = begin;
this.end = end;
}
public String getStartDate() {
return begin;
}
public String getEndDate() {
return end;
}
}
What you need to do is to merge a Interval list. A solution is sort list with start date then end date. And then store the earliest start time and latest end time in a cursor variable. A example:
public List<Interval> merge(List<Interval> intervals) {
Collections.sort(intervals, new Comparator<Interval>() {
#Override
public int compare(Interval o1, Interval o2) {
if (o1.getStartDate().equals(o2.getStartDate())) {
return o1.getEndDate().compareTo(o2.getEndDate());
}
return o1.getStartDate().compareTo(o2.getStartDate());
}
});
List<Interval> ret = new ArrayList<>();
String MAX_VAL = "99999999";
String MIN_VAL = "00000000";
String start = MAX_VAL, end = MIN_VAL;
for (Interval interval : intervals) {
if (interval.getStartDate().compareTo(end) > 0) {
if (start.compareTo(MAX_VAL) < 0) {
ret.add(new Interval(start, end));
}
start = interval.getStartDate();
end = interval.getEndDate();
} else {
if (start.compareTo(interval.getStartDate()) < 0) {
start = interval.getStartDate();
}
if (end.compareTo(interval.getEndDate()) > 0) {
end = interval.getEndDate();
}
}
}
if (start.compareTo(MAX_VAL) < 0) {
ret.add(new Interval(start, end));
}
return ret;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
ArrayList<MainLab.Interval> list = new ArrayList<MainLab.Interval>();
list.add(new MainLab.Interval("20170430", "20170501"));
list.add(new MainLab.Interval("20170101", "20170430"));
list.add(new MainLab.Interval("20170101", "20170331"));
for (Iterator iterator = mergeInterval(list).iterator(); iterator.hasNext();) {
Interval interval = (Interval) iterator.next();
System.out.println(interval.getStart()+ "==="+interval.getEnd());
}
}
public static List<Interval> mergeInterval(ArrayList<MainLab.Interval> list){
/*
* Sort the list , Interval class have implemented Comparable Interface.
* So we will get sorted intervals. Intervals sorted based on start of interval
*/
Collections.sort(list);
Set<MainLab.Interval> resultlist = new TreeSet<MainLab.Interval>();
List<MainLab.Interval> mergedIntervals = new ArrayList<MainLab.Interval>();
//declare date formate to parse and format date from string to and from
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
if(list.size() == 1){
//resultlist = list
return list;
}
if(list.size() > 1){
// get first interval Object. conside it as first interval
Interval mergeInterval = list.get(0);
// loop other intervals from second in the list
for(int i=1; i< list.size() ; i++){
Interval interval2 = list.get(i);
try{
Date startDate1 = sdf.parse(mergeInterval.getStart());
Date endDate1 = sdf.parse(mergeInterval.getEnd());
Date startDate2 = sdf.parse(interval2.getStart());
Date endDate2 = sdf.parse(interval2.getEnd());
// compare if current interval's start date is before merging interval's end date
// then the two intervals are overlaping
if(startDate2.compareTo(endDate1) < 0 ){
// check whether end date of current loop interval is after the merging interval.
// then we need to update the end date of merging interval with looping interval's end date
if(endDate2.compareTo(endDate1) > 0 ){
mergeInterval.setEnd(interval2.getEnd());
}
}else{
// compare if current interval's start date is after merging interval's end date
// then it must be a new interval start so swap mergInterval variable with current looping interval
mergeInterval = interval2;
}
//add merge interval to set.
resultlist.add(mergeInterval);
}catch(Exception ex){
ex.printStackTrace();
}
}
}
mergedIntervals.addAll(resultlist);
return mergedIntervals;
}
public static class Interval implements Comparable<Interval>{
private String start;
private String end;
public String getStart() {
return start;
}
public void setStart(String start) {
this.start = start;
}
public String getEnd() {
return end;
}
public void setEnd(String end) {
this.end = end;
}
public Interval(){
}
public Interval(String start,String end){
this.start = start;
this.end = end;
}
#Override
public boolean equals(Object obj) {
// TODO Auto-generated method stub
Interval inteval = (Interval)obj;
return this.getStart().equals(inteval.getStart()) && this.getEnd().equals(inteval.getEnd()) ;
}
#Override
public int compareTo(Interval o) {
// TODO Auto-generated method stub
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
try{
Date startDate = sdf.parse(start);
Date endDate = sdf.parse(end);
Date pstartDate = sdf.parse(o.start);
Date pendDate = sdf.parse(o.end);
return startDate.compareTo(pstartDate);
}catch(Exception ex){
ex.printStackTrace();
}
return 0;
}
}
I want to add a number of months to a specific date based on what that user selected. for instance adding 3 months to 15/05/2015.
I tried something but its showing me the same date.
Code below:
Calendar aed = Calendar.getInstance();
int monthsToAdd = 0;
if (advertPostedDate.equals(1)) {
monthsToAdd = 1;
}
if (advertPostedDate.equals(2)) {
monthsToAdd = 2;
}
if (advertPostedDate.equals(3)) {
monthsToAdd = 3;
}
aed.add(Calendar.MONTH, monthsToAdd);
Date advertED = aed.getTime();
DateFormat df = new SimpleDateFormat("dd-MM-yyyy");
String advertExpiryDate = df.format(advertED);
Your code looks fine, with exception that I would use an if/else if structure instead of just the if structure. Are you sure advertPostedDate has a value of 1, 2, or 3? Because if it doesn't then 0 is being added to months.
public static void main(String[] args) {
Integer advertPostedDate = 2;
Calendar aed = Calendar.getInstance(); // 15-5-2015
int monthsToAdd = 0;
if (advertPostedDate.equals(1)) {
monthsToAdd = 1;
} else if (advertPostedDate.equals(2)) {
monthsToAdd = 2;
} else if (advertPostedDate.equals(3)) {
monthsToAdd = 3;
}
aed.add(Calendar.MONTH, monthsToAdd);
Date advertED = aed.getTime();
DateFormat df = new SimpleDateFormat("dd-MM-yyyy");
String advertExpiryDate = df.format(advertED);
System.out.println(advertExpiryDate);
}
Results:
15-07-2015
I suggest that you use Joda-Time
DateTime dt = new DateTime(2015, 5, 15, 12, 0, 0, 0);
DateTime plusPeriod = dt.plusMonths(3);
I want to randomly generate times and numbers.. Here I used hashmap generate some records. Now I can generate the numbers but I cant separate them. I have to separate the values so that I can set those in database..
Here is my code...
public class DateTimePopulation {
private Random rand = new Random();
private Date theDay;
private String callDuration = null;
private String endDay = null;
SimpleDateFormat mytimeFormat = new SimpleDateFormat("HH:mm:ss");
public static void main(String[] args) throws ParseException {
DateTimePopulation d = new DateTimePopulation();
for (int i = 1; i <= 3; i++) {
Map rec = d.getRecord();
for (int j = 0; j < rec.size(); j++) {
Collection c = rec.values();
Iterator itr = c.iterator();
int count=0;
while (itr.hasNext()) {
Object element=itr.next();
System.out.println(element);
}
System.out.println();
}
}
}
private Map getRecord() {
Map<String, Object> rec = new LinkedHashMap<String, Object>();
Date startDate;
try {
startDate = getRandStartDate();
rec.put("StartTime", startDate);
int start = 7200000, end = 0;
int duration = getRandDuration(start, end);
rec.put("Duration", duration);
Date endDate = getRandEndDate(startDate, duration);
rec.put("EndTime", endDate);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rec;
}
private Date getRandEndDate(Date startDate, int duration) {
Random r = new Random();
int ranSec = r.nextInt(duration - 0) + 0;
return new Date(startDate.getTime() + ranSec * 1000);
}
private int getRandDuration(int High, int Low) {
Random r = new Random();
return r.nextInt(High - Low) + Low;
}
private Date getRandStartDate() throws ParseException {
Date theDay = new SimpleDateFormat("yyyyMMdd hh:mm:ss")
.parse("20130101 00:00:00");
int High = 60 * 60 * 24 * 30 * 6;
Random r = new Random();
int Low = 10;
int R = r.nextInt(High - Low) + Low;
return new Date(theDay.getTime() + R * 1000);
}
}
Here is the output. I am showing 2 set of it. I have to separate the time, duration etc.
Tue Jan 08 11:01:57 IST 2013
6074479
Fri Jan 18 12:56:24 IST 2013
Firstly, your design is strange to start with - why are you calling getRecord() on an instance, when it doesn't do anything with the fields of the object you're calling it on?
Additionally, when you're iterating over a map, you're actually iterating over the same map 3 times:
for (int j = 0; j < rec.size(); j++) {
Collection c = rec.values();
Iterator itr = c.iterator();
int count=0;
while (itr.hasNext()) {
Object element=itr.next();
System.out.println(element);
}
System.out.println();
}
Your outer loop is pointless here - you're never using j, after all. I would probably iterate over the entries rather than the values, if you really want to - then you can print out the key which goes with each value.
Next, I would encourage you not to use a map for this at all - create a separate type with fields for start time, duration and end time. That will fix things very simply.
Next, if you still want to use a map, stop using the raw types - it'll make your life simpler.
Finally, if you really still want to use a map, you already know the keys, so there's no point in iterating over it:
System.out.println("Start: " + map.get("StartTime");
System.out.println("Duration: " + map.get("Duration");
System.out.println("End: " + map.get("EndTime");
Basically, I strongly suggest that you take a step back and revisit your whole design. You may well find it's better to start from scratch than to change your existing code.
Try to generify this code:
private Map getRecord() {
Map<String, Object> rec = new LinkedHashMap<String, Object>();
Date startDate;
try {
startDate = getRandStartDate();
rec.put("StartTime", startDate);
int start = 7200000, end = 0;
int duration = getRandDuration(start, end);
rec.put("Duration", duration);
Date endDate = getRandEndDate(startDate, duration);
rec.put("EndTime", endDate);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rec;
}
Something like that:
private DateInterval getRecord() {
DateInterval interval = null;
try {
Date startDate = getRandStartDate();
int start = 7200000, end = 0;
int duration = getRandDuration(start, end);
Date endDate = getRandEndDate(startDate, duration);
interval = new DateInterval(startDate, endDate, duration);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return interval;
}
See also:
public class DateInterval {
private Date startDate;
private Date endDate;
private int duration;
public DateInterval(Date startDate, Date endDate, int duration) {
this.startDate = startDate;
this.endDate = endDate;
this.duration = duration;
}
public Date getStartDate() {
return startDate;
}
public Date getEndDate() {
return endDate;
}
public int getDuration() {
return duration;
}
}
I mean, you don't need Map for this purpose, use the your own entity. If you need to hold all your entities at Collection, use Map with DB UUIDs as a keys or List.