Fix code style
This commit is contained in:
parent
6c79bf8514
commit
984aec2342
@ -11,7 +11,7 @@ public class Main {
|
||||
byte[] classFile = ByteArrays.fromInputStream(Main.class.getResourceAsStream("/Test.class"));
|
||||
Utils.generateReport(classFile);
|
||||
|
||||
System.out.println("=== Suure class faili pakkimise test (100x)");
|
||||
System.out.println("==== Suure class faili pakkimise test (100x)");
|
||||
byte[] classFile2 = ByteArrays.fromInputStream(Main.class.getResourceAsStream("/TestBig.class"));
|
||||
Utils.generateReport(classFile2);
|
||||
}
|
||||
|
@ -21,14 +21,13 @@ import static eu.mikroskeem.uurimustoo.algoritmidetest.Utils.DummyCompressor.of;
|
||||
* @author Mark Vainomaa
|
||||
*/
|
||||
public class Utils {
|
||||
public static List<AbstractAlgorithm> getAllCompressors(){
|
||||
public static List<AbstractAlgorithm> getAllCompressors() {
|
||||
return new FastClasspathScanner(AbstractAlgorithm.class.getPackage().getName())
|
||||
.scan().getNamesOfSubclassesOf(AbstractAlgorithm.class)
|
||||
.stream()
|
||||
.map(className -> {
|
||||
try {
|
||||
return (AbstractAlgorithm)Reflect.getClass(className)
|
||||
.get().construct().getClassInstance();
|
||||
return (AbstractAlgorithm) Reflect.getClass(className).get().construct().getClassInstance();
|
||||
} catch (Exception e){
|
||||
return null;
|
||||
}
|
||||
@ -38,7 +37,7 @@ public class Utils {
|
||||
}
|
||||
|
||||
|
||||
public static CompressorResult executeCompressor(byte[] input, AbstractAlgorithm compressor){
|
||||
public static CompressorResult executeCompressor(byte[] input, AbstractAlgorithm compressor) {
|
||||
String compressorName = compressor.getName();
|
||||
boolean decompressFailed = false;
|
||||
|
||||
@ -56,17 +55,17 @@ public class Utils {
|
||||
end2 = Instant.now();
|
||||
Validate.checkGeneratedClass(decompressed);
|
||||
assert decompressed.length == input.length;
|
||||
} catch (Throwable e){
|
||||
} catch (Throwable e) {
|
||||
System.out.println(String.format("Tekkis viga %s algoritmi lahtipakkimisel! %s", compressorName, e.toString()));
|
||||
decompressFailed = true;
|
||||
}
|
||||
float sizeDiff = (float)input.length / (float)compressed.length;
|
||||
int compressTime = Duration.between(start, end).getNano();
|
||||
int decompressTime = start2!=null&&end2!=null?Duration.between(start2, end2).getNano():-1;
|
||||
int decompressTime = (start2 != null && end2 != null) ? Duration.between(start2, end2).getNano() : -1;
|
||||
return new CompressorResult(compressor, decompressFailed, compressed.length, sizeDiff, compressTime, decompressTime);
|
||||
}
|
||||
|
||||
public static List<CompressorResult> executeAllNTimes(byte[] input, int n){
|
||||
public static List<CompressorResult> executeAllNTimes(byte[] input, int n) {
|
||||
int i = 0;
|
||||
List<CompressorResult> lastExecuted = executeAll(input, getAllCompressors());
|
||||
while(i < n-1){
|
||||
@ -82,11 +81,11 @@ public class Utils {
|
||||
return lastExecuted;
|
||||
}
|
||||
|
||||
public static List<CompressorResult> executeAll(byte[] input, List<AbstractAlgorithm> compressors){
|
||||
public static List<CompressorResult> executeAll(byte[] input, List<AbstractAlgorithm> compressors) {
|
||||
return compressors.stream().map(c -> executeCompressor(input, c)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static void generateReport(byte[] input){
|
||||
public static void generateReport(byte[] input) {
|
||||
|
||||
System.out.println("----------------------------------------------------------------------------");
|
||||
System.out.println("| Algoritm | Suurus | Väiksem | Aeg (kokku) | Aeg (lahti) |");
|
||||
@ -97,8 +96,8 @@ public class Utils {
|
||||
compressorResult.getCompressor().getName(),
|
||||
compressorResult.getSize(),
|
||||
compressorResult.getDifference(),
|
||||
(compressorResult.getTimeInNS() / 1000000)+"ms",
|
||||
(compressorResult.getDecompressTimeInNS() / 1000000)+"ms"
|
||||
(compressorResult.getTimeInNS() / 1000000) + "ms",
|
||||
(compressorResult.getDecompressTimeInNS() / 1000000) + "ms"
|
||||
);
|
||||
});
|
||||
System.out.println("|--------------------------------------------------------------------------|");
|
||||
@ -116,7 +115,7 @@ public class Utils {
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull Utils.CompressorResult o) {
|
||||
return new Integer(size).compareTo(o.getSize());
|
||||
return Integer.compare(size, o.getSize());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,11 @@ package eu.mikroskeem.uurimustoo.algoritmidetest.algoritmid;
|
||||
|
||||
import eu.mikroskeem.shuriken.common.SneakyThrow;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* @author Mark Vainomaa
|
||||
@ -10,25 +14,25 @@ import java.io.*;
|
||||
public abstract class AbstractAlgorithm {
|
||||
public abstract String getName();
|
||||
|
||||
public byte[] compress(byte[] input){
|
||||
public byte[] compress(byte[] input) {
|
||||
try {
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(input);
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
compress(bais, baos);
|
||||
return baos.toByteArray();
|
||||
} catch (IOException e){
|
||||
} catch (IOException e) {
|
||||
SneakyThrow.throwException(e);
|
||||
}
|
||||
return new byte[0]; // Never reaches here anyway
|
||||
}
|
||||
|
||||
public byte[] decompress(byte[] input){
|
||||
public byte[] decompress(byte[] input) {
|
||||
try {
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(input);
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
decompress(bais, baos);
|
||||
return baos.toByteArray();
|
||||
} catch (IOException e){
|
||||
} catch (IOException e) {
|
||||
SneakyThrow.throwException(e);
|
||||
}
|
||||
return new byte[0]; // Never reaches here anyway
|
||||
|
@ -1,7 +1,12 @@
|
||||
package eu.mikroskeem.uurimustoo.algoritmidetest.algoritmid;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.anarres.lzo.*;
|
||||
import org.anarres.lzo.LzoAlgorithm;
|
||||
import org.anarres.lzo.LzoCompressor;
|
||||
import org.anarres.lzo.LzoDecompressor;
|
||||
import org.anarres.lzo.LzoInputStream;
|
||||
import org.anarres.lzo.LzoLibrary;
|
||||
import org.anarres.lzo.LzoOutputStream;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -17,7 +17,7 @@ public class Zip extends AbstractAlgorithm {
|
||||
|
||||
@Override
|
||||
public void compress(InputStream inputStream, OutputStream outputStream) throws IOException {
|
||||
try(ZipOutputStream out = new ZipOutputStream(outputStream)){
|
||||
try(ZipOutputStream out = new ZipOutputStream(outputStream)) {
|
||||
ZipEntry ze = new ZipEntry("Test.class");
|
||||
out.putNextEntry(ze);
|
||||
byte[] buf = new byte[8192];
|
||||
@ -32,7 +32,7 @@ public class Zip extends AbstractAlgorithm {
|
||||
|
||||
@Override
|
||||
public void decompress(InputStream inputStream, OutputStream outputStream) throws IOException {
|
||||
try(ZipInputStream in = new ZipInputStream(inputStream)){
|
||||
try(ZipInputStream in = new ZipInputStream(inputStream)) {
|
||||
ZipEntry ze = in.getNextEntry();
|
||||
assert ze.getName().equals("Test.class");
|
||||
byte[] buf = new byte[8192];
|
||||
|
Loading…
Reference in New Issue
Block a user