Rewrite from functional style to simplify code

change_data_scheme
Terekhin Alexander 5 years ago
parent e7dd1a131e
commit 9f94469ff1
  1. 20
      src/main/java/me/bearns/fias/helpers/ThrowingBiConsumer.java
  2. 17
      src/main/java/me/bearns/fias/helpers/UpdaterImpl.java

@ -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)) { try (InputStream is = zipFile.getInputStream(entry)) {
log.debug("Process '{}' in zip", entry.getName()); log.debug("Process '{}' in zip", entry.getName());
unmarshaller.process(is, config, filter); 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"); log.debug("Completed Zip file");
} catch (IOException e) { } catch (IOException e) {
log.error("IO Unzip Exception"); log.error("IO Unzip Exception");
throw new UnzipException(e); throw new UnzipException(e);
} catch (RuntimeException e) { } /*catch (RuntimeException e) {
final Throwable cause = e.getCause(); final Throwable cause = e.getCause();
if(cause instanceof CommonException) { if(cause instanceof CommonException) {
@ -156,7 +165,7 @@ public class UpdaterImpl implements UpdateHelper {
} else { } else {
log.error("Unknown exception occured"); log.error("Unknown exception occured");
} }
} }*/
} }
} }

Loading…
Cancel
Save