Repository: TheAlgorithms/Java
File: src/main/java/com/thealgorithms/datastructures/crdt/PNCounter.java (Java)

Code before:
     * Constructs a PN-Counter for a cluster of n nodes.
     *
     * @param myId The identifier of the current node.
     * @param n    The number of nodes in the cluster.
     */
    public PNCounter(int myId, int n) {
        this.myId = myId;
        this.n = n;
        this.P = new HashMap<>();
        this.N = new HashMap<>();

        for (int i = 0; i < n; i++) {
            P.put(i, 0);
            N.put(i, 0);
        }
    }

    /**
     * Increments the increment counter for the current node.
     */
    public void increment() {
        P.put(myId, P.get(myId) + 1);
    }

    /**
     * Decrements the decrement counter for the current node.
     */
    public void decrement() {
        N.put(myId, N.get(myId) + 1);
    }

    /**
     * Gets the total value of the counter by subtracting the decrement counter from the increment counter.
     *
     * @return The total value of the counter.
     */
    public int value() {
        int sumP = P.values().stream().mapToInt(Integer::intValue).sum();
        int sumN = N.values().stream().mapToInt(Integer::intValue).sum();
        return sumP - sumN;
    }

    /**
     * Compares the state of this PN-Counter with another PN-Counter.
     *
     * @param other The other PN-Counter to compare with.
     * @return True if the state of this PN-Counter is less than or equal to the state of the other PN-Counter.
     */
    public boolean compare(PNCounter other) {
        for (int i = 0; i < n; i++) {
            if (this.P.get(i) > other.P.get(i) && this.N.get(i) > other.N.get(i)) {

Review comment (suggestion):
```suggestion
     * Increments the decrement counter for the current node.
```

Code after:
     * Constructs a PN-Counter for a cluster of n nodes.
     *
     * @param myId The identifier of the current node.
     * @param n    The number of nodes in the cluster.
     */
    public PNCounter(int myId, int n) {
        this.myId = myId;
        this.n = n;
        this.P = new HashMap<>();
        this.N = new HashMap<>();

        for (int i = 0; i < n; i++) {
            P.put(i, 0);
            N.put(i, 0);
        }
    }

    /**
     * Increments the increment counter for the current node.
     */
    public void increment() {
        P.put(myId, P.get(myId) + 1);
    }

    /**
     * Increments the decrement counter for the current node.
     */
    public void decrement() {
        N.put(myId, N.get(myId) + 1);
    }

    /**
     * Gets the total value of the counter by subtracting the decrement counter from the increment counter.
     *
     * @return The total value of the counter.
     */
    public int value() {
        int sumP = P.values().stream().mapToInt(Integer::intValue).sum();
        int sumN = N.values().stream().mapToInt(Integer::intValue).sum();
        return sumP - sumN;
    }

    /**
     * Compares the state of this PN-Counter with another PN-Counter.
     *
     * @param other The other PN-Counter to compare with.
     * @return True if the state of this PN-Counter is less than or equal to the state of the other PN-Counter.
     */
    public boolean compare(PNCounter other) {
        if (this.n != other.n) {
            throw new IllegalArgumentException("Cannot compare PN-Counters with different number of nodes");