Skip to content

Commit 886b215

Browse files
committed
Expand Proto functionality
I decided against using doubles to represent protos in shorthand, swhitching to a more complete string. I also added a range feature, which can be used to furter test Protos.
1 parent 84843c0 commit 886b215

3 files changed

Lines changed: 24 additions & 12 deletions

File tree

src/main/java/in/twizmwaz/cardinal/module/objective/wool/WoolModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ public boolean loadMatch(Match match) {
132132

133133
String locationValue = ParseUtil.getFirstAttribute("location", woolElement, woolsElement);
134134
Proto proto = match.getMap().getProto();
135-
if (locationValue != null && proto.isBefore(1.4)) {
135+
if (locationValue != null && proto.isBefore("1.4.0")) {
136136
errors.add(new ModuleError(this, match.getMap(),
137137
new String[]{"Attribute \"location\" is supported in proto 1.4.0 or later",
138138
"Element at " + located.getLine() + ", " + located.getColumn()}, false));
139-
} else if (locationValue == null && proto.isAfterOrAt(1.4)) {
139+
} else if (locationValue == null && proto.isAfterOrAt("1.4.0")) {
140140
errors.add(new ModuleError(this, match.getMap(),
141141
new String[]{"Attribute \"location\" should be specified for wool in proto 1.4.0 or later",
142142
"Element at " + located.getLine() + ", " + located.getColumn()}, false));

src/main/java/in/twizmwaz/cardinal/module/region/RegionModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ public Region getRegion(Match match, Element element, String... alternateAttribu
130130
if (value != null) {
131131
String attr = value.getKey();
132132
Proto proto = match.getMap().getProto();
133-
if (attr.equals("id") && proto.isBefore(1.4)) {
133+
if (attr.equals("id") && proto.isBefore("1.4.0")) {
134134
errors.add(new ModuleError(this, match.getMap(),
135135
new String[]{"Attribute \"id\" should be \"name\" prior to proto 1.4.0"}, false));
136-
} else if (attr.equals("name") && proto.isAfterOrAt(1.4)) {
136+
} else if (attr.equals("name") && proto.isAfterOrAt("1.4.0")) {
137137
errors.add(new ModuleError(this, match.getMap(),
138138
new String[]{"Attribute \"name\" should be \"id\" in proto 1.4.0 or later"}, false));
139139
}

src/main/java/in/twizmwaz/cardinal/util/Proto.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@ public boolean isAfter(@NonNull Proto proto) {
6363
|| (this.minor == proto.getMinor() && this.patch > proto.getPatch())));
6464
}
6565

66-
public boolean isAfter(double proto) {
67-
return major + minor * 0.1 + patch * 0.01 > proto;
66+
public boolean isAfter(String proto) {
67+
return isAfter(parseProto(proto));
6868
}
6969

7070
public boolean isAfterOrAt(@NonNull Proto proto) {
7171
return this.equals(proto) || this.isAfter(proto);
7272
}
7373

74-
public boolean isAfterOrAt(double proto) {
75-
return this.equals(proto) || this.isAfter(proto);
74+
public boolean isAfterOrAt(String proto) {
75+
return isAfterOrAt(parseProto(proto));
7676
}
7777

7878
/**
@@ -85,16 +85,28 @@ public boolean isBefore(@NonNull Proto proto) {
8585
|| (this.minor == proto.getMinor() && this.patch < proto.getPatch())));
8686
}
8787

88-
public boolean isBefore(double proto) {
89-
return major + minor * 0.1 + patch * 0.01 < proto;
88+
public boolean isBefore(String proto) {
89+
return isBefore(parseProto(proto));
9090
}
9191

9292
public boolean isBeforeOrAt(@NonNull Proto proto) {
9393
return this.equals(proto) || this.isBefore(proto);
9494
}
9595

96-
public boolean isBeforeOrAt(double proto) {
97-
return this.equals(proto) || this.isBefore(proto);
96+
public boolean isBeforeOrAt(String proto) {
97+
return isBeforeOrAt(parseProto(proto));
98+
}
99+
100+
/**
101+
* Returns if a Proto is within a given range.
102+
* Note: The range is [min, max), a proto that equals the max will return false.
103+
*
104+
* @param min The minimum bound, inclusive.
105+
* @param max The maximum bound, exclusive.
106+
* @return If the proto is within the given range.
107+
*/
108+
public boolean isInRange(Proto min, Proto max) {
109+
return isAfterOrAt(min) && isBefore(max);
98110
}
99111

100112
}

0 commit comments

Comments
 (0)