Let's say I have a class with a method that uses some static final variables as constants, but no other method in the class uses them.
For example, an AVLTree class with a balance method that uses these constants to describe balance factors for rotations
private static final int L_HEAVY = 2;
private static final int LL_HEAVY = 1;
private static final int R_HEAVY = -2;
private static final int RR_HEAVY = -1;
Where is it best to place these constants according to Java coding conventions (e.g., Oracle's Code Conventions)?
public class AVLTree {
private Node root;
// (1) Here, among members, right after class declaration ?
public AVLTree() {
root = null;
}
...
// (2) Here, just above the method that uses them?
private Node balance(Node node) {
// (3) Here, inside the method that uses them?
if (height(node.left) - height(node.right) == L_HEAVY) {
if (height(node.left.left) - height(node.left.right) == LL_HEAVY) {
...
}
}
if (height(node.left) - height(node.right) == R_HEAVY) {
if (height(node.right.left) - height(node.right.right) == RR_HEAVY) {
...
}
}
return node;
}
...
}