Consistent Stream.of usage over Arrays.stream

This commit is contained in:
Brady 2019-09-21 17:37:13 -05:00
parent 204f9d2e31
commit 376c93bd3b
No known key found for this signature in database
GPG Key ID: 73A788379A197567
7 changed files with 14 additions and 26 deletions

View File

@ -23,6 +23,7 @@ import net.minecraft.item.ItemStack;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
public class BlockOptionalMetaLookup {
@ -33,7 +34,7 @@ public class BlockOptionalMetaLookup {
}
public BlockOptionalMetaLookup(Block... blocks) {
this.boms = Arrays.stream(blocks)
this.boms = Stream.of(blocks)
.map(BlockOptionalMeta::new)
.toArray(BlockOptionalMeta[]::new);
}
@ -45,7 +46,7 @@ public class BlockOptionalMetaLookup {
}
public BlockOptionalMetaLookup(String... blocks) {
this.boms = Arrays.stream(blocks)
this.boms = Stream.of(blocks)
.map(BlockOptionalMeta::new)
.toArray(BlockOptionalMeta[]::new);
}

View File

@ -29,6 +29,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
/**
* A {@link CommandArgument} is an immutable object representing one command argument. It contains data on the index of
@ -66,7 +67,7 @@ public class CommandArgument {
* @see ArgConsumer#getEnumOrNull(Class)
*/
public <E extends Enum<?>> E getEnum(Class<E> enumClass) throws CommandInvalidTypeException {
return Arrays.stream(enumClass.getEnumConstants())
return Stream.of(enumClass.getEnumConstants())
.filter(e -> e.name().equalsIgnoreCase(value))
.findFirst()
.orElseThrow(() -> new CommandInvalidTypeException(this, enumClass.getSimpleName()));

View File

@ -48,7 +48,7 @@ public class ForEnumFacing implements IDatatypeFor<EnumFacing> {
public Stream<String> tabComplete(ArgConsumer consumer) throws CommandException {
return new TabCompleteHelper()
.append(
Arrays.stream(EnumFacing.values())
Stream.of(EnumFacing.values())
.map(EnumFacing::getName)
.map(String::toLowerCase)
)

View File

@ -76,7 +76,7 @@ public class ForWaypoints implements IDatatypeFor<IWaypoint[]> {
}
public static String[] getWaypointNames() {
return Arrays.stream(getWaypoints())
return Stream.of(getWaypoints())
.map(IWaypoint::getName)
.filter(name -> !name.isEmpty())
.toArray(String[]::new);
@ -89,7 +89,7 @@ public class ForWaypoints implements IDatatypeFor<IWaypoint[]> {
}
public static IWaypoint[] getWaypointsByName(String name) {
return Arrays.stream(getWaypoints())
return Stream.of(getWaypoints())
.filter(waypoint -> waypoint.getName().equalsIgnoreCase(name))
.toArray(IWaypoint[]::new);
}

View File

@ -82,7 +82,7 @@ public class RelativeFile implements IDatatypePost<File, File> {
Path basePath = currentPath.isAbsolute() ? currentPath.getRoot() : base.toPath();
boolean useParent = !currentPathStringThing.isEmpty() && !currentPathStringThing.endsWith(File.separator);
File currentFile = currentPath.isAbsolute() ? currentPath.toFile() : new File(base, currentPathStringThing);
return Arrays.stream(Objects.requireNonNull(getCanonicalFileUnchecked(
return Stream.of(Objects.requireNonNull(getCanonicalFileUnchecked(
useParent
? currentFile.getParentFile()
: currentFile

View File

@ -22,6 +22,7 @@ import java.io.StringWriter;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class CommandUnhandledException extends RuntimeException implements ICommandException {
@ -39,7 +40,7 @@ public class CommandUnhandledException extends RuntimeException implements IComm
}
private static String getBaritoneStackTrace(String stackTrace) {
List<String> lines = Arrays.stream(stackTrace.split("\n"))
List<String> lines = Stream.of(stackTrace.split("\n"))
.collect(Collectors.toList());
int lastBaritoneLine = 0;
for (int i = 0; i < lines.size(); i++) {

View File

@ -57,7 +57,7 @@ public class TabCompleteHelper {
private Stream<String> stream;
public TabCompleteHelper(String[] base) {
stream = Arrays.stream(base);
stream = Stream.of(base);
}
public TabCompleteHelper(List<String> base) {
@ -75,9 +75,6 @@ public class TabCompleteHelper {
* @return This {@link TabCompleteHelper} after having appended the stream
* @see #append(String...)
* @see #append(Class)
* @see #prepend(Stream)
* @see #prepend(String...)
* @see #prepend(Class)
*/
public TabCompleteHelper append(Stream<String> source) {
stream = Stream.concat(stream, source);
@ -91,9 +88,6 @@ public class TabCompleteHelper {
* @return This {@link TabCompleteHelper} after having appended the strings
* @see #append(Stream)
* @see #append(Class)
* @see #prepend(Stream)
* @see #prepend(String...)
* @see #prepend(Class)
*/
public TabCompleteHelper append(String... source) {
return append(Stream.of(source));
@ -106,13 +100,10 @@ public class TabCompleteHelper {
* @return This {@link TabCompleteHelper} after having appended the values
* @see #append(Stream)
* @see #append(String...)
* @see #prepend(Stream)
* @see #prepend(String...)
* @see #prepend(Class)
*/
public TabCompleteHelper append(Class<? extends Enum<?>> num) {
return append(
Arrays.stream(num.getEnumConstants())
Stream.of(num.getEnumConstants())
.map(Enum::name)
.map(String::toLowerCase)
);
@ -123,9 +114,6 @@ public class TabCompleteHelper {
*
* @param source The stream to prepend
* @return This {@link TabCompleteHelper} after having prepended the stream
* @see #append(Stream)
* @see #append(String...)
* @see #append(Class)
* @see #prepend(String...)
* @see #prepend(Class)
*/
@ -154,15 +142,12 @@ public class TabCompleteHelper {
*
* @param num The enum to prepend the values of
* @return This {@link TabCompleteHelper} after having prepended the values
* @see #append(Stream)
* @see #append(String...)
* @see #append(Class)
* @see #prepend(Stream)
* @see #prepend(String...)
*/
public TabCompleteHelper prepend(Class<? extends Enum<?>> num) {
return prepend(
Arrays.stream(num.getEnumConstants())
Stream.of(num.getEnumConstants())
.map(Enum::name)
.map(String::toLowerCase)
);