Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.cantaa.util.type;
  
  import java.util.Calendar;
  
The Time-Class encapsulates a time during the day. The time itself is stored as a long in Minutes since midnight

Author(s):
Hans Lesmeister
 
 public final class Time implements Serializable {
 
     private long longValue;
     private boolean simpleFormat = false;

    
Default Constructor
 
     public Time() {
         this(0);
     }

    
Private so force using factory-methods

Parameters:
minutesSinceMidnight
 
     private Time(long minutesSinceMidnight) {
         this. = minutesSinceMidnight;
     }

    

Returns:
the internally stored value
 
     public Long getLongValue() {
         if ( < 0) {
             return null;
         }
 
         return Long.valueOf();
     }
 
     @Override
     public String toString() {
         return "Time{" +
                 "timeOfDay=" +  +
                 "} " + super.toString();
     }
 
     @Override
     public boolean equals(Object o) {
         if (this == o) {
             return true;
         }
         if (o == null || getClass() != o.getClass()) {
             return false;
         }
 
         Time time = (Timeo;
 
         if ( != time.longValue) {
             return false;
         }
 
         return true;
     }
 
     @Override
     public int hashCode() {
         return (int) ( ^ ( >>> 32));
     }

    

Parameters:
time a Time-Object
Returns:
null if time is null, otherwise the internal value
 
     public static Long longValueOf(Time time) {
         if (time == null) {
             return null;
         }
 
         return time.getLongValue();
     }

    

Parameters:
calendar represents a time. If null, current time is taken
Returns:
Time-Object
 
     public static Time valueOf(Calendar calendar) {
         Calendar c = calendar;
 
         if (c == null) {
             c = Calendar.getInstance();
         }
 
         return Time.valueOf(c.get(.), c.get(.));
     }

    

Parameters:
timeValue internal time value
Returns:
Time-Object
    public static Time valueOf(long timeValue) {
        return valueOf(Long.valueOf(timeValue));
    }

    

Parameters:
timeValue internal time value
Returns:
Time-Object or null if the timeValue is null
    public static Time valueOf(Long timeValue) {
        if (timeValue == null) {
            return null;
        }
        return new Time(timeValue);
    }

    
Create a time object

Parameters:
hours number of hours passed since midnight
minutes minutes to be added to the hours
Returns:
Time-Object
    public static Time valueOf(int hoursint minutes) {
        Reject.ifTrue((hours < 0) || (hours > 23), "hours not between 0 and 23");
        Reject.ifTrue((minutes < 0) || (minutes > 60), "minutes not between 0 and 59");
        return new Time((hours * 60) + minutes);
    }
    public int getHours() {
        Long value = getLongValue();
        if (value == null) {
            return -1;
        }
        int longValue = value.intValue();
        int m = longValue % 60;
        return (longValue - m) / 60;
    }
    public int getMinutes() {
        Long value = getLongValue();
        if (value == null) {
            return -1;
        }
        return value.intValue() % 60;
    }
    public boolean isSimpleFormat() {
        return ;
    }
    public Time setSimpleFormat(boolean simpleFormat) {
        this. = simpleFormat;
        return this;
    }
New to GrepCode? Check out our FAQ X