Remove some unnecessary newArrayList calls

pull/996/head
Alex Baker 5 years ago
parent 9baf3d5e2a
commit 8f8650840d

@ -30,13 +30,13 @@ public class DeletionDaoTests extends InjectingTestCase {
@Test
public void deleting1000DoesntCrash() {
deletionDao.delete(
newArrayList(ContiguousSet.create(Range.closed(1L, 1000L), DiscreteDomain.longs())));
new ArrayList<>(ContiguousSet.create(Range.closed(1L, 1000L), DiscreteDomain.longs())));
}
@Test
public void marking998ForDeletionDoesntCrash() {
deletionDao.markDeleted(
newArrayList(ContiguousSet.create(Range.closed(1L, 1000L), DiscreteDomain.longs())));
new ArrayList<>(ContiguousSet.create(Range.closed(1L, 1000L), DiscreteDomain.longs())));
}
@Test

@ -8,7 +8,6 @@ package com.todoroo.astrid.activity;
import static android.app.Activity.RESULT_OK;
import static com.google.common.base.Strings.padStart;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Lists.transform;
import static com.todoroo.andlib.utility.AndroidUtilities.assertMainThread;
import static org.tasks.activities.RemoteListPicker.newRemoteListSupportPicker;
@ -736,9 +735,9 @@ public final class TaskListFragment extends InjectingFragment
intent.putExtra(TagPickerActivity.EXTRA_TASKS, selected);
intent.putParcelableArrayListExtra(
TagPickerActivity.EXTRA_PARTIALLY_SELECTED,
newArrayList(tagDataDao.getByUuid(tags.first)));
new ArrayList<>(tagDataDao.getByUuid(tags.first)));
intent.putParcelableArrayListExtra(
TagPickerActivity.EXTRA_SELECTED, newArrayList(tagDataDao.getByUuid(tags.second)));
TagPickerActivity.EXTRA_SELECTED, new ArrayList<>(tagDataDao.getByUuid(tags.second)));
startActivityForResult(intent, REQUEST_TAG_TASKS);
return true;
case R.id.move_tasks:

@ -6,7 +6,6 @@
package com.todoroo.astrid.adapter;
import static com.google.common.collect.Lists.newArrayList;
import static com.todoroo.andlib.utility.AndroidUtilities.assertMainThread;
import android.app.Activity;
@ -143,7 +142,7 @@ public class FilterAdapter extends BaseAdapter {
private ArrayList<FilterListItem> getItems() {
assertMainThread();
return newArrayList(items);
return new ArrayList<>(items);
}
@NonNull

@ -6,7 +6,6 @@
package com.todoroo.astrid.adapter;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.primitives.Longs.asList;
import com.todoroo.astrid.data.Task;
@ -41,7 +40,7 @@ public class TaskAdapter {
}
public ArrayList<Long> getSelected() {
return newArrayList(selected);
return new ArrayList<>(selected);
}
public void setSelected(long... ids) {

@ -6,11 +6,11 @@
package com.todoroo.astrid.core;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Lists.transform;
import com.todoroo.astrid.api.CustomFilter;
import com.todoroo.astrid.api.Filter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.inject.Inject;
@ -27,7 +27,7 @@ public final class CustomFilterExposer {
}
public List<Filter> getFilters() {
List<Filter> filters = newArrayList(transform(filterDao.getFilters(), this::load));
List<Filter> filters = new ArrayList<>(transform(filterDao.getFilters(), this::load));
Collections.sort(filters, new AlphanumComparator<>(AlphanumComparator.FILTER));
return filters;
}

@ -8,7 +8,6 @@ package com.todoroo.astrid.dao;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Lists.transform;
import static com.todoroo.andlib.sql.SqlConstants.COUNT;
import static com.todoroo.andlib.utility.DateUtilities.now;
@ -32,6 +31,7 @@ import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.PermaSql;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.helper.UUIDHelper;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.tasks.BuildConfig;
@ -234,7 +234,7 @@ public abstract class TaskDao {
public abstract List<Long> getChildren(List<Long> ids);
public List<Long> findChildrenInList(List<Long> ids) {
List<Long> result = newArrayList(ids);
List<Long> result = new ArrayList<>(ids);
result.retainAll(getChildren(ids));
return result;
}

@ -6,6 +6,7 @@ import static com.todoroo.andlib.utility.DateUtilities.now;
import com.google.common.collect.Iterables;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Task;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.inject.Inject;
@ -35,7 +36,7 @@ public class TaskCompleter {
public void setComplete(Task item, boolean completed) {
long completionDate = completed ? now() : 0L;
setComplete(Collections.singletonList(item), completionDate);
List<Task> tasks = newArrayList(googleTaskDao.getChildTasks(item.getId()));
List<Task> tasks = new ArrayList<>(googleTaskDao.getChildTasks(item.getId()));
List<Long> caldavChildren = taskDao.getChildren(item.getId());
if (!caldavChildren.isEmpty()) {
tasks.addAll(taskDao.fetch(caldavChildren));

@ -65,7 +65,7 @@ public class TaskMover {
}
public void move(List<Long> tasks, Filter selectedList) {
tasks = newArrayList(tasks);
tasks = new ArrayList<>(tasks);
tasks.removeAll(googleTaskDao.findChildrenInList(tasks));
tasks.removeAll(taskDao.findChildrenInList(tasks));
taskDao.setParent(0, null, tasks);

@ -1,7 +1,6 @@
package com.todoroo.astrid.service;
import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Lists.newArrayList;
import static org.tasks.Strings.isNullOrEmpty;
import static org.tasks.db.DbUtils.batch;
@ -15,6 +14,7 @@ import com.google.common.collect.Multimaps;
import com.todoroo.astrid.api.GtasksFilter;
import com.todoroo.astrid.dao.TaskDao;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import net.fortuna.ical4j.model.property.Geo;
@ -227,7 +227,7 @@ public class Upgrader {
}
private void applyCaldavSubtasks() {
List<CaldavTask> updated = newArrayList();
List<CaldavTask> updated = new ArrayList<>();
for (CaldavTask task : transform(caldavDao.getTasks(), CaldavTaskContainer::getCaldavTask)) {
at.bitfire.ical4android.Task remoteTask = iCalendar.Companion.fromVtodo(task.getVtodo());

@ -6,17 +6,14 @@
package com.todoroo.astrid.timers;
import static com.google.common.collect.Lists.newArrayList;
import static java.util.Collections.emptyList;
import android.content.Context;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.QueryTemplate;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Task;
import java.util.List;
import javax.inject.Inject;
import org.jetbrains.annotations.Nullable;
import org.tasks.R;
import org.tasks.injection.ForApplication;
@ -36,7 +33,7 @@ public final class TimerFilterExposer {
this.taskDao = taskDao;
}
public static Filter createFilter(Context context) {
static Filter createFilter(Context context) {
Filter filter =
new Filter(
context.getString(R.string.TFE_workingOn),
@ -46,11 +43,7 @@ public final class TimerFilterExposer {
return filter;
}
public List<Filter> getFilters() {
if (taskDao.activeTimers() == 0) {
return emptyList();
}
return newArrayList(createFilter(context));
public @Nullable Filter getFilters() {
return taskDao.activeTimers() == 0 ? null : createFilter(context);
}
}

@ -14,7 +14,6 @@ import butterknife.OnClick
import com.google.android.material.button.MaterialButtonToggleGroup
import com.google.common.collect.ContiguousSet
import com.google.common.collect.DiscreteDomain
import com.google.common.collect.Lists
import com.google.common.collect.Range
import org.tasks.LocalBroadcastManager
import org.tasks.R
@ -149,7 +148,7 @@ class PurchaseActivity : ThemedInjectingAppCompatActivity(), OnPurchasesUpdated,
updateSubscribeButton()
setWaitScreen(false)
adapter.submitList(
Lists.newArrayList(ContiguousSet.create(Range.closed(1, 10), DiscreteDomain.integers())))
ArrayList(ContiguousSet.create(Range.closed(1, 10), DiscreteDomain.integers())))
binding.recyclerView.layoutManager = IconLayoutManager(this)
binding.recyclerView.adapter = adapter
}

@ -133,7 +133,7 @@ public class CaldavSynchronizer {
Set<String> urls = newHashSet(transform(resources, c -> c.getHref().toString()));
Timber.d("Found calendars: %s", urls);
for (CaldavCalendar calendar :
caldavDao.findDeletedCalendars(account.getUuid(), newArrayList(urls))) {
caldavDao.findDeletedCalendars(account.getUuid(), new ArrayList<>(urls))) {
taskDeleter.delete(calendar);
}
for (Response resource : resources) {
@ -242,7 +242,7 @@ public class CaldavSynchronizer {
}
List<String> deleted =
newArrayList(
new ArrayList<>(
difference(
newHashSet(caldavDao.getObjects(caldavCalendar.getUuid())),
newHashSet(remoteObjects)));

@ -3,7 +3,6 @@ package org.tasks.data;
import static com.google.common.collect.FluentIterable.concat;
import static com.google.common.collect.FluentIterable.from;
import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Lists.transform;
import static com.google.common.collect.Sets.difference;
import static com.google.common.collect.Sets.newHashSet;
@ -22,6 +21,7 @@ import com.google.common.collect.Collections2;
import com.google.common.collect.Iterables;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.helper.UUIDHelper;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@ -124,7 +124,7 @@ public abstract class TagDataDao {
insert(transform(added, td -> new Tag(task, td)));
}
}
return newArrayList(modified);
return new ArrayList<>(modified);
}
@Transaction

@ -21,6 +21,7 @@ import com.todoroo.astrid.api.PermaSql;
import com.todoroo.astrid.core.SortHelper;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.data.Task;
import java.util.ArrayList;
import java.util.List;
import org.tasks.preferences.Preferences;
@ -87,7 +88,7 @@ public class TaskListQuery {
com.todoroo.astrid.api.Filter filter,
Preferences preferences,
SubtaskInfo subtasks) {
List<Field> fields = newArrayList(FIELDS);
List<Field> fields = new ArrayList<>(FIELDS);
fields.add(TAG_QUERY);
fields.add(INDENT);
fields.add(CHILDREN);
@ -180,7 +181,7 @@ public class TaskListQuery {
}
private static List<String> getNonRecursiveQuery(Filter filter, Preferences preferences) {
List<Field> fields = newArrayList(FIELDS);
List<Field> fields = new ArrayList<>(FIELDS);
fields.add(TAGS);
if (filter instanceof GtasksFilter && preferences.isManualSort()) {

@ -1,6 +1,5 @@
package org.tasks.db;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Lists.partition;
import com.google.common.base.Function;
@ -16,7 +15,7 @@ public class DbUtils {
public static <F, T> List<T> collect(Collection<F> items, Function<List<F>, List<T>> func) {
if (items.size() < MAX_SQLITE_ARGS) {
return func.apply(items instanceof List ? (List<F>) items : newArrayList(items));
return func.apply(items instanceof List ? (List<F>) items : new ArrayList<>(items));
}
List<T> result = new ArrayList<>();
batch(items, b -> result.addAll(func.apply(b)));

@ -1,6 +1,5 @@
package org.tasks.dialogs;
import static com.google.common.collect.Lists.newArrayList;
import static org.tasks.dialogs.RecordAudioDialog.newRecordAudioDialog;
import static org.tasks.files.FileHelper.newFilePickerIntent;
@ -11,6 +10,7 @@ import android.os.Bundle;
import android.provider.MediaStore.Images.Media;
import androidx.annotation.NonNull;
import com.todoroo.astrid.files.FilesControlSet;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import org.tasks.R;
@ -45,8 +45,8 @@ public class AddAttachmentDialog extends InjectingDialogFragment {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
List<String> entries = newArrayList();
final List<Runnable> actions = newArrayList();
List<String> entries = new ArrayList<>();
final List<Runnable> actions = new ArrayList<>();
if (device.hasCamera()) {
entries.add(getString(R.string.take_a_picture));
actions.add(this::takePicture);

@ -1,7 +1,6 @@
package org.tasks.etesync;
import static com.google.common.collect.FluentIterable.from;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Maps.newHashMap;
import static com.google.common.collect.Sets.newHashSet;
import static java.util.Collections.emptySet;
@ -113,7 +112,7 @@ public class EteSynchronizer {
Set<String> uids = newHashSet(Iterables.transform(resources.values(), CollectionInfo::getUid));
Timber.d("Found uids: %s", uids);
for (CaldavCalendar calendar :
caldavDao.findDeletedCalendars(account.getUuid(), newArrayList(uids))) {
caldavDao.findDeletedCalendars(account.getUuid(), new ArrayList<>(uids))) {
taskDeleter.delete(calendar);
}

@ -1,7 +1,6 @@
package org.tasks.filters;
import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Sets.newLinkedHashSet;
import android.content.Context;
@ -17,6 +16,7 @@ import com.todoroo.astrid.api.TextInputCriterion;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.Task.Priority;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -99,7 +99,7 @@ public class FilterCriteriaProvider {
}
public List<CustomFilterCriterion> getAll() {
List<CustomFilterCriterion> result = newArrayList();
List<CustomFilterCriterion> result = new ArrayList<>();
result.add(getTagFilter());
result.add(getTagNameContainsFilter());

@ -307,9 +307,11 @@ public class FilterProvider {
}
private List<Filter> getFilters() {
ArrayList<Filter> filters = new ArrayList<>();
filters.addAll(builtInFilterExposer.getFilters());
filters.addAll(timerFilterExposer.getFilters());
ArrayList<Filter> filters = new ArrayList<>(builtInFilterExposer.getFilters());
Filter filter = timerFilterExposer.getFilters();
if (filter != null) {
filters.add(filter);
}
filters.addAll(customFilterExposer.getFilters());
return filters;
}
@ -322,7 +324,7 @@ public class FilterProvider {
account,
account.isCollapsed()
? emptyList()
: newArrayList(
: new ArrayList<>(
transform(
googleTaskListDao.getGoogleTaskFilters(account.getAccount(), now()),
GoogleTaskFilters::toGtasksFilter)));
@ -341,7 +343,7 @@ public class FilterProvider {
account,
account.isCollapsed()
? emptyList()
: newArrayList(
: new ArrayList<>(
transform(
caldavDao.getCaldavFilters(account.getUuid(), now()),
CaldavFilters::toCaldavFilter)));

@ -8,6 +8,7 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.Ordering;
import com.google.common.collect.TreeMultimap;
import com.google.common.primitives.Ints;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.inject.Inject;
@ -67,7 +68,7 @@ public class NotificationQueue {
}
synchronized List<? extends NotificationQueueEntry> getOverdueJobs() {
List<NotificationQueueEntry> result = newArrayList();
List<NotificationQueueEntry> result = new ArrayList<>();
long cutoff = new DateTime().startOfMinute().plusMinutes(1).getMillis();
for (Long key : jobs.keySet().headSet(cutoff)) {
result.addAll(jobs.get(key));

@ -1,6 +1,5 @@
package org.tasks.location;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Lists.transform;
import static com.todoroo.andlib.utility.AndroidUtilities.hideKeyboard;
import static org.tasks.PermissionUtil.verifyPermissions;
@ -387,7 +386,7 @@ public class LocationPickerActivity extends InjectingAppCompatActivity
private void updateMarkers() {
if (map != null) {
map.setMarkers(newArrayList(transform(places, PlaceUsage::getPlace)));
map.setMarkers(transform(places, PlaceUsage::getPlace));
}
}

@ -251,7 +251,7 @@ public class NotificationManager {
cancelSummaryNotification();
return;
}
ArrayList<Long> taskIds = newArrayList(transform(tasks, Task::getId));
ArrayList<Long> taskIds = new ArrayList<>(transform(tasks, Task::getId));
Filter filter =
new Filter(
context.getString(R.string.notifications),
@ -263,8 +263,8 @@ public class NotificationManager {
context.getResources().getQuantityString(R.plurals.task_count, taskCount, taskCount);
NotificationCompat.InboxStyle style =
new NotificationCompat.InboxStyle().setBigContentTitle(summaryTitle);
List<String> titles = newArrayList();
List<String> ticker = newArrayList();
List<String> titles = new ArrayList<>();
List<String> ticker = new ArrayList<>();
for (Task task : tasks) {
String title = task.getTitle();
style.addLine(title);

@ -1,7 +1,6 @@
package org.tasks.tags;
import static com.google.common.collect.Iterables.any;
import static com.google.common.collect.Lists.newArrayList;
import static org.tasks.Strings.isNullOrEmpty;
import androidx.annotation.Nullable;
@ -46,11 +45,11 @@ public class TagPickerViewModel extends ViewModel {
}
public ArrayList<TagData> getSelected() {
return newArrayList(selected);
return new ArrayList<>(selected);
}
ArrayList<TagData> getPartiallySelected() {
return newArrayList(partiallySelected);
return new ArrayList<>(partiallySelected);
}
public String getText() {

@ -1,6 +1,5 @@
package org.tasks.ui;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Lists.transform;
import static com.todoroo.astrid.data.SyncFlags.FORCE_CALDAV_SYNC;
import static org.tasks.PermissionUtil.verifyPermissions;
@ -167,7 +166,7 @@ public class LocationControlSet extends TaskEditControlFragment {
dialogBuilder
.newDialog(location.getDisplayName())
.setItems(
newArrayList(transform(options, o -> getString(o.first))),
new ArrayList<>(transform(options, o -> getString(o.first))),
(dialog, which) -> options.get(which).second.run())
.show();
}

Loading…
Cancel
Save