Use android.util.Pair

Use the Android builtin Pair class instead of a DroidFish specific
class that does the same thing.
This commit is contained in:
Peter Osterlund 2019-08-10 23:38:17 +02:00
parent 6c4ff122ac
commit 2a01797dfa
20 changed files with 31 additions and 47 deletions

View File

@ -18,6 +18,8 @@
package org.petero.droidfish.gamelogic; package org.petero.droidfish.gamelogic;
import android.util.Pair;
import java.util.ArrayList; import java.util.ArrayList;
import org.petero.droidfish.PGNOptions; import org.petero.droidfish.PGNOptions;

View File

@ -19,6 +19,8 @@
package org.petero.droidfish.gamelogic; package org.petero.droidfish.gamelogic;
import android.util.Pair;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.DataInputStream; import java.io.DataInputStream;

View File

@ -18,6 +18,8 @@
package org.petero.droidfish.gamelogic; package org.petero.droidfish.gamelogic;
import android.util.Pair;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
@ -45,7 +47,7 @@ public class PGNFileTest extends TestCase {
}; };
writeFile(f, lines); writeFile(f, lines);
PGNFile pgnFile = new PGNFile(f.getAbsolutePath()); PGNFile pgnFile = new PGNFile(f.getAbsolutePath());
Pair<GameInfoResult,ArrayList<GameInfo>> res = pgnFile.getGameInfo(null, null); Pair<GameInfoResult,ArrayList<GameInfo>> res = pgnFile.getGameInfo(null, null);
assertEquals(GameInfoResult.OK, res.first); assertEquals(GameInfoResult.OK, res.first);
ArrayList<GameInfo> gi = res.second; ArrayList<GameInfo> gi = res.second;
assertEquals(1, gi.size()); assertEquals(1, gi.size());

View File

@ -18,6 +18,8 @@
package org.petero.droidfish.gamelogic; package org.petero.droidfish.gamelogic;
import android.util.Pair;
import org.petero.droidfish.Speech; import org.petero.droidfish.Speech;
import junit.framework.TestCase; import junit.framework.TestCase;

View File

@ -22,7 +22,6 @@ import java.util.ArrayList;
import org.petero.droidfish.gamelogic.Move; import org.petero.droidfish.gamelogic.Move;
import org.petero.droidfish.gamelogic.MoveGen; import org.petero.droidfish.gamelogic.MoveGen;
import org.petero.droidfish.gamelogic.Pair;
import org.petero.droidfish.gamelogic.Piece; import org.petero.droidfish.gamelogic.Piece;
import org.petero.droidfish.gamelogic.Position; import org.petero.droidfish.gamelogic.Position;
import org.petero.droidfish.gamelogic.TextIO; import org.petero.droidfish.gamelogic.TextIO;
@ -32,6 +31,7 @@ import android.content.Context;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Pair;
import android.widget.Toast; import android.widget.Toast;
/** Chess board widget suitable for play mode. */ /** Chess board widget suitable for play mode. */

View File

@ -54,7 +54,6 @@ import org.petero.droidfish.engine.UCIOptions;
import org.petero.droidfish.gamelogic.DroidChessController; import org.petero.droidfish.gamelogic.DroidChessController;
import org.petero.droidfish.gamelogic.ChessParseError; import org.petero.droidfish.gamelogic.ChessParseError;
import org.petero.droidfish.gamelogic.Move; import org.petero.droidfish.gamelogic.Move;
import org.petero.droidfish.gamelogic.Pair;
import org.petero.droidfish.gamelogic.Piece; import org.petero.droidfish.gamelogic.Piece;
import org.petero.droidfish.gamelogic.Position; import org.petero.droidfish.gamelogic.Position;
import org.petero.droidfish.gamelogic.TextIO; import org.petero.droidfish.gamelogic.TextIO;
@ -135,6 +134,7 @@ import android.text.style.BackgroundColorSpan;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
import android.text.style.LeadingMarginSpan; import android.text.style.LeadingMarginSpan;
import android.text.style.StyleSpan; import android.text.style.StyleSpan;
import android.util.Pair;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.Gravity; import android.view.Gravity;
import android.view.ViewConfiguration; import android.view.ViewConfiguration;

View File

@ -28,7 +28,6 @@ import org.petero.droidfish.Util;
import org.petero.droidfish.Util.MaterialDiff; import org.petero.droidfish.Util.MaterialDiff;
import org.petero.droidfish.gamelogic.ChessParseError; import org.petero.droidfish.gamelogic.ChessParseError;
import org.petero.droidfish.gamelogic.Move; import org.petero.droidfish.gamelogic.Move;
import org.petero.droidfish.gamelogic.Pair;
import org.petero.droidfish.gamelogic.Piece; import org.petero.droidfish.gamelogic.Piece;
import org.petero.droidfish.gamelogic.Position; import org.petero.droidfish.gamelogic.Position;
import org.petero.droidfish.gamelogic.TextIO; import org.petero.droidfish.gamelogic.TextIO;
@ -58,6 +57,7 @@ import android.preference.PreferenceManager;
import androidx.core.view.MotionEventCompat; import androidx.core.view.MotionEventCompat;
import androidx.drawerlayout.widget.DrawerLayout; import androidx.drawerlayout.widget.DrawerLayout;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Pair;
import android.view.Gravity; import android.view.Gravity;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.Menu; import android.view.Menu;

View File

@ -31,6 +31,7 @@ import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.util.Pair;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -50,7 +51,6 @@ import org.petero.droidfish.Util;
import org.petero.droidfish.activities.PGNFile.GameInfo; import org.petero.droidfish.activities.PGNFile.GameInfo;
import org.petero.droidfish.activities.PGNFile.GameInfoResult; import org.petero.droidfish.activities.PGNFile.GameInfoResult;
import org.petero.droidfish.databinding.SelectGameBinding; import org.petero.droidfish.databinding.SelectGameBinding;
import org.petero.droidfish.gamelogic.Pair;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -22,10 +22,9 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import org.petero.droidfish.gamelogic.Pair;
import android.app.Activity; import android.app.Activity;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.util.Pair;
public class FENFile { public class FENFile {
private final File fileName; private final File fileName;

View File

@ -32,10 +32,10 @@ import android.content.SharedPreferences.Editor;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Pair;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -50,7 +50,6 @@ import org.petero.droidfish.activities.FENFile.FenInfo;
import org.petero.droidfish.activities.FENFile.FenInfoResult; import org.petero.droidfish.activities.FENFile.FenInfoResult;
import org.petero.droidfish.databinding.LoadFenBinding; import org.petero.droidfish.databinding.LoadFenBinding;
import org.petero.droidfish.gamelogic.ChessParseError; import org.petero.droidfish.gamelogic.ChessParseError;
import org.petero.droidfish.gamelogic.Pair;
import org.petero.droidfish.gamelogic.Position; import org.petero.droidfish.gamelogic.Position;
import org.petero.droidfish.gamelogic.TextIO; import org.petero.droidfish.gamelogic.TextIO;

View File

@ -29,11 +29,10 @@ import java.util.ArrayList;
import org.petero.droidfish.DroidFishApp; import org.petero.droidfish.DroidFishApp;
import org.petero.droidfish.R; import org.petero.droidfish.R;
import org.petero.droidfish.gamelogic.Pair;
import android.app.Activity; import android.app.Activity;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.Context; import android.util.Pair;
import android.widget.Toast; import android.widget.Toast;
public class PGNFile { public class PGNFile {

View File

@ -19,10 +19,11 @@
package org.petero.droidfish.book; package org.petero.droidfish.book;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.util.Pair;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
@ -31,7 +32,6 @@ import org.petero.droidfish.gamelogic.Move;
import org.petero.droidfish.gamelogic.MoveGen; import org.petero.droidfish.gamelogic.MoveGen;
import org.petero.droidfish.gamelogic.Position; import org.petero.droidfish.gamelogic.Position;
import org.petero.droidfish.gamelogic.TextIO; import org.petero.droidfish.gamelogic.TextIO;
import org.petero.droidfish.gamelogic.Pair;
/** Implements an opening book. */ /** Implements an opening book. */
public final class DroidBook { public final class DroidBook {

View File

@ -19,7 +19,7 @@
package org.petero.droidfish.book; package org.petero.droidfish.book;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.text.style.TabStopSpan; import android.util.Pair;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
@ -32,7 +32,6 @@ import org.petero.droidfish.DroidFishApp;
import org.petero.droidfish.gamelogic.ChessParseError; import org.petero.droidfish.gamelogic.ChessParseError;
import org.petero.droidfish.gamelogic.GameTree; import org.petero.droidfish.gamelogic.GameTree;
import org.petero.droidfish.gamelogic.Move; import org.petero.droidfish.gamelogic.Move;
import org.petero.droidfish.gamelogic.Pair;
import org.petero.droidfish.gamelogic.Position; import org.petero.droidfish.gamelogic.Position;
import org.petero.droidfish.gamelogic.TextIO; import org.petero.droidfish.gamelogic.TextIO;
import org.petero.droidfish.gamelogic.UndoInfo; import org.petero.droidfish.gamelogic.UndoInfo;

View File

@ -18,6 +18,8 @@
package org.petero.droidfish.engine; package org.petero.droidfish.engine;
import android.util.Pair;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
@ -28,7 +30,6 @@ import org.petero.droidfish.book.BookOptions;
import org.petero.droidfish.book.DroidBook; import org.petero.droidfish.book.DroidBook;
import org.petero.droidfish.gamelogic.Move; import org.petero.droidfish.gamelogic.Move;
import org.petero.droidfish.gamelogic.MoveGen; import org.petero.droidfish.gamelogic.MoveGen;
import org.petero.droidfish.gamelogic.Pair;
import org.petero.droidfish.gamelogic.Position; import org.petero.droidfish.gamelogic.Position;
import org.petero.droidfish.gamelogic.SearchListener; import org.petero.droidfish.gamelogic.SearchListener;
import org.petero.droidfish.gamelogic.TextIO; import org.petero.droidfish.gamelogic.TextIO;

View File

@ -18,6 +18,8 @@
package org.petero.droidfish.gamelogic; package org.petero.droidfish.gamelogic;
import android.util.Pair;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.DataInputStream; import java.io.DataInputStream;

View File

@ -18,6 +18,8 @@
package org.petero.droidfish.gamelogic; package org.petero.droidfish.gamelogic;
import android.util.Pair;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;

View File

@ -18,6 +18,8 @@
package org.petero.droidfish.gamelogic; package org.petero.droidfish.gamelogic;
import android.util.Pair;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;

View File

@ -1,30 +0,0 @@
/*
DroidFish - An Android chess program.
Copyright (C) 2011 Peter Österlund, peterosterlund2@gmail.com
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
(at your option) any later version.
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.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.petero.droidfish.gamelogic;
/** A helper class that makes it possible to return two values from a function. */
public final class Pair<T1, T2> {
public final T1 first;
public final T2 second;
public Pair(T1 first, T2 second) {
this.first = first;
this.second = second;
}
}

View File

@ -18,6 +18,8 @@
package org.petero.droidfish.gamelogic; package org.petero.droidfish.gamelogic;
import android.util.Pair;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;

View File

@ -18,12 +18,13 @@
package org.petero.droidfish.tb; package org.petero.droidfish.tb;
import android.util.Pair;
import java.util.ArrayList; import java.util.ArrayList;
import org.petero.droidfish.gamelogic.ChessParseError; import org.petero.droidfish.gamelogic.ChessParseError;
import org.petero.droidfish.gamelogic.Move; import org.petero.droidfish.gamelogic.Move;
import org.petero.droidfish.gamelogic.MoveGen; import org.petero.droidfish.gamelogic.MoveGen;
import org.petero.droidfish.gamelogic.Pair;
import org.petero.droidfish.gamelogic.Piece; import org.petero.droidfish.gamelogic.Piece;
import org.petero.droidfish.gamelogic.Position; import org.petero.droidfish.gamelogic.Position;
import org.petero.droidfish.gamelogic.TextIO; import org.petero.droidfish.gamelogic.TextIO;