Skip to content

Instantly share code, notes, and snippets.

@fermopili
Created May 19, 2017 11:31
Show Gist options
  • Save fermopili/0dc02c1212bfcb0c121c343fa4f8f40d to your computer and use it in GitHub Desktop.
Save fermopili/0dc02c1212bfcb0c121c343fa4f8f40d to your computer and use it in GitHub Desktop.
com.javarush.task.task36.task3612
package com.javarush.task.task36.task3612;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
/*
Почему сет не содержит элемент?
*/
public class Solution
{
private Set<Date> dates;
private Date lastDate;
public static void main(String[] args)
{
Solution solution = new Solution ( );
solution.initializeDates ( );
solution.updateLastDate ( 3_600_000L );
System.out.println ( solution.isLastDateContainsInDates ( ) );
}
public boolean isLastDateContainsInDates()
{
return dates.contains ( lastDate );
}
private void initializeDates()
{
dates = new HashSet<> ( );
lastDate = new Date ( 9999999L );
dates.add ( lastDate );
dates.add ( new Date ( 2222222L ) );
dates.add ( new Date ( 3333333L ) );
dates.add ( new Date ( 4444444L ) );
dates.add ( new Date ( 5555555L ) );
}
protected void updateLastDate(long delta)
{
dates.remove ( lastDate );
lastDate.setTime ( lastDate.getTime ( ) + delta );
dates.add (lastDate);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment