class OpearFile implements Opear {

    public static Result<OpearFile> fromDirectory(final @NotNull File directory) {
        return Result.success(Optional.of(new File(directory, JarFile.MANIFEST_NAME)))
                .flatMap(oMfFile -> oMfFile
                        // non-existent manifest should indicate simple directory.
                        // see .orElseGet() at the end of this chain
                        .filter(File::exists)
                        // if the manifest file exists, expect a valid manifest object.
                        .map(OpearFile::readExpectedManifest)
                        .map(manResult -> manResult.flatMap(OpearFile::validateOpearManifest))
                        // only when manifest file does not exist, return success with simple metadata
                        .orElseGet(() -> Result.success(metaForSimpleDir(directory)))
                )
                .map(meta -> new OpearFile(directory, meta));
    }

      OpearFile(final File cacheDir, final OpearMetadata metadata);

}