Skip to content

Commit

Permalink
Refactor optional handling for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
lbergelson committed Oct 4, 2024
1 parent de2ec4c commit 58d48b6
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/main/java/htsjdk/beta/codecs/variants/vcf/VCFDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import htsjdk.variant.vcf.VCFHeader;

import java.io.IOException;
import java.nio.channels.SeekableByteChannel;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;

/**
* InternalAPII
Expand Down Expand Up @@ -197,7 +199,7 @@ private static FeatureReader<VariantContext> getVCFReader(
"The provided %s resource (%s) must be a readable/input resource",
BundleResourceType.CT_VARIANT_CONTEXTS,
variantsResource));
} else if (!variantsResource.getIOPath().isPresent()) {
} else if (variantsResource.getIOPath().isEmpty()) {
throw new HtsjdkUnsupportedOperationException("VCF reader from stream not implemented");
}
final IOPath variantsIOPath = variantsResource.getIOPath().get();
Expand All @@ -207,24 +209,18 @@ private static FeatureReader<VariantContext> getVCFReader(
// matches the one that is automatically resolved, otherwise throw since the request will not be honored
return AbstractFeatureReader.getFeatureReader(
variantsIOPath.getURIString(),
indexIOPath.isPresent() ?
indexIOPath.get().getURIString() :
null,
indexIOPath.map(IOPath::getURIString).orElse(null),
vcfCodec,
indexIOPath.isPresent(),
decoderOptions.getVariantsChannelTransformer().isPresent() ?
decoderOptions.getVariantsChannelTransformer().get() :
null,
decoderOptions.getIndexChannelTransformer().isPresent() ?
decoderOptions.getIndexChannelTransformer().get() :
null
decoderOptions.getVariantsChannelTransformer().orElse(null),
decoderOptions.getIndexChannelTransformer().orElse(null)
);
}

// the underlying readers can't handle index streams, so for now we can only handle IOPaths
private static Optional<IOPath> getIndexIOPath(final Bundle inputBundle) {
final Optional<BundleResource> optIndexResource = inputBundle.get(BundleResourceType.CT_VARIANTS_INDEX);
if (!optIndexResource.isPresent()) {
if (optIndexResource.isEmpty()) {
return Optional.empty();
}
final BundleResource indexResource = optIndexResource.get();
Expand All @@ -234,7 +230,7 @@ private static Optional<IOPath> getIndexIOPath(final Bundle inputBundle) {
BundleResourceType.CT_VARIANTS_INDEX,
indexResource));
}
if (!indexResource.getIOPath().isPresent()) {
if (indexResource.getIOPath().isEmpty()) {
throw new HtsjdkUnsupportedOperationException("Reading a VCF index from a stream not implemented");
}
return indexResource.getIOPath();
Expand Down

0 comments on commit 58d48b6

Please sign in to comment.