CPD Results
The following document contains the results of PMD's CPD 6.55.0.
Duplications
File |
Line |
org/threeten/extra/chrono/Symmetry010Chronology.java |
418 |
org/threeten/extra/chrono/Symmetry454Chronology.java |
411 |
return (ChronoZonedDateTime<Symmetry010Date>) super.zonedDateTime(instant, zone);
}
//-----------------------------------------------------------------------
/**
* Checks if the specified year is a leap year.
* <p>
* A leap-year is a year of a longer length than normal.
* Leap years in the calendar system match those of the ISO calendar system.
*
* @param year the proleptic-year to check, not validated for range
* @return true if the year is a leap year
*/
@Override
public boolean isLeapYear(long year) {
return WEEKS_IN_YEAR > ((WEEKS_IN_YEAR * year + 146) % YEARS_IN_CYCLE);
}
//-----------------------------------------------------------------------
/**
* Creates the chronology era object from the numeric value.
* <p>
* The list of eras is shared with {@link IsoEra}.
*
* @param eraValue the era value
* @return the calendar system era, not null
* @throws DateTimeException if unable to create the era
*/
@Override
public IsoEra eraOf(int eraValue) {
return IsoEra.of(eraValue);
}
/**
* Gets the list of eras for the chronology.
* <p>
* The list of eras is shared with {@link IsoEra}.
*
* @return the list of eras for the chronology, may be immutable, not null
*/
@Override
public List<Era> eras() {
return Arrays.<Era>asList(IsoEra.values());
}
//-----------------------------------------------------------------------
@Override
public ValueRange range(ChronoField field) {
switch (field) {
case ALIGNED_DAY_OF_WEEK_IN_YEAR:
case ALIGNED_DAY_OF_WEEK_IN_MONTH:
case DAY_OF_WEEK:
return ValueRange.of(1, DAYS_IN_WEEK);
case ALIGNED_WEEK_OF_MONTH:
return ValueRange.of(1, WEEKS_IN_MONTH, WEEKS_IN_MONTH_LONG);
case ALIGNED_WEEK_OF_YEAR:
return ValueRange.of(1, WEEKS_IN_YEAR, WEEKS_IN_YEAR + 1);
case DAY_OF_MONTH:
return DAY_OF_MONTH_RANGE;
case DAY_OF_YEAR:
return DAY_OF_YEAR_RANGE;
case EPOCH_DAY:
return EPOCH_DAY_RANGE;
case ERA:
return ERA_RANGE;
case MONTH_OF_YEAR:
return MONTH_OF_YEAR_RANGE;
case PROLEPTIC_MONTH:
return PROLEPTIC_MONTH_RANGE;
case YEAR_OF_ERA:
case YEAR:
return YEAR_RANGE;
default:
return field.range();
}
}
@Override
public int prolepticYear(Era era, int yearOfEra) {
if (!(era instanceof IsoEra)) {
throw new ClassCastException("Invalid era: " + era);
}
return YEAR_RANGE.checkValidIntValue(yearOfEra, ChronoField.YEAR_OF_ERA);
}
/**
* Get the count of leap years since CE 1.
*
* @param prolepticYear the year
* @return the number of leap years since CE 1
*/
public static long getLeapYearsBefore(long prolepticYear) {
return Math.floorDiv(WEEKS_IN_YEAR * (prolepticYear - 1) + 146, YEARS_IN_CYCLE);
}
}
|
File |
Line |
org/threeten/extra/chrono/Symmetry010Chronology.java |
141 |
org/threeten/extra/chrono/Symmetry454Chronology.java |
134 |
static final int WEEKS_IN_YEAR_LONG = DAYS_IN_YEAR_LONG / DAYS_IN_WEEK;
/**
* Number of years in a cycle.
*/
private static final int YEARS_IN_CYCLE = 293;
/**
* Number of days in a cycle.
*/
static final int DAYS_PER_CYCLE = YEARS_IN_CYCLE * DAYS_IN_YEAR + WEEKS_IN_YEAR * DAYS_IN_WEEK; // == 294 full years!
/**
* The number of days from year zero to CE 1970, still the era only allows CE 1 and higher.
* There are 6 full 293-year cycles from CE 1 to 1758, with 6 * 52 leap years, i.e. 312.
* There are 37 leap years from CE 1758 to 1970.
*/
public static final long DAYS_0001_TO_1970 = (146097 * 5L) - (31L * 365L + 7L) - 1;
/**
* Highest year in the range.
*/
private static final long MAX_YEAR = 1_000_000L;
/**
* Range of year.
*/
static final ValueRange YEAR_RANGE = ValueRange.of(-MAX_YEAR, MAX_YEAR);
/**
* Epoch day range.
*/
static final ValueRange EPOCH_DAY_RANGE = ValueRange.of(
-MAX_YEAR * DAYS_IN_YEAR - getLeapYearsBefore(MAX_YEAR) * DAYS_IN_WEEK - DAYS_0001_TO_1970,
MAX_YEAR * DAYS_IN_YEAR + getLeapYearsBefore(MAX_YEAR) * DAYS_IN_WEEK - DAYS_0001_TO_1970);
/**
* Range of proleptic month.
*/
private static final ValueRange PROLEPTIC_MONTH_RANGE = ValueRange.of(-MAX_YEAR * MONTHS_IN_YEAR, MAX_YEAR * MONTHS_IN_YEAR - 1);
/**
* Range of day of month.
*/
static final ValueRange DAY_OF_MONTH_RANGE = ValueRange.of(1, DAYS_IN_MONTH, DAYS_IN_MONTH_LONG + 6);
|
File |
Line |
org/threeten/extra/chrono/Symmetry010Date.java |
630 |
org/threeten/extra/chrono/Symmetry454Date.java |
648 |
Symmetry010Chronology.getLeapYearsBefore(this.prolepticYear) * DAYS_IN_WEEK +
this.dayOfYear -
DAYS_0001_TO_1970 - 1;
return epochDay;
}
/**
* Display the date in human-readable format.
*
* @return the string representation
*/
@Override
public String toString() {
StringBuilder buf = new StringBuilder(30);
return buf.append(getChronology().toString())
.append(' ')
.append(getEra())
.append(' ')
.append(getYearOfEra())
.append(this.month < 10 && this.month > 0 ? "/0" : '/')
.append(this.month)
.append(this.day < 10 ? "/0" : '/')
.append(this.day)
.toString();
}
}
|
File |
Line |
org/threeten/extra/YearHalf.java |
840 |
org/threeten/extra/YearQuarter.java |
841 |
return plusHalves(amountToAdd);
} else if (unit instanceof ChronoUnit) {
switch ((ChronoUnit) unit) {
case YEARS:
return plusYears(amountToAdd);
case DECADES:
return plusYears(Math.multiplyExact(amountToAdd, 10));
case CENTURIES:
return plusYears(Math.multiplyExact(amountToAdd, 100));
case MILLENNIA:
return plusYears(Math.multiplyExact(amountToAdd, 1000));
case ERAS:
return with(ERA, Math.addExact(getLong(ERA), amountToAdd));
default:
throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
}
}
return unit.addTo(this, amountToAdd);
}
/**
* Returns a copy of this year-half with the specified period in years added.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param yearsToAdd the years to add, may be negative
* @return a {@code YearHalf} based on this year-half with the years added, not null
* @throws DateTimeException if the result exceeds the supported range
*/
public YearHalf plusYears(long yearsToAdd) {
|
File |
Line |
org/threeten/extra/chrono/Symmetry010Date.java |
429 |
org/threeten/extra/chrono/Symmetry454Date.java |
433 |
return ValueRange.of(1, lengthOfMonth() / DAYS_IN_WEEK);
case ALIGNED_WEEK_OF_YEAR:
return ValueRange.of(1, WEEKS_IN_YEAR + (isLeapYear() ? 1 : 0));
case DAY_OF_MONTH:
return ValueRange.of(1, lengthOfMonth());
case DAY_OF_YEAR:
return ValueRange.of(1, lengthOfYear());
case EPOCH_DAY:
return EPOCH_DAY_RANGE;
case ERA:
return ERA_RANGE;
case MONTH_OF_YEAR:
return MONTH_OF_YEAR_RANGE;
default:
break;
}
} else {
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
}
return super.range(field);
}
@Override
ValueRange rangeAlignedWeekOfMonth() {
// never invoked
return ValueRange.of(1, WEEKS_IN_MONTH);
}
@Override
|
File |
Line |
org/threeten/extra/YearHalf.java |
1259 |
org/threeten/extra/YearQuarter.java |
1260 |
return year ^ (half.getValue() << 28);
}
//-----------------------------------------------------------------------
/**
* Outputs this year-half as a {@code String}, such as {@code 2007-H2}.
*
* @return a string representation of this year-half, not null
*/
@Override
@ToString
public String toString() {
int absYear = Math.abs(year);
StringBuilder buf = new StringBuilder(10);
if (absYear < 1000) {
if (year < 0) {
buf.append(year - 10000).deleteCharAt(1);
} else {
buf.append(year + 10000).deleteCharAt(0);
}
} else {
if (year > 9999) {
buf.append('+');
}
buf.append(year);
}
return buf.append('-').append(half).toString();
|
File |
Line |
org/threeten/extra/chrono/InternationalFixedDate.java |
762 |
org/threeten/extra/chrono/Symmetry010Date.java |
635 |
org/threeten/extra/chrono/Symmetry454Date.java |
653 |
}
/**
* Display the date in human-readable format.
*
* @return the string representation
*/
@Override
public String toString() {
StringBuilder buf = new StringBuilder(30);
return buf.append(getChronology().toString())
.append(' ')
.append(getEra())
.append(' ')
.append(getYearOfEra())
.append(this.month < 10 && this.month > 0 ? "/0" : '/')
.append(this.month)
.append(this.day < 10 ? "/0" : '/')
.append(this.day)
.toString();
}
}
|
File |
Line |
org/threeten/extra/YearHalf.java |
713 |
org/threeten/extra/YearQuarter.java |
714 |
return withHalf(HALF_OF_YEAR.range().checkValidIntValue(newValue, HALF_OF_YEAR));
} else if (field instanceof ChronoField) {
ChronoField f = (ChronoField) field;
f.checkValidValue(newValue);
switch (f) {
case YEAR_OF_ERA:
return withYear((int) (year < 1 ? 1 - newValue : newValue));
case YEAR:
return withYear((int) newValue);
case ERA:
return (getLong(ERA) == newValue ? this : withYear(1 - year));
default:
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
}
return field.adjustInto(this, newValue);
}
//-----------------------------------------------------------------------
/**
* Returns a copy of this {@code YearHalf} with the year altered.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param year the year to set in the returned year-half, from MIN_YEAR to MAX_YEAR
* @return a {@code YearHalf} based on this year-half with the requested year, not null
* @throws DateTimeException if the year value is invalid
*/
public YearHalf withYear(int year) {
|
File |
Line |
org/threeten/extra/chrono/BritishCutoverChronology.java |
421 |
org/threeten/extra/chrono/JulianChronology.java |
351 |
}
@Override
public int prolepticYear(Era era, int yearOfEra) {
if (era instanceof JulianEra == false) {
throw new ClassCastException("Era must be JulianEra");
}
return (era == JulianEra.AD ? yearOfEra : 1 - yearOfEra);
}
@Override
public JulianEra eraOf(int eraValue) {
return JulianEra.of(eraValue);
}
@Override
public List<Era> eras() {
return Arrays.<Era>asList(JulianEra.values());
}
//-----------------------------------------------------------------------
@Override
public ValueRange range(ChronoField field) {
switch (field) {
case DAY_OF_YEAR:
|
File |
Line |
org/threeten/extra/YearHalf.java |
1259 |
org/threeten/extra/YearQuarter.java |
1260 |
org/threeten/extra/YearWeek.java |
1090 |
return year ^ (half.getValue() << 28);
}
//-----------------------------------------------------------------------
/**
* Outputs this year-half as a {@code String}, such as {@code 2007-H2}.
*
* @return a string representation of this year-half, not null
*/
@Override
@ToString
public String toString() {
int absYear = Math.abs(year);
StringBuilder buf = new StringBuilder(10);
if (absYear < 1000) {
if (year < 0) {
buf.append(year - 10000).deleteCharAt(1);
} else {
buf.append(year + 10000).deleteCharAt(0);
}
} else {
if (year > 9999) {
buf.append('+');
}
buf.append(year);
}
return buf.append('-').append(half).toString();
|