Search in sources :

Example 16 with ThaiBuddhistDate

use of java.time.chrono.ThaiBuddhistDate in project sonar-java by SonarSource.

the class A method foo.

void foo() {
    HijrahDate hijrahDate = HijrahDate.now();
    // Noncompliant {{Synchronize on a non-value-based object; synchronizing on a "HijrahDate" could lead to contention. (sonar.java.source not set. Assuming 8 or greater.)}}
    synchronized (hijrahDate) {
    }
    JapaneseDate japaneseDate = JapaneseDate.now();
    // Noncompliant
    synchronized (japaneseDate) {
    }
    MinguoDate minguoDate = MinguoDate.now();
    // Noncompliant
    synchronized (minguoDate) {
    }
    ThaiBuddhistDate thaiBuddhistDate = ThaiBuddhistDate.now();
    // Noncompliant
    synchronized (thaiBuddhistDate) {
    }
    LocalDateTime localDateTime = LocalDateTime.now();
    // Noncompliant
    synchronized (localDateTime) {
    }
    Optional<Object> optionalEmpty = Optional.empty();
    // Noncompliant {{Synchronize on a non-value-based object; synchronizing on a "Optional" could lead to contention. (sonar.java.source not set. Assuming 8 or greater.)}}
    synchronized (optionalEmpty) {
    }
    OptionalDouble optionalDouble = OptionalDouble.empty();
    // Noncompliant
    synchronized (optionalDouble) {
    }
    OptionalLong optionalLong = OptionalLong.empty();
    // Noncompliant
    synchronized (optionalLong) {
    }
    OptionalInt optionalInt = OptionalInt.empty();
    // Noncompliant
    synchronized (optionalInt) {
    }
    Clock clock = Clock.systemUTC();
    // Compliant
    synchronized (clock) {
    }
    Object object = new Object();
    // Compliant
    synchronized (object) {
    }
    DateTimeFormatterBuilder dateTimeFormatter = new DateTimeFormatterBuilder();
    // Compliant - not part of 'java.time' package but subpackage 'java.time.format'
    synchronized (dateTimeFormatter) {
    }
    // Compliant
    synchronized (unknownObject) {
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) HijrahDate(java.time.chrono.HijrahDate) MinguoDate(java.time.chrono.MinguoDate) ThaiBuddhistDate(java.time.chrono.ThaiBuddhistDate) OptionalLong(java.util.OptionalLong) JapaneseDate(java.time.chrono.JapaneseDate) OptionalInt(java.util.OptionalInt) Clock(java.time.Clock) OptionalDouble(java.util.OptionalDouble) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder)

Example 17 with ThaiBuddhistDate

use of java.time.chrono.ThaiBuddhistDate in project jdk8u_jdk by JetBrains.

the class TCKThaiBuddhistChronology method test_withEra_BBE.

@Test
public void test_withEra_BBE() {
    ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(-2554, 8, 29);
    ThaiBuddhistDate test = base.with(ChronoField.ERA, ThaiBuddhistEra.BEFORE_BE.getValue());
    assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(-2554, 8, 29));
}
Also used : ThaiBuddhistDate(java.time.chrono.ThaiBuddhistDate) Test(org.testng.annotations.Test)

Example 18 with ThaiBuddhistDate

use of java.time.chrono.ThaiBuddhistDate in project jdk8u_jdk by JetBrains.

the class TCKThaiBuddhistChronology method test_resolve_yearOfEra.

@Test(dataProvider = "resolve_yearOfEra")
public void test_resolve_yearOfEra(ResolverStyle style, Integer e, Integer yoe, Integer y, ChronoField field, Integer expected) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    if (e != null) {
        fieldValues.put(ChronoField.ERA, (long) e);
    }
    if (yoe != null) {
        fieldValues.put(ChronoField.YEAR_OF_ERA, (long) yoe);
    }
    if (y != null) {
        fieldValues.put(ChronoField.YEAR, (long) y);
    }
    if (field != null) {
        ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, style);
        assertEquals(date, null);
        assertEquals(fieldValues.get(field), (Long) expected.longValue());
        assertEquals(fieldValues.size(), 1);
    } else {
        try {
            ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, style);
            fail("Should have failed");
        } catch (DateTimeException ex) {
        // expected
        }
    }
}
Also used : ThaiBuddhistDate(java.time.chrono.ThaiBuddhistDate) TemporalField(java.time.temporal.TemporalField) DateTimeException(java.time.DateTimeException) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Example 19 with ThaiBuddhistDate

use of java.time.chrono.ThaiBuddhistDate in project jdk8u_jdk by JetBrains.

the class TCKThaiBuddhistChronology method test_resolve_ymd_lenient.

@Test(dataProvider = "resolve_ymd")
public void test_resolve_ymd_lenient(int y, int m, int d, ThaiBuddhistDate expected, Object smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
    fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
    ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
    assertEquals(date, expected);
    assertEquals(fieldValues.size(), 0);
}
Also used : ThaiBuddhistDate(java.time.chrono.ThaiBuddhistDate) TemporalField(java.time.temporal.TemporalField) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Example 20 with ThaiBuddhistDate

use of java.time.chrono.ThaiBuddhistDate in project jdk8u_jdk by JetBrains.

the class TCKThaiBuddhistChronology method test_resolve_yd_smart.

@Test(dataProvider = "resolve_yd")
public void test_resolve_yd_smart(int y, int d, ThaiBuddhistDate expected, boolean smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
    if (smart) {
        ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
            fail("Should have failed");
        } catch (DateTimeException ex) {
        // expected
        }
    }
}
Also used : ThaiBuddhistDate(java.time.chrono.ThaiBuddhistDate) TemporalField(java.time.temporal.TemporalField) DateTimeException(java.time.DateTimeException) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Aggregations

ThaiBuddhistDate (java.time.chrono.ThaiBuddhistDate)32 Test (org.testng.annotations.Test)29 TemporalField (java.time.temporal.TemporalField)10 HashMap (java.util.HashMap)10 DateTimeException (java.time.DateTimeException)7 LocalDateTime (java.time.LocalDateTime)3 ChronoPeriod (java.time.chrono.ChronoPeriod)3 MinguoDate (java.time.chrono.MinguoDate)3 LocalDate (java.time.LocalDate)2 ChronoLocalDate (java.time.chrono.ChronoLocalDate)2 DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)2 ParsePosition (java.text.ParsePosition)1 Clock (java.time.Clock)1 Instant (java.time.Instant)1 LocalTime (java.time.LocalTime)1 OffsetDateTime (java.time.OffsetDateTime)1 OffsetTime (java.time.OffsetTime)1 YearMonth (java.time.YearMonth)1 ZonedDateTime (java.time.ZonedDateTime)1 ChronoZonedDateTime (java.time.chrono.ChronoZonedDateTime)1