All Downloads are FREE. Search and download functionalities are using the official Maven repository.

internal.sdmxdl.ext.PersistenceLoader Maven / Gradle / Ivy

The newest version!
package internal.sdmxdl.ext;

import java.lang.Iterable;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.ServiceLoader;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import sdmxdl.ext.Persistence;

/**
 * Custom service loader for {@link sdmxdl.ext.Persistence}.
 * 
This class is thread-safe. *

Properties: *

    *
  • Quantifier: MULTIPLE
  • *
  • Fallback: null
  • *
  • Preprocessing: wrapper: none filters:[] sorters:[getPersistenceRank]
  • *
  • Mutability: NONE
  • *
  • Singleton: false
  • *
  • Name: internal.{{canonicalName}}Loader
  • *
  • Backend: null
  • *
  • Cleaner: null
  • *
  • Batch: false
  • *
  • Batch name: null
  • *
*/ public final class PersistenceLoader { public static final Pattern ID_PATTERN = Pattern.compile("^[A-Z0-9]+(?:_[A-Z0-9]+)*$"); private final Iterable source = ServiceLoader.load(Persistence.class); private final Predicate filter = o -> ID_PATTERN.matcher(o.getPersistenceId()).matches(); private final Comparator sorter = Collections.reverseOrder(Comparator.comparingInt(Persistence::getPersistenceRank)); private final List resource = doLoad(); private List doLoad() { return StreamSupport.stream(source.spliterator(), false) .filter(filter) .sorted(sorter) .collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList)); } /** * Gets a list of {@link sdmxdl.ext.Persistence} instances. *
This method is thread-safe. * @return the current non-null value */ public List get() { return resource; } /** * Gets a list of {@link sdmxdl.ext.Persistence} instances. *
This is equivalent to the following code: new PersistenceLoader().get() *
Therefore, the returned value might be different at each call. *
This method is thread-safe. * @return a non-null value */ public static List load() { return new PersistenceLoader().get(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy