Last active
February 16, 2021 18:44
-
-
Save tomwhoiscontrary/40a5ff92de0bc9aa864fa20ef4ccb4b8 to your computer and use it in GitHub Desktop.
Some code in need of good names
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Class1 { | |
public static <Type1, Type2 extends Collection<Type1>> Type2 method(Supplier<Type2> parameter1, Collection<Type1> parameter2, Collection<Type1> parameter3) { | |
Type2 variable = Stream.concat(parameter2.stream() | |
.filter(Predicate.not(parameter3::contains)), | |
parameter3.stream() | |
.filter(Predicate.not(parameter2::contains))) | |
.collect(Collectors.toCollection(parameter1)); | |
return variable; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Class2 { | |
public static <Type1, Type2 extends Collection<Type1>> Stream<Type2> method1(Stream<Type1> parameter1, int parameter2, IntFunction<Type2> parameter3) { | |
return Stream.concat(parameter1.map(Optional::of), Stream.of(Optional.<Type1>empty())) | |
.flatMap(new Function<Optional<Type1>, Stream<Type2>>() { | |
Type2 field1; | |
@Override | |
public Stream<Type2> apply(Optional<Type1> parameter4) { | |
if (parameter4.isEmpty()) { | |
return method2(); | |
} | |
if (field1 == null) { | |
field1 = parameter3.apply(parameter2); | |
} | |
field1.add(parameter4.get()); | |
if (field1.size() == parameter2) { | |
return method2(); | |
} else { | |
return Stream.empty(); | |
} | |
} | |
private Stream<Type2> method2() { | |
Type2 variable = this.field1; | |
this.field1 = null; | |
return variable != null ? Stream.of(variable) : Stream.empty(); | |
} | |
}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Class3 implements Closeable { | |
private final Function<String, Path> field1; | |
private final Map<String, BufferedWriter> field2; | |
private final String field3; | |
public Class3(Function<String, Path> parameter1, String parameter2) { | |
this.field1 = parameter1; | |
field2 = new HashMap<>(); | |
this.field3 = parameter2; | |
} | |
public void method(String parameter3, String parameter4) throws IOException { | |
BufferedWriter variable = field2.get(parameter3); | |
if (variable == null) { | |
variable = Files.newBufferedWriter(field1.apply(parameter3)); | |
variable.write(field3); | |
variable.newLine(); | |
field2.put(parameter3, variable); | |
} | |
variable.write(parameter4); | |
variable.newLine(); | |
} | |
@Override | |
public void close() throws IOException { | |
for (BufferedWriter out : field2.values()) { | |
out.close(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Class4 implements DoubleConsumer, Supplier<double[]> { | |
private static final int CONSTANT = 2; | |
private final double[] field1; | |
private int field2; | |
public Class4(int parameter1) { | |
field1 = new double[parameter1 * CONSTANT]; | |
this.field2 = 0; | |
} | |
@Override | |
public void accept(double parameter2) { | |
if (field2 >= field1.length) { | |
method2(); | |
} | |
// TODO it would be possible to just discard parameter2 under some conditions, do that | |
field1[field1.length - field2 - 1] = parameter2; | |
++field2; | |
} | |
@Override | |
public double[] get() { | |
method2(); | |
int variable1 = method1(); | |
double[] variable2 = new double[variable1]; | |
System.arraycopy(this.field1, this.field1.length - variable1, variable2, 0, variable1); | |
return variable2; | |
} | |
public int method1() { | |
return Math.min(field2, field1.length / CONSTANT); | |
} | |
private void method2() { | |
Arrays.sort(field1); | |
field2 = Math.min(field2, field1.length / CONSTANT); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment