Java 8 Delayed - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Delayed class.

This code example shows how to use the following methods:getDelay
            this.future = future;
        } 
 
        @Override 
        public long getDelay(TimeUnit unit) {
            return this.future.getDelay(unit);
        } 
 
        @Override 
        public int compareTo(Delayed delayed) {
            return this.future.compareTo(delayed);
        } 
 
        @Override 
        public boolean cancel(boolean mayInterruptIfRunning) {
            return this.future.cancel(mayInterruptIfRunning);
        } 
 
        @Override 
        public boolean isCancelled() { 
6
CodeRank
This code example shows how to use the following methods:getDelay
		        if( delayed instanceof DelayedGeneric ) {
		            long diff = delay - ( ( DelayedGeneric<?> )delayed ).delay;
		            return ( ( diff == 0 ) ? 0 : ( ( diff < 0 ) ? -1 : 1 ) );
		        } 
		  
		        long d = ( getDelay( TimeUnit.MILLISECONDS ) - delayed.getDelay( TimeUnit.MILLISECONDS ) );
		        return ( ( d == 0 ) ? 0 : ( ( d < 0 ) ? -1 : 1 ) );
		    } 
		} 
5
CodeRank
This code example shows how to use the following methods:getDelay
        } else if (other instanceof AlarmRecoveryDelayed) {
            AlarmRecoveryDelayed x = (AlarmRecoveryDelayed) other;
            long diff = now + timeout - (x.now + x.timeout);
            return (diff == 0) ? 0 : ((diff < 0) ? 1 : -1); // 时间越小的,越应该排在前面
        } else { 
            long d = (getDelay(TimeUnit.MILLISECONDS) - other.getDelay(TimeUnit.MILLISECONDS));
            return (d == 0) ? 0 : ((d < 0) ? 1 : -1);
        } 
    } 
 
    @Override 
    public int hashCode() { 
        final int prime = 31;
        int result = 1;
        result = prime * result + (int) (channelId ^ (channelId >>> 32));
        return result;
    } 
 
    public boolean equals(Object obj) { 
        if (this == obj) {
5
CodeRank
This code example shows how to use the following methods:getDelay
    private long getDelay(E e) {
        return e != null ? e.getDelay(TimeUnit.NANOSECONDS) : Long.MAX_VALUE;
    } 
 
    protected boolean isExpired(E e) {
        return e.getDelay(TimeUnit.NANOSECONDS) <= 0;
    } 
} 
5
CodeRank
This code example shows how to use the following methods:getDelay
                else if (sequenceNumber < x.sequenceNumber)
                    return -1; 
                else 
                    return 1; 
            } 
            long diff = getDelay(TimeUnit.NANOSECONDS) - other.getDelay(TimeUnit.NANOSECONDS);
            return (diff < 0) ? -1 : (diff > 0) ? 1 : 0;
        } 
    } 
 
    static class DelayedValue2 extends DelayedValue { 
        public DelayedValue2(int value, long millis) {
            super(value, millis);
        } 
 
        @Override 
        public int compareTo(Delayed other) {
            if (other == this) // compare zero if same object
                return 0; 
            if (other instanceof DelayedValue2) {
5
CodeRank
This code example shows how to use the following methods:getDelay
          TimeUnit.MILLISECONDS);
    } 
 
    public int compareTo(Delayed o) {
      long delta = this.getDelay(TimeUnit.MILLISECONDS) -
        o.getDelay(TimeUnit.MILLISECONDS);
 
      return this.equals(o) ? 0 : (delta > 0 ? 1 : -1);
    } 
 
    /** @param expirationTime the expirationTime to set */ 
    public void setExpirationTime(long expirationTime) {
      this.expirationTime = expirationTime;
    } 
  } 
} 
3
CodeRank
This code example shows how to use the following methods:getDelay
    if (this == that) {
      return 0; 
    } 
    return SliderUtils.compareTo( 
        getDelay(TimeUnit.NANOSECONDS),
        that.getDelay(TimeUnit.NANOSECONDS));
  } 
 
  @Override 
  public String toString() {
    final StringBuilder sb =
        new StringBuilder(super.toString());
    sb.append(" name='").append(name).append('\'');
    sb.append(", delay=").append(getDelay(TimeUnit.SECONDS));
    sb.append(", attrs=").append(attrs);
    sb.append(", sequenceNumber=").append(sequenceNumber);
    sb.append('}');
    return sb.toString();
  } 
 
3
CodeRank
This code example shows how to use the following methods:getDelay
		public long getDelay(TimeUnit unit) {
			return unit.convert(this.deadline - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
		} 
 
		public int compareTo(Delayed o) {
			return o.getDelay(TimeUnit.MILLISECONDS) >= this.getDelay(TimeUnit.MILLISECONDS) ? 1 : -1;
		} 
	} 
} 
3
CodeRank
This code example shows how to use the following methods:getDelay
            else if (sequenceNumber < x.sequenceNumber)
                return -1; 
            else 
                return 1; 
        } 
        long d = (getDelay(TimeUnit.NANOSECONDS) - other.getDelay(TimeUnit.NANOSECONDS));
        return (d == 0) ? 0 : ((d < 0) ? -1 : 1);
    } 
} 
3
CodeRank
This code example shows how to use the following methods:getDelay
    public int compareTo(Delayed other) {
        if (other instanceof SkillXpGain) {
            // Use more efficient method if possible (private fields) 
            return this.compareTo((SkillXpGain) other);
        } 
        return (int) (getDelay(TimeUnit.MILLISECONDS) - other.getDelay(TimeUnit.MILLISECONDS));
    } 
 
    @Override 
    public long getDelay(TimeUnit arg0) {
        return arg0.convert(expiryTime - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
    } 
} 
5
CodeRank
This code example shows how to use the following methods:getDelay
			else if (sequenceNumber < x.sequenceNumber)
				return -1; 
			else 
				return 1; 
		} 
		long d = (getDelay(TimeUnit.NANOSECONDS) - other.getDelay(TimeUnit.NANOSECONDS));
		return (d == 0) ? 0 : ((d < 0) ? -1 : 1);
	} 
} 
3
CodeRank
This code example shows how to use the following methods:getDelay
          TimeUnit.MILLISECONDS);
    } 
 
    public int compareTo(Delayed o) {
      long delta = this.getDelay(TimeUnit.MILLISECONDS) -
        o.getDelay(TimeUnit.MILLISECONDS);
 
      return this.equals(o) ? 0 : (delta > 0 ? 1 : -1);
    } 
 
    /** @param expirationTime the expirationTime to set */ 
    public void setExpirationTime(long expirationTime) {
      this.expirationTime = expirationTime;
    } 
  } 
} 
5
CodeRank
This code example shows how to use the following methods:getDelay
    this.delayed = delayed;
  } 
   
  @Override 
  public long getDelay(TimeUnit unit) {
    return delayed.getDelay(unit);
  } 
 
  @Override 
  public int compareTo(Delayed o) {
    return delayed.compareTo(o);
  } 
 
  @Override 
  public boolean cancel(boolean mayInterruptIfRunning) {
    return futureImp.cancel(mayInterruptIfRunning);
  } 
 
  @Override 
  public boolean isCancelled() { 
4
CodeRank
This code example shows how to use the following methods:getDelay
            return convert;
        } 
 
        @Override 
        public int compareTo(Delayed o) {
            return new Long(getDelay(TimeUnit.MILLISECONDS)).compareTo(o.getDelay(TimeUnit.MILLISECONDS));
        } 
    } 
 
    public DelayQueueScheduler(long time, TimeUnit timeUnit) {
        this.time = time;
        this.timeUnit = timeUnit;
    } 
 
    @Override 
    public synchronized void push(Request request, Task task) {
        if (urls.add(request.getUrl())) {
            queue.add(new RequestWrapper(request));
        } 
 
5
CodeRank
This code example shows how to use the following methods:getDelay
        { 
            if (delayed instanceof SerialScheduledFuture) {
                SerialScheduledFuture other = (SerialScheduledFuture) delayed;
                return Longs.compare(this.remainingDelayNanos, other.remainingDelayNanos);
            } 
            return Longs.compare(remainingDelayNanos, delayed.getDelay(NANOSECONDS));
        } 
 
        @Override 
        public boolean cancel(boolean b)
        { 
            return task.cancel(b);
        } 
 
        @Override 
        public boolean isCancelled() 
        { 
            return task.isCancelled();
        } 
 
4
CodeRank
This code example shows how to use the following methods:getDelay
    } 
 
    @Override 
    public int compareTo(Delayed o) {
        long thisVal = getDelay(TimeUnit.MILLISECONDS);
        long anotherVal = o.getDelay(TimeUnit.MILLISECONDS);
 
        if (thisVal < anotherVal ) {
            return -1; 
        } 
 
        return (thisVal == anotherVal ) ? 0 : 1;
    } 
 
    @Override 
    public long getDelay(TimeUnit unit) {
        return unit.convert(whenToRunMillis - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
    } 
 
    @Override 
3
CodeRank
This code example shows how to use the following methods:getDelay
		} 
 
		@Override 
		public int compareTo(Delayed other) {
			long d = (getDelay(TimeUnit.NANOSECONDS) -
					other.getDelay(TimeUnit.NANOSECONDS));
			return (d == 0)? 0 : ((d < 0)? -1 : 1);
		} 
 
		@Override 
		public boolean isPeriodic() { 
			return false; 
		} 
 
	} 
 
 
} 
4
CodeRank
This code example shows how to use the following methods:getDelay
  public int compareTo(Delayed o) {
    if (this == o) {
      return 0; 
    } else { 
      long thisDelay = this.getDelay(TimeUnit.MILLISECONDS);
      long otherDelay = o.getDelay(TimeUnit.MILLISECONDS);
      if (thisDelay == otherDelay) {
        return 0; 
      } else if (thisDelay > otherDelay) {
        return 1; 
      } else { 
        return -1; 
      } 
    } 
  } 
} 
4
CodeRank
This code example shows how to use the following methods:getDelay
     * @return a int. 
     */ 
    @Override 
    public int compareTo(Delayed request) {
        long myDelay = getDelay(TimeUnit.MILLISECONDS);
        long otherDelay = request.getDelay(TimeUnit.MILLISECONDS);
        if (myDelay < otherDelay) return -1;
        if (myDelay == otherDelay) return 0;
        return 1; 
    } 
 
    /** {@inheritDoc} */ 
    @Override 
    public void processError(Throwable t) {
        try { 
            m_callback.handleError(this, getRequest(), t);
        } finally { 
            m_processed = true;
        } 
    } 
4
CodeRank
This code example shows how to use the following methods:getDelay
     * @return a int. 
     */ 
    @Override 
    public int compareTo(Delayed request) {
        long myDelay = getDelay(TimeUnit.MILLISECONDS);
        long otherDelay = request.getDelay(TimeUnit.MILLISECONDS);
        if (myDelay < otherDelay) return -1;
        if (myDelay == otherDelay) return 0;
        return 1; 
    } 
 
    /** 
     * <p>getId</p> 
     * 
     * @return a {@link org.opennms.netmgt.icmp.spi.JniPingRequestId.PingRequestId} object. 
     */ 
    @Override 
    public JniPingRequestId getId() { 
        return m_id;
    } 
4
CodeRank
This code example shows how to use the following methods:getDelay
		 */ 
		@Override 
		public int compareTo(Delayed o) {
			Delayed that = o;
			return (int) (getDelay(TimeUnit.MILLISECONDS) - that
					.getDelay(TimeUnit.MILLISECONDS));
		} 
 
		/** 
		 * @see java.util.concurrent.Delayed#getDelay(java.util.concurrent.TimeUnit) 
		 */ 
		@Override 
		public long getDelay(TimeUnit unit) {
 
			long value = time - referenceTime;
			return unit.convert(value, TimeUnit.MILLISECONDS);
		} 
 
	} 
 
4
CodeRank
This code example shows how to use the following methods:getDelay
     * @return a int. 
     */ 
    @Override 
    public int compareTo(final Delayed request) {
        final long myDelay = getDelay(TimeUnit.MILLISECONDS);
        final long otherDelay = request.getDelay(TimeUnit.MILLISECONDS);
        if (myDelay < otherDelay) return -1;
        if (myDelay == otherDelay) return 0;
        return 1; 
    } 
 
    /** 
     * <p>getId</p> 
     * 
     * @return a {@link org.opennms.netmgt.icmp.Jni6PingRequestId.JniPingRequestId.PingRequestId} object. 
     */ 
    @Override 
    public Jni6PingRequestId getId() { 
        return m_id;
    } 
4
CodeRank
This code example shows how to use the following methods:getDelay
	 */ 
	@Override 
	public int compareTo(Delayed o) {
 
		Delayed that = o;
		return (int) (getDelay(TimeUnit.MILLISECONDS) - that.getDelay(TimeUnit.MILLISECONDS));
	} 
 
	/** 
	 * @see java.util.concurrent.Delayed#getDelay(java.util.concurrent.TimeUnit) 
	 */ 
	@Override 
	public long getDelay(TimeUnit unit) {
 
		long remainingTime = time - System.currentTimeMillis();
		return unit.convert(remainingTime, TimeUnit.MILLISECONDS);
	} 
 
} 
5
CodeRank
This code example shows how to use the following methods:getDelay
         * 
         * @return less than zero if this wrapper is older, zero if both wrapper elements have the same age, greater 
         *         than zero if the parameter wrapper element is older. 
         */ 
        public int compareTo(Delayed o) {
            long diff = (getDelay(TimeUnit.MILLISECONDS) - o.getDelay(TimeUnit.MILLISECONDS));
            if(diff > 0) {
                return 1; 
            } else if(diff < 0) {
                return -1; 
            } else { 
                return 0; 
            } 
        } 
 
        /** 
         * Return the string representation of the wrapper element. 
         * 
         * @return the string representation of the wrapper element. 
         */ 
5
CodeRank
This code example shows how to use the following methods:getDelay
     * @return a int. 
     */ 
    @Override 
    public int compareTo(final Delayed request) {
        final long myDelay = getDelay(TimeUnit.MILLISECONDS);
        final long otherDelay = request.getDelay(TimeUnit.MILLISECONDS);
        if (myDelay < otherDelay) return -1;
        if (myDelay == otherDelay) return 0;
        return 1; 
    } 
 
    /** 
     * <p>getId</p> 
     * 
     * @return a {@link org.opennms.netmgt.icmp.spi.JnaPingRequestId.PingRequestId} object. 
     */ 
    @Override 
    public JnaPingRequestId getId() { 
        return m_id;
    } 
4
CodeRank
This code example shows how to use the following methods:getDelay
 
	@Override 
	public int compareTo(Delayed o) {
 
		Long myDelay = Long.valueOf(getDelay(TimeUnit.MILLISECONDS));
		Long oDelay  = Long.valueOf(o.getDelay(TimeUnit.MILLISECONDS));
 
		return myDelay.compareTo(oDelay);
	} 
 
	//~--- get methods ---------------------------------------------------- 
 
	public long getDelayToNextExecutionInMillis() { 
 
		Calendar now       = GregorianCalendar.getInstance();
		int nowSeconds     = now.get(Calendar.SECOND);
		int nowMinutes     = now.get(Calendar.MINUTE);
		int nowHours       = now.get(Calendar.HOUR_OF_DAY);
		int nowDays        = now.get(Calendar.DAY_OF_MONTH);		// DAY_OF_MONTH starts with 1
		int nowDow         = now.get(Calendar.DAY_OF_WEEK) - 1;		// DAY_OF_WEEK starts with 1 (sunday)
5
CodeRank
This code example shows how to use the following methods:getDelay
     * @return a int. 
     */ 
    @Override 
    public int compareTo(Delayed o) {
        long thisVal = this.getDelay(TimeUnit.NANOSECONDS);
        long anotherVal = o.getDelay(TimeUnit.NANOSECONDS);
        return (thisVal<anotherVal ? -1 : (thisVal==anotherVal ? 0 : 1));
    } 
 
    /** 
     * <p>matches</p> 
     * 
     * @param response a {@link org.opennms.sms.reflector.smsservice.MobileMsgResponse} object. 
     * @return a boolean. 
     */ 
    public boolean matches(MobileMsgResponse response) {
        return m_responseMatcher.matches(this, response);
    } 
 
    /** 
4
CodeRank
This code example shows how to use the following methods:getDelay
    this.delegate = delegate;
  } 
 
  @Override 
  public long getDelay(TimeUnit unit) {
    return delegate.getDelay(unit);
  } 
 
  @Override 
  public int compareTo(Delayed o) {
    return delegate.compareTo(o);
  } 
 
  @Override 
  public boolean cancel(boolean mayInterruptIfRunning) {
    return delegate.cancel(mayInterruptIfRunning);
  } 
 
  @Override 
  public boolean isCancelled() { 
5
CodeRank
This code example shows how to use the following methods:getDelay
	public Object get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
		return this.currentFuture.get(timeout, unit);
	} 
 
	public long getDelay(TimeUnit unit) {
		return this.currentFuture.getDelay(unit);
	} 
 
	public int compareTo(Delayed other) {
		if (this == other) {
			return 0; 
		} 
		long diff = getDelay(TimeUnit.MILLISECONDS) - other.getDelay(TimeUnit.MILLISECONDS);
		return (diff == 0 ? 0 : ((diff < 0)? -1 : 1));
	} 
 
} 
4
CodeRank
This code example shows how to use the following methods:getDelay
            if (_enableStats) {
                // If we are called early, then delay will be positive. If we are called late, then the delay will be negative. 
                // NOTE: don't allow _enableStats to be set until future has been set 
                if (future != null)
                { 
                    _lastDrift = Math.abs(future.getDelay(TimeUnit.MILLISECONDS));
                } 
                _totalDrift += _lastDrift;
                _invocationCount++;
                if (_lastDrift > _maxDrift) _maxDrift = _lastDrift;
            } 
 
            try 
            { 
                callback.timerCallback();
            } 
            catch (Throwable t)
            { 
                log.error("Timer thread caught unhandled exception: " + t.getMessage(), t);
            } 
4
CodeRank

Related Java 8 Delayed Questions & Answers:

See Code Examples for Java 8 Delayed Methods: