TimeUnit convert - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for TimeUnit convert method.

This code example shows how to use the following methods:convert
    public TimeUnit getUnit() {
        return this.unit;
    } 
 
    public long convert(TimeUnit unit) {
        return unit.convert(this.value, this.unit);
    } 
 
    @Override 
    public boolean equals(Object object) {
        if ((object == null) || !(object instanceof Time)) return false;
        Time time = (Time) object;
        TimeUnit compareUnit = TimeUnit.MILLISECONDS;
        return compareUnit.convert(this.value, this.unit) == compareUnit.convert(time.value, time.unit);
    } 
 
    @Override 
    public int hashCode() { 
        return Long.valueOf(TimeUnit.MILLISECONDS.convert(this.value, this.unit)).hashCode();
    } 
7
CodeRank
This code example shows how to use the following methods:convert
    public TimeUnit getUnit() {
        return this.unit;
    } 
 
    public long convert(TimeUnit unit) {
        return unit.convert(this.value, this.unit);
    } 
 
    @Override 
    public boolean equals(Object object) {
        if ((object == null) || !(object instanceof Time)) return false;
        Time time = (Time) object;
        TimeUnit compareUnit = TimeUnit.MILLISECONDS;
        return compareUnit.convert(this.value, this.unit) == compareUnit.convert(time.value, time.unit);
    } 
 
    @Override 
    public int hashCode() { 
        return Long.valueOf(TimeUnit.MILLISECONDS.convert(this.value, this.unit)).hashCode();
    } 
7
CodeRank
This code example shows how to use the following methods:convert
        return this.lastAccessedTime;
    } 
 
    @Override 
    public long getMaxInactiveInterval(TimeUnit unit) {
        return unit.convert(this.maxInactiveInterval, TimeUnit.MILLISECONDS);
    } 
} 
7
CodeRank
This code example shows how to use the following methods:ordinal, convert
    @Deprecated 
    public String toString(final int significantDigits) {
        final long mNanos = elapsedNanos();
 
        final TimeUnit mUnit = chooseUnit(mNanos);
        final double mValue = (double)mNanos / NANOSECONDS.convert(1, mUnit);
 
        /* Too bad this functionality is not exposed as a regular method call */ 
        return String.format("%." + significantDigits + "g %s", mValue, abbreviate(mUnit));
    } 
 
    private static TimeUnit chooseUnit(final long nanos) {
        if (SECONDS.convert(nanos, NANOSECONDS) > 0) {
            return SECONDS;
        } 
        if (MILLISECONDS.convert(nanos, NANOSECONDS) > 0) {
            return MILLISECONDS;
        } 
        if (MICROSECONDS.convert(nanos, NANOSECONDS) > 0) {
            return MICROSECONDS;

7
CodeRank
This code example shows how to use the following methods:convert
        this.maxInactiveInterval = new Time(0, TimeUnit.MILLISECONDS);
    } 
 
    public SimpleSessionMetaData(Date creationTime, Date lastAccessedTime, Time maxInactiveInterval) {
        this.creationTime = creationTime;
        this.lastAccessedTime = lastAccessedTime;
        this.maxInactiveInterval = maxInactiveInterval;
    } 
 
    @Override 
    public boolean isExpired() { 
        long maxInactiveInterval = this.getMaxInactiveInterval(TimeUnit.MILLISECONDS);
        return (maxInactiveInterval > 0) ? (System.currentTimeMillis() - this.lastAccessedTime.getTime()) > maxInactiveInterval : false;
    } 
 
    @Override 
    public boolean isNew() { 
        // Identity comparison is intentional 
        return this.lastAccessedTime == this.creationTime;
    } 
7
CodeRank
This code example shows how to use the following methods:convert
     
    private final long nanos;
 
    public Duration(long value, TimeUnit unit) {
        if (value!=0) 
            Preconditions.checkNotNull(unit, "Cannot accept null timeunit (unless value is 0)");
        else 
            unit = TimeUnit.MILLISECONDS;
         
        nanos = TimeUnit.NANOSECONDS.convert(value, unit);
    } 
 
 
    @Override 
    public int compareTo(Duration o) {
        return ((Long)toNanoseconds()).compareTo(o.toNanoseconds());
    } 
 
    @Override 
    public String toString() {
6
CodeRank
This code example shows how to use the following methods:convert
 * @param <I> the bean identifier type 
 * @param <T> the bean type 
 */ 
public class InfinispanBean<G, I, T> implements Bean<G, I, T> { 
 
    private final I id;
    private final BeanEntry<G> entry;
    private final BeanGroup<G, I, T> group;
    private final Mutator mutator;
    private final BeanRemover<I, T> remover;
    private final Time timeout; 
    private final PassivationListener<T> listener;
    private final AtomicBoolean valid = new AtomicBoolean(true);
 
    public InfinispanBean(I id, BeanEntry<G> entry, BeanGroup<G, I, T> group, Mutator mutator, BeanRemover<I, T> remover, Time timeout, PassivationListener<T> listener) {
        this.id = id;
        this.entry = entry;
        this.group = group;
        this.mutator = mutator;
        this.remover = remover;
7
CodeRank
This code example shows how to use the following methods:convert
This code example shows how to use the following methods:convert
            boolean bVal = true;
            try 
            { 
                if (!done.get())
                { 
                    timeout = TimeUnit.MILLISECONDS.convert(timeout, tu);
                    long overall_timeout = timeout - (System.currentTimeMillis() - startTime);
                    bVal = overall_timeout > 0 && condition.await(overall_timeout, TimeUnit.MILLISECONDS);
                } 
            } 
            catch (InterruptedException ex)
            { 
                throw new AssertionError(ex);
            } 
             
            if (!bVal && !done.get())
            {                                            
                throw new TimeoutException("Operation timed out.");
            } 
        } 
6
CodeRank
This code example shows how to use the following methods:convert

Related TimeUnit convert Questions & Answers:

convert Method Overview
Converts the given time duration in the given unit to this unit.
See Code Examples for other Java 8 TimeUnit Methods: