Click here to Skip to main content
15,886,110 members
Home / Discussions / Java
   

Java

 
AnswerRe: Insert blob from android to oracle Pin
Richard MacCutchan17-Jun-13 21:18
mveRichard MacCutchan17-Jun-13 21:18 
QuestionJava Scanner Pin
User 100606655-Jun-13 22:47
User 100606655-Jun-13 22:47 
AnswerRe: Java Scanner Pin
Richard MacCutchan5-Jun-13 23:34
mveRichard MacCutchan5-Jun-13 23:34 
QuestionHow to send Email using VB 6.0 Pin
Saranya-from-Tamil-Nadu-India4-Jun-13 1:50
Saranya-from-Tamil-Nadu-India4-Jun-13 1:50 
SuggestionRe: How to send Email using VB 6.0 Pin
AlphaDeltaTheta4-Jun-13 5:36
AlphaDeltaTheta4-Jun-13 5:36 
QuestionParallel processing of two methods in main class Pin
Sachin k Rajput 1-Jun-13 0:30
Sachin k Rajput 1-Jun-13 0:30 
AnswerRe: Parallel processing of two methods in main class Pin
Richard MacCutchan1-Jun-13 4:28
mveRichard MacCutchan1-Jun-13 4:28 
QuestionPut and order values in a List Pin
Ghandil31-May-13 8:36
Ghandil31-May-13 8:36 
I have a class which compares a set of times (using JodaTime Lib) to find the closest one to now:
Java
public class TimeComparitor {

private List<LocalTime> targetTimes;

public TimeComparitor() {
    targetTimes = new ArrayList<LocalTime>();
}

public void addTargetTime(LocalTime target) {
    targetTimes.add(target);
}

public LocalTime getClosestFutureTarget(DateTime now) {
    LocalTime result = null;
    long resultOffset = Long.MAX_VALUE;
    ArrayList<String> bigger = new ArrayList<String>();

    for (LocalTime target : targetTimes) {
        DateTime todayTarget = target.toDateTimeToday();
        long differenceMillis = todayTarget.getMillis() - now.getMillis();
        if (differenceMillis > 0 && differenceMillis < resultOffset) {
            resultOffset = differenceMillis;
            result = target;
        } 
    }
    return result;
}

As you see I could catch the closest time by getClosestFutureTarget method, ‌But I not only want the closest one, but also an ordered list of all Times greater than now.
The question is: First, how to save them in a list? Should it be through getClosestFutureTarget?

Second, to sort the list from closest to farthest I'm told to use something like this:
Java
public class LocalTime implements Comparable<LocalTime> {
    ...
    public int compareTo(LocalTime o){
         // compare "this" to o
    }
}
and then using Collections.sort. But not sure how to adapt it to my code.Just define this class in the same file for Previous class? Or creat a new class file? What should be inside class and where to call Collections.sort.

Thanks in advance
AnswerRe: Put and order values in a List Pin
Prasad Khandekar3-Jun-13 3:45
professionalPrasad Khandekar3-Jun-13 3:45 
QuestionCipherInputStream.read(byte[]) Dropping Final Block Pin
Skippums31-May-13 6:40
Skippums31-May-13 6:40 
SuggestionRe: CipherInputStream.read(byte[]) Dropping Final Block Pin
AlphaDeltaTheta31-May-13 21:51
AlphaDeltaTheta31-May-13 21:51 
AnswerRe: CipherInputStream.read(byte[]) Dropping Final Block Pin
AlphaDeltaTheta31-May-13 22:06
AlphaDeltaTheta31-May-13 22:06 
GeneralRe: CipherInputStream.read(byte[]) Dropping Final Block Pin
Skippums3-Jun-13 7:26
Skippums3-Jun-13 7:26 
AnswerRe: CipherInputStream.read(byte[]) Dropping Final Block Pin
Skippums3-Jun-13 7:33
Skippums3-Jun-13 7:33 
SuggestionRe: CipherInputStream.read(byte[]) Dropping Final Block Pin
AlphaDeltaTheta3-Jun-13 17:05
AlphaDeltaTheta3-Jun-13 17:05 
GeneralRe: CipherInputStream.read(byte[]) Dropping Final Block Pin
Skippums4-Jun-13 4:47
Skippums4-Jun-13 4:47 
AnswerRe: CipherInputStream.read(byte[]) Dropping Final Block Pin
AlphaDeltaTheta4-Jun-13 5:30
AlphaDeltaTheta4-Jun-13 5:30 
GeneralRe: CipherInputStream.read(byte[]) Dropping Final Block Pin
Skippums4-Jun-13 6:33
Skippums4-Jun-13 6:33 
AnswerRe: CipherInputStream.read(byte[]) Dropping Final Block Pin
AlphaDeltaTheta4-Jun-13 6:41
AlphaDeltaTheta4-Jun-13 6:41 
QuestionNew in Java Pin
Garde33330-May-13 18:47
Garde33330-May-13 18:47 
QuestionRe: New in Java Pin
AlphaDeltaTheta30-May-13 20:42
AlphaDeltaTheta30-May-13 20:42 
AnswerRe: New in Java Pin
Garde33331-May-13 17:57
Garde33331-May-13 17:57 
AnswerRe: New in Java Pin
dusty_dex30-May-13 20:56
dusty_dex30-May-13 20:56 
AnswerRe: New in Java Pin
Richard MacCutchan30-May-13 21:18
mveRichard MacCutchan30-May-13 21:18 
GeneralRe: New in Java Pin
Garde33331-May-13 17:45
Garde33331-May-13 17:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.