当前位置: 首页>>代码示例>>Java>>正文


Java GregorianCalendar.equals方法代码示例

本文整理汇总了Java中java.util.GregorianCalendar.equals方法的典型用法代码示例。如果您正苦于以下问题:Java GregorianCalendar.equals方法的具体用法?Java GregorianCalendar.equals怎么用?Java GregorianCalendar.equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.GregorianCalendar的用法示例。


在下文中一共展示了GregorianCalendar.equals方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: TestFieldSet4781

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public void TestFieldSet4781() {
    try {
        GregorianCalendar g = new GregorianCalendar();
        GregorianCalendar g2 = new GregorianCalendar();
        // At this point UTC value is set, various fields are not.
        // Now set to noon.
        g2.set(HOUR, 12);
        g2.set(MINUTE, 0);
        g2.set(SECOND, 0);
        // At this point the object thinks UTC is NOT set, but fields are set.
        // The following line will result in IllegalArgumentException because
        // it thinks the YEAR is set and it is NOT.
        if (g2.equals(g)) {
            logln("Same");
        } else {
            logln("Different");
        }
    } catch (IllegalArgumentException e) {
        errln("Unexpected exception seen: " + e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:CalendarTest.java

示例2: Test4966499

import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
 * 4973919: Inconsistent GregorianCalendar hashCode before and after serialization
 */
public void Test4966499() throws Exception {
    GregorianCalendar date1 = new GregorianCalendar(2004, JANUARY, 7);

    // Serialize date1
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(date1);

    byte[] buffer = baos.toByteArray();

    // Deserialize it
    ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
    ObjectInputStream ois = new ObjectInputStream(bais);
    GregorianCalendar date2 = (GregorianCalendar) ois.readObject();

    if (!date1.equals(date2)) {
        errln("date1.equals(date2) != true");
    }
    if (date1.hashCode() != date2.hashCode()) {
        errln("inconsistent hashCode() value (before=0x"
                + Integer.toHexString(date1.hashCode())
                + ", after=0x" + Integer.toHexString(date2.hashCode()) + ")");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:CalendarRegression.java

示例3: Test4035301

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public void Test4035301() {
    GregorianCalendar c = new GregorianCalendar(98, 8, 7);
    GregorianCalendar d = new GregorianCalendar(98, 8, 7);
    if (c.after(d)
            || c.after(c)
            || c.before(d)
            || c.before(c)
            || !c.equals(c)
            || !c.equals(d)) {
        errln("Fail");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:CalendarRegression.java

示例4: Test4092362

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public void Test4092362() {
    GregorianCalendar cal1 = new GregorianCalendar(1997, 10, 11, 10, 20, 40);
    /*cal1.set( Calendar.YEAR, 1997 );
    cal1.set( Calendar.MONTH, 10 );
    cal1.set( Calendar.DATE, 11 );
    cal1.set( Calendar.HOUR, 10 );
    cal1.set( Calendar.MINUTE, 20 );
    cal1.set( Calendar.SECOND, 40 ); */

    logln(" Cal1 = " + cal1.getTime().getTime());
    logln(" Cal1 time in ms = " + cal1.get(MILLISECOND));
    for (int k = 0; k < 100; k++);

    GregorianCalendar cal2 = new GregorianCalendar(1997, 10, 11, 10, 20, 40);
    /*cal2.set( Calendar.YEAR, 1997 );
    cal2.set( Calendar.MONTH, 10 );
    cal2.set( Calendar.DATE, 11 );
    cal2.set( Calendar.HOUR, 10 );
    cal2.set( Calendar.MINUTE, 20 );
    cal2.set( Calendar.SECOND, 40 ); */

    logln(" Cal2 = " + cal2.getTime().getTime());
    logln(" Cal2 time in ms = " + cal2.get(MILLISECOND));
    if (!cal1.equals(cal2)) {
        errln("Fail: Milliseconds randomized");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:CalendarRegression.java

示例5: Test4141665

import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
 * GregorianCalendar.equals() ignores cutover date
 */
public void Test4141665() {
    GregorianCalendar cal = new GregorianCalendar();
    GregorianCalendar cal2 = (GregorianCalendar) cal.clone();
    Date cut = cal.getGregorianChange();
    Date cut2 = new Date(cut.getTime() + 100 * 24 * 60 * 60 * 1000L); // 100 days later
    if (!cal.equals(cal2)) {
        errln("Cloned GregorianCalendars not equal");
    }
    cal2.setGregorianChange(cut2);
    if (cal.equals(cal2)) {
        errln("GregorianCalendar.equals() ignores cutover");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:CalendarRegression.java


注:本文中的java.util.GregorianCalendar.equals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。