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

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

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

Timestamp.equals介绍

[英]Tests to see if this timestamp is equal to a supplied object.
[中]测试此时间戳是否等于提供的对象。

代码示例

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

/**
 * Tests to see if this timestamp is equal to a supplied object.
 *
 * @param theObject
 *            the object to which this timestamp is compared.
 * @return {@code true} if this {@code Timestamp} object is equal to the
 *         supplied {@code Timestamp} object<br>{@code false} if the object
 *         is not a {@code Timestamp} object or if the object is a {@code
 *         Timestamp} but represents a different instant in time.
 */
@Override
public boolean equals(Object theObject) {
  if (theObject instanceof Timestamp) {
    return equals((Timestamp) theObject);
  }
  return false;
}

代码示例来源:origin: org.postgresql/postgresql

@Override
public boolean equals(Object obj) {
 if (this == obj) {
  return true;
 }
 if (!super.equals(obj)) {
  return false;
 }
 if (!(obj instanceof PGTimestamp)) {
  return false;
 }
 PGTimestamp other = (PGTimestamp) obj;
 if (calendar == null) {
  if (other.calendar != null) {
   return false;
  }
 } else if (!calendar.equals(other.calendar)) {
  return false;
 }
 return true;
}

代码示例来源:origin: cloudfoundry/uaa

@Override
public boolean equals(Object o) {
  if (this == o)
    return true;
  if (!(o instanceof ExpiringCode))
    return false;
  ExpiringCode that = (ExpiringCode) o;
  if (code != null ? !code.equals(that.code) : that.code != null)
    return false;
  if (data != null ? !data.equals(that.data) : that.data != null)
    return false;
  if (expiresAt != null ? !expiresAt.equals(that.expiresAt) : that.expiresAt != null)
    return false;
  return true;
}

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

return false;
if (createdTime != null ? !createdTime.equals(stage.createdTime) : stage.createdTime != null) {
  return false;

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

/** {@inheritDoc} */
@Override public boolean equals(final Object o) {
  if (this == o) return true;
  if (o == null || getClass() != o.getClass()) return false;
  final SearchValue that = (SearchValue) o;
  if (uuid != null ? !uuid.equals(that.uuid) : that.uuid != null) return false;
  if (str != null ? !str.equals(that.str) : that.str != null) return false;
  if (decimal != null ? !decimal.equals(that.decimal) : that.decimal != null) return false;
  if (integer != null ? !integer.equals(that.integer) : that.integer != null) return false;
  if (date != null ? !date.equals(that.date) : that.date != null) return false;
  if (ts != null ? !ts.equals(that.ts) : that.ts != null) return false;
  if (person != null ? !person.equals(that.person) : that.person != null) return false;
  return enumKey == that.enumKey;
}

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

/**
 * @throws Exception If failed.
 */
@Test
public void testTimestamp() throws Exception {
  ResultSet rs = stmt.executeQuery(SQL);
  int cnt = 0;
  while (rs.next()) {
    if (cnt == 0) {
      assert rs.getTimestamp("tsVal").getTime() == 1;
      assert rs.getDate(14).equals(new Date(new Timestamp(1).getTime()));
      assert rs.getTime(14).equals(new Time(new Timestamp(1).getTime()));
      assert rs.getTimestamp(14).equals(new Timestamp(1));
      assert rs.getObject(14, Date.class).equals(new Date(new Timestamp(1).getTime()));
      assert rs.getObject(14, Time.class).equals(new Time(new Timestamp(1).getTime()));
      assert rs.getObject(14, Timestamp.class).equals(new Timestamp(1));
    }
    cnt++;
  }
  assert cnt == 1;
}

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

/**
 * @throws Exception If failed.
 */
@Test
public void testTimestamp() throws Exception {
  ResultSet rs = stmt.executeQuery(SQL);
  int cnt = 0;
  while (rs.next()) {
    if (cnt == 0) {
      assert rs.getTimestamp("tsVal").getTime() == 1;
      assert rs.getDate(14).equals(new Date(new Timestamp(1).getTime()));
      assert rs.getTime(14).equals(new Time(new Timestamp(1).getTime()));
      assert rs.getTimestamp(14).equals(new Timestamp(1));
      assert rs.getObject(14, Date.class).equals(new Date(new Timestamp(1).getTime()));
      assert rs.getObject(14, Time.class).equals(new Time(new Timestamp(1).getTime()));
      assert rs.getObject(14, Timestamp.class).equals(new Timestamp(1));
    }
    cnt++;
  }
  assert cnt == 1;
}

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

/** {@inheritDoc} */
@Override public boolean equals(Object o) {
  if (this == o) return true;
  if (o == null || getClass() != o.getClass()) return false;
  AllTypes allTypes = (AllTypes) o;
  if (Double.compare(allTypes.doubleCol, doubleCol) != 0) return false;
  if (booleanCol != allTypes.booleanCol) return false;
  if (intCol != allTypes.intCol) return false;
  if (shortCol != allTypes.shortCol) return false;
  if (longCol != null ? !longCol.equals(allTypes.longCol) : allTypes.longCol != null) return false;
  if (strCol != null ? !strCol.equals(allTypes.strCol) : allTypes.strCol != null) return false;
  if (dateCol != null ? !dateCol.equals(allTypes.dateCol) : allTypes.dateCol != null) return false;
  if (sqlDateCol != null ? !sqlDateCol.equals(allTypes.sqlDateCol) : allTypes.sqlDateCol != null) return false;
  if (tsCol != null ? !tsCol.equals(allTypes.tsCol) : allTypes.tsCol != null) return false;
  if (bigDecimalCol != null ? !bigDecimalCol.equals(allTypes.bigDecimalCol) : allTypes.bigDecimalCol != null)
    return false;
  // Probably incorrect - comparing Object[] arrays with Arrays.equals
  if (!Arrays.equals(bytesCol, allTypes.bytesCol)) return false;
  if (innerTypeCol != null ? !innerTypeCol.equals(allTypes.innerTypeCol) : allTypes.innerTypeCol != null)
    return false;
  return enumCol == allTypes.enumCol;
}

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

/**
 * @throws Exception If failed.
 */
@SuppressWarnings("deprecation")
@Test
public void testTime() throws Exception {
  ResultSet rs = stmt.executeQuery(SQL);
  int cnt = 0;
  while (rs.next()) {
    if (cnt == 0) {
      assert rs.getTime("timeVal").equals(new Time(1, 1, 1));
      assert rs.getDate(13).equals(new Date(new Time(1, 1, 1).getTime()));
      assert rs.getTime(13).equals(new Time(1, 1, 1));
      assert rs.getTimestamp(13).equals(new Timestamp(new Time(1, 1, 1).getTime()));
      assert rs.getObject(13, Date.class).equals(new Date(new Time(1, 1, 1).getTime()));
      assert rs.getObject(13, Time.class).equals(new Time(1, 1, 1));
      assert rs.getObject(13, Timestamp.class).equals(new Timestamp(new Time(1, 1, 1).getTime()));
    }
    cnt++;
  }
  assert cnt == 1;
}

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

/**
 * @throws Exception If failed.
 */
@SuppressWarnings("deprecation")
@Test
public void testDate() throws Exception {
  ResultSet rs = stmt.executeQuery(SQL);
  int cnt = 0;
  while (rs.next()) {
    if (cnt == 0) {
      assert rs.getDate("dateVal").equals(new Date(1, 1, 1));
      assert rs.getDate(12).equals(new Date(1, 1, 1));
      assert rs.getTime(12).equals(new Time(new Date(1, 1, 1).getTime()));
      assert rs.getTimestamp(12).equals(new Timestamp(new Date(1, 1, 1).getTime()));
      assert rs.getObject(12, Date.class).equals(new Date(1, 1, 1));
      assert rs.getObject(12, Time.class).equals(new Time(new Date(1, 1, 1).getTime()));
      assert rs.getObject(12, Timestamp.class).equals(new Timestamp(new Date(1, 1, 1).getTime()));
    }
    cnt++;
  }
  assert cnt == 1;
}

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

/**
 * @throws Exception If failed.
 */
@SuppressWarnings("deprecation")
@Test
public void testDate() throws Exception {
  ResultSet rs = stmt.executeQuery(SQL);
  int cnt = 0;
  while (rs.next()) {
    if (cnt == 0) {
      assert rs.getDate("dateVal").equals(new Date(1, 1, 1));
      assert rs.getDate(12).equals(new Date(1, 1, 1));
      assert rs.getTime(12).equals(new Time(new Date(1, 1, 1).getTime()));
      assert rs.getTimestamp(12).equals(new Timestamp(new Date(1, 1, 1).getTime()));
      assert rs.getObject(12, Date.class).equals(new Date(1, 1, 1));
      assert rs.getObject(12, Time.class).equals(new Time(new Date(1, 1, 1).getTime()));
      assert rs.getObject(12, Timestamp.class).equals(new Timestamp(new Date(1, 1, 1).getTime()));
    }
    cnt++;
  }
  assert cnt == 1;
}

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

/**
 * @throws Exception If failed.
 */
@SuppressWarnings("deprecation")
@Test
public void testTime() throws Exception {
  ResultSet rs = stmt.executeQuery(SQL);
  int cnt = 0;
  while (rs.next()) {
    if (cnt == 0) {
      assert rs.getTime("timeVal").equals(new Time(1, 1, 1));
      assert rs.getDate(13).equals(new Date(new Time(1, 1, 1).getTime()));
      assert rs.getTime(13).equals(new Time(1, 1, 1));
      assert rs.getTimestamp(13).equals(new Timestamp(new Time(1, 1, 1).getTime()));
      assert rs.getObject(13, Date.class).equals(new Date(new Time(1, 1, 1).getTime()));
      assert rs.getObject(13, Time.class).equals(new Time(1, 1, 1));
      assert rs.getObject(13, Timestamp.class).equals(new Timestamp(new Time(1, 1, 1).getTime()));
    }
    cnt++;
  }
  assert cnt == 1;
}

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

/** {@inheritDoc} */
@SuppressWarnings({"BigDecimalEquals", "EqualsHashCodeCalledOnUrl", "RedundantIfStatement"})
@Override public boolean equals(Object o) {
  if (this == o) return true;
  if (o == null || getClass() != o.getClass()) return false;
  TestObject that = (TestObject)o;
  if (id != that.id) return false;
  if (!Arrays.equals(arrVal, that.arrVal)) return false;
  if (bigVal != null ? !bigVal.equals(that.bigVal) : that.bigVal != null) return false;
  if (boolVal != null ? !boolVal.equals(that.boolVal) : that.boolVal != null) return false;
  if (byteVal != null ? !byteVal.equals(that.byteVal) : that.byteVal != null) return false;
  if (dateVal != null ? !dateVal.equals(that.dateVal) : that.dateVal != null) return false;
  if (doubleVal != null ? !doubleVal.equals(that.doubleVal) : that.doubleVal != null) return false;
  if (f1 != null ? !f1.equals(that.f1) : that.f1 != null) return false;
  if (f2 != null ? !f2.equals(that.f2) : that.f2 != null) return false;
  if (f3 != null ? !f3.equals(that.f3) : that.f3 != null) return false;
  if (floatVal != null ? !floatVal.equals(that.floatVal) : that.floatVal != null) return false;
  if (intVal != null ? !intVal.equals(that.intVal) : that.intVal != null) return false;
  if (longVal != null ? !longVal.equals(that.longVal) : that.longVal != null) return false;
  if (shortVal != null ? !shortVal.equals(that.shortVal) : that.shortVal != null) return false;
  if (strVal != null ? !strVal.equals(that.strVal) : that.strVal != null) return false;
  if (timeVal != null ? !timeVal.equals(that.timeVal) : that.timeVal != null) return false;
  if (tsVal != null ? !tsVal.equals(that.tsVal) : that.tsVal != null) return false;
  if (urlVal != null ? !urlVal.equals(that.urlVal) : that.urlVal != null) return false;
  return true;
}

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

/** {@inheritDoc} */
@SuppressWarnings({"BigDecimalEquals", "EqualsHashCodeCalledOnUrl", "RedundantIfStatement"})
@Override public boolean equals(Object o) {
  if (this == o) return true;
  if (o == null || getClass() != o.getClass()) return false;
  TestObject that = (TestObject)o;
  if (id != that.id) return false;
  if (!Arrays.equals(arrVal, that.arrVal)) return false;
  if (bigVal != null ? !bigVal.equals(that.bigVal) : that.bigVal != null) return false;
  if (boolVal != null ? !boolVal.equals(that.boolVal) : that.boolVal != null) return false;
  if (byteVal != null ? !byteVal.equals(that.byteVal) : that.byteVal != null) return false;
  if (dateVal != null ? !dateVal.equals(that.dateVal) : that.dateVal != null) return false;
  if (doubleVal != null ? !doubleVal.equals(that.doubleVal) : that.doubleVal != null) return false;
  if (f1 != null ? !f1.equals(that.f1) : that.f1 != null) return false;
  if (f2 != null ? !f2.equals(that.f2) : that.f2 != null) return false;
  if (f3 != null ? !f3.equals(that.f3) : that.f3 != null) return false;
  if (floatVal != null ? !floatVal.equals(that.floatVal) : that.floatVal != null) return false;
  if (intVal != null ? !intVal.equals(that.intVal) : that.intVal != null) return false;
  if (longVal != null ? !longVal.equals(that.longVal) : that.longVal != null) return false;
  if (shortVal != null ? !shortVal.equals(that.shortVal) : that.shortVal != null) return false;
  if (strVal != null ? !strVal.equals(that.strVal) : that.strVal != null) return false;
  if (timeVal != null ? !timeVal.equals(that.timeVal) : that.timeVal != null) return false;
  if (tsVal != null ? !tsVal.equals(that.tsVal) : that.tsVal != null) return false;
  if (urlVal != null ? !urlVal.equals(that.urlVal) : that.urlVal != null) return false;
  return true;
}

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

/** {@inheritDoc} */
@SuppressWarnings({"BigDecimalEquals", "EqualsHashCodeCalledOnUrl", "RedundantIfStatement"})
@Override public boolean equals(Object o) {
  if (this == o) return true;
  if (o == null || getClass() != o.getClass()) return false;
  TestObject that = (TestObject)o;
  if (id != that.id) return false;
  if (!Arrays.equals(arrVal, that.arrVal)) return false;
  if (bigVal != null ? !bigVal.equals(that.bigVal) : that.bigVal != null) return false;
  if (boolVal != null ? !boolVal.equals(that.boolVal) : that.boolVal != null) return false;
  if (byteVal != null ? !byteVal.equals(that.byteVal) : that.byteVal != null) return false;
  if (dateVal != null ? !dateVal.equals(that.dateVal) : that.dateVal != null) return false;
  if (doubleVal != null ? !doubleVal.equals(that.doubleVal) : that.doubleVal != null) return false;
  if (f1 != null ? !f1.equals(that.f1) : that.f1 != null) return false;
  if (f2 != null ? !f2.equals(that.f2) : that.f2 != null) return false;
  if (f3 != null ? !f3.equals(that.f3) : that.f3 != null) return false;
  if (floatVal != null ? !floatVal.equals(that.floatVal) : that.floatVal != null) return false;
  if (intVal != null ? !intVal.equals(that.intVal) : that.intVal != null) return false;
  if (longVal != null ? !longVal.equals(that.longVal) : that.longVal != null) return false;
  if (shortVal != null ? !shortVal.equals(that.shortVal) : that.shortVal != null) return false;
  if (strVal != null ? !strVal.equals(that.strVal) : that.strVal != null) return false;
  if (timeVal != null ? !timeVal.equals(that.timeVal) : that.timeVal != null) return false;
  if (tsVal != null ? !tsVal.equals(that.tsVal) : that.tsVal != null) return false;
  if (urlVal != null ? !urlVal.equals(that.urlVal) : that.urlVal != null) return false;
  return true;
}

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

@Test
 public void testDouble() throws Exception {

  Random r = new Random(1234);
  TimestampColumnVector timestampColVector = new TimestampColumnVector();
  Timestamp[] randTimestamps = new Timestamp[VectorizedRowBatch.DEFAULT_SIZE];

  for (int i = 0; i < VectorizedRowBatch.DEFAULT_SIZE; i++) {
   Timestamp randTimestamp = RandomTypeUtil.getRandTimestamp(r).toSqlTimestamp();
   randTimestamps[i] = randTimestamp;
   timestampColVector.set(i, randTimestamp);
  }
  for (int i = 0; i < VectorizedRowBatch.DEFAULT_SIZE; i++) {
   Timestamp retrievedTimestamp = timestampColVector.asScratchTimestamp(i);
   Timestamp randTimestamp = randTimestamps[i];
   if (!retrievedTimestamp.equals(randTimestamp)) {
    assertTrue(false);
   }
   double randDouble = TimestampUtils.getDouble(randTimestamp);
   double retrievedDouble = timestampColVector.getDouble(i);
   if (randDouble != retrievedDouble) {
    assertTrue(false);
   }
  }
 }
}

代码示例来源:origin: org.apache.spark/spark-sql_2.11

@Override
public boolean equals(Object o) {
 if (this == o) return true;
 if (o == null || getClass() != o.getClass()) return false;
 SimpleJavaBean2 that = (SimpleJavaBean2) o;
 if (!a.equals(that.a)) return false;
 if (!b.equals(that.b)) return false;
 return c.equals(that.c);
}

代码示例来源:origin: org.apache.spark/spark-sql

@Override
public boolean equals(Object o) {
 if (this == o) return true;
 if (o == null || getClass() != o.getClass()) return false;
 SimpleJavaBean2 that = (SimpleJavaBean2) o;
 if (!a.equals(that.a)) return false;
 if (!b.equals(that.b)) return false;
 return c.equals(that.c);
}

代码示例来源:origin: org.apache.spark/spark-sql_2.10

@Override
public boolean equals(Object o) {
 if (this == o) return true;
 if (o == null || getClass() != o.getClass()) return false;
 SimpleJavaBean2 that = (SimpleJavaBean2) o;
 if (!a.equals(that.a)) return false;
 if (!b.equals(that.b)) return false;
 return c.equals(that.c);
}

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

@Test
public void testDemonstrateSetNanosOnTimestampLosingMillis() {
  Timestamp ts1 = new Timestamp(120055);
  ts1.setNanos(60);
  
  Timestamp ts2 = new Timestamp(120100);
  ts2.setNanos(60);
  
  /*
   * This really should have been assertFalse() because we started with timestamps that 
   * had different milliseconds 120055 and 120100. THe problem is that the timestamp's 
   * constructor converts the milliseconds passed into seconds and assigns the left-over
   * milliseconds to the nanos part of the timestamp. If setNanos() is called after that
   * then the previous value of nanos gets overwritten resulting in loss of milliseconds.
   */
  assertTrue(ts1.equals(ts2));
  
  /*
   * The right way to deal with timestamps when you have both milliseconds and nanos to assign
   * is to use the DateUtil.getTimestamp(long millis, int nanos).
   */
  ts1 = DateUtil.getTimestamp(120055,  60);
  ts2 = DateUtil.getTimestamp(120100, 60);
  assertFalse(ts1.equals(ts2));
  assertTrue(ts2.after(ts1));
}

相关文章