Sorting a date represented in three integers.

Hey,
I have an other question. I want to sort a collection on the data. In my collection I have three integers representing the date (int matchDay, int matchMonth, int matchYear)
The constructor for the Collection<Comment> is:
public Comment(int matchID, int matchDay, int matchMonth, int matchYear, String namePlayer, String comments) I want the comments which happened at the beginning at the bottom and the comments which just happened at the top. So, I want to sort in a decending order.
I tried to sort with severly options. The most likely which I thought was to succed, is this code:
// To sort Comments selection
public Collection<Comment> sortCommentCollection(Collection<Comment> comments) {
    Collection<Comment> backup = new ArrayList<Comment>();
    String DATE_FORMAT = "yyyy-MM-dd";
    java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(DATE_FORMAT);
    Calendar c1 = Calendar.getInstance();
    Calendar c2 = Calendar.getInstance();
    int year = 1000, month = 00, day = 00, x = 0;
    boolean attached = false;
    for(Comment c : comments) {
        // remember months are zero-based : 0 jan 1 feb ...
        c1.set(year, month, day);
        c2.set(c.getMatchYear(), c.getMatchMonth() , c.getMatchDay());
        if (c1.before(c2) && !attached) {
            // Remove 'older' comment before adding this comment
            backup.remove(x - 1);
            Comment temporary = new Comment(c.getMatchID(), c.getMatchDay(), c.c.getMatchMonth(), c .c.getMatchYear(), c.getNamePlayer(), c.getComments());
            backup.add(temporary);
            attached = true;
        if (c1.after(c2) && !atteched) {
            Comment temporary = new Comment(c.getMatchID(), c.getMatchDay(), c.c.getMatchMonth(), c .c.getMatchYear(), c.getNamePlayer(), c.getComments());
            backup.add(temporary);
            attached = true;
        if (c1.equals(c2)) {
            // To prevent double entries
            backup.remove(x - 1);
        year = c.getMatchYear();
        month = c.getMatchMonth();
        day = c.getMatchDay();
        attached = false;
        x++;
        return backup;
}But this did not work either. Does anyboedy have a suggestion? You would help me a lot! Thanks in advance.

Vinvar wrote:
I want to sort a collection on the data. In my collection I have three integers representing the date (int matchDay, int matchMonth, int matchYear)Just add another integer representing roughly the days since Jesus' birth, then you can simply sort by that.
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Random;
public class Comment
     private final int _year;
     private final int _month;
     private final int _day;
     private final int _jesus;
     private final String _string;
     public Comment(int year, int month, int day)
          _year = year;
          _month = month;
          _day = day;
          // calculate approx. days since Jesus' birth
          _jesus = (_year * 12 + _month) * 31 + _day;
          _string = String.format("%02d-%02d-%04d", _month, _day, _year);
     public int getMatchYear()
          return _year;
     public int getMatchMonth()
          return _month;
     public int getMatchDay()
          return _day;
     public int getJesus()
          return _jesus;
     @Override
     public String toString()
          return _string;
class DescendingComments implements Comparator<Comment>
     @Override
     public int compare(Comment o1, Comment o2)
          return o2.getJesus() - o1.getJesus();
class TestComment
     public static void main(String[] args)
          List<Comment> comments = new ArrayList<Comment>();
          Random rand = new Random();
          for (int i = 0; i < 10; ++i)
               comments.add(new Comment(
                         rand.nextInt(2000),
                         rand.nextInt(12) + 1,
                         rand.nextInt(31) + 1));
          System.out.println(comments);
          Collections.sort(comments, new DescendingComments());
          System.out.println(comments);
}

Similar Messages

  • Love Icloud Reminders but Why Not Sorting by Date?

    Have Icloud reminders on Ipad Air.  Love this application however all the reminders are only sorted by date when I click the "Scheduled" category. 
    Why is there no feature that permits this sorting outside of "Scheduled" category.  Seems like a big flaw to me.

    You may already know this but you can manually sort them by tapping Edit, then dragging the three stacked lines icon to the right of each reminder to a different position in the list, then dropping.

  • Need to arrange photos according to date/time taken, three synced cameras

    Hello, we recently shot a wedding using three different cameras (with inner clocks synced).  Now I need to combine them into one folder and arrange in correct sequence according to date/time taken.  Can't figure this out.  Using Photoshop full version.

    Put them in one folder and in Bridge Sort by date created.

  • Trying to compare three integers... and failing miserably

    I had to write this application for Java class I am taking. Everything works except for comparing the numbers. For some reason, it always outputs that number1 is greatest, And number2 is least. What am I doing wrong?
    import javax.swing.*;
    * Assignment 2.18
    * Write an application that asks the user to input three integer values, and then outputs The sum, product, average and the least and greatest of the integers.
    public class CalcGUI
        // main method begins execution of Java application
        public static void main( String args[] )
            String firstNumber;    // first string entered by user
            String secondNumber; // second string entered by user
            String thirdNumber; // third string entered by user
            String result; // string containing the greater And lesser outputs
            int number1;    // first number to add
            int number2;    // second number to add
            int number3;    // third number to add
            int sum;    // sum of number1 and number2 and number3
            int product;    // product of number1 and number2 and number3
            int average;    // average of number1, number2 and number3
            // read in first number from user as a string
            firstNumber = JOptionPane.showInputDialog( "Enter First Integer" );
            // read in second number from user as a string
            secondNumber = JOptionPane.showInputDialog( "Enter Second Integer" );
            // read in third number from user as a string
            thirdNumber = JOptionPane.showInputDialog( "Enter Third Integer" );
            // convert numbers from type String to type int
            number1 = Integer.parseInt( firstNumber );
            number2 = Integer.parseInt( secondNumber );
            number3 = Integer.parseInt( thirdNumber );
            // add numbers
            sum = number1 + number2 + number3;
            // multiply numbers
            product = number1 * number2 * number3;
            // average of numbers
            average = (number1 + number2 + number3) / 3;
            //  compare numbers -- initialize result to empty String
            result = "";
            if ( number1 < number2 )
            if ( number2 < number3 )
            if ( number1 < number3 )
            result = number3 + " is greatest. And " + number1 + " is least.";
            if ( number1 == number2 )
            if ( number2 == number3 )
            if ( number1 == number3 )
            result = number3 + " is greatest. And " + number1 + " is least.";
            if ( number1 > number2 )
            if ( number2 > number3 )
            if ( number1 > number3 )
            result = number1 + " is greatest. And " + number3 + " is least.";
            if ( number1 < number2 )
            if ( number2 > number3 )
            if ( number3 < number1 )
            result = number3 + " is greatest. And " + number1 + " is least.";
            if ( number1 < number2 )
            if ( number2 > number3 )
            if ( number1 < number3 )
            result = number2 + " is greatest. And " + number1 + " is least.";
            if ( number1 > number2 )
            if ( number2 < number3 )
            if ( number1 > number3 )
            result = number1 + " is greatest. And " + number2 + " is least.";
            if ( number1 < number2 )
            if ( number2 == number3 )
            if ( number1 < number3 )
            result = number2 + " is greatest. And " + number1 + " is least.";
            if ( number1 < number2 )
            if ( number2 > number3 )
            if ( number1 == number3 )
            result = number2 + " is greatest. And " + number1 + " is least.";
            if ( number1 == number2 )
            if ( number2 > number3 )
            if ( number1 > number3 )
            result = number2 + " is greatest. And " + number3 + " is least.";
            if ( number1 == number2 )
            if ( number2 < number3 )
            if ( number1 < number3 )
            result = number3 + " is greatest. And " + number1 + " is least.";
            if ( number1 < number2 )
            if ( number2 > number3 )
            if ( number1 == number3 )
            result = number2 + " is greatest. And " + number1 + " is least.";
            if ( number1 > number2 )
            if ( number2 == number3 )
            if ( number1 > number3 )
            result = number1 + " is greatest. And " + number3 + " is least.";
            // display result
             JOptionPane.showMessageDialog( null, "The Sum is " + sum,
                 "Results", JOptionPane.PLAIN_MESSAGE );
            // display result part two
             JOptionPane.showMessageDialog( null, "The Product is " + product,
                 "Results", JOptionPane.PLAIN_MESSAGE );
            // display result part three
             JOptionPane.showMessageDialog( null, "The Average is " + average,
                 "Results", JOptionPane.PLAIN_MESSAGE );
            // display result part four
             JOptionPane.showMessageDialog( null, result,
                 "Results", JOptionPane.PLAIN_MESSAGE );
             System.exit( 0 );      // terminate application with window
        }    // end method main
    }    // end class Addition
    [/code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    First, you need something like this;-
    average = (int)((number1 + number2 + number3) /3 + 0.5);The division in this formula is an integer division, so the result is an integer. Adding double 0.5 to an integer then converting to an integer will result in the original integer.
    The average of three integers will be a rational, so may be represented as floating point or a ratio. In general an integer would be wrong, so either use
    double average = sum / 3.0;
    or
    int average = sum/3;
    int averageRemainder = sum%3;
    System.out.println("The average is" + average + (average_remainder==0 ? "" : (" "+averageRemainder+"/3"));
    Just use
    Math.min(Math.min(number1, number2), number3);
    and Math.max(Math.max(number1, number2), number3);How exactly would I put this into my code? Is the assignment to get the highest number, or the place of the highest number?
    If you want the greatest or least values:int greatest = Math.max(Math.max(number1, number2), number3);
    int least = Math.min(Math.min(number1, number2), number3);Orint greatest = number1;
    if (number2 > greatest) {
      greatest = number2;
    if (number3 > greatest) {
      greatest = number3;
    int least = number1;
    if (number2 < least) {
      least = number2;
    if (number3 < least) {
      least = number3;
    }If you want the places:int greatest = number1;
    int greatestPlace = 1;
    if (number2 > greatest) {
      greatest = number2;
      greatestPlace = 2;
    if (number3 > greatest) {
      greatest = number3;
      greatestPlace = 3;
    int least = number1;
    int leastPlace = 1;
    if (number2 < least) {
      least = number2;
      leastPlace = 2;
    if (number3 < least) {
      leastPlace = 3;
    System.out.println("number"+greatestPlace+" was the greatest "+
                       "and number"+leastPlace+" was the least");Pete

  • HT4221 I really want my Apple TV, iPad and iPhone to sort them in date taken like in iPhoto on my iMac. How do I do that? Sorting on date modified seems so stupid to me, why would anyone need this? Date taken gives a timeline in your event.

    I really want my Apple TV, iPad and iPhone to sort them in date taken like in iPhoto on my iMac. How do I do that? Sorting on date modified seems so stupid to me, why would anyone need this? Date taken gives a timeline in your event.

    The unix commands you need are:
    GetFileInfo
    SetFileInfo
    and maybe find
    for cryptic details use the man command
    Macintosh-HD -> Applications -> Utilities -> Terminal
    man SetFileInfo
    You may use the SetFileInfo command to set the file type & the program which will open the file.
    # This little gem will do a get info on all files in a directory.
    mac $ ls  | xargs -I {} GetFileInfo "{}"
    file: "/Users/mac/playdoc/oddadocodd"
    type: ""
    creator: ""
    attributes: avbstclinmedz
    created: 05/01/2011 14:53:22
    modified: 05/01/2011 14:53:22
    file: "/Users/mac/playdoc/one.docx"
    type: ""
    creator: ""
    attributes: avbstclinmedz
    created: 05/01/2011 13:57:48
    modified: 05/01/2011 13:57:48
    file: "/Users/mac/playdoc/oneLineFile"
    type: "TEXT"
    creator: "!Rch"
    attributes: avbstclinmedz
    created: 05/07/2011 14:27:17
    modified: 05/07/2011 14:27:17
    file: "/Users/mac/playdoc/oneLineFile.txt"
    type: "TEXT"
    creator: "!Rch"
    attributes: avbstclinmedz
    created: 05/07/2011 14:27:49
    modified: 05/07/2011 14:27:49
    file: "/Users/mac/playdoc/three.docx"
    type: ""
    creator: ""
    attributes: avbstclinmedz
    created: 05/01/2011 13:58:03
    modified: 05/01/2011 13:58:03
    file: "/Users/mac/playdoc/two.docx"
    type: ""
    creator: ""
    attributes: avbstclinmedz
    created: 05/01/2011 13:57:56
    modified: 05/01/2011 13:57:56
    file: "/Users/mac/playdoc/weirder.doc.docx"
    type: ""
    creator: ""
    attributes: avbstclinmedz
    created: 05/01/2011 14:50:03
    modified: 05/01/2011 14:50:03
    # well, ! is a funnie character so we escape it.
    mac $ SetFile -t TEXT -c \!Rch two.docx
    mac $ GetFileInfo two.docx
    file: "/Users/mac/playdoc/two.docx"
    type: "TEXT"
    creator: "!Rch"
    attributes: avbstclinmedz
    created: 05/01/2011 13:57:56
    modified: 05/01/2011 13:57:56
    mac $
    mac $ date
    Sat May  7 14:40:56 EDT 2011
    mac $

  • Sort Table Data

    is there any way to sort tabel data in livecycle like in excel or word tables?

    I put the attached together to demonstrate sorting a static table. If you have a dynamic table then changes will be required. The table header row contains three buttons. When you click Club, Home or Founded all three columns are sorted. I just reverse sort on each click.
    I attached the same script to the click event of all three buttons. Optimize as you see fit. The click event on the Club button is as follows:
    // form1.page1.table.header.clubBtn::click - (JavaScript, client)
    var clubArray = new Array();
    var homeArray = new Array();
    var foundedArray = new Array();
    for (var i=0; i < 4; i++) {
      var club = xfa.resolveNode("form1.page1.table.row[" + i + "].club").rawValue;
      clubArray.push(club);
      var home = xfa.resolveNode("form1.page1.table.row[" + i + "].home").rawValue;
      homeArray.push(home);
      var founded = xfa.resolveNode("form1.page1.table.row[" + i + "].founded").rawValue;
      foundedArray.push(founded);
    clubArray.reverse();
    homeArray.reverse();
    foundedArray.reverse();
    for (var i=0; i < 4; i++) {
      xfa.resolveNode("form1.page1.table.row[" + i + "].club").rawValue = clubArray[i];
      xfa.resolveNode("form1.page1.table.row[" + i + "].home").rawValue = homeArray[i];
      xfa.resolveNode("form1.page1.table.row[" + i + "].founded").rawValue = foundedArray[i];
    Steve

  • Can't sort by date created in Bridge

    I have raw files from two photographers that covered the same event. When I combined them in a folder in Bridge and apply view >sort>by date created, the images are only arranged in chronological order within each photographer's photos and not as a whole. How can I get both groups of photos to sort together by date created?

    It should work as you expected, that is if both have correct time settings
    in their dSLR set.
    First try the purge cache for folder option, while pointing Bridge at the
    problem folder go to the menu tools/cache/purge cache for folder and let the
    cache build again for the files in this folder before you give it a try.
    How can I get both groups of photos to sort together by date created?

  • Not able to show data of prior three quarters,periods along with QTD , MTD

    My requirement is when user selects a date then we have to show data in the report for three ago quarters data and QTD, three ago periods data and MTD.
    eg: let the user selects a date in the 2010 Q 2(May-21-2010) then report should show
    2010 Q 1, 2009 Q 3, 2009 Q 2, QTD(2010Q2 till 21st May), Feb-10, Mar-10, Apr-10, May-10 (MTD till 21st May).
    I have created Ago metrics, Todate time series metrics for quarters and periods...
    but Ago metrics are not working when Todate metrics are filtered with date prompt,
    if I remove date filter then Todate metrics are not working (means not showing correct results).
    Also I tried to create logical columns in BMM layer by using filter condition with enterprise qtr, enterprise periods.
    but major problem is I am unable to go back to previous quarters and periods for the date user selected.
    I am struggling for it a lot, Please assist me
    Any response is highly appreciated.
    Thank you,
    Ramanujan.

    found the problem
    thanks

  • I just upgraded to the latest version of iTunes and it duplicated virtually every track in my music library. I need a quick way to delete the duplicates. Sorting by "Date Added" will not help because they are all listed as added on 12/12/2011.

    Library Duplicated
    I just updated to the latest version of iTunes and it duplicated virtually every track in my library. I need a quick way to delete the duplicates. Sorting by "Date Added" will not work, because every track is listed as added on 12/12/2011 even though this happened today 12/19/2011.

    I've written a script called DeDuper which can help remove unwanted duplicates. See this  thread for background.
    tt2

  • I have downloaded and installed the latest version of numbers on my mac. Everytime I save and then try to reopen that document, I receive a message telling me that I need a new version of numbers. Also, when I try to sort the date column, it sorts out of

    I have downloaded and installed the latest version of numbers on my mac. Everytime I save and then try to reopen that document, I receive a message telling me that I need a new version of numbers. Also, when I try to sort the date column, it sorts out of order. The last version sorted fine.

    Welcome to Apple Support Communities
    When you install the new iWork version, the old iWork version is kept, so it looks like you are opening your old version.
    To fix this, open a Finder window, choose Applications in the sidebar and drag the new Numbers version to the Dock, so you can access to it quickly. Open all documents from this version. I don't recommend you to delete the old Numbers version in case you need it.
    Respecting to the second question, you will get better answers in the Numbers for OS X forum

  • In iPhoto if I select View, then Sort Photos by title, how do I stop it reverting to sorting by date when I close iPhoto and re-open it later?

    In iPhoto if I select View, then Sort Photos by title, how do I stop it reverting to sorting by date when I close iPhoto and re-open it later?

    In what mode, Events, Photos or in an Album, are you when you select View ➙ Sort ➙ By Title?
    As a first fix attempt try the following:
    1 - delete the iPhoto preference file, com.apple.iPhoto.plist, that resides in your
         User/Home/Library/ Preferences folder.
    2 - delete iPhoto's cache file, Cache.db, that is located in your
    User/Home/Library/Caches/com.apple.iPhoto folder (Snow Leopard and Earlier).
    or with Mt. Lion from the User/Library/Containers/com.apple.iPhoto/
    Data/Library/Caches/com.apple.iPhoto folder
    3 - launch iPhoto and try again.
    NOTE 1: If you're moved your library from its default location in your Home/Pictures folder you will have to point iPhoto to its new location when you next open iPhoto by holding down the Option key when launching iPhoto.  You'll also have to reset the iPhoto's various preferences.
    NOTE 2:  In Lion and Mountain Lion the Library folder is now invisible. To make it permanently visible enter the following in the Terminal application window: chflags nohidden ~/Library and hit the Enter button - 10.7: Un-hide the User Library folder.
    OT

  • IPhoto, sort by date is not a true date/time sort

    In iPhoto, sort by date is not a true date/time sort.  If you have two cameras with there own naming convention iPhoto sorts filename by date separating the two cameras in the view. Is there a way to sort by DATE&TIME ONLY?

    Using two cameras using iPhoto to upload pictures.
    Both cameras are set to the correct time and date.
    Connect camera ONE filenames IMGP0101
    By default:
    No event name
    Split events checked
    Select import 12 photos
    Creates events:
    Untitled event December 27, 2013
    In order by time
    Untitled event December 28, 2013
    In order by time
    Untitled event December 29, 2013
    In order by time
    Untitled event December 30, 2013
    Connect camera TWO filenames IMG_1101
    By default:
    No event name
    Split events checked
    Select import 12 photos
    Creates events:
    Untitled event December 28, 2013
    In order by time
    Untitled event December 29, 2013
    In order by time
    Untitled event December 30, 2013
    Now I have 2 events for each of December 28, 29 and 30 they are not all under the same event name. My only option is to click and drag the pictures from the second set of events to the first set of events then they are in order.  This is a real pain to do.  There needs to be a way to reset the event dates so all pictures from both cameras end up in the right event date.

  • List View: How to force update of *actual* file dates when sort by date?

    List View: How do I force and update of actual file dates when sort by date?
    When I go in, I often see the sort order and dates from 12-15 hours ago!
    not good

    Hi, did you ever get that Windows® Sharing thing worked out?
    On this problem, If it's just that you need the Finder to wake up to the fact that it needs to update the window give a try with Refresh Finder - 1.3...
    http://www.versiontracker.com/dyn/moreinfo/macosx/33066

  • I-photo:  I used 2 cameras to take pictures on a trip --- i have put the pictures from both cameras into an album --- when i click on view and then sort by date, the pictures do not sort by date --- any ideas on how to get the pics sorted by date?

    I-photo:  I used 2 cameras to take pictures on a trip --- i have put the pictures from both cameras into an album --- when i click on view and then sort by date, the pictures do not sort by date --- any ideas on how to get the pics sorted by date?

    Select all the photos that you need to change, then click the "Photos" menu and choose "Adjust Date and Time".
    If you add a year, it will adjust all the photos that you selected by adding a year (so if you accidentally select one of the photos that already has "2012", that will change to "2013"). 

  • When I drag music from a folder that contains songs by different artists and then sort by date added it shows the songs in alphabetical order by artist?

    When I drag a bunch of songs with different artists from a folder on my computer to the itunes library and sort by Date added it puts them into alphabetical order by artist. I am able to workaround this by using date modified. Why does itunes do this? This started happening in July. Prior to that never had this problem. Been adding my music the same way for almost a decade.

    They are added in the same minute. I do not see the second area next to that if it should be. I'm guessing an update to a newer itunes build is responsible. It's a shame. I am using the sort by date modified. But now whenever I modify a file in Itunes it automatically moves it to the top of the list. I am trying to keep the newest stuff at the top of my itunes.

Maybe you are looking for