Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Stream.toList instead of Collectors #227

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2020 Red Hat.
* Copyright (c) 2016, 2023 Red Hat.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -151,13 +151,13 @@ public List<IDockerImageSearchResult> getImages(String term)
}
List<ImageSearchResult> tmp = cisr.getRepositories().stream()
.filter(e -> e.name().contains(term))
.collect(Collectors.toList());
.toList();

result.addAll(tmp.stream()
.map(r -> new DockerImageSearchResult(r.description(),
r.official(), r.automated(), r.name(),
r.starCount()))
.collect(Collectors.toList()));
.toList());
} else {
ImageSearchResultV1 pisr = null;
final GenericType<ImageSearchResultV1> IMAGE_SEARCH_RESULT_LIST = new GenericType<>() {
Expand All @@ -178,7 +178,7 @@ public List<IDockerImageSearchResult> getImages(String term)
.map(r -> new DockerImageSearchResult(
r.description(), r.official(),
r.automated(), r.name(), r.starCount()))
.collect(Collectors.toList()));
.toList());
}
} catch (InterruptedException | ExecutionException e) {
throw new DockerException(e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*******************************************************************************
* Copyright (c) 2014, 2018 Red Hat.
*
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
Expand All @@ -14,7 +14,6 @@

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import org.eclipse.core.runtime.ListenerList;
import org.eclipse.linuxtools.docker.core.IDockerConnectionSettings.BindingType;
Expand Down Expand Up @@ -200,7 +199,7 @@ public boolean hasConnections() {

/**
* Finds the {@link IDockerConnection} from the given {@code connectionName}
*
*
* @param connectionName
* the name of the connection to find
* @return the {@link IDockerConnection} or <code>null</code> if none
Expand All @@ -223,7 +222,7 @@ public IDockerConnection getConnectionByName(

/**
* Finds the {@link IDockerConnection} from the given {@code connectionUri}
*
*
* @param connectionUri
* the URI of the connection to find
* @return the {@link IDockerConnection} or <code>null</code> if none
Expand Down Expand Up @@ -258,11 +257,11 @@ public List<String> getConnectionNames() {
reloadThread = null;
}
return Collections.unmodifiableList(getAllConnections().stream()
.map(c -> c.getName())
.map(IDockerConnection::getName)
// making sure that no 'null' name is returned in the list of
// connection names.
.filter(n -> n != null)
.collect(Collectors.toList()));
.toList());
}

public IDockerConnection findConnection(final String name) {
Expand All @@ -287,7 +286,7 @@ public IDockerConnection findConnection(final String name) {
/**
* Adds the given connection and notifies all registered
* {@link IDockerConnectionManagerListener}
*
*
* @param dockerConnection
* the connection to add
*/
Expand All @@ -307,7 +306,7 @@ public void addConnection(
/**
* Adds the given connection and notifies optionally all registered
* {@link IDockerConnectionManagerListener}
*
*
* @param dockerConnection
* the connection to add
* @param notifyListeners
Expand Down Expand Up @@ -376,7 +375,7 @@ public void removeConnectionManagerListener(

/**
* Notifies all listeners that a change occurred on the given connection
*
*
* @param connection
* the connection that changed
* @param type
Expand All @@ -394,12 +393,12 @@ public void notifyListeners(final IDockerConnection connection,
/**
* Notifies all listeners that a change occurred on the given connection but
* does nothing if DockerConnectionManager isn't instantiated
*
*
* @param connection
* the connection that changed
* @param type
* the type of change
*
*
* @since 4.0
*/
public static void instanceNotifyListeners(
Expand All @@ -412,7 +411,7 @@ public static void instanceNotifyListeners(

/**
* Finds the default {@link IDockerConnectionSettings}
*
*
* @return the default {@link IDockerConnectionSettings} or
* <code>null</code> if nothing was found
*/
Expand All @@ -424,7 +423,7 @@ public IDockerConnectionSettings findDefaultConnectionSettings() {
/**
* Resolves the name of the Docker instance, given the
* {@link IDockerConnectionSettings}
*
*
* @param connectionSettings
* the settings to use to connect
* @return the name retrieved from the Docker instance or <code>null</code>
Expand All @@ -439,7 +438,7 @@ public String resolveConnectionName(
/**
* Updates the given {@link IDockerConnection} with the given {@code name}
* and {@code connectionSettings}
*
*
* @param connection
* the {@link IDockerConnection} to update
* @param name
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*******************************************************************************
* Copyright (c) 2016, 2018 Red Hat.
*
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
Expand All @@ -25,7 +25,7 @@

/**
* Binding for Repository Tag results from a Registry V2.
*
*
* Currently the returned repo tag results lack the same degree of information
* returned from the V1 registries.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018 Red Hat, Inc.
* Copyright (c) 2018, 2023 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -18,7 +18,6 @@
import java.lang.annotation.Target;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.eclipse.linuxtools.docker.reddeer.ui.DockerExplorerView;
import org.eclipse.linuxtools.docker.reddeer.ui.resources.DockerConnection;
Expand Down Expand Up @@ -87,7 +86,7 @@ public List<DockerConnection> getDockerConnections() {
try {
return new DefaultTree().getItems().stream()
.map(x -> new DockerConnection(x))
.collect(Collectors.toList());
.toList();
} catch (CoreLayerException coreExc) {
// there is no item in docker explorer
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022 Mathema.
* Copyright (c) 2022, 2023 Mathema and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -19,7 +19,6 @@
import java.util.List;
import java.util.Set;
import java.util.Vector;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import org.assertj.core.api.Assertions;
Expand Down Expand Up @@ -88,7 +87,7 @@ public void setConnection() {

@After
public void cleanTemp() throws IOException {
var paths = Files.walk(localTempWork).collect(Collectors.toList());
var paths = Files.walk(localTempWork).toList();
// Must delete recursively
Collections.reverse(paths);
paths.stream().forEach(p -> p.toFile().delete());
Expand All @@ -101,7 +100,7 @@ private java.nio.file.Path stripTemp(java.nio.file.Path p) {
}

private List<String> getTempLs() throws IOException {
var paths = Files.walk(localTempWork).sorted().collect(Collectors.toList());
var paths = Files.walk(localTempWork).sorted().toList();

var sep = File.separatorChar;

Expand All @@ -120,7 +119,7 @@ private List<String> getTempLs() throws IOException {
return "U " + sep + stripTemp(f);
}

}).map(f -> f.replace(sep, '/')).collect(Collectors.toList());
}).map(f -> f.replace(sep, '/')).toList();

}

Expand Down Expand Up @@ -283,7 +282,7 @@ public void FolderFromImageMany() throws Exception {
exp.add("D /");
exp.add("D /manyfiles");
var files = IntStream.range(1, 10001).mapToObj(n -> "/manyfiles/F" + n).sorted().map(f -> "R " + f)
.collect(Collectors.toList());
.toList();
exp.addAll(files);
Assertions.assertThat(getTempLs()).isEqualTo(exp);
}
Expand All @@ -296,7 +295,7 @@ public void MirrorFromImageMany() throws Exception {
exp.addAll(List.of("D /", "R /.copyState", "R /.image_id", "D /test", "D /test/manyfiles"));

var files = IntStream.range(1, 10001).mapToObj(n -> "/test/manyfiles/F" + n).sorted().map(f -> "R " + f)
.collect(Collectors.toList());
.toList();
exp.addAll(files);

Assertions.assertThat(getTempLs()).isEqualTo(exp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.assertj.core.data.MapEntry;
import org.eclipse.linuxtools.docker.core.IDockerImage;
Expand Down Expand Up @@ -139,7 +138,7 @@ public void shouldDuplicateImageByRepo() {
final IDockerImage fooImage = MockDockerImageFactory.id("sha256:foo_image")
.name("foo_image", "foo_image_alias:alias").build();
// when
final List<IDockerImage> result = DockerImage.duplicateImageByRepo(fooImage).collect(Collectors.toList());
final List<IDockerImage> result = DockerImage.duplicateImageByRepo(fooImage).toList();
// then
assertThat(result).hasSize(2);
assertThat(result.get(0).id()).isEqualTo("sha256:foo_image");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package org.eclipse.linuxtools.internal.docker.ui.testutils;

import java.util.Collections;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.linuxtools.docker.core.IDockerConnection;
Expand All @@ -36,7 +35,7 @@ public static IDockerConnectionStorageManager loadNone() {
public static IDockerConnectionStorageManager providing(final IDockerConnection... mockedConnections) {
final IDockerConnectionStorageManager connectionStorageManager = Mockito
.mock(IDockerConnectionStorageManager.class);
Mockito.when(connectionStorageManager.loadConnections()).thenReturn(Stream.of(mockedConnections).collect(Collectors.toList()));
Mockito.when(connectionStorageManager.loadConnections()).thenReturn(Stream.of(mockedConnections).toList());
return connectionStorageManager;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2018 Red Hat Inc. and others.
* Copyright (c) 2016, 2023 Red Hat Inc. and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -264,7 +264,7 @@ public static SWTBotTreeItem getTreeItem(final SWTBotTreeItem parentTreeItem, fi
private static SWTBotTreeItem getTreeItem(final SWTBotTreeItem[] treeItems, final String[] paths) {
final SWTBotTreeItem swtBotTreeItem = Stream.of(treeItems).filter(item -> item.getText().startsWith(paths[0]))
.findFirst().orElseThrow(() -> new RuntimeException("Only available items: "
+ Stream.of(treeItems).map(item -> item.getText()).collect(Collectors.joining(", "))));
+ Stream.of(treeItems).map(SWTBotTreeItem::getText).collect(Collectors.joining(", "))));
if (paths.length > 1) {
syncExec(() -> swtBotTreeItem.expand());
final String[] remainingPath = new String[paths.length - 1];
Expand All @@ -276,10 +276,8 @@ private static SWTBotTreeItem getTreeItem(final SWTBotTreeItem[] treeItems, fina

public static SWTBotTableItem getListItem(final SWTBotTable table, final String name) {
return Stream.iterate(0, i -> i + 1).limit(table.rowCount()).map(rowNumber -> table.getTableItem(rowNumber))
.filter(rowItem -> {
return Stream.iterate(0, j -> j + 1).limit(table.columnCount())
.map(colNum -> rowItem.getText(colNum)).anyMatch(colValue -> colValue.contains(name));
}).findFirst().orElse(null);
.filter(rowItem -> Stream.iterate(0, j -> j + 1).limit(table.columnCount())
.map(colNum -> rowItem.getText(colNum)).anyMatch(colValue -> colValue.contains(name))).findFirst().orElse(null);
}

/**
Expand Down Expand Up @@ -312,7 +310,7 @@ public static void wait(final int duration, final TimeUnit unit) {
public static SWTBotTreeItem select(final SWTBotTreeItem parentTreeItem, final String... matchItems) {
final List<String> fullyQualifiedItems = Stream.of(parentTreeItem.getItems()).filter(
treeItem -> Stream.of(matchItems).anyMatch(matchItem -> treeItem.getText().startsWith(matchItem)))
.map(item -> item.getText()).collect(Collectors.toList());
.map(SWTBotTreeItem::getText).toList();
return parentTreeItem.select(fullyQualifiedItems.toArray(new String[0]));
}

Expand All @@ -330,7 +328,7 @@ public static SWTBotTreeItem select(final SWTBotTreeItem parentTreeItem, final S
public static SWTBotTree select(final SWTBotTree parentTree, final String... matchItems) {
final List<String> fullyQualifiedItems = Stream.of(parentTree.getAllItems()).filter(
treeItem -> Stream.of(matchItems).anyMatch(matchItem -> treeItem.getText().startsWith(matchItem)))
.map(item -> item.getText()).collect(Collectors.toList());
.map(SWTBotTreeItem::getText).toList();
return parentTree.select(fullyQualifiedItems.toArray(new String[0]));
}

Expand Down Expand Up @@ -500,7 +498,7 @@ public static SWTBotToolbarButton getConsoleToolbarButtonWithTooltipText(final S
}

public static void closeView(final SWTWorkbenchBot bot, final String viewId) {
bot.views().stream().filter(v -> v.getReference().getId().equals(viewId)).forEach(v -> v.close());
bot.views().stream().filter(v -> v.getReference().getId().equals(viewId)).forEach(SWTBotView::close);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.assertj.core.api.Assertions;
Expand Down Expand Up @@ -641,14 +640,14 @@ public void shouldRemoveAllConnectionsSimultaneously() {
.withDefaultTCPConnectionSettings();
DockerConnectionManagerUtils.configureConnectionManager(dockerConnection1, dockerConnection2);
final List<String> initialConnections = Stream.of(dockerExplorerViewBot.bot().tree().getAllItems())
.map(SWTBotTreeItem::getText).collect(Collectors.toList());
.map(SWTBotTreeItem::getText).toList();
assertThat(initialConnections).contains("Test1", "Test2");
// when
SWTUtils.select(dockerExplorerViewBot.bot().tree(), "Test1", "Test2");
SWTUtils.getContextMenu(dockerExplorerViewBot.bot().tree(), "Remove").click();
// then
final List<String> remainingConnections = Stream.of(dockerExplorerViewBot.bot().tree().getAllItems())
.map(SWTBotTreeItem::getText).collect(Collectors.toList());
.map(SWTBotTreeItem::getText).toList();
assertThat(remainingConnections).doesNotContain("Test1", "Test2");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import static org.assertj.core.api.Assertions.assertThat;

import java.util.List;
import java.util.stream.Collectors;

import org.eclipse.linuxtools.docker.core.IDockerContainer;
import org.eclipse.linuxtools.docker.core.IDockerImage;
Expand Down Expand Up @@ -48,7 +47,6 @@
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;

import org.mandas.docker.client.DockerClient;
import org.mandas.docker.client.messages.Container;
import org.mandas.docker.client.messages.Image;
Expand Down Expand Up @@ -88,7 +86,7 @@ public void setupViews() {
this.dockerExplorerViewBot = bot.viewById(DockerExplorerView.VIEW_ID);
// make sure that the Docker Image Hierarchy view is closed
this.bot.views().stream().filter(v -> v.getReference().getId().equals(DockerImageHierarchyView.VIEW_ID))
.forEach(v -> v.close());
.forEach(SWTBotView::close);
}

@Before
Expand Down Expand Up @@ -145,7 +143,7 @@ private List<String> getChildrenElementIds(final IDockerImageHierarchyNode fooIm
return ((IDockerImage) e.getElement()).id();
}
return ((IDockerContainer) e.getElement()).id();
}).collect(Collectors.toList());
}).toList();
}

private DockerImageHierarchyView getDockerImageHierarchyView() {
Expand Down
Loading