Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ import java.text.ParseException
object HijrahDateConfigurator {

/** File separator. */
private val FILE_SEP: Char = File.separatorChar
private def FILE_SEP: Char = File.separatorChar

/** Path separator. */
private val PATH_SEP: String = File.pathSeparator
private def PATH_SEP: String = File.pathSeparator

/** Default config file name. */
private val DEFAULT_CONFIG_FILENAME: String = "hijrah_deviation.cfg"
private def DEFAULT_CONFIG_FILENAME: String = "hijrah_deviation.cfg"

/** Default path to the config file. */
private val DEFAULT_CONFIG_PATH: String = s"org${FILE_SEP}threeten${FILE_SEP}bp${FILE_SEP}chrono"
private def DEFAULT_CONFIG_PATH: String = s"org${FILE_SEP}threeten${FILE_SEP}bp${FILE_SEP}chrono"

/** Read hijrah_deviation.cfg file. The config file contains the deviation data with
* following format.
Expand Down
6 changes: 3 additions & 3 deletions core/shared/src/main/scala/org/threeten/bp/DayOfWeek.scala
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ object DayOfWeek {

/** Private cache of all the constants.
*/
private lazy val ENUMS: Array[DayOfWeek] = DayOfWeek.values
private def ENUMS: Array[DayOfWeek] = DayOfWeek.values

/** Obtains an instance of {@code DayOfWeek} from an {@code int} value.
*
Expand Down Expand Up @@ -242,7 +242,7 @@ final class DayOfWeek(name: String, ordinal: Int)
if (field eq DAY_OF_WEEK)
field.range
else if (field.isInstanceOf[ChronoField])
throw new UnsupportedTemporalTypeException(s"Unsupported field: $field")
throw throw UnsupportedTemporalTypeException.field(field)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these throw throw intended ?

else
field.rangeRefinedBy(this)

Expand Down Expand Up @@ -299,7 +299,7 @@ final class DayOfWeek(name: String, ordinal: Int)
if (field eq DAY_OF_WEEK)
getValue.toLong
else if (field.isInstanceOf[ChronoField])
throw new UnsupportedTemporalTypeException(s"Unsupported field: $field")
throw throw UnsupportedTemporalTypeException.field(field)
else
field.getFrom(this)

Expand Down
92 changes: 46 additions & 46 deletions core/shared/src/main/scala/org/threeten/bp/Duration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ object Duration {
lazy val ZERO: Duration = new Duration(0, 0)

/** Constant for nanos per second. */
private val NANOS_PER_SECOND: Int = 1000000000
private def NANOS_PER_SECOND: Int = 1000000000

/** Constant for nanos per milli. */
private val NANOS_PER_MILLI: Int = 1000000
private def NANOS_PER_MILLI: Int = 1000000

/** Constant for nanos per second. */
private lazy val BI_NANOS_PER_SECOND: BigInteger = BigInteger.valueOf(NANOS_PER_SECOND.toLong)
private def BI_NANOS_PER_SECOND: BigInteger = BigInteger.valueOf(NANOS_PER_SECOND.toLong)

/** The pattern for parsing. */
private lazy val PATTERN: Pattern = Pattern.compile(
private def PATTERN: Pattern = Pattern.compile(
"([-+]?)P(?:([-+]?[0-9]+)D)?" + "(T(?:([-+]?[0-9]+)H)?(?:([-+]?[0-9]+)M)?(?:([-+]?[0-9]+)(?:[.,]([0-9]{0,9}))?S)?)?",
Pattern.CASE_INSENSITIVE
)
Expand Down Expand Up @@ -351,49 +351,49 @@ object Duration {
parsed: String,
multiplier: Int,
errorText: String
): Long = {
var _parsed = parsed
if (_parsed == null)
return 0
try {
if (_parsed.startsWith("+"))
_parsed = _parsed.substring(1)
val `val`: Long = java.lang.Long.parseLong(_parsed)
Math.multiplyExact(`val`, multiplier.toLong)
} catch {
case ex: NumberFormatException =>
throw new DateTimeParseException(s"Text cannot be parsed to a Duration: $errorText",
text,
0,
ex)
case ex: ArithmeticException =>
throw new DateTimeParseException(s"Text cannot be parsed to a Duration: $errorText",
text,
0,
ex)
): Long =
if (parsed == null) {
0
} else {
try {
val p =
if (parsed.startsWith("+"))
parsed.substring(1)
else parsed
val v: Long = java.lang.Long.parseLong(p)
Math.multiplyExact(v, multiplier.toLong)
} catch {
case ex: NumberFormatException =>
throw new DateTimeParseException(s"Text cannot be parsed to a Duration: $errorText",
text,
0,
ex)
case ex: ArithmeticException =>
throw new DateTimeParseException(s"Text cannot be parsed to a Duration: $errorText",
text,
0,
ex)
}
}
}

private def parseFraction(text: CharSequence, parsed: String, negate: Int): Int = {
var _parsed = parsed
if (_parsed == null || _parsed.length == 0)
return 0
try {
_parsed = (_parsed + "000000000").substring(0, 9)
_parsed.toInt * negate
} catch {
case ex: NumberFormatException =>
throw new DateTimeParseException("Text cannot be parsed to a Duration: fraction",
text,
0,
ex)
case ex: ArithmeticException =>
throw new DateTimeParseException("Text cannot be parsed to a Duration: fraction",
text,
0,
ex)
}
}
private def parseFraction(text: CharSequence, parsed: String, negate: Int): Int =
if (parsed == null || parsed.length == 0) {
0
} else
try {
(parsed + "000000000").substring(0, 9).toInt * negate
} catch {
case ex: NumberFormatException =>
throw new DateTimeParseException("Text cannot be parsed to a Duration: fraction",
text,
0,
ex)
case ex: ArithmeticException =>
throw new DateTimeParseException("Text cannot be parsed to a Duration: fraction",
text,
0,
ex)
}

private def create(
negate: Boolean,
Expand Down Expand Up @@ -485,7 +485,7 @@ final class Duration private (private val seconds: Long, private val nanos: Int)
def get(unit: TemporalUnit): Long =
if (unit eq SECONDS) seconds
else if (unit eq NANOS) nanos.toLong
else throw new UnsupportedTemporalTypeException(s"Unsupported unit: $unit")
else throw UnsupportedTemporalTypeException.unit(unit)

/** Checks if this duration is zero length.
*
Expand Down
20 changes: 10 additions & 10 deletions core/shared/src/main/scala/org/threeten/bp/Instant.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,19 @@ object Instant {
lazy val EPOCH: Instant = new Instant(0, 0)

/** The minimum supported epoch second. */
private val MIN_SECOND: Long = -31557014167219200L
private def MIN_SECOND: Long = -31557014167219200L

/** The maximum supported epoch second. */
private val MAX_SECOND: Long = 31556889864403199L
private def MAX_SECOND: Long = 31556889864403199L

/** Constant for nanos per second. */
private val NANOS_PER_SECOND: Int = 1000000000
private def NANOS_PER_SECOND: Int = 1000000000

/** Constant for nanos per milli. */
private val NANOS_PER_MILLI: Int = 1000000
private def NANOS_PER_MILLI: Int = 1000000

/** Constant for millis per sec. */
private val MILLIS_PER_SEC = 1000
private def MILLIS_PER_SEC = 1000

/** The minimum supported {@code Instant}, '-1000000000-01-01T00:00Z'.
* This could be used by an application as a "far past" instant.
Expand Down Expand Up @@ -437,7 +437,7 @@ final class Instant private (private val seconds: Long, private val nanos: Int)
case NANO_OF_SECOND => nanos
case MICRO_OF_SECOND => nanos / 1000
case MILLI_OF_SECOND => nanos / Instant.NANOS_PER_MILLI
case _ => throw new UnsupportedTemporalTypeException(s"Unsupported field: $field")
case _ => throw UnsupportedTemporalTypeException.field(field)
}
case _ => range(field).checkValidIntValue(field.getFrom(this), field)
}
Expand Down Expand Up @@ -471,7 +471,7 @@ final class Instant private (private val seconds: Long, private val nanos: Int)
case MICRO_OF_SECOND => nanos / 1000L
case MILLI_OF_SECOND => nanos.toLong / Instant.NANOS_PER_MILLI
case INSTANT_SECONDS => seconds
case _ => throw new UnsupportedTemporalTypeException(s"Unsupported field: $field")
case _ => throw UnsupportedTemporalTypeException.field(field)
}
case _ => field.getFrom(this)
}
Expand Down Expand Up @@ -574,7 +574,7 @@ final class Instant private (private val seconds: Long, private val nanos: Int)
case INSTANT_SECONDS =>
return if (newValue != seconds) Instant.create(newValue, nanos) else this
case _ =>
throw new UnsupportedTemporalTypeException(s"Unsupported field: $field")
throw UnsupportedTemporalTypeException.field(field)
}
case _ =>
}
Expand Down Expand Up @@ -651,7 +651,7 @@ final class Instant private (private val seconds: Long, private val nanos: Int)
case DAYS =>
return plusSeconds(Math.multiplyExact(amountToAdd, SECONDS_PER_DAY.toLong))
case _ =>
throw new UnsupportedTemporalTypeException(s"Unsupported unit: $unit")
throw UnsupportedTemporalTypeException.unit(unit)
}
case _ =>
}
Expand Down Expand Up @@ -890,7 +890,7 @@ final class Instant private (private val seconds: Long, private val nanos: Int)
case DAYS =>
return secondsUntil(end) / SECONDS_PER_DAY
case _ =>
throw new UnsupportedTemporalTypeException(s"Unsupported unit: $unit")
throw throw UnsupportedTemporalTypeException.unit(unit)
}
case _ =>
}
Expand Down
12 changes: 6 additions & 6 deletions core/shared/src/main/scala/org/threeten/bp/LocalDate.scala
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ object LocalDate {
lazy val MAX: LocalDate = LocalDate.of(Year.MAX_VALUE, 12, 31)

/** The number of days in a 400 year cycle. */
private val DAYS_PER_CYCLE: Int = 146097
private def DAYS_PER_CYCLE: Int = 146097

/** The number of days from year zero to year 1970.
* There are five 400 year cycles from year zero to 2000.
* There are 7 leap years from 1970 to 2000.
*/
private[bp] val DAYS_0000_TO_1970: Long = (DAYS_PER_CYCLE * 5L) - (30L * 365L + 7L)
private[bp] def DAYS_0000_TO_1970: Long = (DAYS_PER_CYCLE * 5L) - (30L * 365L + 7L)

/** Obtains the current date from the system clock in the default time-zone.
*
Expand Down Expand Up @@ -439,7 +439,7 @@ final class LocalDate private (private val year: Int, monthOfYear: Int, dayOfMon
case _ => field.range
}
} else {
throw new UnsupportedTemporalTypeException(s"Unsupported field: $field")
throw UnsupportedTemporalTypeException.field(field)
}
} else {
field.rangeRefinedBy(this)
Expand Down Expand Up @@ -519,7 +519,7 @@ final class LocalDate private (private val year: Int, monthOfYear: Int, dayOfMon
case YEAR_OF_ERA => if (year >= 1) year.toLong else 1 - year.toLong
case YEAR => year.toLong
case ERA => if (year >= 1) 1 else 0
case _ => throw new UnsupportedTemporalTypeException(s"Unsupported field: $field")
case _ => throw UnsupportedTemporalTypeException.field(field)
}

private def getProlepticMonth: Long = (year * 12L) + (month - 1)
Expand Down Expand Up @@ -934,7 +934,7 @@ final class LocalDate private (private val year: Int, monthOfYear: Int, dayOfMon
case CENTURIES => plusYears(Math.multiplyExact(amountToAdd, 100))
case MILLENNIA => plusYears(Math.multiplyExact(amountToAdd, 1000))
case ERAS => `with`(ERA, Math.addExact(getLong(ERA), amountToAdd))
case _ => throw new UnsupportedTemporalTypeException(s"Unsupported unit: $unit")
case _ => throw throw UnsupportedTemporalTypeException.unit(unit)
}
} else {
unit.addTo(this, amountToAdd)
Expand Down Expand Up @@ -1254,7 +1254,7 @@ final class LocalDate private (private val year: Int, monthOfYear: Int, dayOfMon
case CENTURIES => monthsUntil(end) / 1200
case MILLENNIA => monthsUntil(end) / 12000
case ERAS => end.getLong(ERA) - getLong(ERA)
case _ => throw new UnsupportedTemporalTypeException(s"Unsupported unit: $unit")
case _ => throw throw UnsupportedTemporalTypeException.unit(unit)
}

} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,7 @@ final class LocalDateTime private (private val date: LocalDate, private val time
case HALF_DAYS =>
return Math.addExact(Math.multiplyExact(daysUntil, 2),
timeUntil / (NANOS_PER_HOUR * 12))
case _ => throw new UnsupportedTemporalTypeException(s"Unsupported unit: $unit")
case _ => throw UnsupportedTemporalTypeException.unit(unit)

}
}
Expand Down
24 changes: 12 additions & 12 deletions core/shared/src/main/scala/org/threeten/bp/LocalTime.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,40 +91,40 @@ object LocalTime {
lazy val NOON: LocalTime = HOURS(12)

/** Hours per day. */
private[bp] val HOURS_PER_DAY: Int = 24
private[bp] def HOURS_PER_DAY: Int = 24

/** Minutes per hour. */
private[bp] val MINUTES_PER_HOUR: Int = 60
private[bp] def MINUTES_PER_HOUR: Int = 60

/** Minutes per day. */
private[bp] val MINUTES_PER_DAY: Int = MINUTES_PER_HOUR * HOURS_PER_DAY
private[bp] def MINUTES_PER_DAY: Int = MINUTES_PER_HOUR * HOURS_PER_DAY

/** Seconds per minute. */
private[bp] val SECONDS_PER_MINUTE: Int = 60
private[bp] def SECONDS_PER_MINUTE: Int = 60

/** Seconds per hour. */
private[bp] val SECONDS_PER_HOUR: Int = SECONDS_PER_MINUTE * MINUTES_PER_HOUR
private[bp] def SECONDS_PER_HOUR: Int = SECONDS_PER_MINUTE * MINUTES_PER_HOUR

/** Seconds per day. */
private[bp] val SECONDS_PER_DAY: Int = SECONDS_PER_HOUR * HOURS_PER_DAY
private[bp] def SECONDS_PER_DAY: Int = SECONDS_PER_HOUR * HOURS_PER_DAY

/** Milliseconds per day. */
private[bp] val MILLIS_PER_DAY: Long = SECONDS_PER_DAY * 1000L
private[bp] def MILLIS_PER_DAY: Long = SECONDS_PER_DAY * 1000L

/** Microseconds per day. */
private[bp] val MICROS_PER_DAY: Long = SECONDS_PER_DAY * 1000000L
private[bp] def MICROS_PER_DAY: Long = SECONDS_PER_DAY * 1000000L

/** Nanos per second. */
private[bp] val NANOS_PER_SECOND: Long = 1000000000L
private[bp] def NANOS_PER_SECOND: Long = 1000000000L

/** Nanos per minute. */
private[bp] val NANOS_PER_MINUTE: Long = NANOS_PER_SECOND * SECONDS_PER_MINUTE
private[bp] def NANOS_PER_MINUTE: Long = NANOS_PER_SECOND * SECONDS_PER_MINUTE

/** Nanos per hour. */
private[bp] val NANOS_PER_HOUR: Long = NANOS_PER_MINUTE * MINUTES_PER_HOUR
private[bp] def NANOS_PER_HOUR: Long = NANOS_PER_MINUTE * MINUTES_PER_HOUR

/** Nanos per day. */
private[bp] val NANOS_PER_DAY: Long = NANOS_PER_HOUR * HOURS_PER_DAY
private[bp] def NANOS_PER_DAY: Long = NANOS_PER_HOUR * HOURS_PER_DAY

/** Obtains the current time from the system clock in the default time-zone.
*
Expand Down
6 changes: 3 additions & 3 deletions core/shared/src/main/scala/org/threeten/bp/Month.scala
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ object Month {

/** Private cache of all the constants.
*/
private lazy val ENUMS: Array[Month] = Month.values
private def ENUMS: Array[Month] = Month.values

/** Obtains an instance of {@code Month} from an {@code int} value.
*
Expand Down Expand Up @@ -282,7 +282,7 @@ final class Month private (name: String, ordinal: Int)
if (field eq MONTH_OF_YEAR)
field.range
else if (field.isInstanceOf[ChronoField])
throw new UnsupportedTemporalTypeException(s"Unsupported field: $field")
throw UnsupportedTemporalTypeException.field(field)
else
field.rangeRefinedBy(this)

Expand Down Expand Up @@ -339,7 +339,7 @@ final class Month private (name: String, ordinal: Int)
if (field eq MONTH_OF_YEAR)
getValue.toLong
else if (field.isInstanceOf[ChronoField])
throw new UnsupportedTemporalTypeException(s"Unsupported field: $field")
throw throw UnsupportedTemporalTypeException.field(field)
else
field.getFrom(this)

Expand Down
Loading