Skip to content

Commit

Permalink
ForgetfulMap
Browse files Browse the repository at this point in the history
  • Loading branch information
apete committed Nov 24, 2024
1 parent 135198c commit bde45d1
Show file tree
Hide file tree
Showing 6 changed files with 508 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.ojalgo</groupId>
<artifactId>ojalgo</artifactId>
<version>55.0.1</version>
<version>55.0.2-SNAPSHOT</version>
<name>ojAlgo</name>
<description>oj! Algorithms - ojAlgo - is Open Source Java code that has to do with mathematics, linear algebra and optimisation.</description>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static ExecutorService newSingleThreadExecutor(final String name) {
/**
* Like {@link Executors#newSingleThreadScheduledExecutor()} but with identifiable (daemon) threads
*/
public static ExecutorService newSingleThreadScheduledExecutor(final String name) {
public static ScheduledExecutorService newSingleThreadScheduledExecutor(final String name) {
return Executors.newSingleThreadScheduledExecutor(DaemonPoolExecutor.newThreadFactory(name));
}

Expand Down
34 changes: 22 additions & 12 deletions src/main/java/org/ojalgo/type/CalendarDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ default CalendarDate adjustInto(final CalendarDate temporal) {
default long adjustInto(final long epochMilli) {
long duration = this.toDurationInMillis();
long half = duration / 2L;
return ((epochMilli / duration) * duration) + half;
return epochMilli / duration * duration + half;
}

/**
Expand All @@ -95,10 +95,12 @@ default long toDurationInNanos() {
return this.toDurationInMillis() * NANOS_PER_MILLIS;
}

@Override
default long toIndex(final CalendarDate key) {
return this.adjustInto(key.millis);
}

@Override
default CalendarDate toKey(final long index) {
return new CalendarDate(index);
}
Expand All @@ -120,7 +122,7 @@ public static CalendarDate from(final TemporalAccessor temporal) {
try {
long tmpSeconds = temporal.getLong(ChronoField.INSTANT_SECONDS);
int tmpMillisOfSecond = temporal.get(ChronoField.MILLI_OF_SECOND);
return new CalendarDate((tmpSeconds * MILLIS_PER_SECOND) + tmpMillisOfSecond);
return new CalendarDate(tmpSeconds * MILLIS_PER_SECOND + tmpMillisOfSecond);
} catch (DateTimeException ex) {
throw new DateTimeException("Unable to obtain CalendarDate from TemporalAccessor: " + temporal + " of type " + temporal.getClass().getName(),
ex);
Expand Down Expand Up @@ -232,7 +234,7 @@ static long millis(final TemporalAccessor temporal) {
try {
long tmpSeconds = temporal.getLong(ChronoField.INSTANT_SECONDS);
int tmpMillisOfSecond = temporal.get(ChronoField.MILLI_OF_SECOND);
return (tmpSeconds * MILLIS_PER_SECOND) + tmpMillisOfSecond;
return tmpSeconds * MILLIS_PER_SECOND + tmpMillisOfSecond;
} catch (DateTimeException ex) {
throw new DateTimeException("No millis!");
}
Expand Down Expand Up @@ -312,11 +314,12 @@ public <T extends Temporal> T adjustInto(final T temporal) {
return (T) this;
} else {
long seconds = millis / MILLIS_PER_SECOND;
long nanos = (millis % MILLIS_PER_SECOND) * (NANOS_PER_SECOND / MILLIS_PER_SECOND);
long nanos = millis % MILLIS_PER_SECOND * (NANOS_PER_SECOND / MILLIS_PER_SECOND);
return (T) temporal.with(INSTANT_SECONDS, seconds).with(NANO_OF_SECOND, nanos);
}
}

@Override
public int compareTo(final CalendarDate ref) {
return Long.signum(millis - ref.millis);
}
Expand All @@ -326,7 +329,7 @@ public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if ((obj == null) || !(obj instanceof CalendarDate)) {
if (obj == null || !(obj instanceof CalendarDate)) {
return false;
}
CalendarDate other = (CalendarDate) obj;
Expand All @@ -344,6 +347,7 @@ public CalendarDate filter(final CalendarDateUnit resolution) {
}
}

@Override
public long getLong(final TemporalField field) {
if (field instanceof ChronoField) {
if (field == ChronoField.INSTANT_SECONDS) {
Expand All @@ -358,29 +362,32 @@ public long getLong(final TemporalField field) {

@Override
public int hashCode() {
return (int) (millis ^ (millis >>> 32));
return (int) (millis ^ millis >>> 32);
}

@Override
public boolean isSupported(final TemporalField field) {
if (field instanceof ChronoField) {
return (field == ChronoField.INSTANT_SECONDS) || (field == ChronoField.MILLI_OF_SECOND);
return field == ChronoField.INSTANT_SECONDS || field == ChronoField.MILLI_OF_SECOND;
} else {
return field.isSupportedBy(this);
}
}

@Override
public boolean isSupported(final TemporalUnit unit) {
if (unit instanceof CalendarDateUnit) {
return true;
} else if (unit instanceof ChronoUnit) {
return unit.isTimeBased() || (unit == ChronoUnit.DAYS);
return unit.isTimeBased() || unit == ChronoUnit.DAYS;
} else if (unit != null) {
return unit.isSupportedBy(this);
} else {
return false;
}
}

@Override
public Temporal plus(final long amountToAdd, final TemporalUnit unit) {
if (unit instanceof CalendarDateUnit) {
return this.step((int) amountToAdd, (CalendarDateUnit) unit);
Expand All @@ -403,7 +410,7 @@ public CalendarDate step(final CalendarDateUnit aStepUnit) {
}

public CalendarDate step(final int aStepCount, final CalendarDateUnit aStepUnit) {
return new CalendarDate(millis + (aStepCount * aStepUnit.toDurationInMillis()));
return new CalendarDate(millis + aStepCount * aStepUnit.toDurationInMillis());
}

public Calendar toCalendar() {
Expand Down Expand Up @@ -456,7 +463,7 @@ public LocalTime toLocalTime(final ZoneOffset offset) {
int tmpNanos = (int) Math.floorMod(millis, MILLIS_PER_SECOND);
long tmpLocalSeconds = tmpSeconds + offset.getTotalSeconds();
int tmpSecondOfDay = (int) Math.floorMod(tmpLocalSeconds, CalendarDate.SECONDS_PER_DAY);
int tmpNanoOfDay = (tmpSecondOfDay * CalendarDate.NANOS_PER_SECOND) + tmpNanos;
int tmpNanoOfDay = tmpSecondOfDay * CalendarDate.NANOS_PER_SECOND + tmpNanos;
return LocalTime.ofNanoOfDay(tmpNanoOfDay);
}

Expand All @@ -473,6 +480,7 @@ public ZonedDateTime toZonedDateTime(final ZoneOffset offset) {
return ZonedDateTime.of(this.toLocalDateTime(offset), offset);
}

@Override
public long until(final Temporal endExclusive, final TemporalUnit unit) {
if (unit instanceof CalendarDateUnit) {
return ((CalendarDateUnit) unit).count(millis, CalendarDate.millis(endExclusive));
Expand All @@ -483,18 +491,20 @@ public long until(final Temporal endExclusive, final TemporalUnit unit) {
}
}

@Override
public CalendarDate with(final TemporalAdjuster adjuster) {
return (CalendarDate) Temporal.super.with(adjuster);
}

@Override
public CalendarDate with(final TemporalField field, final long newValue) {
if (field instanceof ChronoField) {
if (field == ChronoField.INSTANT_SECONDS) {
long tmpMillisOfSecond = millis % MILLIS_PER_SECOND;
return new CalendarDate((newValue * MILLIS_PER_SECOND) + tmpMillisOfSecond);
return new CalendarDate(newValue * MILLIS_PER_SECOND + tmpMillisOfSecond);
} else if (field == ChronoField.MILLI_OF_SECOND) {
long tmpSeconds = millis / MILLIS_PER_SECOND;
return new CalendarDate((tmpSeconds * MILLIS_PER_SECOND) + newValue);
return new CalendarDate(tmpSeconds * MILLIS_PER_SECOND + newValue);
} else {
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
Expand Down
Loading

0 comments on commit bde45d1

Please sign in to comment.