Skip to content

Commit

Permalink
Simplify class hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
charphi committed Feb 24, 2022
1 parent 01ceaa0 commit 85e1ca3
Show file tree
Hide file tree
Showing 63 changed files with 244 additions and 1,004 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- Replace `SdmxWebConnection#ping()` with `SdmxConnection#testConnection()`
- Refactor data query API [#218](https://github.com/nbbrd/sdmx-dl/issues/218)
- Replace `SdmxConnection#isDetailSupported()` with a more general solution [#89](https://github.com/nbbrd/sdmx-dl/issues/89)
- Simplify class hierarchy [#222](https://github.com/nbbrd/sdmx-dl/issues/222)

### Fixed

Expand Down
45 changes: 0 additions & 45 deletions sdmx-dl-api/src/main/java/internal/sdmxdl/FunctionalListener.java

This file was deleted.

35 changes: 0 additions & 35 deletions sdmx-dl-api/src/main/java/internal/sdmxdl/LoggingListener.java

This file was deleted.

32 changes: 0 additions & 32 deletions sdmx-dl-api/src/main/java/internal/sdmxdl/NoOpListener.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import lombok.AccessLevel;
import org.checkerframework.checker.nullness.qual.NonNull;
import sdmxdl.*;
import sdmxdl.web.SdmxWebConnection;

import java.io.IOException;
import java.util.Collection;
Expand All @@ -34,16 +33,16 @@
*/
@SuppressWarnings("ConstantConditions")
@lombok.AllArgsConstructor(access = AccessLevel.PACKAGE)
final class FailsafeWebConnection implements SdmxWebConnection {
final class FailsafeConnection implements SdmxConnection {

static SdmxWebConnection wrap(SdmxWebConnection obj) {
if (obj instanceof FailsafeWebConnection) return obj;
static SdmxConnection wrap(SdmxConnection obj) {
if (obj instanceof FailsafeConnection) return obj;
FailsafeLogging logging = FailsafeLogging.of(FailsafeWebDriver.class);
return new FailsafeWebConnection(obj, logging::logUnexpectedError, logging::logUnexpectedNull);
return new FailsafeConnection(obj, logging::logUnexpectedError, logging::logUnexpectedNull);
}

@lombok.NonNull
private final SdmxWebConnection delegate;
private final SdmxConnection delegate;

@lombok.NonNull
private final BiConsumer<? super String, ? super RuntimeException> onUnexpectedError;
Expand All @@ -60,23 +59,6 @@ public void testConnection() throws IOException {
}
}

@Override
public String getDriver() throws IOException {
String result;

try {
result = delegate.getDriver();
} catch (RuntimeException ex) {
throw unexpectedError(ex, "while getting driver");
}

if (result == null) {
throw unexpectedNull("driver");
}

return result;
}

@Override
public Collection<Dataflow> getFlows() throws IOException {
Collection<Dataflow> result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package internal.sdmxdl.web.spi;

import lombok.AccessLevel;
import sdmxdl.web.SdmxWebConnection;
import sdmxdl.SdmxConnection;
import sdmxdl.web.SdmxWebSource;
import sdmxdl.web.spi.SdmxWebContext;
import sdmxdl.web.spi.SdmxWebDriver;
Expand Down Expand Up @@ -90,11 +90,11 @@ public boolean isAvailable() {
}

@Override
public SdmxWebConnection connect(SdmxWebSource source, SdmxWebContext context) throws IOException, IllegalArgumentException {
public SdmxConnection connect(SdmxWebSource source, SdmxWebContext context) throws IOException, IllegalArgumentException {
Objects.requireNonNull(source);
Objects.requireNonNull(context);

SdmxWebConnection result;
SdmxConnection result;

try {
result = delegate.connect(source, context);
Expand All @@ -108,7 +108,7 @@ public SdmxWebConnection connect(SdmxWebSource source, SdmxWebContext context) t
throw newUnexpectedNull("null connection");
}

return FailsafeWebConnection.wrap(result);
return FailsafeConnection.wrap(result);
}

@Override
Expand Down
10 changes: 9 additions & 1 deletion sdmx-dl-api/src/main/java/sdmxdl/SdmxManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import java.io.IOException;
import java.util.List;
import java.util.function.BiConsumer;

/**
* @author Philippe Charles
Expand All @@ -35,13 +36,20 @@
SdmxWebManager.class
})
@ThreadSafe
public abstract class SdmxManager<SOURCE> {
public abstract class SdmxManager<SOURCE extends SdmxSource> {

public abstract @NonNull SdmxConnection getConnection(@NonNull SOURCE source) throws IOException;

public abstract @NonNull LanguagePriorityList getLanguages();

public abstract @NonNull SdmxCache getCache();

public abstract @NonNull BiConsumer<? super SOURCE, ? super String> getEventListener();

public abstract @NonNull List<SdmxDialect> getDialects();

public static final BiConsumer<SdmxSource, String> NO_OP_EVENT_LISTENER = SdmxManager::doNothing;

private static void doNothing(SdmxSource source, String message) {
}
}
12 changes: 12 additions & 0 deletions sdmx-dl-api/src/main/java/sdmxdl/SdmxSource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package sdmxdl;

import nbbrd.design.SealedType;
import sdmxdl.file.SdmxFileSource;
import sdmxdl.web.SdmxWebSource;

@SealedType({
SdmxFileSource.class,
SdmxWebSource.class
})
public abstract class SdmxSource {
}
52 changes: 0 additions & 52 deletions sdmx-dl-api/src/main/java/sdmxdl/file/SdmxFileConnection.java

This file was deleted.

33 changes: 0 additions & 33 deletions sdmx-dl-api/src/main/java/sdmxdl/file/SdmxFileListener.java

This file was deleted.

6 changes: 4 additions & 2 deletions sdmx-dl-api/src/main/java/sdmxdl/file/SdmxFileManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import lombok.AccessLevel;
import org.checkerframework.checker.nullness.qual.NonNull;
import sdmxdl.LanguagePriorityList;
import sdmxdl.SdmxConnection;
import sdmxdl.SdmxManager;
import sdmxdl.ext.SdmxCache;
import sdmxdl.ext.spi.SdmxDialect;
Expand All @@ -31,6 +32,7 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;

/**
* @author Philippe Charles
Expand Down Expand Up @@ -58,7 +60,7 @@ public static SdmxFileManager ofServiceLoader() {

@lombok.NonNull
@lombok.Builder.Default
SdmxFileListener eventListener = SdmxFileListener.getDefault();
BiConsumer<? super SdmxFileSource, ? super String> eventListener = NO_OP_EVENT_LISTENER;

@lombok.NonNull
@lombok.Singular
Expand All @@ -73,7 +75,7 @@ public static SdmxFileManager ofServiceLoader() {
SdmxFileContext context = initContext();

@Override
public @NonNull SdmxFileConnection getConnection(@NonNull SdmxFileSource source) throws IOException {
public @NonNull SdmxConnection getConnection(@NonNull SdmxFileSource source) throws IOException {
Objects.requireNonNull(source);

SdmxFileReader reader = lookupReader(source)
Expand Down
4 changes: 3 additions & 1 deletion sdmx-dl-api/src/main/java/sdmxdl/file/SdmxFileSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import sdmxdl.DataflowRef;
import sdmxdl.SdmxSource;

import java.io.File;

Expand All @@ -27,7 +28,8 @@
*/
@lombok.Value
@lombok.Builder(toBuilder = true)
public class SdmxFileSource {
@lombok.EqualsAndHashCode(callSuper = false)
public class SdmxFileSource extends SdmxSource {

@lombok.NonNull
File data;
Expand Down
Loading

0 comments on commit 85e1ca3

Please sign in to comment.