Example usage for com.google.common.base Suppliers memoize

List of usage examples for com.google.common.base Suppliers memoize

Introduction

In this page you can find the example usage for com.google.common.base Suppliers memoize.

Prototype

public static <T> Supplier<T> memoize(Supplier<T> delegate) 

Source Link

Document

Returns a supplier which caches the instance retrieved during the first call to get() and returns that value on subsequent calls to get() .

Usage

From source file:org.jabylon.common.util.config.DynamicConfigUtil.java

private static synchronized void createSuppliers() {
    configTabs = Suppliers.memoize(Suppliers.compose(new IConfigurationElementLoader(),
            Suppliers.ofInstance("org.jabylon.rest.ui.configTab")));
    configSections = Suppliers.memoize(Suppliers.compose(new IConfigurationElementLoader(),
            Suppliers.ofInstance("org.jabylon.rest.ui.config")));

}

From source file:org.apache.beam.sdk.io.AvroUtils.java

/** Helper to get around the fact that {@link Schema} itself is not serializable. */
public static Supplier<Schema> serializableSchemaSupplier(String jsonSchema) {
    return Suppliers.memoize(Suppliers.compose(new JsonToSchema(), Suppliers.ofInstance(jsonSchema)));
}

From source file:org.locationtech.geogig.storage.bdbje.JEStagingDatabase_v0_2.java

private static Supplier<JEObjectDatabase> stagingDbSupplier(final EnvironmentBuilder envBuilder,
        final ConfigDatabase configDB, final Hints hints) {
    return Suppliers.memoize(new Supplier<JEObjectDatabase>() {
        @Override//  w w w .j a  v a2 s.  co  m
        public JEObjectDatabase get() {
            boolean readOnly = hints.getBoolean(Hints.STAGING_READ_ONLY);
            envBuilder.setIsStagingDatabase(true);
            JEObjectDatabase db = new JEObjectDatabase_v0_2(configDB, envBuilder, readOnly,
                    JEStagingDatabase.ENVIRONMENT_NAME);
            return db;
        }
    });
}

From source file:org.locationtech.geogig.storage.bdbje.JEStagingDatabase_v0_1.java

private static Supplier<JEObjectDatabase> stagingDbSupplier(final EnvironmentBuilder envBuilder,
        final ConfigDatabase configDB, final Hints hints) {
    return Suppliers.memoize(new Supplier<JEObjectDatabase>() {
        @Override/*w w w .ja v a2 s. c  o  m*/
        public JEObjectDatabase get() {
            boolean readOnly = hints.getBoolean(Hints.STAGING_READ_ONLY);
            envBuilder.setIsStagingDatabase(true);
            JEObjectDatabase db = new JEObjectDatabase_v0_1(configDB, envBuilder, readOnly,
                    JEStagingDatabase.ENVIRONMENT_NAME);
            return db;
        }
    });
}

From source file:com.eucalyptus.auth.Regions.java

private static <T> Supplier<T> serviceLoaderSupplier(final Class<T> serviceClass) {
    return Suppliers.memoize(new Supplier<T>() {
        @Override/*from w ww .j a v a2  s .com*/
        public T get() {
            return ServiceLoader.load(serviceClass).iterator().next();
        }
    });
}

From source file:com.facebook.buck.android.ClassNodeListSupplier.java

public static Supplier<ImmutableList<ClassNode>> createMemoized(Iterable<Path> jarPaths) {
    return Suppliers.memoize(new ClassNodeListSupplier(jarPaths));
}

From source file:org.immutables.generator.ExtensionLoader.java

public static Supplier<ImmutableSet<String>> findExtensions(final String resource) {
    // Provide lazy-once supplier
    return Suppliers.memoize(new Supplier<ImmutableSet<String>>() {
        @Override//from   w  ww  . ja  v  a2 s  .c  o  m
        public ImmutableSet<String> get() {
            List<String> extensions = Lists.newArrayList();

            // best effort to read it from compilation classpath
            if (StaticEnvironment.isInitialized()) {
                try {
                    String lines = getClasspathResourceText(StaticEnvironment.processing().getFiler(),
                            resource);
                    extensions.addAll(RESOURCE_SPLITTER.splitToList(lines));
                } catch (RuntimeException | IOException cannotReadCompilationClasspath) {
                    // we ignore this as we did or best effort
                    // and there are no plans to halt whole compilation
                }
            }

            ClassLoader classLoader = ExtensionLoader.class.getClassLoader();
            try {
                Enumeration<URL> resources = classLoader.getResources(resource);
                while (resources.hasMoreElements()) {
                    URL nextElement = resources.nextElement();
                    String lines = Resources.toString(nextElement, StandardCharsets.UTF_8);
                    extensions.addAll(RESOURCE_SPLITTER.splitToList(lines));
                }
            } catch (RuntimeException | IOException cannotReadAnnotationProcessingClasspath) {
                // we ignore this as we did or best effort
                // and there are no plans to halt whole compilation
            }
            return FluentIterable.from(extensions).toSet();
        }
    });
}

From source file:org.jabylon.rest.ui.model.ProgressionModel.java

public ProgressionModel(String id) {
    this.modelSupplier = Suppliers.memoize(Suppliers.compose(new LookupFunction(), Suppliers.ofInstance(id)));
    this.id = id;
}

From source file:org.opendaylight.controller.cluster.datastore.identifiers.TransactionChainIdentifier.java

public TransactionChainIdentifier(final String memberName, final long counter) {
    this.memberName = memberName;
    stringRepresentation = Suppliers.memoize(new Supplier<String>() {
        @Override/*ww w . ja  v  a  2  s . co  m*/
        public String get() {
            final StringBuilder sb = new StringBuilder();
            sb.append(memberName).append(CHAIN_SEPARATOR);
            sb.append(counter);
            return sb.toString();
        }
    });
}

From source file:com.google.eclipse.mechanic.internal.ScannersExtensionPoint.java

/**
 * Return the {@link TaskScanner} supplier, initializing it if required.
 *
 * <p>The supplier is memoized, so it will return the same instantiated
 * objects upon repeated calls./*w  w w .j  a va 2 s.  c om*/
 */
public static Supplier<List<TaskScanner>> getInstance() {
    return Suppliers.memoize(new Supplier<List<TaskScanner>>() {
        public List<TaskScanner> get() {
            return SingletonHolder.instance.getInstances();
        }
    });
}