java.sql.Timestamp.compareTo()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.0k)|赞(0)|评价(0)|浏览(188)

本文整理了Java中java.sql.Timestamp.compareTo()方法的一些代码示例,展示了Timestamp.compareTo()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Timestamp.compareTo()方法的具体详情如下:
包路径:java.sql.Timestamp
类名称:Timestamp
方法名:compareTo

Timestamp.compareTo介绍

[英]Compares this Timestamp object with a supplied Timestampobject.
[中]

代码示例

代码示例来源:origin: lealone/Lealone

@Override
public int compare(Object aObj, Object bObj) {
  Timestamp a = (Timestamp) aObj;
  Timestamp b = (Timestamp) bObj;
  return a.compareTo(b);
}

代码示例来源:origin: robovm/robovm

/**
 * Compares this {@code Timestamp} object with a supplied {@code Timestamp}
 * object.
 *
 * @param theObject
 *            the timestamp to compare with this {@code Timestamp} object,
 *            passed as an {@code Object}.
 * @return <dd>
 *         <dl>
 *         {@code 0} if the two {@code Timestamp} objects are equal in time
 *         </dl>
 *         <dl>
 *         a value {@code < 0} if this {@code Timestamp} object is before
 *         the supplied {@code Timestamp} and a value
 *         </dl>
 *         <dl>
 *         {@code > 0} if this {@code Timestamp} object is after the
 *         supplied {@code Timestamp}
 *         </dl>
 *         </dd>
 * @throws ClassCastException
 *             if the supplied object is not a {@code Timestamp} object.
 */
@Override
public int compareTo(Date theObject) throws ClassCastException {
  return this.compareTo((Timestamp) theObject);
}

代码示例来源:origin: apache/hive

/**
 * Compare Timestamp to row.
 * We assume the entry has already been NULL checked and isRepeated adjusted.
 * @param timestamp
 * @param elementNum
 * @return -1, 0, 1 standard compareTo values.
 */
public int compareTo(Timestamp timestamp, int elementNum) {
 return timestamp.compareTo(asScratchTimestamp(elementNum));
}

代码示例来源:origin: apache/hive

/**
 * Compare row to Timestamp.
 * We assume the entry has already been NULL checked and isRepeated adjusted.
 * @param elementNum
 * @param timestamp
 * @return -1, 0, 1 standard compareTo values.
 */
public int compareTo(int elementNum, Timestamp timestamp) {
 return asScratchTimestamp(elementNum).compareTo(timestamp);
}

代码示例来源:origin: apache/hive

@Override
 public List<MutablePair<String, String>> getIntervals(String lowerBound, String upperBound, int numPartitions, TypeInfo
     typeInfo) {
  List<MutablePair<String, String>> intervals = new ArrayList<>();
  Timestamp timestampLower = Timestamp.valueOf(lowerBound);
  Timestamp timestampUpper = Timestamp.valueOf(upperBound);
  // Note nano is not fully represented as the precision limit
  double timestampInterval = (timestampUpper.getTime() - timestampLower.getTime())/(double)numPartitions;
  Timestamp splitTimestampLower, splitTimestampUpper;
  for (int i=0;i<numPartitions;i++) {
   splitTimestampLower = new Timestamp(Math.round(timestampLower.getTime() + timestampInterval*i));
   splitTimestampUpper = new Timestamp(Math.round(timestampLower.getTime() + timestampInterval*(i+1)));
   if (splitTimestampLower.compareTo(splitTimestampUpper) < 0) {
    intervals.add(new MutablePair<String, String>(splitTimestampLower.toString(), splitTimestampUpper.toString()));
   }
  }
  return intervals;
 }
}

代码示例来源:origin: apache/hive

/**
 * Compare a row to another TimestampColumnVector's row.
 * @param elementNum1
 * @param timestampColVector2
 * @param elementNum2
 * @return
 */
public int compareTo(int elementNum1, TimestampColumnVector timestampColVector2,
  int elementNum2) {
 return asScratchTimestamp(elementNum1).compareTo(
   timestampColVector2.asScratchTimestamp(elementNum2));
}

代码示例来源:origin: apache/hive

/**
 * Compare another TimestampColumnVector's row to a row.
 * @param timestampColVector1
 * @param elementNum1
 * @param elementNum2
 * @return
 */
public int compareTo(TimestampColumnVector timestampColVector1, int elementNum1,
  int elementNum2) {
 return timestampColVector1.asScratchTimestamp(elementNum1).compareTo(
   asScratchTimestamp(elementNum2));
}

代码示例来源:origin: pentaho/pentaho-kettle

public int compare( Object data1, Object data2 ) throws KettleValueException {
 Timestamp timestamp1 = getTimestamp( data1 );
 Timestamp timestamp2 = getTimestamp( data2 );
 int cmp = 0;
 if ( timestamp1 == null ) {
  if ( timestamp2 == null ) {
   cmp = 0;
  } else {
   cmp = -1;
  }
 } else if ( timestamp2 == null ) {
  cmp = 1;
 } else {
  cmp = timestamp1.compareTo( timestamp2 );
 }
 if ( isSortedDescending() ) {
  return -cmp;
 } else {
  return cmp;
 }
}

代码示例来源:origin: forcedotcom/phoenix

@Override
public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
  if (rhsType == TIMESTAMP || rhsType == UNSIGNED_TIMESTAMP) {
    return ((Timestamp)lhs).compareTo((Timestamp)rhs);
  }
  int c = ((Date)rhs).compareTo((Date)lhs);
  if (c != 0) return c;
  return ((Timestamp)lhs).getNanos();
}

代码示例来源:origin: apache/phoenix

@Override
public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
  if (lhs == rhs) {
    return 0;
  }
  if (lhs == null) {
    return -1;
  }
  if (rhs == null) {
    return 1;
  }
  if (equalsAny(rhsType, PTimestamp.INSTANCE, PUnsignedTimestamp.INSTANCE)) {
    return ((java.sql.Timestamp) lhs).compareTo((java.sql.Timestamp) rhs);
  }
  int c = ((java.util.Date) lhs).compareTo((java.util.Date) rhs);
  if (c != 0) return c;
  return ((java.sql.Timestamp) lhs).getNanos();
}

代码示例来源:origin: ebean-orm/ebean

@Override
public int compare(Version<?> o1, Version<?> o2) {
 Timestamp v1 = o1.getStart();
 if (v1 == null) {
  return 1;
 }
 Timestamp v2 = o2.getStart();
 if (v2 == null) {
  return -1;
 }
 return v1.compareTo(v2) * -1;
}

代码示例来源:origin: lujiang-wed/wed-job

public int compareObject(Timestamp o1,Timestamp o2){
  if(o1==null && o2 == null){
    return 0;
  }else if(o1 != null){
    return o1.compareTo(o2);
  }else {
    return -1;
  }
}
public int compare(ScheduleServer o1, ScheduleServer o2) {

代码示例来源:origin: com.atlassian.jira/jira-api

@Override
public int compareTo(ChangeHistoryGroup other)
{
  if (created.compareTo(other.getCreated()) == 0)
  {
    return id.compareTo(other.getId());
  }
  return created.compareTo(other.getCreated());
}

代码示例来源:origin: com.atlassian.jira/jira-core

@Override
  public int compare(ChangeItemBean changeItemBean1, ChangeItemBean changeItemBean2)
  {
    return changeItemBean2.getCreated().compareTo(changeItemBean1.getCreated());
  }
});

代码示例来源:origin: org.avaje.ebean/ebean

@Override
public int compare(Version<?> o1, Version<?> o2) {
 Timestamp v1 = o1.getStart();
 if (v1 == null) {
  return 1;
 }
 Timestamp v2 = o2.getStart();
 if (v2 == null) {
  return -1;
 }
 return v1.compareTo(v2) * -1;
}

代码示例来源:origin: com.atlassian.jira/jira-core

@Override
  public int compare(final Issue o1, final Issue o2)
  {
    return o1.getCreated().compareTo(o2.getCreated());
  }
};

代码示例来源:origin: sakaiproject/sakai

public int compare(Object gradebook, Object otherGradebook) {
    Timestamp modDate1 = ((Gradebook) gradebook).getLastUpdated();
    Timestamp modDate2 = ((Gradebook) otherGradebook).getLastUpdated();
   
    if(modDate1.equals(modDate2)) {
      return compareTitles((Gradebook) gradebook, (Gradebook)otherGradebook);  
      }
   
    return modDate1.compareTo(modDate2);
  }
};

代码示例来源:origin: com.atlassian.jira/jira-core

@Override
  public int compare(final GenericValue o1, final GenericValue o2)
  {
    // Note: intentionally reversed
    int cmp = o2.getTimestamp(UPDATED).compareTo(o1.getTimestamp(UPDATED));
    return (cmp != 0) ? cmp : o2.getLong(ID).compareTo(o1.getLong(ID));
  }
}

代码示例来源:origin: sakaiproject/sakai

public int compare(Object gradebook, Object otherGradebook) {
     Timestamp modDate1 = ((Gradebook) gradebook).getLastUpdated();
     Timestamp modDate2 = ((Gradebook) otherGradebook).getLastUpdated();
     
     if(modDate1.equals(modDate2)) {
       return compareTitles((Gradebook) gradebook, (Gradebook)otherGradebook);  
     }
    
    return modDate2.compareTo(modDate1);
  }
};

代码示例来源:origin: com.atlassian.jira/jira-core

@Override
  public int compare(final EntityProperty o1, final EntityProperty o2)
  {
    // Note: intentionally reversed
    int cmp = o2.getUpdated().compareTo(o1.getUpdated());
    return (cmp != 0) ? cmp : o2.getId().compareTo(o2.getId());
  }
}

相关文章