Skip to content

Commit

Permalink
Fix LGTM issues (#611)
Browse files Browse the repository at this point in the history
These were mostly false positives
  • Loading branch information
jodastephen authored Jul 29, 2022
1 parent d12c456 commit e2f678a
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 40 deletions.
50 changes: 25 additions & 25 deletions src/main/java/org/joda/time/DurationField.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,31 +283,31 @@ public long subtract(long instant, long value) {
// */
// public abstract int compareTo(DurationField durationField);

/**
* Returns a localized unit name of this field, using the given value as an
* aid. For example, the unit name may differ if it is plural.
*
* @param value the duration value to use for selecting a unit name
* @param locale the locale to use for selecting a name, null for default
*/
//String getUnitName(long value, Locale locale);

/**
* Returns a localized unit name of this field, using the given value as an
* aid. For example, the unit name may differ if it is plural.
*
* @param value the duration value to use for selecting a unit name
*/
//String getUnitName(long value);

/**
* Get the maximum length string returned by getUnitName.
*
* @param locale the locale to use for selecting a unit name, null for
* default
* @return the maximum name length
*/
//int getMaximumUnitNameLength(Locale locale);
// /**
// * Returns a localized unit name of this field, using the given value as an
// * aid. For example, the unit name may differ if it is plural.
// *
// * @param value the duration value to use for selecting a unit name
// * @param locale the locale to use for selecting a name, null for default
// */
// //String getUnitName(long value, Locale locale);
//
// /**
// * Returns a localized unit name of this field, using the given value as an
// * aid. For example, the unit name may differ if it is plural.
// *
// * @param value the duration value to use for selecting a unit name
// */
// //String getUnitName(long value);
//
// /**
// * Get the maximum length string returned by getUnitName.
// *
// * @param locale the locale to use for selecting a unit name, null for
// * default
// * @return the maximum name length
// */
// //int getMaximumUnitNameLength(Locale locale);

//------------------------------------------------------------------------
/**
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/org/joda/time/LocalDateTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,21 @@ public boolean equals(Object partial) {
return super.equals(partial);
}

@Override
public int hashCode() {
int total = 157;
total = 23 * total + iChronology.year().get(iLocalMillis);
total = 23 * total + iChronology.year().getType().hashCode();
total = 23 * total + iChronology.monthOfYear().get(iLocalMillis);
total = 23 * total + iChronology.monthOfYear().getType().hashCode();
total = 23 * total + iChronology.dayOfMonth().get(iLocalMillis);
total = 23 * total + iChronology.dayOfMonth().getType().hashCode();
total = 23 * total + iChronology.millisOfDay().get(iLocalMillis);
total = 23 * total + iChronology.millisOfDay().getType().hashCode();
total += getChronology().hashCode();
return total;
}

/**
* Compares this partial with another returning an integer
* indicating the order.
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/org/joda/time/LocalTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,21 @@ public boolean equals(Object partial) {
return super.equals(partial);
}

@Override
public int hashCode() {
int total = 157;
total = 23 * total + iChronology.hourOfDay().get(iLocalMillis);
total = 23 * total + iChronology.hourOfDay().getType().hashCode();
total = 23 * total + iChronology.minuteOfHour().get(iLocalMillis);
total = 23 * total + iChronology.minuteOfHour().getType().hashCode();
total = 23 * total + iChronology.secondOfMinute().get(iLocalMillis);
total = 23 * total + iChronology.secondOfMinute().getType().hashCode();
total = 23 * total + iChronology.millisOfSecond().get(iLocalMillis);
total = 23 * total + iChronology.millisOfSecond().getType().hashCode();
total += getChronology().hashCode();
return total;
}

/**
* Compares this partial with another returning an integer
* indicating the order.
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/joda/time/format/DateTimeFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,9 @@ public DateTimeZone getZone() {
* @since 1.1
*/
public DateTimeFormatter withPivotYear(Integer pivotYear) {
if (iPivotYear == pivotYear || (iPivotYear != null && iPivotYear.equals(pivotYear))) {
long oldVal = iPivotYear == null ? Long.MIN_VALUE : iPivotYear;
long newVal = pivotYear == null ? Long.MIN_VALUE : pivotYear;
if (oldVal == newVal) {
return this;
}
return new DateTimeFormatter(iPrinter, iParser, iLocale,
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/joda/time/format/ISODateTimeFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@ private static void checkNotStrictISO(Collection<DateTimeFieldType> fields, bool
*
* @param bld the builder
* @param extended whether to append the separator
* @param sep the separator
* @since 1.1
*/
private static void appendSeparator(DateTimeFormatterBuilder bld, boolean extended) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,9 @@ public boolean equals(Object obj) {
return false;
}


@Override
public int hashCode() {
return underlying.hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,8 @@ public boolean equals(Object obj) {
return false;
}

@Override
public int hashCode() {
return underlying.hashCode();
}
}
23 changes: 22 additions & 1 deletion src/main/java/org/joda/time/tz/DateTimeZoneBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.Locale;
import java.util.Objects;
import java.util.Set;

import org.joda.time.Chronology;
Expand Down Expand Up @@ -656,6 +657,11 @@ public boolean equals(Object obj) {
}
return false;
}

@Override
public int hashCode() {
return Arrays.hashCode(new Object[] {iMode, iMonthOfYear, iDayOfMonth, iDayOfWeek, iAdvance, iMillisOfDay});
}

@Override
public String toString() {
Expand Down Expand Up @@ -805,6 +811,11 @@ public boolean equals(Object obj) {
return false;
}

@Override
public int hashCode() {
return Arrays.hashCode(new Object[] {iSaveMillis, iNameKey, iOfYear});
}

public void writeTo(DataOutput out) throws IOException {
iOfYear.writeTo(out);
out.writeUTF(iNameKey);
Expand Down Expand Up @@ -1344,6 +1355,11 @@ public boolean equals(Object obj) {
return false;
}

@Override
public int hashCode() {
return Arrays.hashCode(new Object[] {iStandardOffset, iStartRecurrence, iEndRecurrence});
}

public void writeTo(DataOutput out) throws IOException {
writeMillis(out, iStandardOffset);
iStartRecurrence.writeTo(out);
Expand Down Expand Up @@ -1497,7 +1513,7 @@ static PrecalculatedZone create(String id, boolean outputID, ArrayList<Transitio
}
if (curOffset > nextOffset) {
nameKeys[i] = (curNameKey + "-Summer").intern();
} else if (curOffset < nextOffset) {
} else {
nameKeys[i + 1] = (nextNameKey + "-Summer").intern();
i++;
}
Expand Down Expand Up @@ -1691,6 +1707,11 @@ public boolean equals(Object obj) {
return false;
}

@Override
public int hashCode() {
return getID().hashCode();
}

public void writeTo(DataOutput out) throws IOException {
int size = iTransitions.length;

Expand Down
27 changes: 15 additions & 12 deletions src/main/java/org/joda/time/tz/ZoneInfoCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,26 @@ public static void main(String[] args) throws Exception {
boolean verbose = false;

int i;
for (i=0; i<args.length; i++) {
try {
if ("-src".equals(args[i])) {
inputDir = new File(args[++i]);
} else if ("-dst".equals(args[i])) {
outputDir = new File(args[++i]);
} else if ("-verbose".equals(args[i])) {
verbose = true;
} else if ("-?".equals(args[i])) {
for (i = 0; i < args.length; i++) {
if ("-src".equals(args[i])) {
if (++i >= args.length) {
printUsage();
return;
}
inputDir = new File(args[i]);
} else if ("-dst".equals(args[i])) {
if (++i >= args.length) {
printUsage();
return;
} else {
break;
}
} catch (IndexOutOfBoundsException e) {
outputDir = new File(args[i]);
} else if ("-verbose".equals(args[i])) {
verbose = true;
} else if ("-?".equals(args[i])) {
printUsage();
return;
} else {
break;
}
}

Expand Down

0 comments on commit e2f678a

Please sign in to comment.