Skip to content

Commit

Permalink
Use Objects.requireNonNull().
Browse files Browse the repository at this point in the history
  • Loading branch information
Isira-Seneviratne committed Dec 23, 2020
1 parent bf071d6 commit bdd5058
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.Serializable;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Objects;

import io.reactivex.rxjava3.disposables.CompositeDisposable;

Expand All @@ -35,12 +36,10 @@ public class LicenseFragment extends Fragment {
private final CompositeDisposable compositeDisposable = new CompositeDisposable();

public static LicenseFragment newInstance(final SoftwareComponent[] softwareComponents) {
if (softwareComponents == null) {
throw new NullPointerException("softwareComponents is null");
}
final LicenseFragment fragment = new LicenseFragment();
final Bundle bundle = new Bundle();
bundle.putParcelableArray(ARG_COMPONENTS, softwareComponents);
bundle.putParcelableArray(ARG_COMPONENTS, Objects.requireNonNull(softwareComponents,
"softwareComponents is null"));
fragment.setArguments(bundle);
return fragment;
}
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/us/shandian/giga/get/DownloadMission.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.net.URL;
import java.net.UnknownHostException;
import java.nio.channels.ClosedByInterruptException;
import java.util.Objects;

import javax.net.ssl.SSLException;

Expand Down Expand Up @@ -154,8 +155,8 @@ public class DownloadMission extends Mission {
public transient Thread init = null;

public DownloadMission(String[] urls, StoredFileHelper storage, char kind, Postprocessing psInstance) {
if (urls == null) throw new NullPointerException("urls is null");
if (urls.length < 1) throw new IllegalArgumentException("urls is empty");
if (Objects.requireNonNull(urls, "urls is null").length < 1)
throw new IllegalArgumentException("urls is empty");
this.urls = urls;
this.kind = kind;
this.offsets = new long[urls.length];
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/us/shandian/giga/get/DownloadRunnable.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.nio.channels.ClosedByInterruptException;
import java.util.Objects;

import us.shandian.giga.get.DownloadMission.Block;
import us.shandian.giga.get.DownloadMission.HttpError;
Expand All @@ -29,8 +30,7 @@ public class DownloadRunnable extends Thread {
private HttpURLConnection mConn;

DownloadRunnable(DownloadMission mission, int id) {
if (mission == null) throw new NullPointerException("mission is null");
mMission = mission;
mMission = Objects.requireNonNull(mission, "mission is null");
mId = id;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.io.File;
import java.util.ArrayList;
import java.util.Objects;

import us.shandian.giga.get.DownloadMission;
import us.shandian.giga.get.FinishedMission;
Expand Down Expand Up @@ -140,9 +141,8 @@ private ContentValues getValuesOfMission(@NonNull Mission downloadMission) {
}

private FinishedMission getMissionFromCursor(Cursor cursor) {
if (cursor == null) throw new NullPointerException("cursor is null");

String kind = cursor.getString(cursor.getColumnIndex(KEY_KIND));
String kind = Objects.requireNonNull(cursor, "cursor is null")
.getString(cursor.getColumnIndex(KEY_KIND));
if (kind == null || kind.isEmpty()) kind = "?";

String path = cursor.getString(cursor.getColumnIndexOrThrow(KEY_PATH));
Expand Down Expand Up @@ -186,15 +186,14 @@ public ArrayList<FinishedMission> loadFinishedMissions() {
}

public void addFinishedMission(DownloadMission downloadMission) {
if (downloadMission == null) throw new NullPointerException("downloadMission is null");
SQLiteDatabase database = getWritableDatabase();
ContentValues values = getValuesOfMission(downloadMission);
ContentValues values = getValuesOfMission(Objects.requireNonNull(downloadMission,
"downloadMission is null"));
database.insert(FINISHED_TABLE_NAME, null, values);
}

public void deleteMission(Mission mission) {
if (mission == null) throw new NullPointerException("mission is null");
String ts = String.valueOf(mission.timestamp);
String ts = String.valueOf(Objects.requireNonNull(mission, "mission is null").timestamp);

SQLiteDatabase database = getWritableDatabase();

Expand All @@ -212,9 +211,9 @@ public void deleteMission(Mission mission) {
}

public void updateMission(Mission mission) {
if (mission == null) throw new NullPointerException("mission is null");
SQLiteDatabase database = getWritableDatabase();
ContentValues values = getValuesOfMission(mission);
ContentValues values = getValuesOfMission(Objects.requireNonNull(mission,
"mission is null"));
String ts = String.valueOf(mission.timestamp);

int rowsAffected;
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/us/shandian/giga/io/CircularFileWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Objects;

public class CircularFileWriter extends SharpStream {

Expand All @@ -27,9 +28,7 @@ public class CircularFileWriter extends SharpStream {
private BufferedFile aux;

public CircularFileWriter(SharpStream target, File temp, OffsetChecker checker) throws IOException {
if (checker == null) {
throw new NullPointerException("checker is null");
}
Objects.requireNonNull(checker, "checker is null");

if (!temp.exists()) {
if (!temp.createNewFile()) {
Expand Down

0 comments on commit bdd5058

Please sign in to comment.