Skip to content

Commit

Permalink
Version 1.3.0.
Browse files Browse the repository at this point in the history
Deprecate some null-wrapping methods.
Add sortedInReverse.
Add I/O functions based on Input and Output typeclasses and deprecate some old I/O.
Add dot.
Simplify PrintingMode givens.
Make timers AutoCloseable.
(Redo grading code in T module.)
  • Loading branch information
Michel Charpentier authored and Michel Charpentier committed Aug 15, 2024
1 parent fe49c2b commit c354d24
Show file tree
Hide file tree
Showing 139 changed files with 6,373 additions and 1,009 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Set up JDK 21
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '21'
java-version: '11'
distribution: 'temurin'
cache: 'sbt'

Expand Down
16 changes: 8 additions & 8 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 3.7.17
version = 3.8.3
runner.dialect = scala3

fileOverride {
Expand Down Expand Up @@ -27,16 +27,16 @@ newlines {
}

spaces {
beforeContextBoundColon = Always
beforeContextBoundColon = IfMultipleBounds
inImportCurlyBraces = true
afterSymbolicDefs = true
}

literals {
long=Upper
float=Lower
double=Lower
hexPrefix=Lower
hexDigits=Upper
scientific=Upper
long = Upper
float = Lower
double = Lower
hexPrefix = Lower
hexDigits = Upper
scientific = Upper
}
240 changes: 120 additions & 120 deletions J/src/main/java/tinyscalautils/java/Text.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,167 +8,167 @@
* @see tinyscalautils.text
*/
public final class Text {
private Text() {
throw new AssertionError("this class cannot be instantiated");
}
private Text() {
throw new AssertionError("this class cannot be instantiated");
}

public final static class SILENT_MODE {
private SILENT_MODE() {
throw new AssertionError("this class cannot be instantiated");
}
public final static class SILENT_MODE {
private SILENT_MODE() {
throw new AssertionError("this class cannot be instantiated");
}

public static void print(Object ignoredArg) {
}
public static void print(Object ignoredArg) {
}

public static void println(Object ignoredArg) {
}
public static void println(Object ignoredArg) {
}

public static void printf(String ignoredFormat, Object... ignoredArgs) {
}
public static void printf(String ignoredFormat, Object... ignoredArgs) {
}
}

public final static class STANDARD_MODE {
private STANDARD_MODE() {
throw new AssertionError("this class cannot be instantiated");
}
public final static class STANDARD_MODE {
private STANDARD_MODE() {
throw new AssertionError("this class cannot be instantiated");
}

public static void print(Object arg) {
tinyscalautils.text.StandardMode.print(arg, false);
}
public static void print(Object arg) {
textScala.standardMode().print(arg, false);
}

public static void println(Object arg) {
tinyscalautils.text.StandardMode.print(arg, true);
}
public static void println(Object arg) {
textScala.standardMode().print(arg, true);
}

public static void printf(String format, Object... arg) {
tinyscalautils.text.StandardMode.print(String.format(format, arg), false);
}
public static void printf(String format, Object... arg) {
textScala.standardMode().print(String.format(format, arg), false);
}
}

public final static class THREAD_MODE {
private THREAD_MODE() {
throw new AssertionError("this class cannot be instantiated");
}
public final static class THREAD_MODE {
private THREAD_MODE() {
throw new AssertionError("this class cannot be instantiated");
}

public static void print(Object arg) {
tinyscalautils.text.ThreadMode.print(arg, false);
}
public static void print(Object arg) {
textScala.threadMode().print(arg, false);
}

public static void println(Object arg) {
tinyscalautils.text.ThreadMode.print(arg, true);
}
public static void println(Object arg) {
textScala.threadMode().print(arg, true);
}

public static void printf(String format, Object... arg) {
tinyscalautils.text.ThreadMode.print(String.format(format, arg), false);
}
public static void printf(String format, Object... arg) {
textScala.threadMode().print(String.format(format, arg), false);
}
}

public final static class THREAD_TIME_DEMO_MODE {
private THREAD_TIME_DEMO_MODE() {
throw new AssertionError("this class cannot be instantiated");
}
public final static class THREAD_TIME_DEMO_MODE {
private THREAD_TIME_DEMO_MODE() {
throw new AssertionError("this class cannot be instantiated");
}

public static void print(Object arg) {
tinyscalautils.text.ThreadTimeDemoMode.print(arg, false);
}
public static void print(Object arg) {
textScala.threadTimeDemoMode().print(arg, false);
}

public static void println(Object arg) {
tinyscalautils.text.ThreadTimeDemoMode.print(arg, true);
}
public static void println(Object arg) {
textScala.threadTimeDemoMode().print(arg, true);
}

public static void printf(String format, Object... arg) {
tinyscalautils.text.ThreadTimeDemoMode.print(String.format(format, arg), false);
}
public static void printf(String format, Object... arg) {
textScala.threadTimeDemoMode().print(String.format(format, arg), false);
}
}

public final static class THREAD_TIME_MODE {
private THREAD_TIME_MODE() {
throw new AssertionError("this class cannot be instantiated");
}
public final static class THREAD_TIME_MODE {
private THREAD_TIME_MODE() {
throw new AssertionError("this class cannot be instantiated");
}

public static void print(Object arg) {
tinyscalautils.text.ThreadTimeMode.print(arg, false);
}
public static void print(Object arg) {
textScala.threadTimeMode().print(arg, false);
}

public static void println(Object arg) {
tinyscalautils.text.ThreadTimeMode.print(arg, true);
}
public static void println(Object arg) {
textScala.threadTimeMode().print(arg, true);
}

public static void printf(String format, Object... arg) {
tinyscalautils.text.ThreadTimeMode.print(String.format(format, arg), false);
}
public static void printf(String format, Object... arg) {
textScala.threadTimeMode().print(String.format(format, arg), false);
}
}

public final static class TIME_DEMO_MODE {
private TIME_DEMO_MODE() {
throw new AssertionError("this class cannot be instantiated");
}
public final static class TIME_DEMO_MODE {
private TIME_DEMO_MODE() {
throw new AssertionError("this class cannot be instantiated");
}

public static void print(Object arg) {
tinyscalautils.text.TimeDemoMode.print(arg, false);
}
public static void print(Object arg) {
textScala.timeDemoMode().print(arg, false);
}

public static void println(Object arg) {
tinyscalautils.text.TimeDemoMode.print(arg, true);
}
public static void println(Object arg) {
textScala.timeDemoMode().print(arg, true);
}

public static void printf(String format, Object... arg) {
tinyscalautils.text.TimeDemoMode.print(String.format(format, arg), false);
}
public static void printf(String format, Object... arg) {
textScala.timeDemoMode().print(String.format(format, arg), false);
}
}

public final static class TIME_MODE {
private TIME_MODE() {
throw new AssertionError("this class cannot be instantiated");
}
public final static class TIME_MODE {
private TIME_MODE() {
throw new AssertionError("this class cannot be instantiated");
}

public static void print(Object arg) {
tinyscalautils.text.TimeMode.print(arg, false);
}
public static void print(Object arg) {
textScala.timeMode().print(arg, false);
}

public static void println(Object arg) {
tinyscalautils.text.TimeMode.print(arg, true);
}
public static void println(Object arg) {
textScala.timeMode().print(arg, true);
}

public static void printf(String format, Object... arg) {
tinyscalautils.text.TimeMode.print(String.format(format, arg), false);
}
public static void printf(String format, Object... arg) {
textScala.timeMode().print(String.format(format, arg), false);
}
}

private static final TextScala textScala = new TextScala();
private static final TextScala textScala = new TextScala();

/**
* Note that, contrary to the Scala variant, this method sets {@code includeSystem} to true by default.
*/
public static String printout(Runnable code) {
return printout(false, true, Charset.defaultCharset(), code);
}
/**
* Note that, contrary to the Scala variant, this method sets {@code includeSystem} to true by default.
*/
public static String printout(Runnable code) {
return printout(false, true, Charset.defaultCharset(), code);
}

public static String printout(boolean includeErr, boolean includeSystem, Runnable code) {
return printout(includeErr, includeSystem, Charset.defaultCharset(), code);
}
public static String printout(boolean includeErr, boolean includeSystem, Runnable code) {
return printout(includeErr, includeSystem, Charset.defaultCharset(), code);
}

public static String printout(boolean includeErr, boolean includeSystem, Charset charset, Runnable code) {
return textScala.printout(code, includeErr, includeSystem, charset);
}
public static String printout(boolean includeErr, boolean includeSystem, Charset charset, Runnable code) {
return textScala.printout(code, includeErr, includeSystem, charset);
}

public static void info() {
textScala.info();
}
public static void info() {
textScala.info();
}

public static String plural(Number x, String singularForm, String pluralForm) {
return textScala.plural(x, singularForm, pluralForm);
}
public static String plural(Number x, String singularForm, String pluralForm) {
return textScala.plural(x, singularForm, pluralForm);
}

public static String plural(Number x, String singularForm) {
return textScala.plural(x, singularForm);
}

public static String timeString(double seconds, int unitsCount) {
return textScala.timeString(seconds, unitsCount);
}
public static String plural(Number x, String singularForm) {
return textScala.plural(x, singularForm);
}

public static String timeString(double seconds) {
return timeString(seconds, 2);
}
public static String timeString(double seconds, int unitsCount) {
return textScala.timeString(seconds, unitsCount);
}

public static String timeString(double seconds) {
return timeString(seconds, 2);
}
}
7 changes: 7 additions & 0 deletions J/src/main/scala/tinyscalautils/java/TextScala.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@ private final class TextScala:

def timeString(seconds: Double, unitsCount: Int): String =
tinyscalautils.text.timeString(seconds, unitsCount)

def standardMode = tinyscalautils.text.standardMode
def timeMode = tinyscalautils.text.timeMode
def timeDemoMode = tinyscalautils.text.timeDemoMode
def threadMode = tinyscalautils.text.threadMode
def threadTimeMode = tinyscalautils.text.threadTimeMode
def threadTimeDemoMode = tinyscalautils.text.threadTimeDemoMode
2 changes: 0 additions & 2 deletions S/src/main/scala/tinyscalautils/assertions/implies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ extension (left: Boolean)
/** Logical implication. LHS is always evaluated. RHS is only evaluated if LHS side evaluated to
* true.
*
* Also available as `==>`
*
* @since 1.1
*/
inline infix def implies(inline right: Boolean): Boolean = !left || right
Expand Down
10 changes: 2 additions & 8 deletions S/src/main/scala/tinyscalautils/collection/Queue.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@ package tinyscalautils.collection
import java.util

extension [A](queue: util.Queue[A])
/** Like `poll` but wrapping `null` in an option.
*
* @since 1.2
*/
@deprecated("use Option instead", since = "1.3")
def pollOption(): Option[A] = Option(queue.poll())

/** Like `peek` but wrapping `null` in an option.
*
* @since 1.2
*/
@deprecated("use Option instead", since = "1.3")
def peekOption: Option[A] = Option(queue.peek())
7 changes: 7 additions & 0 deletions S/src/main/scala/tinyscalautils/collection/sorted.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package tinyscalautils.collection

import scala.collection.SeqOps

extension [A, CC[_]](self: SeqOps[A, CC, CC[A]])
/** Sorted according to implicit order, but in reverse. */
def sortedInReverse[B >: A : Ordering]: CC[A] = self.sorted(using Ordering[B].reverse)
Loading

0 comments on commit c354d24

Please sign in to comment.