Rewrite from functional style to simplify code

This commit is contained in:
Terekhin Alexander
2020-09-18 19:36:25 +03:00
parent e7dd1a131e
commit 9f94469ff1
2 changed files with 13 additions and 24 deletions
@@ -1,20 +0,0 @@
package me.bearns.fias.helpers;
import me.bearns.fias.exceptions.UnmarshallingException;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import java.util.function.BiConsumer;
public interface ThrowingBiConsumer<K extends UnmarshallerParameters, V extends ZipArchiveEntry, E extends Throwable> {
void accept(K k, V v) throws E;
static <K extends UnmarshallerParameters, V extends ZipArchiveEntry, E extends Throwable> BiConsumer<K,V> unchecked(ThrowingBiConsumer<K, V, E> f) {
return (k,v) -> {
try {
f.accept(k,v);
} catch (Throwable e) {
throw new RuntimeException(e);
};
};
}
}
@@ -135,19 +135,28 @@ public class UpdaterImpl implements UpdateHelper {
}
}
map.forEach(ThrowingBiConsumer.unchecked((config, entry) -> {
/* map.forEach(ThrowingBiConsumer.unchecked((config, entry) -> {
try (InputStream is = zipFile.getInputStream(entry)) {
log.debug("Process '{}' in zip", entry.getName());
unmarshaller.process(is, config, filter);
}
}));
}));*/
for (Map.Entry<UnmarshallerParameters, ZipArchiveEntry> next : map.entrySet()) {
final UnmarshallerParameters config = next.getKey();
final ZipArchiveEntry entry = next.getValue();
try (InputStream is = zipFile.getInputStream(entry)) {
log.debug("Process '{}' in zip", entry.getName());
unmarshaller.process(is, config, filter);
}
}
log.debug("Completed Zip file");
} catch (IOException e) {
log.error("IO Unzip Exception");
throw new UnzipException(e);
} catch (RuntimeException e) {
} /*catch (RuntimeException e) {
final Throwable cause = e.getCause();
if(cause instanceof CommonException) {
@@ -156,7 +165,7 @@ public class UpdaterImpl implements UpdateHelper {
} else {
log.error("Unknown exception occured");
}
}
}*/
}
}