Skip to content

Commit

Permalink
Added formatter maven plugin. Now auto-formats during build.
Browse files Browse the repository at this point in the history
  • Loading branch information
essiembre committed Aug 28, 2024
1 parent 0af7f5e commit 571bf50
Show file tree
Hide file tree
Showing 316 changed files with 20,933 additions and 19,220 deletions.
419 changes: 419 additions & 0 deletions norconex-formatter.xml

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@
<!-- Test and provided -->
<lombok.version>1.18.32</lombok.version>

<!-- === Maven plugins ================================================= -->

<formatter-maven-plugin.version>2.24.1</formatter-maven-plugin.version>


</properties>

<licenses>
Expand Down Expand Up @@ -362,6 +367,35 @@
</extension>
</extensions>

<pluginManagement>
<plugins>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>${formatter-maven-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>format</goal>
</goals>
</execution>
</executions>
<configuration>
<compilerSource>${java.version}</compilerSource>
<compilerCompliance>${java.version}</compilerCompliance>
<compilerTargetPlatform>${java.version}</compilerTargetPlatform>
<lineEnding>LF</lineEnding>
<encoding>UTF-8</encoding>
<configFile>norconex-formatter.xml</configFile>
<includes>
<include>com/norconex/**/*.java</include>
</includes>
</configuration>
<inherited>true</inherited>
</plugin>
</plugins>
</pluginManagement>

<plugins>

<!-- This is only required to avoid false warnings in Eclipse:
Expand Down Expand Up @@ -826,7 +860,12 @@
</execution>
</executions>
</plugin>


<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
</plugin>

</plugins>

</build>
Expand Down
46 changes: 26 additions & 20 deletions src/main/java/com/norconex/commons/lang/CircularRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ private CircularRange(
if (circleStart == null || circleEnd == null) {
throw new IllegalArgumentException(String.format(
"Circular boundaries must not be null: circleStart=%s"
+ ", circleEnd=%s", circleStart, circleEnd));
+ ", circleEnd=%s",
circleStart, circleEnd));
}
if (minimum == null || maximum == null) {
throw new IllegalArgumentException(String.format(
"Elements in a range must not be null: minimum=%s"
+ ", maximum=%s", minimum, maximum));
+ ", maximum=%s",
minimum, maximum));
}
if (comp == null) {
comparator = ComparableComparator.INSTANCE;
Expand All @@ -76,14 +78,14 @@ private CircularRange(
|| !inNormalRange(maximum, circleStart, circleEnd)) {
throw new IllegalArgumentException(String.format(
"Elements in a range must fit between circular start/end: "
+ "circleStart=%s, circleEnd=%s, minimum=%s, maximum=%s",
circleStart, circleEnd, minimum, maximum));
+ "circleStart=%s, circleEnd=%s, minimum=%s, maximum=%s",
circleStart, circleEnd, minimum, maximum));
}
if (compare(circleEnd, circleStart) < 0) {
throw new IllegalArgumentException(String.format(
"Circular start must be smaller than or equal to circlar "
+ "end: circleStart=%s, circleEnd=%s",
circleStart, circleEnd));
+ "end: circleStart=%s, circleEnd=%s",
circleStart, circleEnd));
}
this.circleStart = circleStart;
this.circleEnd = circleEnd;
Expand Down Expand Up @@ -207,14 +209,10 @@ public static <T> CircularRange<T> between(
*/
@JsonCreator
public static <T extends Comparable<T>> CircularRange<T> between(
@JsonProperty("start")
final T circleStartInclusive,
@JsonProperty("end")
final T circleEndInclusive,
@JsonProperty("minimum")
final T rangeFromInclusive,
@JsonProperty("maximum")
final T rangeToInclusive) {
@JsonProperty("start") final T circleStartInclusive,
@JsonProperty("end") final T circleEndInclusive,
@JsonProperty("minimum") final T rangeFromInclusive,
@JsonProperty("maximum") final T rangeToInclusive) {
return between(circleStartInclusive, circleEndInclusive,
rangeFromInclusive, rangeToInclusive, null);
}
Expand Down Expand Up @@ -273,6 +271,7 @@ public CircularRange<T> withCircularBoundaries(
circleStartInclusive, circleEndInclusive,
getMinimum(), getMaximum(), getComparator());
}

/**
* <p>Obtains a new range with the specified minimum and maximum range
* values (both inclusive). The circular start and end are the same.</p>
Expand Down Expand Up @@ -301,6 +300,7 @@ public CircularRange<T> withRange(
public T getMinimum() {
return minimum;
}

/**
* <p>Gets the maximum value in this range.</p>
* @return the maximum value in this range, not null
Expand All @@ -309,6 +309,7 @@ public T getMinimum() {
public T getMaximum() {
return maximum;
}

/**
* <p>Gets the start value of this circular range.</p>
* @return the start value of this circular range, not null
Expand All @@ -317,6 +318,7 @@ public T getMaximum() {
public T getCircleStart() {
return circleStart;
}

/**
* <p>Gets the end value of this circular range.</p>
* @return the end value of this circular range, not null
Expand All @@ -325,6 +327,7 @@ public T getCircleStart() {
public T getCircleEnd() {
return circleEnd;
}

/**
* <p>Gets the comparator being used to determine if objects are
* within the range.</p>
Expand Down Expand Up @@ -449,8 +452,9 @@ public boolean containsRange(final CircularRange<T> otherRange) {
if (isRolling() && !otherRange.isRolling()) {
return (inNormalRange(otherRange.minimum, minimum, circleEnd)
&& inNormalRange(otherRange.maximum, minimum, circleEnd))
|| (inNormalRange(otherRange.minimum, circleStart, maximum)
&& inNormalRange(otherRange.maximum, circleStart, maximum));
|| (inNormalRange(otherRange.minimum, circleStart, maximum)
&& inNormalRange(otherRange.maximum, circleStart,
maximum));
}

// Normal vs rolling is always false
Expand All @@ -475,13 +479,14 @@ public boolean isOverlappedBy(final CircularRange<T> otherRange) {
return false;
}
return otherRange.contains(minimum)
|| otherRange.contains(maximum)
|| contains(otherRange.minimum);
|| otherRange.contains(maximum)
|| contains(otherRange.minimum);
}

private int compare(T o1, T o2) {
return comparator.compare(o1, o2);
}

private boolean inNormalRange(T element, T min, T max) {
return compare(element, min) > -1 && compare(element, max) < 1;
}
Expand All @@ -498,7 +503,7 @@ private boolean inNormalRange(T element, T min, T max) {
public String toString() {
if (toString == null) {
toString = "[" + minimum + ".." + maximum
+ "](" + circleStart + ".." + circleEnd + ")";
+ "](" + circleStart + ".." + circleEnd + ")";
}
return toString;
}
Expand Down Expand Up @@ -528,9 +533,10 @@ public String toString(final String format) {
}

//-----------------------------------------------------------------------
@SuppressWarnings({"rawtypes", "unchecked"})
@SuppressWarnings({ "rawtypes", "unchecked" })
private enum ComparableComparator implements Comparator { //NOSONAR
INSTANCE;

/**
* Comparable based compare implementation.
*
Expand Down
Loading

0 comments on commit 571bf50

Please sign in to comment.