From 9267f03d61f7e0215c479b1288cf1e85ecc34276 Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Mon, 15 Apr 2019 01:12:19 -0700 Subject: [PATCH] Refactored Preconditions to Validate (guava to apache commons) --- core/src/com/riiablo/GdxCvarManager.java | 9 ++++--- .../com/riiablo/audio/MusicController.java | 8 +++---- .../audio/VolumeControlledMusicLoader.java | 8 +++---- .../audio/VolumeControlledSoundLoader.java | 10 ++++---- core/src/com/riiablo/codec/Animation.java | 10 ++++---- core/src/com/riiablo/codec/DCC.java | 4 ++-- core/src/com/riiablo/command/Command.java | 24 +++++++++---------- core/src/com/riiablo/command/Parameter.java | 12 +++++----- core/src/com/riiablo/console/Console.java | 8 +++---- .../com/riiablo/console/RenderedConsole.java | 12 ++++------ core/src/com/riiablo/cvar/Cvar.java | 15 ++++++------ .../com/riiablo/cvar/GdxFileSuggester.java | 10 ++++---- core/src/com/riiablo/key/KeyMapper.java | 9 +++---- core/src/com/riiablo/key/MappedKey.java | 24 +++++++++---------- core/src/com/riiablo/map/DT1.java | 7 +++--- core/src/com/riiablo/map/Map.java | 9 ++++--- core/src/com/riiablo/util/BufferUtils.java | 5 ++-- .../riiablo/validator/GdxFileValidator.java | 10 ++++---- 18 files changed, 94 insertions(+), 100 deletions(-) diff --git a/core/src/com/riiablo/GdxCvarManager.java b/core/src/com/riiablo/GdxCvarManager.java index ae2b987d..9a3b566b 100644 --- a/core/src/com/riiablo/GdxCvarManager.java +++ b/core/src/com/riiablo/GdxCvarManager.java @@ -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 serializer = MoreObjects.firstNonNull(cvar.getSerializer(), getSerializer(cvar)); + StringSerializer 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 load(Cvar cvar) { String alias = cvar.getAlias(); - StringSerializer serializer = MoreObjects.firstNonNull(cvar.getSerializer(), getSerializer(cvar)); + StringSerializer 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()); diff --git a/core/src/com/riiablo/audio/MusicController.java b/core/src/com/riiablo/audio/MusicController.java index 3bf01759..ac00e58a 100644 --- a/core/src/com/riiablo/audio/MusicController.java +++ b/core/src/com/riiablo/audio/MusicController.java @@ -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(); } diff --git a/core/src/com/riiablo/audio/VolumeControlledMusicLoader.java b/core/src/com/riiablo/audio/VolumeControlledMusicLoader.java index 2f5a719e..91174707 100644 --- a/core/src/com/riiablo/audio/VolumeControlledMusicLoader.java +++ b/core/src/com/riiablo/audio/VolumeControlledMusicLoader.java @@ -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 { @@ -21,12 +21,12 @@ public class VolumeControlledMusicLoader extends MusicLoader implements VolumeCo public VolumeControlledMusicLoader(@NonNull FileHandleResolver resolver, @NonNull VolumeController 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 controller) { - this.controller = Preconditions.checkNotNull(controller, "VolumeController cannot be null"); + this.controller = Validate.notNull(controller, "VolumeController cannot be null"); } @Nullable diff --git a/core/src/com/riiablo/audio/VolumeControlledSoundLoader.java b/core/src/com/riiablo/audio/VolumeControlledSoundLoader.java index b936c411..218dfe4c 100644 --- a/core/src/com/riiablo/audio/VolumeControlledSoundLoader.java +++ b/core/src/com/riiablo/audio/VolumeControlledSoundLoader.java @@ -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 { @@ -24,12 +24,12 @@ public class VolumeControlledSoundLoader extends SoundLoader implements VolumeCo public VolumeControlledSoundLoader(@NonNull FileHandleResolver resolver, @NonNull VolumeController 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 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 diff --git a/core/src/com/riiablo/codec/Animation.java b/core/src/com/riiablo/codec/Animation.java index 67f8cd16..b9eaec22 100644 --- a/core/src/com/riiablo/codec/Animation.java +++ b/core/src/com/riiablo/codec/Animation.java @@ -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 listeners = animationListeners.get(frame); if (listeners == null) animationListeners.put(frame, listeners = new Array<>(1)); diff --git a/core/src/com/riiablo/codec/DCC.java b/core/src/com/riiablo/codec/DCC.java index 39af663b..e75dc487 100644 --- a/core/src/com/riiablo/codec/DCC.java +++ b/core/src/com/riiablo/codec/DCC.java @@ -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); diff --git a/core/src/com/riiablo/command/Command.java b/core/src/com/riiablo/command/Command.java index 00015bb8..5aee5fe7 100644 --- a/core/src/com/riiablo/command/Command.java +++ b/core/src/com/riiablo/command/Command.java @@ -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 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; } diff --git a/core/src/com/riiablo/command/Parameter.java b/core/src/com/riiablo/command/Parameter.java index 0dbca003..af8abe8a 100644 --- a/core/src/com/riiablo/command/Parameter.java +++ b/core/src/com/riiablo/command/Parameter.java @@ -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 implements StringSerializer, Validator, Console.SuggestionProvider { public static Parameter of (Class type) { @@ -21,25 +21,25 @@ public class Parameter implements StringSerializer, Validator, Console.Sug private Console.SuggestionProvider suggestionProvider; Parameter(Class type) { - Preconditions.checkArgument(type != null, "type cannot be null"); + Validate.isTrue(type != null, "type cannot be null"); this.TYPE = type; } public Parameter serializer(StringSerializer 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 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 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; } diff --git a/core/src/com/riiablo/console/Console.java b/core/src/com/riiablo/console/Console.java index 62cda6d2..7bc2ba7f 100644 --- a/core/src/com/riiablo/console/Console.java +++ b/core/src/com/riiablo/console/Console.java @@ -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); } diff --git a/core/src/com/riiablo/console/RenderedConsole.java b/core/src/com/riiablo/console/RenderedConsole.java index 8a227099..481dfc31 100644 --- a/core/src/com/riiablo/console/RenderedConsole.java +++ b/core/src/com/riiablo/console/RenderedConsole.java @@ -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; } diff --git a/core/src/com/riiablo/cvar/Cvar.java b/core/src/com/riiablo/cvar/Cvar.java index ab6d0109..d8147823 100644 --- a/core/src/com/riiablo/cvar/Cvar.java +++ b/core/src/com/riiablo/cvar/Cvar.java @@ -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 implements SuggestionProvider { @NonNull final String ALIAS; @@ -214,13 +213,13 @@ public class Cvar implements SuggestionProvider { } public Builder 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 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 implements SuggestionProvider { } public Builder 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 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 serializer(@NonNull StringSerializer serializer) { - Preconditions.checkNotNull(serializer, "serializer cannot be null"); + Validate.notNull(serializer, "serializer cannot be null"); this.serializer = serializer; return this; } diff --git a/core/src/com/riiablo/cvar/GdxFileSuggester.java b/core/src/com/riiablo/cvar/GdxFileSuggester.java index aa952043..a2ef9a56 100644 --- a/core/src/com/riiablo/cvar/GdxFileSuggester.java +++ b/core/src/com/riiablo/cvar/GdxFileSuggester.java @@ -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 diff --git a/core/src/com/riiablo/key/KeyMapper.java b/core/src/com/riiablo/key/KeyMapper.java index 46913649..e96e3b61 100644 --- a/core/src/com/riiablo/key/KeyMapper.java +++ b/core/src/com/riiablo/key/KeyMapper.java @@ -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 keys = KEYS.get(keycode); if (keys == null) { keys = new ObjectSet<>(); @@ -92,7 +93,7 @@ public class KeyMapper implements MappedKey.AssignmentListener, Iterable keys = KEYS.get(keycode); if (keys == null) return false; boolean removed = keys.remove(key); diff --git a/core/src/com/riiablo/key/MappedKey.java b/core/src/com/riiablo/key/MappedKey.java index 0940127b..63fe1081 100644 --- a/core/src/com/riiablo/key/MappedKey.java +++ b/core/src/com/riiablo/key/MappedKey.java @@ -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 { } 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 { } 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 { @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 { } 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 { } 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++) { diff --git a/core/src/com/riiablo/map/DT1.java b/core/src/com/riiablo/map/DT1.java index 8e5bb267..4d33fbea 100644 --- a/core/src/com/riiablo/map/DT1.java +++ b/core/src/com/riiablo/map/DT1.java @@ -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; diff --git a/core/src/com/riiablo/map/Map.java b/core/src/com/riiablo/map/Map.java index 8d039284..eb578fe3 100644 --- a/core/src/com/riiablo/map/Map.java +++ b/core/src/com/riiablo/map/Map.java @@ -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>> 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>> 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) { diff --git a/core/src/com/riiablo/util/BufferUtils.java b/core/src/com/riiablo/util/BufferUtils.java index d7a4363b..b49ac74d 100644 --- a/core/src/com/riiablo/util/BufferUtils.java +++ b/core/src/com/riiablo/util/BufferUtils.java @@ -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; diff --git a/core/src/com/riiablo/validator/GdxFileValidator.java b/core/src/com/riiablo/validator/GdxFileValidator.java index e550dd42..1895a4fa 100644 --- a/core/src/com/riiablo/validator/GdxFileValidator.java +++ b/core/src/com/riiablo/validator/GdxFileValidator.java @@ -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