Skip to content

Commit e6fc42e

Browse files
committed
Deprecate the api.
1 parent 6e5db94 commit e6fc42e

File tree

8 files changed

+175
-122
lines changed

8 files changed

+175
-122
lines changed

src/main/java/com/falsepattern/lib/FalsePatternLib.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.falsepattern.lib;
22

3-
import com.falsepattern.lib.api.Version;
3+
import com.falsepattern.lib.version.Version;
44
import com.google.common.eventbus.EventBus;
55
import cpw.mods.fml.common.DummyModContainer;
66
import cpw.mods.fml.common.LoadController;
Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,15 @@
11
package com.falsepattern.lib.api;
22

3+
import com.falsepattern.lib.version.Version;
34
import lombok.NonNull;
4-
import lombok.val;
55

6-
import java.util.Arrays;
7-
import java.util.stream.Collectors;
8-
9-
public class ComplexVersion extends Version {
10-
final Version[] versions;
6+
/**
7+
* Deprecated in 0.6.*, will be removed in 0.7.0.
8+
* Moved to {@link com.falsepattern.lib.version.ComplexVersion}.
9+
*/
10+
@Deprecated
11+
public class ComplexVersion extends com.falsepattern.lib.version.ComplexVersion {
1112
public ComplexVersion(@NonNull Version mainVersion, Version... subVersions) {
12-
this.versions = new Version[subVersions.length + 1];
13-
this.versions[0] = mainVersion;
14-
System.arraycopy(subVersions, 0, this.versions, 1, subVersions.length);
15-
}
16-
17-
@Override
18-
public int compareTo(@NonNull Version o) {
19-
if (o instanceof ComplexVersion) {
20-
val other = (ComplexVersion) o;
21-
int count = Math.min(versions.length, other.versions.length);
22-
for (int i = 0; i < count; i++) {
23-
val result = versions[i].compareTo(other.versions[i]);
24-
if (result != 0) return result;
25-
}
26-
if (versions.length != other.versions.length) {
27-
return versions.length - other.versions.length;
28-
} else {
29-
return 0;
30-
}
31-
} else if (o instanceof SemanticVersion) {
32-
val other = (SemanticVersion) o;
33-
val result = other.compareTo(versions[0]);
34-
if (result != 0) {
35-
return result;
36-
}
37-
if (versions.length > 1) {
38-
return -1;
39-
}
40-
return 0;
41-
} else {
42-
throw new IllegalArgumentException("Could not compare version with class " + o.getClass().getName());
43-
}
44-
}
45-
46-
@Override
47-
public String toString() {
48-
return Arrays.stream(versions).map(Version::toString).collect(Collectors.joining("-"));
13+
super(mainVersion, subVersions);
4914
}
5015
}

src/main/java/com/falsepattern/lib/api/DependencyLoader.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
package com.falsepattern.lib.api;
22

33
import com.falsepattern.lib.FalsePatternLib;
4+
import com.falsepattern.lib.version.Version;
45
import lombok.Builder;
56
import lombok.NonNull;
67

8+
/**
9+
* Deprecated in 0.6.*, will be removed in 0.7.0.
10+
* Outdated wrapper on top of the {@link FalsePatternLib} class. Use that one instead.
11+
*/
12+
@Deprecated
713
public class DependencyLoader {
814
@Builder
915
public static void loadLibrary(String loadingModId, String groupId, String artifactId, @NonNull Version minVersion, Version maxVersion, @NonNull Version preferredVersion, String regularSuffix, String devSuffix) {
Lines changed: 9 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,20 @@
11
package com.falsepattern.lib.api;
22

3-
import lombok.Builder;
4-
import lombok.Getter;
5-
import lombok.NonNull;
6-
import lombok.val;
7-
8-
import java.util.Objects;
9-
10-
public class SemanticVersion extends Version {
11-
@Getter
12-
private final int majorVersion;
13-
@Getter
14-
private final int minorVersion;
15-
@Getter
16-
private final int patchVersion;
17-
@Getter
18-
private final String preRelease;
19-
@Getter
20-
private final String build;
21-
22-
@Builder
3+
/**
4+
* Deprecated in 0.6.*, will be removed in 0.7.0.
5+
* Moved to {@link com.falsepattern.lib.version.SemanticVersion}.
6+
*/
7+
@Deprecated
8+
public class SemanticVersion extends com.falsepattern.lib.version.SemanticVersion {
239
public SemanticVersion(int majorVersion, int minorVersion, int patchVersion, String preRelease, String build) {
24-
this.majorVersion = majorVersion;
25-
this.minorVersion = minorVersion;
26-
this.patchVersion = patchVersion;
27-
preRelease = preRelease == null ? null : preRelease.trim();
28-
build = build == null ? null : build.trim();
29-
this.preRelease = "".equals(preRelease) ? null : preRelease;
30-
this.build = "".equals(build) ? null : build;
10+
super(majorVersion, minorVersion, patchVersion, preRelease, build);
3111
}
3212

3313
public SemanticVersion(int majorVersion, int minorVersion, int patchVersion, String preRelease) {
34-
this(majorVersion, minorVersion, patchVersion, preRelease, null);
14+
super(majorVersion, minorVersion, patchVersion, preRelease);
3515
}
3616

3717
public SemanticVersion(int majorVersion, int minorVersion, int patchVersion) {
38-
this(majorVersion, minorVersion, patchVersion, null, null);
39-
}
40-
41-
@Override
42-
public int compareTo(@NonNull Version o) {
43-
if (o instanceof ComplexVersion) {
44-
val result = this.compareTo(((ComplexVersion)o).versions[0]);
45-
if (result != 0) {
46-
return result;
47-
} else if (((ComplexVersion) o).versions.length > 1) {
48-
return 1;
49-
} else {
50-
return 0;
51-
}
52-
} else if (o instanceof SemanticVersion) {
53-
val other = (SemanticVersion)o;
54-
if (majorVersion != other.majorVersion) {
55-
return majorVersion - other.majorVersion;
56-
} else if (minorVersion != other.minorVersion) {
57-
return minorVersion - other.minorVersion;
58-
} else if (patchVersion != other.patchVersion) {
59-
return patchVersion - other.patchVersion;
60-
} else if (!Objects.equals(preRelease, other.preRelease)) {
61-
if (preRelease == null) {
62-
return 1;
63-
} else if (other.preRelease == null) {
64-
return -1;
65-
}
66-
return preRelease.compareTo(other.preRelease);
67-
} else {
68-
return 0;
69-
}
70-
}
71-
return 0;
72-
}
73-
74-
@Override
75-
public String toString() {
76-
return majorVersion + "." + minorVersion + "." + patchVersion + (preRelease == null ? "" : "-" + preRelease) + (build == null ? "" : "+" + build);
18+
super(majorVersion, minorVersion, patchVersion);
7719
}
7820
}
Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package com.falsepattern.lib.api;
22

3-
public abstract class Version implements Comparable<Version> {
4-
Version(){}
5-
6-
public boolean equals(Version other) {
7-
return compareTo(other) == 0;
8-
}
9-
10-
@Override
11-
public boolean equals(Object obj) {
12-
if (!(obj instanceof Version)) return false;
13-
return equals((Version) obj);
3+
/**
4+
* Deprecated in 0.6.*, will be removed in 0.7.0.
5+
* Moved to {@link com.falsepattern.lib.version.SemanticVersion}.
6+
*/
7+
@Deprecated
8+
public abstract class Version extends com.falsepattern.lib.version.Version {
9+
protected Version() {
10+
super();
1411
}
1512
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.falsepattern.lib.version;
2+
3+
import lombok.NonNull;
4+
import lombok.val;
5+
6+
import java.util.Arrays;
7+
import java.util.stream.Collectors;
8+
9+
public class ComplexVersion extends Version {
10+
final Version[] versions;
11+
public ComplexVersion(@NonNull Version mainVersion, Version... subVersions) {
12+
this.versions = new Version[subVersions.length + 1];
13+
this.versions[0] = mainVersion;
14+
System.arraycopy(subVersions, 0, this.versions, 1, subVersions.length);
15+
}
16+
17+
@Override
18+
public int compareTo(@NonNull Version o) {
19+
if (o instanceof ComplexVersion) {
20+
val other = (ComplexVersion) o;
21+
int count = Math.min(versions.length, other.versions.length);
22+
for (int i = 0; i < count; i++) {
23+
val result = versions[i].compareTo(other.versions[i]);
24+
if (result != 0) return result;
25+
}
26+
if (versions.length != other.versions.length) {
27+
return versions.length - other.versions.length;
28+
} else {
29+
return 0;
30+
}
31+
} else if (o instanceof SemanticVersion) {
32+
val other = (SemanticVersion) o;
33+
val result = other.compareTo(versions[0]);
34+
if (result != 0) {
35+
return result;
36+
}
37+
if (versions.length > 1) {
38+
return -1;
39+
}
40+
return 0;
41+
} else {
42+
throw new IllegalArgumentException("Could not compare version with class " + o.getClass().getName());
43+
}
44+
}
45+
46+
@Override
47+
public String toString() {
48+
return Arrays.stream(versions).map(Version::toString).collect(Collectors.joining("-"));
49+
}
50+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package com.falsepattern.lib.version;
2+
3+
import lombok.Builder;
4+
import lombok.Getter;
5+
import lombok.NonNull;
6+
import lombok.val;
7+
8+
import java.util.Objects;
9+
10+
public class SemanticVersion extends Version {
11+
@Getter
12+
private final int majorVersion;
13+
@Getter
14+
private final int minorVersion;
15+
@Getter
16+
private final int patchVersion;
17+
@Getter
18+
private final String preRelease;
19+
@Getter
20+
private final String build;
21+
22+
@Builder
23+
public SemanticVersion(int majorVersion, int minorVersion, int patchVersion, String preRelease, String build) {
24+
this.majorVersion = majorVersion;
25+
this.minorVersion = minorVersion;
26+
this.patchVersion = patchVersion;
27+
preRelease = preRelease == null ? null : preRelease.trim();
28+
build = build == null ? null : build.trim();
29+
this.preRelease = "".equals(preRelease) ? null : preRelease;
30+
this.build = "".equals(build) ? null : build;
31+
}
32+
33+
public SemanticVersion(int majorVersion, int minorVersion, int patchVersion, String preRelease) {
34+
this(majorVersion, minorVersion, patchVersion, preRelease, null);
35+
}
36+
37+
public SemanticVersion(int majorVersion, int minorVersion, int patchVersion) {
38+
this(majorVersion, minorVersion, patchVersion, null, null);
39+
}
40+
41+
@Override
42+
public int compareTo(@NonNull Version o) {
43+
if (o instanceof ComplexVersion) {
44+
val result = this.compareTo(((ComplexVersion)o).versions[0]);
45+
if (result != 0) {
46+
return result;
47+
} else if (((ComplexVersion) o).versions.length > 1) {
48+
return 1;
49+
} else {
50+
return 0;
51+
}
52+
} else if (o instanceof SemanticVersion) {
53+
val other = (SemanticVersion)o;
54+
if (majorVersion != other.majorVersion) {
55+
return majorVersion - other.majorVersion;
56+
} else if (minorVersion != other.minorVersion) {
57+
return minorVersion - other.minorVersion;
58+
} else if (patchVersion != other.patchVersion) {
59+
return patchVersion - other.patchVersion;
60+
} else if (!Objects.equals(preRelease, other.preRelease)) {
61+
if (preRelease == null) {
62+
return 1;
63+
} else if (other.preRelease == null) {
64+
return -1;
65+
}
66+
return preRelease.compareTo(other.preRelease);
67+
} else {
68+
return 0;
69+
}
70+
}
71+
return 0;
72+
}
73+
74+
@Override
75+
public String toString() {
76+
return majorVersion + "." + minorVersion + "." + patchVersion + (preRelease == null ? "" : "-" + preRelease) + (build == null ? "" : "+" + build);
77+
}
78+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.falsepattern.lib.version;
2+
3+
public abstract class Version implements Comparable<Version> {
4+
protected Version(){}
5+
6+
public boolean equals(Version other) {
7+
return compareTo(other) == 0;
8+
}
9+
10+
@Override
11+
public boolean equals(Object obj) {
12+
if (!(obj instanceof Version)) return false;
13+
return equals((Version) obj);
14+
}
15+
}

0 commit comments

Comments
 (0)