Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
107 views
in Technique[技术] by (71.8m points)

java - How do I auto flag related records in an arraylist based on date and time?

I'm designing a simple covid 19 tracking system. The system creates Visits object that is stored in an ArrayList everytime a Customer(objects in ArrayList) visits a Shop(objects in ArrayList).

The superclass Details.

public class Details {

  private String name;
  private String phoneNumber;
  private Status status;

  // Customer
  public Details(String name, String phoneNumber, Status status) {
    this.name = name;
    this.phoneNumber = phoneNumber;
    this.status = status;
  }

I'm using java.time package to create the datetime along with Visit object like so

public class Visit extends Details {
    
    private String dateTimeFinal;
    private String shopName;
    
    public Visit(String name, String phoneNumber,String shopName, Status status) {
        super(name, phoneNumber, status);
        this.shopName = shopName;
        LocalDateTime dateTime = LocalDateTime.now();
        DateTimeFormatter dateTimeFormatted = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");
        dateTimeFinal = dateTime.format(dateTimeFormatted);
    }

My customer class constructor looks like this

public class Customer extends Details {
  
  private String password;

  public Customer (String name, String phoneNumber, String password, Status status){
    super(name, phoneNumber, status);
    this.password = password;
  }

My shop class constructor looks like this

public class Shop extends Details{

  private String managerName;
  
  public Shop(String name, String phoneNumber, Status status, String managerName){
    super(name, phoneNumber, status);
    this.managerName = managerName;
  }

I also have a Status enum in another file that looks like this

public enum Status{
  NORMAL,
  CASE,
  CLOSE    
}

What I'm trying to accomplish now is, if a customer that has been flagged as CASE visits a Shop, all customers that also visit the shop within a 1 hour time range before & after automatically gets flagged as a close contact (CLOSE). I also want know how to create time&date that is not localdatetime.now, because I need to generate visits to test if the flagging algorithm works or not.

question from:https://stackoverflow.com/questions/65650037/how-do-i-auto-flag-related-records-in-an-arraylist-based-on-date-and-time

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use one of the LocalDateTime.of() methods (found here) to create a specific time.

To keep track of possible flags, one solution would be to keep track of the last risky Visit for a Shop, and each time a new visit is made to that Shop to check if it is recent enough, and if so update the Status of the Visit, Shop, and Customer. Use LocalDateTime.minusHours() to compare the times.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...