Skip to content
This repository has been archived by the owner on Jan 18, 2025. It is now read-only.

Commit

Permalink
Add toString override & remove unused symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
powersagitar committed Jan 11, 2025
1 parent 3acceef commit 151ceac
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions culminating-mastermind/app/src/main/java/mastermind/core/Code.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package mastermind.core;

import mastermind.Mastermind;

import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
import java.util.function.Function;

import mastermind.Mastermind;

public class Code {
public enum Color {
Green, Red, Blue, Yellow, Orange, Purple;
Expand All @@ -22,17 +22,6 @@ public enum Color {
public static Color fromIndex(final int index) {
return Color.values()[index];
}

/**
* Converts the zero-based index of a {@code Color} constant to its string representation.
*
* @param index the zero-based index of the {@code Color} constant.
* @return the string representation of the {@code Color} constant at the specified index.
* @throws ArrayIndexOutOfBoundsException if the index is out of range for the {@code Color} values.
*/
public static String toString(final int index) {
return fromIndex(index).toString();
}
}

private final ArrayList<Color> code;
Expand Down Expand Up @@ -87,7 +76,7 @@ public static Code generateRandomCode(List<Function<Code, Boolean>> filters) {
* @param code a {@link List} of integers, where each integer is the index of a {@code Color}.
* The indices must be within the range of valid {@code Color} values.
* @throws ArrayIndexOutOfBoundsException if any index in the provided list is out of range
* for the {@code Color} enum.
* for the {@code Color} enum.
*/
public Code(final List<Integer> code) {
ArrayList<Color> codeBuilder = new ArrayList<>(Mastermind.CODE_LENGTH);
Expand Down Expand Up @@ -130,8 +119,8 @@ public ArrayList<Color> getColors() {
* </p>
*
* @return a {@link HashMap} where the keys are {@link Color} values and the values
* are integers representing the number of occurrences of each color in the
* code sequence.
* are integers representing the number of occurrences of each color in the
* code sequence.
*/
public HashMap<Color, Integer> getOccurrences() {
HashMap<Color, Integer> occurrences = new HashMap<>(Mastermind.TOTAL_COLORS);
Expand All @@ -146,4 +135,9 @@ public HashMap<Color, Integer> getOccurrences() {

return occurrences;
}

@Override
public String toString() {
return code.toString();
}
}

0 comments on commit 151ceac

Please sign in to comment.