Results 1 to 4 of 4
  1. #1
    TeKay92 is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default problem with an counter class

    Hey, could you please help me.

    This class should count how often an IP address appears ​​in a given interval of time.

    Example: 192.168.3.12, 1 Jan 2012 00:00:00 GMT

    If the same IP appears in the next 5 minutes the counter increase.


    But now my problem.. i don't know how to give every IP address an List with dates..

    Thx 4 help!

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: problem with an counter class

    Well, you could do it lots of ways. You could model the ip/date/count combo as an object or you could use a HashMap or combine the two. You could really do it 100 different ways. What have you done so far?

  3. #3
    TeKay92 is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default Re: problem with an counter class

    Thx for your answer!

    I've solved the problem now and used the hashMap like u described.
    Here is my code:
    [JAVA]
    public static int add(String value, Date currentDate) {
    ArrayList<Date> dateList = map.get(value);

    if (dateList == null) {
    dateList = new ArrayList<Date>();
    map.put(value, dateList);
    }
    dateList.add(currentDate);

    int count = 0;

    for (int i = 0; i < dateList.size(); i++) {
    Date dateInList = dateList.get(i);
    if (currentDate.getMinutes() - 5 < dateInList.getMinutes()) {
    count++;
    } else {
    dateList.remove(i);
    i--;
    }
    }

    return count;
    }

    [/JAVA]

  4. #4
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: problem with an counter class

    Cool, grats. In the future, use code tags to make your code more legible! :D

Similar Threads

  1. Letter counter homework problem
    By Djgnl in forum New To Java
    Replies: 15
    Last Post: 09-24-2011, 03:37 AM
  2. Counter problem
    By Razpet22 in forum NetBeans
    Replies: 5
    Last Post: 06-14-2011, 09:27 PM
  3. Increment Counter for ID
    By blkshrk81 in forum New To Java
    Replies: 6
    Last Post: 12-01-2010, 02:25 AM
  4. Counter
    By ks1615 in forum New To Java
    Replies: 6
    Last Post: 02-20-2009, 04:02 AM
  5. Frequency Counter
    By justlearning in forum New To Java
    Replies: 0
    Last Post: 05-07-2008, 11:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •