Skip to content

Commit

Permalink
feat: upgrade and simplify a lot (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
to-kn committed Aug 14, 2024
1 parent b34f90f commit b11f502
Show file tree
Hide file tree
Showing 46 changed files with 357 additions and 301 deletions.
14 changes: 8 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.6.3'
Expand All @@ -16,8 +16,10 @@ buildscript {
// turn off Java 8's doclint (causes problems with HTML5 markup in Javadoc)
if (JavaVersion.current().isJava8Compatible()) {
allprojects {
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
tasks.withType(Javadoc).tap {
configureEach {
options.addStringOption('Xdoclint:none', '-quiet')
}
}
}
}
Expand All @@ -38,9 +40,9 @@ nexusStaging {
password = nexusPassword
}

task uploadAndReleaseParser {
tasks.register('uploadAndReleaseParser') {
// uploads the parser to Maven Central and releases from staging repository into maven central repo
dependsOn ':parser:publish'
dependsOn 'closeAndReleaseRepository'
tasks.findByName('closeAndReleaseRepository').mustRunAfter ':parser:publish'
mustRunAfter ':parser:publish'
}
40 changes: 19 additions & 21 deletions parser/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ compileJava.options.encoding = 'UTF-8'
compileTestJava.options.encoding = 'UTF-8'

dependencies {
compile 'joda-time:joda-time:2.8.1'
compile 'org.jsoup:jsoup:1.15.3'
compile 'org.apache.httpcomponents:fluent-hc:4.5.3'
compile 'org.apache.httpcomponents:httpmime:4.5.3'
compile 'org.json:json:20231013'
compile 'org.apache.commons:commons-lang3:3.4'
compile 'org.jetbrains:annotations:13.0'
compile 'commons-io:commons-io:2.7'
compile 'com.github.mifmif:generex:1.0.2'
compile 'net.sf.biweekly:biweekly:0.6.1'
compile 'com.googlecode.juniversalchardet:juniversalchardet:1.0.3'
compile 'org.bouncycastle:bcprov-jdk15on:1.56'
compile 'io.jsonwebtoken:jjwt:0.7.0'
compile 'com.github.lookfirst:sardine:5.8'
testCompile 'junit:junit:4.11'
testCompile 'com.github.tomakehurst:wiremock-jre8:2.24.0'
testCompile 'com.google.jimfs:jimfs:1.1'
implementation 'joda-time:joda-time:2.8.1'
implementation 'org.jsoup:jsoup:1.15.3'
implementation 'org.apache.httpcomponents:fluent-hc:4.5.3'
implementation 'org.apache.httpcomponents:httpmime:4.5.3'
implementation 'org.json:json:20231013'
implementation 'org.apache.commons:commons-lang3:3.4'
implementation 'org.jetbrains:annotations:13.0'
implementation 'commons-io:commons-io:2.7'
implementation 'com.github.mifmif:generex:1.0.2'
implementation 'net.sf.biweekly:biweekly:0.6.1'
implementation 'com.googlecode.juniversalchardet:juniversalchardet:1.0.3'
implementation 'org.bouncycastle:bcprov-jdk15on:1.56'
implementation 'io.jsonwebtoken:jjwt:0.7.0'
implementation 'com.github.lookfirst:sardine:5.8'
testImplementation 'junit:junit:4.13.1'
testImplementation 'com.github.tomakehurst:wiremock-jre8:2.35.1'
testImplementation 'com.google.jimfs:jimfs:1.1'
}

jacocoTestReport {
Expand All @@ -43,13 +43,11 @@ jacocoTestReport {
}
}

task javadocJar(type: Jar) {
classifier = 'javadoc'
tasks.register('javadocJar', Jar) {
from javadoc
}

task sourcesJar(type: Jar) {
classifier = 'sources'
tasks.register('sourcesJar', Jar) {
from sourceSets.main.allSource
}

Expand Down
162 changes: 89 additions & 73 deletions parser/src/main/java/com/paour/comparator/NaturalOrderComparator.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,14 @@
3. This notice may not be removed or altered from any source distribution.
*/

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.*;

@SuppressWarnings("ALL")
public class NaturalOrderComparator implements Comparator
{
int compareRight(String a, String b)
{
int bias = 0;
int ia = 0;
int ib = 0;
int bias = 0, ia = 0, ib = 0;

// The longest run of digits wins. That aside, the greatest
// value wins, but we can't know that it will until we've scanned
Expand All @@ -45,33 +41,25 @@ int compareRight(String a, String b)
char ca = charAt(a, ia);
char cb = charAt(b, ib);

if (!Character.isDigit(ca) && !Character.isDigit(cb))
{
if (!isDigit(ca) && !isDigit(cb)) {
return bias;
}
else if (!Character.isDigit(ca))
{
if (!isDigit(ca)) {
return -1;
}
else if (!Character.isDigit(cb))
{
if (!isDigit(cb)) {
return +1;
}
else if (ca < cb)
{
if (bias == 0)
{
bias = -1;
}
if (ca == 0 && cb == 0) {
return bias;
}
else if (ca > cb)
{
if (bias == 0)

if (bias == 0) {
if (ca < cb) {
bias = -1;
} else if (ca > cb) {
bias = +1;
}
else if (ca == 0 && cb == 0)
{
return bias;
}
}
}
}
Expand All @@ -84,69 +72,54 @@ public int compare(Object o1, Object o2)
int ia = 0, ib = 0;
int nza = 0, nzb = 0;
char ca, cb;
int result;

while (true)
{
// only count the number of zeroes leading the last number compared
while (true) {
// Only count the number of zeroes leading the last number compared
nza = nzb = 0;

ca = charAt(a, ia);
cb = charAt(b, ib);

// skip over leading spaces or zeros
while (Character.isSpaceChar(ca) || ca == '0')
{
if (ca == '0')
{
while (Character.isSpaceChar(ca) || ca == '0') {
if (ca == '0') {
nza++;
}
else
{
// only count consecutive zeroes
} else {
// Only count consecutive zeroes
nza = 0;
}

ca = charAt(a, ++ia);
}

while (Character.isSpaceChar(cb) || cb == '0')
{
if (cb == '0')
{
while (Character.isSpaceChar(cb) || cb == '0') {
if (cb == '0') {
nzb++;
}
else
{
// only count consecutive zeroes
} else {
// Only count consecutive zeroes
nzb = 0;
}

cb = charAt(b, ++ib);
}

// process run of digits
if (Character.isDigit(ca) && Character.isDigit(cb))
{
if ((result = compareRight(a.substring(ia), b.substring(ib))) != 0)
{
return result;
// Process run of digits
if (Character.isDigit(ca) && Character.isDigit(cb)) {
int bias = compareRight(a.substring(ia), b.substring(ib));
if (bias != 0) {
return bias;
}
}

if (ca == 0 && cb == 0)
{
if (ca == 0 && cb == 0) {
// The strings compare the same. Perhaps the caller
// will want to call strcmp to break the tie.
return nza - nzb;
return compareEqual(a, b, nza, nzb);
}

if (ca < cb)
{
if (ca < cb) {
return -1;
}
else if (ca > cb)
{
if (ca > cb) {
return +1;
}

Expand All @@ -155,24 +128,30 @@ else if (ca > cb)
}
}

static char charAt(String s, int i)
{
if (i >= s.length())
{
return 0;
}
else
{
return s.charAt(i);
}
static boolean isDigit(char c) {
return Character.isDigit(c) || c == '.' || c == ',';
}

static char charAt(String s, int i) {
return i >= s.length() ? 0 : s.charAt(i);
}

static int compareEqual(String a, String b, int nza, int nzb) {
if (nza - nzb != 0)
return nza - nzb;

if (a.length() == b.length())
return a.compareTo(b);

return a.length() - b.length();
}

public static void main(String[] args)
{
String[] strings = new String[] { "1-2", "1-02", "1-20", "10-20", "fred", "jane", "pic01",
"pic2", "pic02", "pic02a", "pic3", "pic4", "pic 4 else", "pic 5", "pic05", "pic 5",
"pic 5 something", "pic 6", "pic 7", "pic100", "pic100a", "pic120", "pic121",
"pic02000", "tom", "x2-g8", "x2-y7", "x2-y08", "x8-y8" };
"pic2", "pic02", "pic02a", "pic3", "pic4", "pic 4 else", "pic 5", "pic05", "pic 5",
"pic 5 something", "pic 6", "pic 7", "pic100", "pic100a", "pic120", "pic121",
"pic02000", "tom", "x2-g8", "x2-y7", "x2-y08", "x8-y8" };

List orig = Arrays.asList(strings);

Expand All @@ -186,5 +165,42 @@ public static void main(String[] args)
Collections.sort(scrambled, new NaturalOrderComparator());

System.out.println("Sorted: " + scrambled);

shuffle3000(scrambled);

compareSymmetric();

floatsWithCommas();
}

static void shuffle3000(List<? extends Object> scrambled) {
Collections.shuffle(scrambled, new Random(3000));
Collections.sort(scrambled, new NaturalOrderComparator());

System.out.println("Sorted: " + scrambled);
}

static void compareSymmetric() {
NaturalOrderComparator naturalOrderComparator = new NaturalOrderComparator();

int compare1 = naturalOrderComparator.compare("1-2", "1-02");
int compare2 = naturalOrderComparator.compare("1-02", "1-2");

System.out.println(compare1 + " == " + compare2);

compare1 = naturalOrderComparator.compare("pic 5", "pic05");
compare2 = naturalOrderComparator.compare("pic05", "pic 5");

System.out.println(compare1 + " == " + compare2);
}

static void floatsWithCommas() {
List<String> unSorted = Arrays.asList("0.9", "1.0c", "1.2", "1.3", "0.6", "1.1", "0.7", "0.3", "1.0b", "1.0", "0.8");

System.out.println("Unsorted: " + unSorted);

unSorted.sort(new NaturalOrderComparator());

System.out.println("Sorted: " + unSorted);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static BaseAdditionalInfoParser getInstance(String type) {
return parser;
}

public abstract AdditionalInfo getAdditionalInfo() throws IOException;
public abstract AdditionalInfo getAdditionalInfo() throws IOException, CloneNotSupportedException;

@SuppressWarnings("SameParameterValue")
protected String httpGet(String url, String encoding) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected int getMaxItemsCount() {
}

@Override
public AdditionalInfo getAdditionalInfo() throws IOException {
public AdditionalInfo getAdditionalInfo() throws IOException, CloneNotSupportedException {
AdditionalInfo info = new AdditionalInfo();
info.setTitle(getTitle());

Expand Down Expand Up @@ -134,8 +134,9 @@ public AdditionalInfo getAdditionalInfo() throws IOException {
events.add(item);
}
}
Collections.sort(events, new Comparator<Event>() {
@Override public int compare(Event o1, Event o2) {
events.sort(new Comparator<Event>() {
@Override
public int compare(Event o1, Event o2) {
return o1.startDate.compareTo(o2.startDate);
}
});
Expand Down Expand Up @@ -210,7 +211,7 @@ private TimeZone getTimeZoneStart(ICalendar ical, VEvent event) {
return timezone;
}

private class Event implements Cloneable {
private static class Event implements Cloneable {
public String summary;
public String description;
public String location;
Expand All @@ -221,8 +222,8 @@ private class Event implements Cloneable {
public boolean endHasTime;

@Override
protected Event clone() {
Event clone = new Event();
protected Event clone() throws CloneNotSupportedException {
Event clone = (Event) super.clone();
clone.summary = this.summary;
clone.description = this.description;
clone.location = this.location;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ public X509Certificate[] getAcceptedIssuers()
for (X509TrustManager trustManager : trustManagers) {
certificates.addAll(Arrays.asList(trustManager.getAcceptedIssuers()));
}
return certificates.toArray(new X509Certificate[certificates.size()]);
return certificates.toArray(new X509Certificate[0]);
}
}
Loading

0 comments on commit b11f502

Please sign in to comment.