Skip to content

Finish SortMeta and merge showcaseName with runName, and organize impractical sorts #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"java.configuration.updateBuildConfiguration": "interactive",
"java.configuration.updateBuildConfiguration": "automatic",
"java.checkstyle.configuration": "${workspaceFolder}/checkstyle.xml",
"java.checkstyle.version": "9.3",
"java.completion.filteredTypes": [
Expand All @@ -9,4 +9,4 @@
"org.graalvm.*",
"io.micrometer.shaded.*"
]
}
}
14 changes: 8 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

Expand All @@ -14,8 +15,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.release>17</maven.compiler.release>
</properties>

<dependencies>
Expand Down Expand Up @@ -176,7 +176,8 @@
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<!-- see
http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
Expand All @@ -197,7 +198,8 @@
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<!-- site lifecycle, see
https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
Expand All @@ -209,4 +211,4 @@
</plugins>
</pluginManagement>
</build>
</project>
</project>
120 changes: 60 additions & 60 deletions src/main/java/io/github/arrayv/sortdata/SortInfo.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package io.github.arrayv.sortdata;

import io.github.arrayv.main.ArrayVisualizer;
import io.github.arrayv.sorts.templates.Sort;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Objects;
import java.util.function.IntUnaryOperator;
import java.util.function.Supplier;

import io.github.arrayv.main.ArrayVisualizer;
import io.github.arrayv.sorts.templates.Sort;

public final class SortInfo {
private static final String NAME_MUST_BE_SPECIFIED =
"name must be specified unless all three of listName, showcaseName, and runName are specified";
private static final String NAME_MUST_BE_SPECIFIED = "name must be specified unless all three of listName, showcaseName, and runName are specified";

private final int id;
private final String internalName;
Expand Down Expand Up @@ -78,15 +77,16 @@ public SortInfo(int id, Class<? extends Sort> sortClass) {
this.disabled = metaAnnotation.disabled();
this.unreasonableLimit = metaAnnotation.unreasonableLimit();
this.listName = metaAnnotation.listName().isEmpty()
? requireName(name)
: metaAnnotation.listName();
? requireName(name)
: metaAnnotation.listName();
this.runName = metaAnnotation.runName().isEmpty()
? requireName(name) + "sort"
: metaAnnotation.runName();
this.runAllName = metaAnnotation.showcaseName().isEmpty()
? requireName(name) + " Sort"
: metaAnnotation.showcaseName();
this.category = metaAnnotation.category().isEmpty() ? findSortCategory(sortClass) : metaAnnotation.category();
? requireName(name) + " Sort"
: metaAnnotation.runName();
this.runAllName = metaAnnotation.runName().isEmpty()
? requireName(name) + " Sort"
: metaAnnotation.runName();
this.category = metaAnnotation.category().isEmpty() ? findSortCategory(sortClass)
: metaAnnotation.category();
this.bogoSort = metaAnnotation.bogoSort();
this.radixSort = metaAnnotation.radixSort();
this.bucketSort = metaAnnotation.bucketSort();
Expand Down Expand Up @@ -124,15 +124,16 @@ public SortInfo(int id, Sort sort) {
this.disabled = metaAnnotation.disabled();
this.unreasonableLimit = metaAnnotation.unreasonableLimit();
this.listName = metaAnnotation.listName().isEmpty()
? requireName(name)
: metaAnnotation.listName();
? requireName(name)
: metaAnnotation.listName();
this.runName = metaAnnotation.runName().isEmpty()
? requireName(name) + "sort"
: metaAnnotation.runName();
this.runAllName = metaAnnotation.showcaseName().isEmpty()
? requireName(name) + " Sort"
: metaAnnotation.showcaseName();
this.category = metaAnnotation.category().isEmpty() ? findSortCategory(sort.getClass()) : metaAnnotation.category();
? requireName(name) + " Sort"
: metaAnnotation.runName();
this.runAllName = metaAnnotation.runName().isEmpty()
? requireName(name) + " Sort"
: metaAnnotation.runName();
this.category = metaAnnotation.category().isEmpty() ? findSortCategory(sort.getClass())
: metaAnnotation.category();
this.bogoSort = metaAnnotation.bogoSort();
this.radixSort = metaAnnotation.radixSort();
this.bucketSort = metaAnnotation.bucketSort();
Expand All @@ -143,23 +144,22 @@ public SortInfo(int id, Sort sort) {
}

private SortInfo(
int id,
String internalName,
Supplier<? extends Sort> instanceSupplier,
boolean disabled,
int unreasonableLimit,
String listName,
String runName,
String runAllName,
String category,
boolean slowSort,
boolean bogoSort,
boolean radixSort,
boolean bucketSort,
String question,
int defaultAnswer,
IntUnaryOperator answerValidator
) {
int id,
String internalName,
Supplier<? extends Sort> instanceSupplier,
boolean disabled,
int unreasonableLimit,
String listName,
String runName,
String runAllName,
String category,
boolean slowSort,
boolean bogoSort,
boolean radixSort,
boolean bucketSort,
String question,
int defaultAnswer,
IntUnaryOperator answerValidator) {
this.id = id;
this.internalName = internalName;
this.instanceSupplier = instanceSupplier;
Expand Down Expand Up @@ -195,8 +195,8 @@ private static String findSortCategory(Class<? extends Sort> sortClass) {
}
}
throw new NullPointerException(
"Sort " + sortClass.getSimpleName() + " does not declare a category, and neither do any of its packages"
);
"Sort " + sortClass.getSimpleName()
+ " does not declare a category, and neither do any of its packages");
}

private static String requireName(String name) {
Expand All @@ -211,7 +211,8 @@ private static String normalizeName(SortMeta meta) {
if (name.endsWith("sort")) {
return name.substring(0, name.length() - 4);
}
// Cause an NPE if name isn't specified, and all three required names also aren't
// Cause an NPE if name isn't specified, and all three required names also
// aren't
return name.isEmpty() ? null : name;
}

Expand Down Expand Up @@ -293,6 +294,7 @@ public boolean isFromExtra() {

/**
* Creates a copy of this info with a new ID
*
* @param id The ID for the new instance
* @return Copied info with new ID
*/
Expand Down Expand Up @@ -343,10 +345,9 @@ public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof SortInfo)) {
if (!(obj instanceof SortInfo other)) {
return false;
}
SortInfo other = (SortInfo) obj;
if (bogoSort != other.bogoSort) {
return false;
}
Expand Down Expand Up @@ -438,23 +439,22 @@ private Builder() {

public SortInfo build() {
return new SortInfo(
id,
internalName,
Objects.requireNonNull(instanceSupplier, "instanceSupplier"),
disabled,
unreasonableLimit,
Objects.requireNonNull(listName, "listName"),
runName != null ? runName : (listName + "sort"),
runAllName != null ? runAllName : (listName + " Sort"),
Objects.requireNonNull(category, "category"),
slowSort,
bogoSort,
radixSort,
bucketSort,
question,
defaultAnswer,
answerValidator
);
id,
internalName,
Objects.requireNonNull(instanceSupplier, "instanceSupplier"),
disabled,
unreasonableLimit,
Objects.requireNonNull(listName, "listName"),
runName != null ? runName : (listName + "sort"),
runAllName != null ? runAllName : (listName + " Sort"),
Objects.requireNonNull(category, "category"),
slowSort,
bogoSort,
radixSort,
bucketSort,
question,
defaultAnswer,
answerValidator);
}

public Builder id(int id) {
Expand Down
51 changes: 34 additions & 17 deletions src/main/java/io/github/arrayv/sortdata/SortMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,91 +3,108 @@
import java.lang.annotation.*;

/**
* Annotation to specify the sorting algorithm's metadata. This should only be applied to subclasses of
* Annotation to specify the sorting algorithm's metadata. This should only be
* applied to subclasses of
* {@link io.github.arrayv.sorts.templates.Sort Sort}.
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface SortMeta {
/**
* The sort's name. This is generally of the form {@code "Something"} or {@code "Something Sort"}. If not
* specified, all three of {@link #listName()}, {@link #runName()}, and {@link #showcaseName()} must be specified.
* The sort's name. This is generally of the form {@code "Something"} or
* {@code "Something Sort"}. If not
* specified, all three of {@link #listName()}, {@link #runName()}, and
* {@link #showcaseName()} must be specified.
*
* @return The sort's annotated name.
*/
String name() default "";

/**
* The sort's category. This may be specified on a package-level in package-info.java. Specifying it here will
* The sort's category. This may be specified on a package-level in
* package-info.java. Specifying it here will
* override it for the package.
* @return The sort's category, or {@code ""} if you should look at the package level.
*
* @return The sort's category, or {@code ""} if you should look at the package
* level.
*/
String category() default "";

/**
* Explicit sort list name. This is generated from {@link #name()} by default.
*
* @return The sort's explicit list name, if it has one. {@code ""} otherwise.
*/
String listName() default "";

/**
* Explicit Run Sort name. This is generated from {@link #name()} by default.
* @return The sort's explicit Run Sort name, if it has one. {@code ""} otherwise.
*
* @return The sort's explicit Run Sort name, if it has one. {@code ""}
* otherwise.
*/
String runName() default "";

/**
* Explicit Showcase Sorts name (and scripting name). This is generated from {@link #name()} by default.
* @return The sort's explicit Showcase Sorts name, if it has one. {@code ""} otherwise.
*/
String showcaseName() default "";

/**
* Whether this sort is disabled. Disabled sorts won't be loaded.
*
* @return Whether this sort is disabled.
*/
boolean disabled() default false;

/**
* This sort's unreasonable limit. If the sort is run with lengths higher than this, a warning is displayed.
* This sort's unreasonable limit. If the sort is run with lengths higher than
* this, a warning is displayed.
*
* @return This sort's unreasonable limit.
*/
int unreasonableLimit() default 0;

/**
* Whether to treat this sort as slow in Showcase Sorts and in sort scripts.
*
* @return Whether to treat this sort as slow.
*/
boolean slowSort() default false;

/**
* Whether this sort is a bogo sort (i.e. it has "bogo" in its name, and it's non-deterministic).
* Whether this sort is a bogo sort (i.e. it has "bogo" in its name, and it's
* non-deterministic).
*
* @return Whether this sort is a bogo sort.
*/
boolean bogoSort() default false;

/**
* Whether this sort is a Radix Sort.
*
* @return Whether this sort is a Radix Sort.
*/
boolean radixSort() default false;

/**
* Whether this sort uses buckets.
*
* @return Whether this sort uses buckets.
*/
boolean bucketSort() default false;

/**
* A question to ask the user when they choose this sort. You can perform response validation by creating a method
* A question to ask the user when they choose this sort. You can perform
* response validation by creating a method
* that is {@code public static int validateAnswer(int answer)}.
*
* @return The question to ask the user, or {@code ""} if there isn't one.
*/
String question() default "";

/**
* The default response to use for {@link #question()}. This is used when the user pressed "Use default". This
* value is ignored if there is no question. This value is <i>not</i> passed through {@code validatorAnswer}.
* The default response to use for {@link #question()}. This is used when the
* user pressed "Use default". This
* value is ignored if there is no question. This value is <i>not</i> passed
* through {@code validatorAnswer}.
*
* @return The default answer response.
*/
int defaultAnswer() default 0;
Expand Down
Loading