Plex-FAWE/worldedit-core/src/main/java/com/sk89q/worldedit/registry/Category.java

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

80 lines
2.1 KiB
Java
Raw Normal View History

2018-07-05 18:09:45 +00:00
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
2020-08-18 17:46:14 +00:00
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
2018-07-05 18:09:45 +00:00
* (at your option) any later version.
*
2020-08-18 17:46:14 +00:00
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
2018-07-05 18:09:45 +00:00
*
2020-08-18 17:46:14 +00:00
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2018-07-05 18:09:45 +00:00
*/
package com.sk89q.worldedit.registry;
import java.util.HashSet;
import java.util.Set;
public abstract class Category<T extends Keyed> implements RegistryItem {
2018-07-05 18:09:45 +00:00
private final Set<T> set = new HashSet<>();
protected final String id;
private boolean empty = true;
protected Category(final String id) {
this.id = id;
}
public final String getId() {
return this.id;
}
public final Set<T> getAll() {
if (this.empty) {
this.set.addAll(this.load());
this.empty = false;
}
return this.set;
}
2019-04-05 04:15:10 +00:00
private int internalId;
@Override
public void setInternalId(int internalId) {
this.internalId = internalId;
}
@Override
public int getInternalId() {
return internalId;
}
2018-07-05 18:09:45 +00:00
protected abstract Set<T> load();
/**
* Checks if this category contains {@code object}.
*
* @param object the object
* @return {@code true} if this category contains the object
*/
public boolean contains(final T object) {
return this.getAll().contains(object);
}
public void invalidateCache() {
this.set.clear();
this.empty = true;
}
2018-08-13 12:18:12 +00:00
@Override
public String toString() {
return getId();
}
2018-07-05 18:09:45 +00:00
}