Skip to content

style: basic linting of NthUglyNumber #4248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/main/java/com/thealgorithms/maths/NthUglyNumber.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.thealgorithms.maths;

import java.lang.IllegalArgumentException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand All @@ -16,16 +15,16 @@
* - the base [2, 3, 5] ugly numbers are the same as base [5, 6, 2, 3, 5] ugly numbers
*/
public class NthUglyNumber {
ArrayList<Long> uglyNumbers = new ArrayList<>(Arrays.asList(1L));
final int[] baseNumbers;
HashMap<Integer, Integer> positions = new HashMap<>();
private ArrayList<Long> uglyNumbers = new ArrayList<>(Arrays.asList(1L));
private final int[] baseNumbers;
private HashMap<Integer, Integer> positions = new HashMap<>();

/**
* @brief initialized the object allowing to compute ugly numbers with given base
* @param baseNumbers the given base of ugly numbers
* @exception IllegalArgumentException baseNumber is empty
*/
NthUglyNumber(int[] baseNumbers) {
NthUglyNumber(final int[] baseNumbers) {
if (baseNumbers.length == 0) {
throw new IllegalArgumentException("baseNumbers must be non-empty.");
}
Expand All @@ -41,7 +40,7 @@ public class NthUglyNumber {
* @exception IllegalArgumentException n is negative
* @return the n-th ugly number (starting from index 0)
*/
public Long get(int n) {
public Long get(final int n) {
if (n < 0) {
throw new IllegalArgumentException("n must be non-negative.");
}
Expand All @@ -67,7 +66,7 @@ private void updatePositions() {
}
}

private long computeCandidate(int candidateBase) {
private long computeCandidate(final int candidateBase) {
return candidateBase * uglyNumbers.get(positions.get(candidateBase));
}

Expand Down