You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2016/04/22 11:23:15 UTC
mina-sshd git commit: [SSHD-663] Wrong if criteria in
org.apache.sshd.common.file.util.ImmutableList.subList()
Repository: mina-sshd
Updated Branches:
refs/heads/master a42f9b553 -> 8efd018f2
[SSHD-663] Wrong if criteria in org.apache.sshd.common.file.util.ImmutableList.subList()
Removed the class altogether
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/8efd018f
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/8efd018f
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/8efd018f
Branch: refs/heads/master
Commit: 8efd018f242713c74d6a587f40c41322c92c32b4
Parents: a42f9b5
Author: Lyor Goldstein <ly...@gmail.com>
Authored: Fri Apr 22 12:23:30 2016 +0300
Committer: Lyor Goldstein <ly...@gmail.com>
Committed: Fri Apr 22 12:23:30 2016 +0300
----------------------------------------------------------------------
.../client/subsystem/sftp/SftpFileSystem.java | 3 +-
.../sshd/client/subsystem/sftp/SftpPath.java | 4 +-
.../sshd/common/file/root/RootedFileSystem.java | 4 +-
.../sshd/common/file/root/RootedPath.java | 4 +-
.../sshd/common/file/util/BaseFileSystem.java | 8 +--
.../apache/sshd/common/file/util/BasePath.java | 10 ++--
.../sshd/common/file/util/ImmutableList.java | 62 --------------------
.../apache/sshd/common/util/GenericUtils.java | 13 ++++
.../sshd/common/file/util/BasePathTest.java | 12 ++--
9 files changed, 36 insertions(+), 84 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/8efd018f/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystem.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystem.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystem.java
index 73e1750..11ff32e 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystem.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystem.java
@@ -44,7 +44,6 @@ import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.client.session.ClientSessionHolder;
import org.apache.sshd.common.PropertyResolverUtils;
import org.apache.sshd.common.file.util.BaseFileSystem;
-import org.apache.sshd.common.file.util.ImmutableList;
import org.apache.sshd.common.subsystem.sftp.SftpConstants;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.ValidateUtils;
@@ -142,7 +141,7 @@ public class SftpFileSystem extends BaseFileSystem<SftpPath> implements ClientSe
}
@Override
- protected SftpPath create(String root, ImmutableList<String> names) {
+ protected SftpPath create(String root, List<String> names) {
return new SftpPath(this, root, names);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/8efd018f/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpPath.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpPath.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpPath.java
index d2f33ce..5567b58 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpPath.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpPath.java
@@ -22,12 +22,12 @@ import java.io.IOException;
import java.nio.file.FileSystem;
import java.nio.file.LinkOption;
import java.nio.file.spi.FileSystemProvider;
+import java.util.List;
import org.apache.sshd.common.file.util.BasePath;
-import org.apache.sshd.common.file.util.ImmutableList;
public class SftpPath extends BasePath<SftpPath, SftpFileSystem> {
- public SftpPath(SftpFileSystem fileSystem, String root, ImmutableList<String> names) {
+ public SftpPath(SftpFileSystem fileSystem, String root, List<String> names) {
super(fileSystem, root, names);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/8efd018f/sshd-core/src/main/java/org/apache/sshd/common/file/root/RootedFileSystem.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/file/root/RootedFileSystem.java b/sshd-core/src/main/java/org/apache/sshd/common/file/root/RootedFileSystem.java
index 974667a..7ded64e 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/file/root/RootedFileSystem.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/file/root/RootedFileSystem.java
@@ -23,11 +23,11 @@ import java.nio.file.FileStore;
import java.nio.file.FileSystem;
import java.nio.file.Path;
import java.nio.file.attribute.UserPrincipalLookupService;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.sshd.common.file.util.BaseFileSystem;
-import org.apache.sshd.common.file.util.ImmutableList;
import org.apache.sshd.common.util.ValidateUtils;
/**
@@ -85,7 +85,7 @@ public class RootedFileSystem extends BaseFileSystem<RootedPath> {
}
@Override
- protected RootedPath create(String root, ImmutableList<String> names) {
+ protected RootedPath create(String root, List<String> names) {
return new RootedPath(this, root, names);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/8efd018f/sshd-core/src/main/java/org/apache/sshd/common/file/root/RootedPath.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/file/root/RootedPath.java b/sshd-core/src/main/java/org/apache/sshd/common/file/root/RootedPath.java
index d89828c..e708aed 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/file/root/RootedPath.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/file/root/RootedPath.java
@@ -24,15 +24,15 @@ import java.nio.file.FileSystem;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.spi.FileSystemProvider;
+import java.util.List;
import org.apache.sshd.common.file.util.BasePath;
-import org.apache.sshd.common.file.util.ImmutableList;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public class RootedPath extends BasePath<RootedPath, RootedFileSystem> {
- public RootedPath(RootedFileSystem fileSystem, String root, ImmutableList<String> names) {
+ public RootedPath(RootedFileSystem fileSystem, String root, List<String> names) {
super(fileSystem, root, names);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/8efd018f/sshd-core/src/main/java/org/apache/sshd/common/file/util/BaseFileSystem.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/file/util/BaseFileSystem.java b/sshd-core/src/main/java/org/apache/sshd/common/file/util/BaseFileSystem.java
index 88c7c73..8d69916 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/file/util/BaseFileSystem.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/file/util/BaseFileSystem.java
@@ -28,6 +28,7 @@ import java.nio.file.spi.FileSystemProvider;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -246,13 +247,12 @@ public abstract class BaseFileSystem<T extends Path> extends FileSystem {
}
protected T create(String root, String... names) {
- return create(root, new ImmutableList<>(names));
+ return create(root, GenericUtils.unmodifiableList(names));
}
protected T create(String root, Collection<String> names) {
- return create(root, new ImmutableList<>(names.toArray(new String[names.size()])));
+ return create(root, GenericUtils.unmodifiableList(names));
}
- protected abstract T create(String root, ImmutableList<String> names);
-
+ protected abstract T create(String root, List<String> names);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/8efd018f/sshd-core/src/main/java/org/apache/sshd/common/file/util/BasePath.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/file/util/BasePath.java b/sshd-core/src/main/java/org/apache/sshd/common/file/util/BasePath.java
index 5f59626..5e42099 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/file/util/BasePath.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/file/util/BasePath.java
@@ -43,12 +43,12 @@ import org.apache.sshd.common.util.ValidateUtils;
public abstract class BasePath<T extends BasePath<T, FS>, FS extends BaseFileSystem<T>> implements Path {
protected final String root;
- protected final ImmutableList<String> names;
+ protected final List<String> names;
private final FS fileSystem;
private String strValue;
private int hashValue;
- public BasePath(FS fileSystem, String root, ImmutableList<String> names) {
+ public BasePath(FS fileSystem, String root, List<String> names) {
this.fileSystem = ValidateUtils.checkNotNull(fileSystem, "No file system provided");
this.root = root;
this.names = names;
@@ -60,14 +60,14 @@ public abstract class BasePath<T extends BasePath<T, FS>, FS extends BaseFileSys
}
protected T create(String root, String... names) {
- return create(root, new ImmutableList<>(names));
+ return create(root, GenericUtils.unmodifiableList(names));
}
protected T create(String root, Collection<String> names) {
- return create(root, new ImmutableList<>(names.toArray(new String[names.size()])));
+ return create(root, GenericUtils.unmodifiableList(names));
}
- protected T create(String root, ImmutableList<String> names) {
+ protected T create(String root, List<String> names) {
return fileSystem.create(root, names);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/8efd018f/sshd-core/src/main/java/org/apache/sshd/common/file/util/ImmutableList.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/file/util/ImmutableList.java b/sshd-core/src/main/java/org/apache/sshd/common/file/util/ImmutableList.java
deleted file mode 100644
index f126c41..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/file/util/ImmutableList.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.sshd.common.file.util;
-
-import java.util.AbstractList;
-
-/**
- * Simple immutable array list
- *
- * @param <T> The element type
- */
-public class ImmutableList<T> extends AbstractList<T> {
-
- private final T[] data;
- private final int from;
- private final int to;
-
- public ImmutableList(T[] data) {
- this(data, 0, data.length);
- }
-
- public ImmutableList(T[] data, int from, int to) {
- this.data = data;
- this.from = from;
- this.to = to;
- }
-
- @Override
- public T get(int index) {
- return data[from + index];
- }
-
- @Override
- public int size() {
- return to - from;
- }
-
- @Override
- public ImmutableList<T> subList(int fromIndex, int toIndex) {
- if (fromIndex == from && toIndex == to) {
- return this;
- }
- return new ImmutableList<>(data, from + fromIndex, from + toIndex);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/8efd018f/sshd-core/src/main/java/org/apache/sshd/common/util/GenericUtils.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/GenericUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/util/GenericUtils.java
index 01743ff..3b23895 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/GenericUtils.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/GenericUtils.java
@@ -284,6 +284,19 @@ public final class GenericUtils {
}
@SafeVarargs
+ public static <T> List<T> unmodifiableList(T ... values) {
+ return unmodifiableList(asList(values));
+ }
+
+ public static <T> List<T> unmodifiableList(Collection<? extends T> values) {
+ if (isEmpty(values)) {
+ return Collections.emptyList();
+ } else {
+ return Collections.unmodifiableList(new ArrayList<T>(values));
+ }
+ }
+
+ @SafeVarargs
public static <T> List<T> asList(T ... values) {
int len = length(values);
if (len <= 0) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/8efd018f/sshd-core/src/test/java/org/apache/sshd/common/file/util/BasePathTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/file/util/BasePathTest.java b/sshd-core/src/test/java/org/apache/sshd/common/file/util/BasePathTest.java
index a9fddc3..5d69f0a 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/file/util/BasePathTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/file/util/BasePathTest.java
@@ -28,9 +28,11 @@ import java.nio.file.spi.FileSystemProvider;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import java.util.Set;
+import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.util.test.BaseTestSupport;
import org.junit.Before;
import org.junit.FixMethodOrder;
@@ -334,7 +336,7 @@ public class BasePathTest extends BaseTestSupport {
}
@Override
- protected TestPath create(String root, ImmutableList<String> names) {
+ protected TestPath create(String root, List<String> names) {
return new TestPath(this, root, names);
}
@@ -361,12 +363,12 @@ public class BasePathTest extends BaseTestSupport {
private static class TestPath extends BasePath<TestPath, TestFileSystem> {
- TestPath(TestFileSystem fileSystem, String root, ImmutableList<String> names) {
+ TestPath(TestFileSystem fileSystem, String root, List<String> names) {
super(fileSystem, root, names);
}
@Override
- protected TestPath create(String root, ImmutableList<String> names) {
+ protected TestPath create(String root, List<String> names) {
return new TestPath(getFileSystem(), root, names);
}
@@ -386,7 +388,7 @@ public class BasePathTest extends BaseTestSupport {
private final FileSystem fileSystem;
private final String string;
private String root;
- private ImmutableList<String> names = new ImmutableList<>(new String[0]);
+ private List<String> names = Collections.<String>emptyList();
public PathTester(FileSystem fileSystem, String string) {
this.fileSystem = fileSystem;
@@ -399,7 +401,7 @@ public class BasePathTest extends BaseTestSupport {
}
public PathTester names(Collection<String> names) {
- this.names = new ImmutableList<>(names.toArray(new String[names.size()]));
+ this.names = GenericUtils.unmodifiableList(names);
return this;
}