Refactored Preconditions to Validate (guava to apache commons)

This commit is contained in:
Collin Smith 2019-04-15 01:12:19 -07:00
parent 33e53d0ef1
commit 9267f03d61
18 changed files with 94 additions and 100 deletions

View File

@ -1,15 +1,14 @@
package com.riiablo;
import com.google.common.base.MoreObjects;
import com.badlogic.gdx.Application;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;
import com.riiablo.cvar.Cvar;
import com.riiablo.cvar.SaveableCvarManager;
import com.riiablo.serializer.StringSerializer;
import org.apache.commons.lang3.ObjectUtils;
public class GdxCvarManager extends SaveableCvarManager {
private static final String TAG = "GdxCvarManager";
@ -22,7 +21,7 @@ public class GdxCvarManager extends SaveableCvarManager {
throw new CvarManagerException("%s must be managed by this CvarManager", alias);
}
StringSerializer<T> serializer = MoreObjects.firstNonNull(cvar.getSerializer(), getSerializer(cvar));
StringSerializer<T> serializer = ObjectUtils.firstNonNull(cvar.getSerializer(), getSerializer(cvar));
if (serializer == null) {
throw new CvarManagerException("%s cannot be saved (no serializer found for %s)", alias, cvar.getType().getName());
}
@ -39,7 +38,7 @@ public class GdxCvarManager extends SaveableCvarManager {
@Override
public <T> T load(Cvar<T> cvar) {
String alias = cvar.getAlias();
StringSerializer<T> serializer = MoreObjects.firstNonNull(cvar.getSerializer(), getSerializer(cvar));
StringSerializer<T> serializer = ObjectUtils.firstNonNull(cvar.getSerializer(), getSerializer(cvar));
if (serializer == null) {
try {
throw new CvarManagerException("%s cannot be loaded (no deserializer found for %s)", alias, cvar.getType().getName());

View File

@ -1,7 +1,5 @@
package com.riiablo.audio;
import com.google.common.base.Preconditions;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@ -11,6 +9,8 @@ import com.badlogic.gdx.assets.AssetDescriptor;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.audio.Music;
import org.apache.commons.lang3.Validate;
import java.util.Deque;
import java.util.LinkedList;
@ -31,7 +31,7 @@ public class MusicController implements Music.OnCompletionListener {
private String asset;
public MusicController(@NonNull AssetManager assetManager) {
this.ASSETS = Preconditions.checkNotNull(assetManager, "The AssetManager cannot be null");
this.ASSETS = Validate.notNull(assetManager, "The AssetManager cannot be null");
this.PLAYLIST = new LinkedList<>();
}
@ -66,7 +66,7 @@ public class MusicController implements Music.OnCompletionListener {
}
public void play(@NonNull String asset) {
Preconditions.checkNotNull(asset, "Asset cannot be null");
Validate.notNull(asset, "Asset cannot be null");
PLAYLIST.addFirst(asset);
next();
}

View File

@ -1,7 +1,5 @@
package com.riiablo.audio;
import com.google.common.base.Preconditions;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@ -11,6 +9,8 @@ import com.badlogic.gdx.assets.loaders.MusicLoader;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.files.FileHandle;
import org.apache.commons.lang3.Validate;
import java.lang.ref.WeakReference;
public class VolumeControlledMusicLoader extends MusicLoader implements VolumeControlled<Music> {
@ -21,12 +21,12 @@ public class VolumeControlledMusicLoader extends MusicLoader implements VolumeCo
public VolumeControlledMusicLoader(@NonNull FileHandleResolver resolver,
@NonNull VolumeController<Music> controller) {
super(resolver);
this.controller = Preconditions.checkNotNull(controller, "VolumeController cannot be null");
this.controller = Validate.notNull(controller, "VolumeController cannot be null");
}
@Override
public void setVolumeController(@NonNull VolumeController<Music> controller) {
this.controller = Preconditions.checkNotNull(controller, "VolumeController cannot be null");
this.controller = Validate.notNull(controller, "VolumeController cannot be null");
}
@Nullable

View File

@ -1,7 +1,5 @@
package com.riiablo.audio;
import com.google.common.base.Preconditions;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@ -11,6 +9,8 @@ import com.badlogic.gdx.assets.loaders.SoundLoader;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.files.FileHandle;
import org.apache.commons.lang3.Validate;
import java.lang.ref.WeakReference;
public class VolumeControlledSoundLoader extends SoundLoader implements VolumeControlled<Sound> {
@ -24,12 +24,12 @@ public class VolumeControlledSoundLoader extends SoundLoader implements VolumeCo
public VolumeControlledSoundLoader(@NonNull FileHandleResolver resolver,
@NonNull VolumeController<Sound> controller) {
super(resolver);
this.controller = Preconditions.checkNotNull(controller, "VolumeController cannot be null");
this.controller = Validate.notNull(controller, "VolumeController cannot be null");
}
@Override
public void setVolumeController(@NonNull VolumeController<Sound> controller) {
this.controller = Preconditions.checkNotNull(controller, "VolumeController cannot be null");
this.controller = Validate.notNull(controller, "VolumeController cannot be null");
}
@Nullable
@ -63,7 +63,7 @@ public class VolumeControlledSoundLoader extends SoundLoader implements VolumeCo
private final Sound PARENT;
private VolumeManagedSound(@NonNull Sound sound) {
this.PARENT = Preconditions.checkNotNull(sound, "Sounds file cannot be null");
this.PARENT = Validate.notNull(sound, "Sounds file cannot be null");
}
@Override

View File

@ -1,7 +1,5 @@
package com.riiablo.codec;
import com.google.common.base.Preconditions;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Batch;
@ -18,6 +16,8 @@ import com.riiablo.codec.util.BBox;
import com.riiablo.graphics.BlendMode;
import com.riiablo.graphics.PaletteIndexedBatch;
import org.apache.commons.lang3.Validate;
public class Animation extends BaseDrawable {
private static final String TAG = "Animation";
private static final int DEBUG_MODE = 1; // 0=off, 1=box, 2=layer box
@ -177,7 +177,7 @@ public class Animation extends BaseDrawable {
public void setDirection(int d) {
if (d != direction) {
Preconditions.checkArgument(0 <= d && d < numDirections, "Invalid direction: " + d);
Validate.isTrue(0 <= d && d < numDirections, "Invalid direction: " + d);
load(d);
direction = d;
}
@ -189,7 +189,7 @@ public class Animation extends BaseDrawable {
public void setFrame(int f) {
if (f != frame) {
Preconditions.checkArgument(0 <= f && f < numFrames, "Invalid frame: " + f);
Validate.isTrue(0 <= f && f < numFrames, "Invalid frame: " + f);
frame = f;
elapsedTime = frameDuration * frame;
//if (frame == numFrames - 1) notifyAnimationFinished();
@ -471,7 +471,7 @@ public class Animation extends BaseDrawable {
}
public boolean addAnimationListener(int frame, AnimationListener l) {
Preconditions.checkArgument(l != null, "l cannot be null");
Validate.isTrue(l != null, "l cannot be null");
if (animationListeners == EMPTY_MAP) animationListeners = new IntMap<>(1);
Array<AnimationListener> listeners = animationListeners.get(frame);
if (listeners == null) animationListeners.put(frame, listeners = new Array<>(1));

View File

@ -175,7 +175,7 @@ public class DCC extends com.riiablo.codec.DC {
@Override
public Pixmap[] frames(int d) {
Preconditions.checkArgument(0 <= d && d < header.directions, "Invalid direction specified: " + d);
Validate.isTrue(0 <= d && d < header.directions, "Invalid direction specified: " + d);
final int numFrames = header.framesPerDir;
Pixmap[] pages = new Pixmap[numFrames];
// TODO: optimize
@ -188,7 +188,7 @@ public class DCC extends com.riiablo.codec.DC {
@Override
public Pixmap[] frameSheets(int d) {
Preconditions.checkArgument(0 <= d && d < header.directions, "Invalid direction specified: " + d);
Validate.isTrue(0 <= d && d < header.directions, "Invalid direction specified: " + d);
Direction dir = directions[d];
if (DEBUG_SHEETS) Gdx.app.debug(TAG, "dir.box = " + dir);

View File

@ -2,7 +2,6 @@ package com.riiablo.command;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableSet;
@ -15,6 +14,7 @@ import com.riiablo.validator.ValidationException;
import com.riiablo.validator.Validator;
import org.apache.commons.collections4.iterators.ArrayIterator;
import org.apache.commons.lang3.Validate;
import java.util.Collections;
import java.util.Iterator;
@ -38,7 +38,7 @@ public class Command implements Validator {
Set<String> aliases;
Command(Builder builder) {
Preconditions.checkArgument(builder.alias != null, "Commands must have at least one alias");
Validate.isTrue(builder.alias != null, "Commands must have at least one alias");
ALIAS = builder.alias;
DESCRIPTION = Strings.nullToEmpty(builder.description);
PARAMS = MoreObjects.firstNonNull(builder.params, EMPTY_PARAMS);
@ -120,7 +120,7 @@ public class Command implements Validator {
}
public Command addAlias(String alias) {
Preconditions.checkArgument(!alias.isEmpty(), "alias cannot be empty");
Validate.isTrue(!alias.isEmpty(), "alias cannot be empty");
if (aliases == null) aliases = new CopyOnWriteArraySet<>();
aliases.add(alias);
for (AssignmentListener l : ASSIGNMENT_LISTENERS) l.onAssigned(this, alias);
@ -129,7 +129,7 @@ public class Command implements Validator {
public boolean removeAlias(@NonNull String alias) {
if (alias == null) return false;
Preconditions.checkArgument(!alias.equals(ALIAS), "The primary alias cannot be removed");
Validate.isTrue(!alias.equals(ALIAS), "The primary alias cannot be removed");
boolean unassigned = aliases.remove(alias);
if (unassigned) {
for (AssignmentListener l : ASSIGNMENT_LISTENERS) l.onUnassigned(this, alias);
@ -139,7 +139,7 @@ public class Command implements Validator {
}
public boolean addAssignmentListener(AssignmentListener l) {
Preconditions.checkArgument(l != null, "l cannot be null");
Validate.isTrue(l != null, "l cannot be null");
boolean added = ASSIGNMENT_LISTENERS.add(l);
if (added) {
l.onAssigned(this, ALIAS);
@ -223,16 +223,16 @@ public class Command implements Validator {
}
Instance(String alias, @Nullable String... args) {
Preconditions.checkArgument(!alias.isEmpty(), "alias cannot be empty");
Validate.isTrue(!alias.isEmpty(), "alias cannot be empty");
this.ALIAS = alias;
this.ARGS = MoreObjects.firstNonNull(args, EMPTY_ARGS);
this.compressed = false;
}
Instance(String[] args) {
Preconditions.checkArgument(args.length >= 1,
Validate.isTrue(args.length >= 1,
"args should at least contain the alias of the command instance as index 0");
Preconditions.checkArgument(!args[0].isEmpty(), "alias cannot be empty");
Validate.isTrue(!args[0].isEmpty(), "alias cannot be empty");
this.ALIAS = args[0];
this.ARGS = args;
this.compressed = true;
@ -292,7 +292,7 @@ public class Command implements Validator {
Builder() {}
public Builder alias(String alias) {
Preconditions.checkArgument(!alias.isEmpty(), "alias cannot be empty");
Validate.isTrue(!alias.isEmpty(), "alias cannot be empty");
if (this.alias == null) {
this.alias = alias;
} else {
@ -304,19 +304,19 @@ public class Command implements Validator {
}
public Builder description(@NonNull String description) {
Preconditions.checkArgument(description != null, "description cannot be null");
Validate.isTrue(description != null, "description cannot be null");
this.description = description;
return this;
}
public Builder params(@NonNull Parameter... params) {
Preconditions.checkArgument(params != null, "params cannot be null");
Validate.isTrue(params != null, "params cannot be null");
this.params = params;
return this;
}
public Builder action(@NonNull Action action) {
Preconditions.checkArgument(action != null, "action cannot be null");
Validate.isTrue(action != null, "action cannot be null");
this.action = action;
return this;
}

View File

@ -1,7 +1,5 @@
package com.riiablo.command;
import com.google.common.base.Preconditions;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@ -9,6 +7,8 @@ import com.riiablo.console.Console;
import com.riiablo.serializer.StringSerializer;
import com.riiablo.validator.Validator;
import org.apache.commons.lang3.Validate;
public class Parameter<T> implements StringSerializer<T>, Validator, Console.SuggestionProvider {
public static <T> Parameter<T> of (Class<T> type) {
@ -21,25 +21,25 @@ public class Parameter<T> implements StringSerializer<T>, Validator, Console.Sug
private Console.SuggestionProvider suggestionProvider;
Parameter(Class<T> type) {
Preconditions.checkArgument(type != null, "type cannot be null");
Validate.isTrue(type != null, "type cannot be null");
this.TYPE = type;
}
public Parameter<T> serializer(StringSerializer<T> serializer) {
Preconditions.checkArgument(serializer != null, "string serializer cannot be null");
Validate.isTrue(serializer != null, "string serializer cannot be null");
this.serializer = serializer;
return this;
}
public Parameter<T> validator(Validator validator) {
Preconditions.checkArgument(validator != null, "validator cannot be null");
Validate.isTrue(validator != null, "validator cannot be null");
this.validator = validator;
return this;
}
public Parameter<T> suggester(Console.SuggestionProvider suggestionProvider) {
Preconditions.checkArgument(suggestionProvider != null, "suggestion provider cannot be null");
Validate.isTrue(suggestionProvider != null, "suggestion provider cannot be null");
this.suggestionProvider = suggestionProvider;
return this;
}

View File

@ -1,7 +1,5 @@
package com.riiablo.console;
import com.google.common.base.Preconditions;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@ -11,6 +9,8 @@ import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor;
import com.riiablo.util.StringUtils;
import org.apache.commons.lang3.Validate;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Set;
@ -50,7 +50,7 @@ public class Console implements InputProcessor {
protected void onCaretMoved(int position) {}
public boolean addProcessor(@NonNull Processor l) {
Preconditions.checkArgument(l != null, "processor cannot be null");
Validate.isTrue(l != null, "processor cannot be null");
return PROCESSORS.add(l);
}
@ -63,7 +63,7 @@ public class Console implements InputProcessor {
}
public boolean addSuggestionProvider(@NonNull SuggestionProvider l) {
Preconditions.checkArgument(l != null, "suggestion provider cannot be null");
Validate.isTrue(l != null, "suggestion provider cannot be null");
return SUGGESTION_PROVIDERS.add(l);
}

View File

@ -1,7 +1,5 @@
package com.riiablo.console;
import com.google.common.base.Preconditions;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor;
@ -14,19 +12,19 @@ import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Disposable;
import com.badlogic.gdx.utils.Pools;
import com.badlogic.gdx.utils.Timer;
import com.riiablo.Cvars;
import com.riiablo.Keys;
import com.riiablo.Riiablo;
import com.riiablo.cvar.Cvar;
import com.riiablo.cvar.CvarStateAdapter;
import org.apache.commons.io.output.TeeOutputStream;
import org.apache.commons.lang3.Validate;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import com.riiablo.Cvars;
import com.riiablo.cvar.Cvar;
import com.riiablo.cvar.CvarStateAdapter;
public class RenderedConsole extends Console implements Disposable, InputProcessor {
private static final String TAG = "RenderedConsole";
@ -351,7 +349,7 @@ public class RenderedConsole extends Console implements Disposable, InputProcess
RenderedConsole console;
void bind(RenderedConsole console) {
Preconditions.checkState(this.console == null, "already bound to " + this.console);
Validate.validState(this.console == null, "already bound to " + this.console);
this.console = console;
}

View File

@ -1,6 +1,5 @@
package com.riiablo.cvar;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.base.Throwables;
@ -8,17 +7,17 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.riiablo.serializer.SerializeException;
import com.riiablo.serializer.StringSerializer;
import com.riiablo.validator.Validator;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.Validate;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import com.riiablo.serializer.StringSerializer;
public class Cvar<T> implements SuggestionProvider {
@NonNull
final String ALIAS;
@ -214,13 +213,13 @@ public class Cvar<T> implements SuggestionProvider {
}
public Builder<T> alias(@NonNull String alias) {
Preconditions.checkNotNull(alias, "alias cannot be null");
Validate.notNull(alias, "alias cannot be null");
this.alias = alias;
return this;
}
public Builder<T> description(@NonNull String description) {
Preconditions.checkNotNull(description, "description cannot be null");
Validate.notNull(description, "description cannot be null");
this.description = description;
return this;
}
@ -231,19 +230,19 @@ public class Cvar<T> implements SuggestionProvider {
}
public Builder<T> validator(@NonNull Validator validator) {
Preconditions.checkNotNull(validator, "validator cannot be null");
Validate.notNull(validator, "validator cannot be null");
this.validator = validator;
return this;
}
public Builder<T> suggestions(@NonNull SuggestionProvider suggestions) {
Preconditions.checkNotNull(suggestions, "suggestion provider cannot be null");
Validate.notNull(suggestions, "suggestion provider cannot be null");
this.suggestions = suggestions;
return this;
}
public Builder<T> serializer(@NonNull StringSerializer<T> serializer) {
Preconditions.checkNotNull(serializer, "serializer cannot be null");
Validate.notNull(serializer, "serializer cannot be null");
this.serializer = serializer;
return this;
}

View File

@ -1,7 +1,5 @@
package com.riiablo.cvar;
import com.google.common.base.Preconditions;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@ -9,6 +7,8 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.loaders.FileHandleResolver;
import com.badlogic.gdx.files.FileHandle;
import org.apache.commons.lang3.Validate;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.Collection;
@ -25,13 +25,13 @@ public class GdxFileSuggester implements SuggestionProvider {
private final FilenameFilter FILTER;
public GdxFileSuggester(@NonNull FileHandleResolver resolver) {
this.RESOLVER = Preconditions.checkNotNull(resolver, "resolver cannot be null");
this.RESOLVER = Validate.notNull(resolver, "resolver cannot be null");
this.FILTER = null;
}
public GdxFileSuggester(@NonNull FileHandleResolver resolver, @NonNull FilenameFilter filter) {
this.RESOLVER = Preconditions.checkNotNull(resolver, "resolver cannot be null");
this.FILTER = Preconditions.checkNotNull(filter, "filter cannot be null");
this.RESOLVER = Validate.notNull(resolver, "resolver cannot be null");
this.FILTER = Validate.notNull(filter, "filter cannot be null");
}
@Override

View File

@ -1,6 +1,5 @@
package com.riiablo.key;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
import android.support.annotation.NonNull;
@ -9,6 +8,8 @@ import android.support.annotation.Nullable;
import com.badlogic.gdx.utils.IntMap;
import com.badlogic.gdx.utils.ObjectSet;
import org.apache.commons.lang3.Validate;
import java.util.Collections;
import java.util.Iterator;
import java.util.Set;
@ -77,11 +78,11 @@ public class KeyMapper implements MappedKey.AssignmentListener, Iterable<MappedK
}
protected final void checkIfManaging(@Nullable MappedKey key) {
Preconditions.checkArgument(!isManaging(key), "key is not managed by this key mapper");
Validate.isTrue(!isManaging(key), "key is not managed by this key mapper");
}
private void assign(MappedKey key, @MappedKey.Assignment int assignment, @MappedKey.Keycode int keycode) {
Preconditions.checkArgument(key != null, "key cannot be null");
Validate.isTrue(key != null, "key cannot be null");
ObjectSet<MappedKey> keys = KEYS.get(keycode);
if (keys == null) {
keys = new ObjectSet<>();
@ -92,7 +93,7 @@ public class KeyMapper implements MappedKey.AssignmentListener, Iterable<MappedK
}
private boolean unassign(MappedKey key, @MappedKey.Keycode int keycode) {
Preconditions.checkArgument(key != null, "key cannot be null");
Validate.isTrue(key != null, "key cannot be null");
ObjectSet<MappedKey> keys = KEYS.get(keycode);
if (keys == null) return false;
boolean removed = keys.remove(key);

View File

@ -1,12 +1,12 @@
package com.riiablo.key;
import com.google.common.base.Preconditions;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.Size;
import org.apache.commons.lang3.Validate;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
@ -62,11 +62,11 @@ public class MappedKey implements Iterable<Integer> {
}
public MappedKey(String name, String alias, @Keycode int primary, @Keycode int secondary) {
Preconditions.checkArgument(!name.isEmpty(), "name cannot be empty");
Preconditions.checkArgument(!alias.isEmpty(), "alias cannot be empty");
//Preconditions.checkArgument(primary != NOT_MAPPED, "primary key mapping must be mapped");
//Preconditions.checkArgument(primary != secondary, "key mappings must be unique");
Preconditions.checkArgument(primary == NOT_MAPPED || primary != secondary, "key mappings must be unique");
Validate.isTrue(!name.isEmpty(), "name cannot be empty");
Validate.isTrue(!alias.isEmpty(), "alias cannot be empty");
//Validate.isTrue(primary != NOT_MAPPED, "primary key mapping must be mapped");
//Validate.isTrue(primary != secondary, "key mappings must be unique");
Validate.isTrue(primary == NOT_MAPPED || primary != secondary, "key mappings must be unique");
NAME = name;
ALIAS = alias;
@ -103,7 +103,7 @@ public class MappedKey implements Iterable<Integer> {
}
private int[] validateAssignments(@Keycode @Size(min = 2) int[] keycodes) {
Preconditions.checkArgument(keycodes.length >= 2, "keycodes.length must be >= 2");
Validate.isTrue(keycodes.length >= 2, "keycodes.length must be >= 2");
boolean forceUnmapped = false;
for (int i = 0; i < keycodes.length; i++) {
@Keycode int keycode = keycodes[i];
@ -180,13 +180,13 @@ public class MappedKey implements Iterable<Integer> {
@Keycode
public int assign(@Assignment int assignment, @Keycode int keycode) {
Preconditions.checkArgument(keycode != NOT_MAPPED, "cannot unmap using this method, use unassign(int) instead");
Validate.isTrue(keycode != NOT_MAPPED, "cannot unmap using this method, use unassign(int) instead");
@Keycode int previous = assignments[assignment];
if (previous == keycode) {
return previous;
}
Preconditions.checkArgument(!isAssigned(keycode), "duplicate keycodes are not allowed. Keycode: " + keycode + " Key:" + this);
Validate.isTrue(!isAssigned(keycode), "duplicate keycodes are not allowed. Keycode: " + keycode + " Key:" + this);
assignments[assignment] = keycode;
for (AssignmentListener l : ASSIGNMENT_LISTENERS) {
if (previous != NOT_MAPPED) l.onUnassigned(this, assignment, keycode);
@ -286,7 +286,7 @@ public class MappedKey implements Iterable<Integer> {
}
public boolean addStateListener(StateListener l) {
Preconditions.checkArgument(l != null, "l cannot be null");
Validate.isTrue(l != null, "l cannot be null");
return STATE_LISTENERS.add(l);
}
@ -299,7 +299,7 @@ public class MappedKey implements Iterable<Integer> {
}
public boolean addAssignmentListener(AssignmentListener l) {
Preconditions.checkArgument(l != null, "l cannot be null");
Validate.isTrue(l != null, "l cannot be null");
boolean added = ASSIGNMENT_LISTENERS.add(l);
if (added) {
for (@Assignment int i = 0; i < assignments.length; i++) {

View File

@ -1,7 +1,5 @@
package com.riiablo.map;
import com.google.common.base.Preconditions;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Pixmap;
@ -17,6 +15,7 @@ import com.riiablo.graphics.PaletteIndexedPixmap;
import com.riiablo.util.BufferUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.builder.ToStringBuilder;
import java.io.IOException;
@ -53,7 +52,7 @@ public class DT1 implements Disposable {
}
public void prepareTextures() {
Preconditions.checkState(textures == null, "textures have already been prepared");
Validate.validState(textures == null, "textures have already been prepared");
textures = new Texture[header.numTiles];
for (int i = 0; i < header.numTiles; i++) {
Texture texture = new Texture(new PixmapTextureData(tiles[i].pixmap, null, false, false, false));
@ -310,7 +309,7 @@ public class DT1 implements Disposable {
public boolean isSpecial() { return Orientation.isSpecial(orientation); }
public void createPixmap() {
Preconditions.checkState(pixmap == null, "pixmap should be null");
Validate.validState(pixmap == null, "pixmap should be null");
int absWidth = width;
int absHeight = -height;

View File

@ -1,7 +1,5 @@
package com.riiablo.map;
import com.google.common.base.Preconditions;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.ai.pfa.GraphPath;
import com.badlogic.gdx.ai.pfa.SmoothableGraphPath;
@ -30,6 +28,7 @@ import com.riiablo.entity.Entity;
import com.riiablo.entity.Monster;
import com.riiablo.entity.Warp;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.builder.ToStringBuilder;
public class Map implements Disposable {
@ -475,7 +474,7 @@ public class Map implements Disposable {
}
public void buildDT1s() {
Preconditions.checkState(dt1s == null, "dt1s have already been loaded");
Validate.validState(dt1s == null, "dt1s have already been loaded");
IntMap<ObjectSet<AssetDescriptor<DT1>>> typeDependencies = new IntMap<>();
for (Zone zone : zones) {
int type = zone.level.LevelType;
@ -512,7 +511,7 @@ public class Map implements Disposable {
}
public void load() {
Preconditions.checkState(dt1s == null, "dt1s have already been loaded");
Validate.validState(dt1s == null, "dt1s have already been loaded");
IntMap<ObjectSet<AssetDescriptor<DT1>>> typeDependencies = new IntMap<>();
for (Zone zone : zones) {
@ -863,7 +862,7 @@ public class Map implements Disposable {
}
void load(DT1s dt1s) {
Preconditions.checkState(tiles == null, "tiles have already been loaded");
Validate.validState(tiles == null, "tiles have already been loaded");
tiles = new Tile[Map.MAX_LAYERS][][];
for (int x = 0, gridX = 0, gridY = 0; x < gridsX; x++, gridX += gridSizeX, gridY = 0) {
for (int y = 0; y < gridsY; y++, gridY += gridSizeY) {

View File

@ -1,10 +1,9 @@
package com.riiablo.util;
import com.google.common.base.Preconditions;
import com.badlogic.gdx.utils.GdxRuntimeException;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.Validate;
import java.io.IOException;
import java.io.InputStream;
@ -107,7 +106,7 @@ public class BufferUtils {
}
public static ByteBuffer slice(ByteBuffer buffer, byte[] MARK, boolean skipFirst) {
Preconditions.checkArgument(MARK.length == 2, "Only supports MARK length of 2");
Validate.isTrue(MARK.length == 2, "Only supports MARK length of 2");
int pos = buffer.position();
buffer.mark();
int read = 0;

View File

@ -1,13 +1,13 @@
package com.riiablo.validator;
import com.google.common.base.Preconditions;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.badlogic.gdx.assets.loaders.FileHandleResolver;
import com.badlogic.gdx.files.FileHandle;
import org.apache.commons.lang3.Validate;
import java.io.File;
import java.io.FilenameFilter;
@ -20,13 +20,13 @@ public class GdxFileValidator implements Validator {
private final FilenameFilter FILTER;
public GdxFileValidator(@NonNull FileHandleResolver resolver) {
this.RESOLVER = Preconditions.checkNotNull(resolver, "resolver cannot be null");
this.RESOLVER = Validate.notNull(resolver, "resolver cannot be null");
this.FILTER = null;
}
public GdxFileValidator(@NonNull FileHandleResolver resolver, @NonNull FilenameFilter filter) {
this.RESOLVER = Preconditions.checkNotNull(resolver, "resolver cannot be null");
this.FILTER = Preconditions.checkNotNull(filter, "filter cannot be null");
this.RESOLVER = Validate.notNull(resolver, "resolver cannot be null");
this.FILTER = Validate.notNull(filter, "filter cannot be null");
}
@Override