3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-12-24 15:20:35 +01:00

Fix Checkstyle issues again

Dieser Commit ist enthalten in:
Andrew Steinborn 2020-07-12 11:56:50 -04:00
Ursprung d47462c606
Commit 21bc050f9c

Datei anzeigen

@ -2,6 +2,10 @@ package com.velocitypowered.proxy.util.collect;
import java.util.EnumSet;
/**
* An immutable map of {@link Enum} entries to {@code int}s.
* @param <E> the enum type
*/
public class Enum2IntMap<E extends Enum<E>> {
private final int[] mappings;
@ -23,6 +27,12 @@ public class Enum2IntMap<E extends Enum<E>> {
this.populated = EnumSet.noneOf(klazz);
}
/**
* Adds a mapping to the map.
* @param key the key to use
* @param value the value to associate with the key
* @return {@code this}, for chaining
*/
public Builder<E> put(E key, int value) {
this.mappings[key.ordinal()] = value;
this.populated.add(key);
@ -39,6 +49,11 @@ public class Enum2IntMap<E extends Enum<E>> {
return this;
}
/**
* Fetches a mapping from the map.
* @param key the key to use
* @return the value in the map
*/
public int get(E key) {
if (this.populated.contains(key)) {
return this.mappings[key.ordinal()];
@ -46,6 +61,10 @@ public class Enum2IntMap<E extends Enum<E>> {
return this.defaultValue;
}
/**
* Builds the map.
* @return the built map
*/
public Enum2IntMap<E> build() {
for (E unpopulated : EnumSet.complementOf(this.populated)) {
this.mappings[unpopulated.ordinal()] = this.defaultValue;