com.exasol.adapter.document.documentfetcher.files.segmentation.FileSegmentDescriptionMatcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of virtual-schema-common-document-files Show documentation
Show all versions of virtual-schema-common-document-files Show documentation
Adapter for document data access from files.
package com.exasol.adapter.document.documentfetcher.files.segmentation;
import java.util.List;
/**
* This class matches part descriptions of a file against a {@link FileSegmentDescription}.
*/
public class FileSegmentDescriptionMatcher {
private final FileSegmentDescription segmentDescription;
/**
* Create a new {@link FileSegmentDescriptionMatcher}.
*
* @param segmentDescription segment description
*/
public FileSegmentDescriptionMatcher(final FileSegmentDescription segmentDescription) {
this.segmentDescription = segmentDescription;
}
/**
* Matches part descriptions of a file against a {@link FileSegmentDescription}.
*
* @param splits list of parts
* @param type of the part descriptions
* @return matched parts
*/
public List filter(final List splits) {
final int numberOfSegments = this.segmentDescription.getNumberOfSegments();
final double segmentSize = (double) splits.size() / (double) numberOfSegments;
final int segmentId = this.segmentDescription.getSegmentId();
final int start = (int) Math.round(segmentId * segmentSize);
final int end = (int) Math.round((segmentId + 1) * segmentSize);
return splits.subList(start, end);
}
}