//# 0 errors, 38 messages
//#
/*
    //#DateCellRenderer.java:1:1: class: com.dmdirc.addons.ui_swing.components.renderers.DateCellRenderer
    //#DateCellRenderer.java:1:1: method: com.dmdirc.addons.ui_swing.components.renderers.DateCellRenderer.com.dmdirc.addons.ui_swing.components.renderers.DateCellRenderer__static_init
 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package com.dmdirc.addons.ui_swing.components.renderers;

import java.util.Date;

import javax.swing.table.DefaultTableCellRenderer;

/**
 * List cell renderer for dates.
 */
public final class DateCellRenderer extends DefaultTableCellRenderer {
    
    /**
     * A version number for this class. It should be changed whenever the class
     * structure is changed (or anything else that would prevent serialized
     * objects being unserialized with the new class).
     */
    private static final long serialVersionUID = 1;
    
    /** Creates a new instance of DateCellRenderer. */
    public DateCellRenderer() {
        super();
    //#DateCellRenderer.java:43: method: void com.dmdirc.addons.ui_swing.components.renderers.DateCellRenderer.com.dmdirc.addons.ui_swing.components.renderers.DateCellRenderer()
    //#input(void com.dmdirc.addons.ui_swing.components.renderers.DateCellRenderer()): this
    }
    //#DateCellRenderer.java:44: end of method: void com.dmdirc.addons.ui_swing.components.renderers.DateCellRenderer.com.dmdirc.addons.ui_swing.components.renderers.DateCellRenderer()
    
    /** {@inheritDoc} */
    @Override
    public void setValue(final Object value) {
        setText("" + duration((new Date().getTime() - ((Date) value).getTime()) / 1000));
    //#DateCellRenderer.java:49: method: void com.dmdirc.addons.ui_swing.components.renderers.DateCellRenderer.setValue(Object)
    //#DateCellRenderer.java:49: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.addons.ui_swing.components.renderers.DateCellRenderer:setText(String)
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.addons.ui_swing.components.renderers.DateCellRenderer
    //#    method: void setValue(Object)
    //#    unanalyzed callee: void com.dmdirc.addons.ui_swing.components.renderers.DateCellRenderer:setText(String)
    //#input(void setValue(Object)): ""._tainted
    //#input(void setValue(Object)): "h "._tainted
    //#input(void setValue(Object)): "m"._tainted
    //#input(void setValue(Object)): this
    //#input(void setValue(Object)): value
    //#pre[2] (void setValue(Object)): value != null
    //#unanalyzed(void setValue(Object)): Effects-of-calling:java.lang.StringBuilder
    //#unanalyzed(void setValue(Object)): Effects-of-calling:java.lang.StringBuilder:append
    //#unanalyzed(void setValue(Object)): Effects-of-calling:java.lang.StringBuilder:toString
    }
    //#DateCellRenderer.java:50: end of method: void com.dmdirc.addons.ui_swing.components.renderers.DateCellRenderer.setValue(Object)
    
    /**
     * Get the duration in seconds as a string.
     *
     * @param secondsInput to get duration for
     *
     * @return Duration as a string
     */
    private String duration(final long secondsInput) {
        final StringBuilder result = new StringBuilder();
    //#DateCellRenderer.java:60: method: String com.dmdirc.addons.ui_swing.components.renderers.DateCellRenderer.duration(long)
    //#input(String duration(long)): "h "._tainted
    //#input(String duration(long)): "m"._tainted
    //#input(String duration(long)): secondsInput
    //#output(String duration(long)): java.lang.StringBuilder:toString(...)._tainted
    //#output(String duration(long)): return_value
    //#new obj(String duration(long)): java.lang.StringBuilder:toString(...)
    //#post(String duration(long)): java.lang.StringBuilder:toString(...)._tainted == 0
    //#post(String duration(long)): return_value == &java.lang.StringBuilder:toString(...)
    //#test_vector(String duration(long)): secondsInput: {-9_223_372_036_854_775_808..3_599}, {3_600..18_446_744_073_709_551_615}
    //#test_vector(String duration(long)): secondsInput/3_600: {-2_562_047_788_015_215..0}, {1..5_124_095_576_030_431}
    //#test_vector(String duration(long)): secondsInput/60: {-153_722_867_280_912_930..59}, {60..307_445_734_561_825_860}
        final long hours = secondsInput / 3600;
        final long minutes = secondsInput / 60 % 60;
        //final long seconds = secondsInput % 60;
        
        if (hours > 0) { 
            result.append(hours).append("h ");
        }
        
        result.append(minutes).append("m");
        
        return result.toString();
    //#DateCellRenderer.java:71: end of method: String com.dmdirc.addons.ui_swing.components.renderers.DateCellRenderer.duration(long)
    }
}
    //#output(com.dmdirc.addons.ui_swing.components.renderers.DateCellRenderer__static_init): __Descendant_Table[com/dmdirc/addons/ui_swing/components/renderers/DateCellRenderer]
    //#output(com.dmdirc.addons.ui_swing.components.renderers.DateCellRenderer__static_init): __Dispatch_Table.duration(J)Ljava/lang/String;
    //#output(com.dmdirc.addons.ui_swing.components.renderers.DateCellRenderer__static_init): __Dispatch_Table.setValue(Ljava/lang/Object;)V
    //#post(com.dmdirc.addons.ui_swing.components.renderers.DateCellRenderer__static_init): __Descendant_Table[com/dmdirc/addons/ui_swing/components/renderers/DateCellRenderer] == &__Dispatch_Table
    //#post(com.dmdirc.addons.ui_swing.components.renderers.DateCellRenderer__static_init): __Dispatch_Table.duration(J)Ljava/lang/String; == &duration
    //#post(com.dmdirc.addons.ui_swing.components.renderers.DateCellRenderer__static_init): __Dispatch_Table.setValue(Ljava/lang/Object;)V == &setValue
    //#DateCellRenderer.java:: end of method: com.dmdirc.addons.ui_swing.components.renderers.DateCellRenderer.com.dmdirc.addons.ui_swing.components.renderers.DateCellRenderer__static_init
    //#DateCellRenderer.java:: end of class: com.dmdirc.addons.ui_swing.components.renderers.DateCellRenderer
