下面列出了java.util.concurrent.Delayed#getDelay ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public int compareTo(Delayed other) {
if (other == this)
return 0;
long d = (getDelay(TimeUnit.MILLISECONDS) -
other.getDelay(TimeUnit.MILLISECONDS));
if(d != 0) {
return (d < 0) ? -1 : 1;
} else {
// use the ordering of the id as well in case the other Delayed is a ScheduledMessage as well
if(other instanceof ScheduledMessage) {
return getId().compareTo(((ScheduledMessage)other).getId());
} else {
return 0;
}
}
}
public int compareTo(Delayed other) {
if (other == this) // compare zero ONLY if same object
return 0;
if (other instanceof MicroDelayItem) {
MicroDelayItem x = (MicroDelayItem) other;
long diff = time - x.time;
if (diff < 0)
return -1;
else if (diff > 0)
return 1;
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);
}
@Override
public int compareTo(Delayed o) {
if (this == o) {
return 0;
} else if (o instanceof TestDelayed) {
return (int)(delayInMs - ((TestDelayed)o).delayInMs);
} 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;
}
}
}
@Override
public int compareTo(Delayed that) {
long thisDelay = this.getDelay(TimeUnit.MILLISECONDS);
long thatDelay = that.getDelay(TimeUnit.MILLISECONDS);
if (thisDelay < thatDelay) {
return -1;
}
if (thisDelay > thatDelay) {
return 1;
}
// 时间判断无法区分时,执行如下判断(用于维持 compareTo 的使用约束)
if (this.equals(that)) {
return 0;
} else {
return this.hashCode() - that.hashCode();
}
}
@Override
public int compareTo(Delayed other) {
if (other instanceof ThrottlingDelayQueue.TenantThrottler) {
long onext = ((ThrottlingDelayQueue.TenantThrottler) other).next;
if (next < onext)
return -1;
else if (next == onext)
return 0;
else
return 1;
} else {
long odelay = other.getDelay(TimeUnit.NANOSECONDS);
long tdelay = this.getDelay(TimeUnit.NANOSECONDS);
if (tdelay < odelay)
return -1;
else if (tdelay == odelay)
return 0;
else
return 1;
}
}
@Override
public int compareTo(Delayed other) {
if (this == other) {
return 0;
}
if (other instanceof GridmixJob) {
final long otherNanos = ((GridmixJob)other).submissionTimeNanos;
if (otherNanos < submissionTimeNanos) {
return 1;
}
if (otherNanos > submissionTimeNanos) {
return -1;
}
return id() - ((GridmixJob)other).id();
}
final long diff =
getDelay(TimeUnit.NANOSECONDS) - other.getDelay(TimeUnit.NANOSECONDS);
return 0 == diff ? 0 : (diff > 0 ? 1 : -1);
}
@Override
public int compareTo(Delayed other) {
if (other == this) { // compare zero if same object
return 0;
}
if (other instanceof ScheduledSQSFutureTask) {
ScheduledSQSFutureTask<?> x = (ScheduledSQSFutureTask<?>)other;
long diff = time - x.time;
if (diff < 0) {
return -1;
} else if (diff > 0) {
return 1;
} else {
return 0;
}
}
long d = getDelay(TimeUnit.NANOSECONDS) -
other.getDelay(TimeUnit.NANOSECONDS);
return (d == 0) ? 0 : ((d < 0) ? -1 : 1);
}
@Override
public int compareTo(Delayed o)
{
if ( o == this )
{
return 0;
}
long diff = getDelay(TimeUnit.MILLISECONDS) - o.getDelay(TimeUnit.MILLISECONDS);
if ( diff == 0 )
{
if ( o instanceof OperationAndData )
{
diff = ordinal.get() - ((OperationAndData)o).ordinal.get();
}
}
return (diff < 0) ? -1 : ((diff > 0) ? 1 : 0);
}
@Override
public int compareTo( Delayed delayed )
{
if ( delayed == this )
{
return 0;
}
if ( delayed instanceof QueuedAudit )
{
long diff = delay - ((QueuedAudit) 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));
}
@Override
public int compareTo(@Nonnull Delayed o) {
if (o == this) {
return 0;
}
long diff = getDelay(TimeUnit.NANOSECONDS) - o.getDelay(TimeUnit.NANOSECONDS);
return (diff < 0L) ? -1 : (diff > 0L) ? 1 : 0;
}
@Override
public int compareTo(Delayed o) {
if (o.getDelay(TimeUnit.MILLISECONDS) < this.getDelay(TimeUnit.MILLISECONDS)) {
return 1;
} else if (o.getDelay(TimeUnit.MILLISECONDS) > this.getDelay(TimeUnit.MILLISECONDS)) {
return -1;
}
return 0;
}
@Override
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));
}
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));
}
@Override
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));
}
@Override
public int compareTo(Delayed o) {
long delta = this.getDelay(TimeUnit.MILLISECONDS) -
o.getDelay(TimeUnit.MILLISECONDS);
return this.equals(o) ? 0 : (delta > 0 ? 1 : -1);
}
@Override
public int compareTo(Delayed o) {
long other = o.getDelay(TimeUnit.MILLISECONDS);
long ours = getDelay(TimeUnit.MILLISECONDS);
//Might overflow on, say, ms compared to Long.MAX_VALUE, TimeUnit.DAYS
return (int) (ours - other);
}
@Override
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));
}
@Override
public int compareTo(Delayed o)
{
long diff = getDelay(TimeUnit.MILLISECONDS) - o.getDelay(TimeUnit.MILLISECONDS);
return (diff < 0) ? -1 : ((diff > 0) ? 1 : 0);
}
@Override
public int compareTo(Delayed o) {
long cmp = getDelay(TimeUnit.MILLISECONDS) - o.getDelay(TimeUnit.MILLISECONDS);
return cmp == 0 ? 0 : ( cmp < 0 ? -1 : 1);
}
public int compareTo(Delayed o) {
return o.getDelay(TimeUnit.MILLISECONDS) >= this.getDelay(TimeUnit.MILLISECONDS) ? 1 : -1;
}