From 2a01797dfa427fc4f8127789f6037b4f71f5ca15 Mon Sep 17 00:00:00 2001 From: Peter Osterlund Date: Sat, 10 Aug 2019 23:38:17 +0200 Subject: [PATCH] Use android.util.Pair Use the Android builtin Pair class instead of a DroidFish specific class that does the same thing. --- .../petero/droidfish/gamelogic/GameTest.java | 2 ++ .../droidfish/gamelogic/GameTreeTest.java | 2 ++ .../droidfish/gamelogic/PGNFileTest.java | 4 ++- .../droidfish/gamelogic/SpeechTest.java | 2 ++ .../org/petero/droidfish/ChessBoardPlay.java | 2 +- .../java/org/petero/droidfish/DroidFish.java | 2 +- .../droidfish/activities/EditBoard.java | 2 +- .../petero/droidfish/activities/EditPGN.java | 2 +- .../petero/droidfish/activities/FENFile.java | 3 +- .../petero/droidfish/activities/LoadFEN.java | 3 +- .../petero/droidfish/activities/PGNFile.java | 3 +- .../org/petero/droidfish/book/DroidBook.java | 4 +-- .../java/org/petero/droidfish/book/EcoDb.java | 3 +- .../droidfish/engine/DroidComputerPlayer.java | 3 +- .../gamelogic/DroidChessController.java | 2 ++ .../org/petero/droidfish/gamelogic/Game.java | 2 ++ .../petero/droidfish/gamelogic/GameTree.java | 2 ++ .../org/petero/droidfish/gamelogic/Pair.java | 30 ------------------- .../droidfish/gamelogic/TimeControl.java | 2 ++ .../java/org/petero/droidfish/tb/Probe.java | 3 +- 20 files changed, 31 insertions(+), 47 deletions(-) delete mode 100644 DroidFishApp/src/main/java/org/petero/droidfish/gamelogic/Pair.java diff --git a/DroidFishApp/src/androidTest/java/org/petero/droidfish/gamelogic/GameTest.java b/DroidFishApp/src/androidTest/java/org/petero/droidfish/gamelogic/GameTest.java index 8e3874d..2df8b62 100644 --- a/DroidFishApp/src/androidTest/java/org/petero/droidfish/gamelogic/GameTest.java +++ b/DroidFishApp/src/androidTest/java/org/petero/droidfish/gamelogic/GameTest.java @@ -18,6 +18,8 @@ package org.petero.droidfish.gamelogic; +import android.util.Pair; + import java.util.ArrayList; import org.petero.droidfish.PGNOptions; diff --git a/DroidFishApp/src/androidTest/java/org/petero/droidfish/gamelogic/GameTreeTest.java b/DroidFishApp/src/androidTest/java/org/petero/droidfish/gamelogic/GameTreeTest.java index 6cf8a33..15f82e5 100644 --- a/DroidFishApp/src/androidTest/java/org/petero/droidfish/gamelogic/GameTreeTest.java +++ b/DroidFishApp/src/androidTest/java/org/petero/droidfish/gamelogic/GameTreeTest.java @@ -19,6 +19,8 @@ package org.petero.droidfish.gamelogic; +import android.util.Pair; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; diff --git a/DroidFishApp/src/androidTest/java/org/petero/droidfish/gamelogic/PGNFileTest.java b/DroidFishApp/src/androidTest/java/org/petero/droidfish/gamelogic/PGNFileTest.java index 3ce6296..f10dcf3 100644 --- a/DroidFishApp/src/androidTest/java/org/petero/droidfish/gamelogic/PGNFileTest.java +++ b/DroidFishApp/src/androidTest/java/org/petero/droidfish/gamelogic/PGNFileTest.java @@ -18,6 +18,8 @@ package org.petero.droidfish.gamelogic; +import android.util.Pair; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -45,7 +47,7 @@ public class PGNFileTest extends TestCase { }; writeFile(f, lines); PGNFile pgnFile = new PGNFile(f.getAbsolutePath()); - Pair> res = pgnFile.getGameInfo(null, null); + Pair> res = pgnFile.getGameInfo(null, null); assertEquals(GameInfoResult.OK, res.first); ArrayList gi = res.second; assertEquals(1, gi.size()); diff --git a/DroidFishApp/src/androidTest/java/org/petero/droidfish/gamelogic/SpeechTest.java b/DroidFishApp/src/androidTest/java/org/petero/droidfish/gamelogic/SpeechTest.java index c68ee20..886d26a 100644 --- a/DroidFishApp/src/androidTest/java/org/petero/droidfish/gamelogic/SpeechTest.java +++ b/DroidFishApp/src/androidTest/java/org/petero/droidfish/gamelogic/SpeechTest.java @@ -18,6 +18,8 @@ package org.petero.droidfish.gamelogic; +import android.util.Pair; + import org.petero.droidfish.Speech; import junit.framework.TestCase; diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/ChessBoardPlay.java b/DroidFishApp/src/main/java/org/petero/droidfish/ChessBoardPlay.java index e681430..7254b51 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/ChessBoardPlay.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/ChessBoardPlay.java @@ -22,7 +22,6 @@ import java.util.ArrayList; import org.petero.droidfish.gamelogic.Move; import org.petero.droidfish.gamelogic.MoveGen; -import org.petero.droidfish.gamelogic.Pair; import org.petero.droidfish.gamelogic.Piece; import org.petero.droidfish.gamelogic.Position; import org.petero.droidfish.gamelogic.TextIO; @@ -32,6 +31,7 @@ import android.content.Context; import android.content.res.Configuration; import android.graphics.Canvas; import android.util.AttributeSet; +import android.util.Pair; import android.widget.Toast; /** Chess board widget suitable for play mode. */ diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/DroidFish.java b/DroidFishApp/src/main/java/org/petero/droidfish/DroidFish.java index 9c68649..ee5e4dd 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/DroidFish.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/DroidFish.java @@ -54,7 +54,6 @@ import org.petero.droidfish.engine.UCIOptions; import org.petero.droidfish.gamelogic.DroidChessController; import org.petero.droidfish.gamelogic.ChessParseError; import org.petero.droidfish.gamelogic.Move; -import org.petero.droidfish.gamelogic.Pair; import org.petero.droidfish.gamelogic.Piece; import org.petero.droidfish.gamelogic.Position; import org.petero.droidfish.gamelogic.TextIO; @@ -135,6 +134,7 @@ import android.text.style.BackgroundColorSpan; import android.text.style.ForegroundColorSpan; import android.text.style.LeadingMarginSpan; import android.text.style.StyleSpan; +import android.util.Pair; import android.util.TypedValue; import android.view.Gravity; import android.view.ViewConfiguration; diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/activities/EditBoard.java b/DroidFishApp/src/main/java/org/petero/droidfish/activities/EditBoard.java index a79545f..339f17d 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/activities/EditBoard.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/activities/EditBoard.java @@ -28,7 +28,6 @@ import org.petero.droidfish.Util; import org.petero.droidfish.Util.MaterialDiff; import org.petero.droidfish.gamelogic.ChessParseError; import org.petero.droidfish.gamelogic.Move; -import org.petero.droidfish.gamelogic.Pair; import org.petero.droidfish.gamelogic.Piece; import org.petero.droidfish.gamelogic.Position; import org.petero.droidfish.gamelogic.TextIO; @@ -58,6 +57,7 @@ import android.preference.PreferenceManager; import androidx.core.view.MotionEventCompat; import androidx.drawerlayout.widget.DrawerLayout; import android.text.TextUtils; +import android.util.Pair; import android.view.Gravity; import android.view.KeyEvent; import android.view.Menu; diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/activities/EditPGN.java b/DroidFishApp/src/main/java/org/petero/droidfish/activities/EditPGN.java index cfaacf0..a3c93e6 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/activities/EditPGN.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/activities/EditPGN.java @@ -31,6 +31,7 @@ import android.os.Bundle; import android.preference.PreferenceManager; import android.text.Editable; import android.text.TextWatcher; +import android.util.Pair; import android.view.Menu; import android.view.MenuItem; 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.GameInfoResult; import org.petero.droidfish.databinding.SelectGameBinding; -import org.petero.droidfish.gamelogic.Pair; import java.io.File; import java.util.ArrayList; diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/activities/FENFile.java b/DroidFishApp/src/main/java/org/petero/droidfish/activities/FENFile.java index 8d7c8d7..64db37b 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/activities/FENFile.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/activities/FENFile.java @@ -22,10 +22,9 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; -import org.petero.droidfish.gamelogic.Pair; - import android.app.Activity; import android.app.ProgressDialog; +import android.util.Pair; public class FENFile { private final File fileName; diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/activities/LoadFEN.java b/DroidFishApp/src/main/java/org/petero/droidfish/activities/LoadFEN.java index aa1a99d..e0e51ab 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/activities/LoadFEN.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/activities/LoadFEN.java @@ -32,10 +32,10 @@ import android.content.SharedPreferences.Editor; import android.content.res.Configuration; import android.os.Bundle; import android.preference.PreferenceManager; +import android.util.Pair; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; -import android.widget.Button; import android.widget.ListView; import android.widget.TextView; 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.databinding.LoadFenBinding; import org.petero.droidfish.gamelogic.ChessParseError; -import org.petero.droidfish.gamelogic.Pair; import org.petero.droidfish.gamelogic.Position; import org.petero.droidfish.gamelogic.TextIO; diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/activities/PGNFile.java b/DroidFishApp/src/main/java/org/petero/droidfish/activities/PGNFile.java index 58566d3..ee09707 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/activities/PGNFile.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/activities/PGNFile.java @@ -29,11 +29,10 @@ import java.util.ArrayList; import org.petero.droidfish.DroidFishApp; import org.petero.droidfish.R; -import org.petero.droidfish.gamelogic.Pair; import android.app.Activity; import android.app.ProgressDialog; -import android.content.Context; +import android.util.Pair; import android.widget.Toast; public class PGNFile { diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/book/DroidBook.java b/DroidFishApp/src/main/java/org/petero/droidfish/book/DroidBook.java index 0f70a13..63274f4 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/book/DroidBook.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/book/DroidBook.java @@ -19,10 +19,11 @@ package org.petero.droidfish.book; import android.annotation.SuppressLint; +import android.util.Pair; + import java.security.SecureRandom; import java.util.ArrayList; import java.util.Collections; -import java.util.Comparator; import java.util.List; 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.Position; import org.petero.droidfish.gamelogic.TextIO; -import org.petero.droidfish.gamelogic.Pair; /** Implements an opening book. */ public final class DroidBook { diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/book/EcoDb.java b/DroidFishApp/src/main/java/org/petero/droidfish/book/EcoDb.java index f9ddb6c..3e8ec49 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/book/EcoDb.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/book/EcoDb.java @@ -19,7 +19,7 @@ package org.petero.droidfish.book; import android.annotation.SuppressLint; -import android.text.style.TabStopSpan; +import android.util.Pair; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -32,7 +32,6 @@ import org.petero.droidfish.DroidFishApp; import org.petero.droidfish.gamelogic.ChessParseError; import org.petero.droidfish.gamelogic.GameTree; import org.petero.droidfish.gamelogic.Move; -import org.petero.droidfish.gamelogic.Pair; import org.petero.droidfish.gamelogic.Position; import org.petero.droidfish.gamelogic.TextIO; import org.petero.droidfish.gamelogic.UndoInfo; diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/engine/DroidComputerPlayer.java b/DroidFishApp/src/main/java/org/petero/droidfish/engine/DroidComputerPlayer.java index fd56edf..909d8b2 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/engine/DroidComputerPlayer.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/engine/DroidComputerPlayer.java @@ -18,6 +18,8 @@ package org.petero.droidfish.engine; +import android.util.Pair; + import java.util.ArrayList; import java.util.Locale; import java.util.Map; @@ -28,7 +30,6 @@ import org.petero.droidfish.book.BookOptions; import org.petero.droidfish.book.DroidBook; import org.petero.droidfish.gamelogic.Move; import org.petero.droidfish.gamelogic.MoveGen; -import org.petero.droidfish.gamelogic.Pair; import org.petero.droidfish.gamelogic.Position; import org.petero.droidfish.gamelogic.SearchListener; import org.petero.droidfish.gamelogic.TextIO; diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/gamelogic/DroidChessController.java b/DroidFishApp/src/main/java/org/petero/droidfish/gamelogic/DroidChessController.java index 533f93d..27eae2b 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/gamelogic/DroidChessController.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/gamelogic/DroidChessController.java @@ -18,6 +18,8 @@ package org.petero.droidfish.gamelogic; +import android.util.Pair; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/gamelogic/Game.java b/DroidFishApp/src/main/java/org/petero/droidfish/gamelogic/Game.java index b26c262..0a5a152 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/gamelogic/Game.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/gamelogic/Game.java @@ -18,6 +18,8 @@ package org.petero.droidfish.gamelogic; +import android.util.Pair; + import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/gamelogic/GameTree.java b/DroidFishApp/src/main/java/org/petero/droidfish/gamelogic/GameTree.java index 7aea7cf..e424279 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/gamelogic/GameTree.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/gamelogic/GameTree.java @@ -18,6 +18,8 @@ package org.petero.droidfish.gamelogic; +import android.util.Pair; + import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/gamelogic/Pair.java b/DroidFishApp/src/main/java/org/petero/droidfish/gamelogic/Pair.java deleted file mode 100644 index 47fed86..0000000 --- a/DroidFishApp/src/main/java/org/petero/droidfish/gamelogic/Pair.java +++ /dev/null @@ -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 . -*/ - -package org.petero.droidfish.gamelogic; - -/** A helper class that makes it possible to return two values from a function. */ -public final class Pair { - public final T1 first; - public final T2 second; - - public Pair(T1 first, T2 second) { - this.first = first; - this.second = second; - } -} diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/gamelogic/TimeControl.java b/DroidFishApp/src/main/java/org/petero/droidfish/gamelogic/TimeControl.java index 2bfc1a5..007f7f7 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/gamelogic/TimeControl.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/gamelogic/TimeControl.java @@ -18,6 +18,8 @@ package org.petero.droidfish.gamelogic; +import android.util.Pair; + import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/tb/Probe.java b/DroidFishApp/src/main/java/org/petero/droidfish/tb/Probe.java index 40ff6db..539eafa 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/tb/Probe.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/tb/Probe.java @@ -18,12 +18,13 @@ package org.petero.droidfish.tb; +import android.util.Pair; + import java.util.ArrayList; import org.petero.droidfish.gamelogic.ChessParseError; import org.petero.droidfish.gamelogic.Move; import org.petero.droidfish.gamelogic.MoveGen; -import org.petero.droidfish.gamelogic.Pair; import org.petero.droidfish.gamelogic.Piece; import org.petero.droidfish.gamelogic.Position; import org.petero.droidfish.gamelogic.TextIO;