Fix formatting of NthUglyNumber (#4248)

This commit is contained in:
Piotr Idzik
2023-07-23 13:16:35 +02:00
committed by GitHub
parent 1afc4cc319
commit e897a93166

View File

@ -1,6 +1,5 @@
package com.thealgorithms.maths; package com.thealgorithms.maths;
import java.lang.IllegalArgumentException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
@ -16,16 +15,16 @@ import java.util.HashMap;
* - the base [2, 3, 5] ugly numbers are the same as base [5, 6, 2, 3, 5] ugly numbers * - the base [2, 3, 5] ugly numbers are the same as base [5, 6, 2, 3, 5] ugly numbers
*/ */
public class NthUglyNumber { public class NthUglyNumber {
ArrayList<Long> uglyNumbers = new ArrayList<>(Arrays.asList(1L)); private ArrayList<Long> uglyNumbers = new ArrayList<>(Arrays.asList(1L));
final int[] baseNumbers; private final int[] baseNumbers;
HashMap<Integer, Integer> positions = new HashMap<>(); private HashMap<Integer, Integer> positions = new HashMap<>();
/** /**
* @brief initialized the object allowing to compute ugly numbers with given base * @brief initialized the object allowing to compute ugly numbers with given base
* @param baseNumbers the given base of ugly numbers * @param baseNumbers the given base of ugly numbers
* @exception IllegalArgumentException baseNumber is empty * @exception IllegalArgumentException baseNumber is empty
*/ */
NthUglyNumber(int[] baseNumbers) { NthUglyNumber(final int[] baseNumbers) {
if (baseNumbers.length == 0) { if (baseNumbers.length == 0) {
throw new IllegalArgumentException("baseNumbers must be non-empty."); throw new IllegalArgumentException("baseNumbers must be non-empty.");
} }
@ -41,7 +40,7 @@ public class NthUglyNumber {
* @exception IllegalArgumentException n is negative * @exception IllegalArgumentException n is negative
* @return the n-th ugly number (starting from index 0) * @return the n-th ugly number (starting from index 0)
*/ */
public Long get(int n) { public Long get(final int n) {
if (n < 0) { if (n < 0) {
throw new IllegalArgumentException("n must be non-negative."); throw new IllegalArgumentException("n must be non-negative.");
} }
@ -67,7 +66,7 @@ public class NthUglyNumber {
} }
} }
private long computeCandidate(int candidateBase) { private long computeCandidate(final int candidateBase) {
return candidateBase * uglyNumbers.get(positions.get(candidateBase)); return candidateBase * uglyNumbers.get(positions.get(candidateBase));
} }