mirror of
https://github.com/topjohnwu/libsu.git
synced 2024-11-26 21:40:42 +00:00
Use UNSET_LIST instead of NOPList
This commit is contained in:
parent
1698dbffef
commit
c4f0a379c6
@ -24,7 +24,6 @@ import androidx.annotation.Nullable;
|
||||
|
||||
import com.topjohnwu.superuser.Shell;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@ -44,14 +43,14 @@ abstract class JobTask extends Shell.Job implements Shell.Task {
|
||||
.format("__RET=$?;echo %1$s;echo %1$s >&2;echo $__RET;unset __RET\n", END_UUID)
|
||||
.getBytes(UTF_8);
|
||||
|
||||
private static final List<String> UNSET_ERR = new ArrayList<>(0);
|
||||
static final List<String> UNSET_LIST = new ArrayList<>(0);
|
||||
|
||||
private final List<ShellInputSource> sources = new ArrayList<>();
|
||||
|
||||
boolean redirect;
|
||||
|
||||
@Nullable protected List<String> out;
|
||||
@Nullable protected List<String> err = UNSET_ERR;
|
||||
@Nullable protected List<String> out = null;
|
||||
@Nullable protected List<String> err = UNSET_LIST;
|
||||
@Nullable protected Executor callbackExecutor;
|
||||
@Nullable protected Shell.ResultCallback callback;
|
||||
|
||||
@ -73,7 +72,7 @@ abstract class JobTask extends Shell.Job implements Shell.Task {
|
||||
public void run(@NonNull OutputStream stdin,
|
||||
@NonNull InputStream stdout,
|
||||
@NonNull InputStream stderr) {
|
||||
boolean noErr = err == UNSET_ERR;
|
||||
boolean noErr = err == UNSET_LIST;
|
||||
|
||||
List<String> outList = out;
|
||||
List<String> errList = noErr ? (redirect ? out : null) : err;
|
||||
|
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023 John "topjohnwu" Wu
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.topjohnwu.superuser.internal;
|
||||
|
||||
import java.util.AbstractList;
|
||||
|
||||
public class NOPList extends AbstractList<String> {
|
||||
|
||||
private static NOPList list;
|
||||
|
||||
public static NOPList getInstance() {
|
||||
if (list == null)
|
||||
list = new NOPList();
|
||||
return list;
|
||||
}
|
||||
|
||||
private NOPList() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(int i) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String set(int index, String element) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(int index, String element) {}
|
||||
|
||||
@Override
|
||||
public String remove(int index) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -33,7 +33,7 @@ class PendingJob extends JobTask {
|
||||
private Runnable retryTask;
|
||||
|
||||
PendingJob() {
|
||||
to(NOPList.getInstance());
|
||||
to(UNSET_LIST);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -67,7 +67,7 @@ class PendingJob extends JobTask {
|
||||
ResultHolder holder = new ResultHolder();
|
||||
callback = holder;
|
||||
callbackExecutor = null;
|
||||
if (out instanceof NOPList)
|
||||
if (out == UNSET_LIST)
|
||||
out = new ArrayList<>();
|
||||
|
||||
exec0();
|
||||
@ -88,7 +88,7 @@ class PendingJob extends JobTask {
|
||||
ResultFuture future = new ResultFuture();
|
||||
callback = future;
|
||||
callbackExecutor = null;
|
||||
if (out instanceof NOPList)
|
||||
if (out == UNSET_LIST)
|
||||
out = new ArrayList<>();
|
||||
submit0();
|
||||
return future;
|
||||
@ -99,7 +99,7 @@ class PendingJob extends JobTask {
|
||||
retryTask = this::submit0;
|
||||
callbackExecutor = executor;
|
||||
callback = cb;
|
||||
if (out instanceof NOPList)
|
||||
if (out == UNSET_LIST)
|
||||
out = (cb == null) ? null : new ArrayList<>();
|
||||
submit0();
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ public final class Utils {
|
||||
public static boolean isSynchronized(Collection<?> collection) {
|
||||
if (synchronizedCollectionClass == null) {
|
||||
synchronizedCollectionClass =
|
||||
Collections.synchronizedCollection(NOPList.getInstance()).getClass();
|
||||
Collections.synchronizedCollection(Collections.emptyList()).getClass();
|
||||
}
|
||||
return synchronizedCollectionClass.isInstance(collection);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user