Skip to content

Commit

Permalink
Add checkstyle Variable/Methode/Type naming convention rules (jgrapht…
Browse files Browse the repository at this point in the history
…#1052 - part 1) (jgrapht#1066)

* [Checkstyle] update to version 8.41 and update DTD-file links

* [CheckStyle] enforce Variable/Method/Type-name conventions for non API

Add variable/method/type naming-convention checkstyle rules.

Fix all variable/method/type naming-convention violations that do not
require modifications of the public API.

* [CheckStyle] suppress Variable/Method/Type-name rules in API elements

Suppress all Variable/Method/Type name violations on API elements.
Fixing those rules requires API modifications.

In case of (static) fields, the fields are already deprecated and a
replacement is provided.

org.jgrapht.nio.DefaultAttribute : make static field 'NULL' final. This
is actually an API break, but I assume it was never intended to make it
modifiable and it was not-final by accident.
  • Loading branch information
HannesWell authored Mar 29, 2021
1 parent 6c5148a commit 3c1dcee
Show file tree
Hide file tree
Showing 81 changed files with 913 additions and 811 deletions.
21 changes: 15 additions & 6 deletions etc/checkstyle_suppressions.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
<?xml version="1.0"?>

<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
"https://checkstyle.org/dtds/suppressions_1_2.dtd">

<suppressions>
<!-- Ignore header checks for package-info.java files -->
<suppress files="package-info\.java" checks="Header"/>
<suppress files="package-info\.java" checks="Header" />

<!-- Suppression of Javadoc related checks for test files -->
<suppress files="[/\\]src[/\\]test[/\\].*" checks="JavadocMethod"/>
<suppress files="[/\\]src[/\\]test[/\\].*" checks="JavadocType"/>
<suppress files="[/\\]src[/\\]test[/\\].*" checks="JavadocPackage"/>
<suppress files="[/\\]src[/\\]test[/\\].*" checks="JavadocMethod" />
<suppress files="[/\\]src[/\\]test[/\\].*" checks="JavadocType" />
<suppress files="[/\\]src[/\\]test[/\\].*" checks="JavadocPackage" />
<!-- Suppress main-checks in test-code and test-checks in main-code -->
<suppress files="[/\\]src[/\\]test[/\\].*" id="LocalFinalVariableNameMain" />
<suppress files="[/\\]src[/\\]main[/\\].*" id="LocalFinalVariableNameTest" />
<suppress files="[/\\]src[/\\]test[/\\].*" id="LocalVariableNameMain" />
<suppress files="[/\\]src[/\\]main[/\\].*" id="LocalVariableNameTest" />
<suppress files="[/\\]src[/\\]test[/\\].*" id="MemberNameMain" />
<suppress files="[/\\]src[/\\]main[/\\].*" id="MemberNameTest" />
<suppress files="[/\\]src[/\\]test[/\\].*" id="MethodNameMain" />
<suppress files="[/\\]src[/\\]main[/\\].*" id="MethodNameTest" />
</suppressions>
62 changes: 55 additions & 7 deletions etc/jgrapht_checks.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">

<module name="Checker">
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$"/>
<property name="fileNamePattern" value="module\-info\.java$" />
</module>
<module name="SuppressionFilter">
<property name="file" value="etc/checkstyle_suppressions.xml"/>
<property name="file" value="etc/checkstyle_suppressions.xml" />
</module>

<!-- Checks for file header -->
<!-- See http://checkstyle.sf.net/config_header.html -->
<module name="Header">
<property name="headerFile" value="etc/header-boilerplate.txt"/>
<property name="ignoreLines" value="2"/>
<property name="fileExtensions" value="java"/>
<property name="headerFile" value="etc/header-boilerplate.txt" />
<property name="ignoreLines" value="2" />
<property name="fileExtensions" value="java" />
</module>

<!-- Checks for whitespace -->
Expand All @@ -38,10 +38,58 @@
<module name="MissingDeprecated" />
<module name="MissingOverride" />

<!-- Checks for naming convention -->
<!-- See https://checkstyle.sourceforge.io/config_naming.html -->
<module name="ConstantName" />
<module name="IllegalIdentifierName" />
<module name="LambdaParameterName" />
<module name="LocalFinalVariableName">
<property name="id" value="LocalFinalVariableNameMain" />
<!-- Use the default configuration in main code -->
</module>
<module name="LocalFinalVariableName">
<property name="id" value="LocalFinalVariableNameTest" />
<property name="format" value="^[a-z][a-zA-Z0-9]*(_[0-9]+)?$" />
</module>
<module name="LocalVariableName">
<property name="id" value="LocalVariableNameMain" />
<!-- Use the default configuration in main code -->
</module>
<module name="LocalVariableName">
<property name="id" value="LocalVariableNameTest" />
<property name="format" value="^[a-z][a-zA-Z0-9]*(_[0-9]+)?$" />
</module>
<module name="MemberName">
<property name="id" value="MemberNameMain" />
<!-- Use the default configuration in main code -->
</module>
<module name="MemberName">
<property name="id" value="MemberNameTest" />
<property name="format" value="^[a-z][a-zA-Z0-9]*(_[0-9]+)?$" />
</module>
<module name="MethodName">
<property name="id" value="MethodNameMain" />
<!-- Use the default configuration in main code -->
</module>
<module name="MethodName">
<property name="id" value="MethodNameTest" />
<property name="format" value="^[a-z](_?[a-zA-Z0-9]+)*$" />
</module>
<module name="PackageName" />
<module name="ParameterName" />
<module name="PatternVariableName" />
<module name="RecordComponentName" />
<module name="StaticVariableName" />
<module name="TypeName" />

<module name="EqualsHashCode" />
<module name="StringLiteralEquality" />

<module name="SuppressWithNearbyCommentFilter">
<property name="commentFormat" value="@CS\.suppress\[(\w+(\|\w+)*)\]" /> <!-- \w[-\.'`,:;\w ]{14,} -->
<property name="checkFormat" value="$1" />
<property name="influenceFormat" value="1" />
</module>
</module>

<module name="JavadocPackage" />
Expand Down
12 changes: 6 additions & 6 deletions jgrapht-core/src/main/java/org/jgrapht/GraphMetrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static <V, E> double getRadius(Graph<V, E> graph)
*/
public static <V, E> int getGirth(Graph<V, E> graph)
{
final int NIL = -1;
final int nil = -1;
final boolean isAllowingMultipleEdges = graph.getType().isAllowingMultipleEdges();

// Ordered sequence of vertices
Expand Down Expand Up @@ -139,8 +139,8 @@ public static <V, E> int getGirth(Graph<V, E> graph)
for (int i = 0; i < vertices.size() - 2 && girth > 3; i++) {

// Reset data structures
Arrays.fill(depth, NIL);
Arrays.fill(parent, NIL);
Arrays.fill(depth, nil);
Arrays.fill(parent, nil);
queue.clear();

depth[i] = 0;
Expand All @@ -163,7 +163,7 @@ public static <V, E> int getGirth(Graph<V, E> graph)
}

int depthV = depth[indexV];
if (depthV == NIL) { // New neighbor discovered
if (depthV == nil) { // New neighbor discovered
queue.add(v);
depth[indexV] = depthU + 1;
parent[indexV] = indexU;
Expand All @@ -177,7 +177,7 @@ public static <V, E> int getGirth(Graph<V, E> graph)
for (int i = 0; i < vertices.size() - 1 && girth > 2; i++) {

// Reset data structures
Arrays.fill(depth, NIL);
Arrays.fill(depth, nil);
queue.clear();

depth[i] = 0;
Expand All @@ -194,7 +194,7 @@ public static <V, E> int getGirth(Graph<V, E> graph)
int indexV = indexMap.get(v);

int depthV = depth[indexV];
if (depthV == NIL) { // New neighbor discovered
if (depthV == nil) { // New neighbor discovered
queue.add(v);
depth[indexV] = depthU + 1;
} else if (depthV == 0) { // Rediscover root: found cycle.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ public <V, E> void reduce(final Graph<V, E> directedGraph)
final V v1 = directedGraph.getEdgeSource(edge);
final V v2 = directedGraph.getEdgeTarget(edge);

final int v_1 = vertices.indexOf(v1);
final int v_2 = vertices.indexOf(v2);
final int i1 = vertices.indexOf(v1);
final int i2 = vertices.indexOf(v2);

originalMatrix[v_1].set(v_2);
originalMatrix[i1].set(i2);
}

// create path matrix from original matrix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private void computeMinimalTriangulation()
}
for (int i = 1, n = graph.vertexSet().size(); i <= n; i++) {
V v = getMaxLabelVertex(vertexLabels);
LinkedList<V> Y = new LinkedList<>(Graphs.neighborListOf(gprime, v));
LinkedList<V> neighborsY = new LinkedList<>(Graphs.neighborListOf(gprime, v));

if (vertexLabels.get(v) <= s) {
generators.add(v);
Expand All @@ -144,7 +144,7 @@ private void computeMinimalTriangulation()
HashMap<Integer, HashSet<V>> reach = new HashMap<>();

// mark y reached and add y to reach
for (V y : Y) {
for (V y : neighborsY) {
reached.add(y);
addToReach(vertexLabels.get(y), y, reach);
}
Expand All @@ -162,7 +162,7 @@ private void computeMinimalTriangulation()
if (!reached.contains(z)) {
reached.add(z);
if (vertexLabels.get(z) > j) {
Y.add(z);
neighborsY.add(z);
E fillEdge = graph.getEdgeSupplier().get();
fillEdges.add(fillEdge);
addToReach(vertexLabels.get(z), z, reach);
Expand All @@ -174,7 +174,7 @@ private void computeMinimalTriangulation()
}
}

for (V y : Y) {
for (V y : neighborsY) {
chordalGraph.addEdge(v, y);
vertexLabels.put(y, vertexLabels.get(y) + 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,29 +110,29 @@ protected void lazyRun()
viNeighbors.add(Graphs.getOppositeVertex(graph, e, vi));
}

Set<V> P = new HashSet<>();
Set<V> p = new HashSet<>();
for (int j = i + 1; j < n; j++) {
V vj = ordering.get(j);
if (viNeighbors.contains(vj)) {
P.add(vj);
p.add(vj);
}
}

Set<V> R = new HashSet<>();
R.add(vi);
Set<V> r = new HashSet<>();
r.add(vi);

Set<V> X = new HashSet<>();
Set<V> x = new HashSet<>();
for (int j = 0; j < i; j++) {
V vj = ordering.get(j);
if (viNeighbors.contains(vj)) {
X.add(vj);
x.add(vj);
}
}

/*
* Call the pivot version
*/
findCliques(P, R, X, nanosTimeLimit);
findCliques(p, r, x, nanosTimeLimit);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,21 @@ protected void lazyRun()
/**
* Choose a pivot.
*
* @param P vertices to consider adding to the clique
* @param X vertices which must be excluded from the clique
* @param p vertices to consider adding to the clique
* @param x vertices which must be excluded from the clique
* @return a pivot
*/
private V choosePivot(Set<V> P, Set<V> X)
private V choosePivot(Set<V> p, Set<V> x)
{
int max = -1;
V pivot = null;

Iterator<V> it = Stream.concat(P.stream(), X.stream()).iterator();
Iterator<V> it = Stream.concat(p.stream(), x.stream()).iterator();
while (it.hasNext()) {
V u = it.next();
int count = 0;
for (E e : graph.edgesOf(u)) {
if (P.contains(Graphs.getOppositeVertex(graph, e, u))) {
if (p.contains(Graphs.getOppositeVertex(graph, e, u))) {
count++;
}
}
Expand All @@ -133,18 +133,18 @@ private V choosePivot(Set<V> P, Set<V> X)
/**
* Recursive implementation of the Bron-Kerbosch with pivot.
*
* @param P vertices to consider adding to the clique
* @param R a possibly non-maximal clique
* @param X vertices which must be excluded from the clique
* @param p vertices to consider adding to the clique
* @param r a possibly non-maximal clique
* @param x vertices which must be excluded from the clique
* @param nanosTimeLimit time limit
*/
protected void findCliques(Set<V> P, Set<V> R, Set<V> X, final long nanosTimeLimit)
protected void findCliques(Set<V> p, Set<V> r, Set<V> x, final long nanosTimeLimit)
{
/*
* Check if maximal clique
*/
if (P.isEmpty() && X.isEmpty()) {
Set<V> maximalClique = new HashSet<>(R);
if (p.isEmpty() && x.isEmpty()) {
Set<V> maximalClique = new HashSet<>(r);
allMaximalCliques.add(maximalClique);
maxSize = Math.max(maxSize, maximalClique.size());
return;
Expand All @@ -161,7 +161,7 @@ protected void findCliques(Set<V> P, Set<V> R, Set<V> X, final long nanosTimeLim
/*
* Choose pivot
*/
V u = choosePivot(P, X);
V u = choosePivot(p, x);

/*
* Find candidates for addition
Expand All @@ -171,7 +171,7 @@ protected void findCliques(Set<V> P, Set<V> R, Set<V> X, final long nanosTimeLim
uNeighbors.add(Graphs.getOppositeVertex(graph, e, u));
}
Set<V> candidates = new HashSet<>();
for (V v : P) {
for (V v : p) {
if (!uNeighbors.contains(v)) {
candidates.add(v);
}
Expand All @@ -186,15 +186,15 @@ protected void findCliques(Set<V> P, Set<V> R, Set<V> X, final long nanosTimeLim
vNeighbors.add(Graphs.getOppositeVertex(graph, e, v));
}

Set<V> newP = P.stream().filter(vNeighbors::contains).collect(Collectors.toSet());
Set<V> newX = X.stream().filter(vNeighbors::contains).collect(Collectors.toSet());
Set<V> newR = new HashSet<>(R);
Set<V> newP = p.stream().filter(vNeighbors::contains).collect(Collectors.toSet());
Set<V> newX = x.stream().filter(vNeighbors::contains).collect(Collectors.toSet());
Set<V> newR = new HashSet<>(r);
newR.add(v);

findCliques(newP, newR, newX, nanosTimeLimit);

P.remove(v);
X.add(v);
p.remove(v);
x.add(v);
}

}
Expand Down
Loading

0 comments on commit 3c1dcee

Please sign in to comment.