当前位置: 首页>>代码示例>>Java>>正文


Java Suppliers.memoize方法代码示例

本文整理汇总了Java中com.google.common.base.Suppliers.memoize方法的典型用法代码示例。如果您正苦于以下问题:Java Suppliers.memoize方法的具体用法?Java Suppliers.memoize怎么用?Java Suppliers.memoize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.base.Suppliers的用法示例。


在下文中一共展示了Suppliers.memoize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: newAccessSupplier

import com.google.common.base.Suppliers; //导入方法依赖的package包/类
private <T> Supplier<Set<T>> newAccessSupplier(final JavaClass owner, final Function<JavaClass, Set<T>> doWithEachClass) {

                return Suppliers.memoize(new Supplier<Set<T>>() {
                    @Override
                    public Set<T> get() {
                        ImmutableSet.Builder<T> result = ImmutableSet.builder();
                        for (final JavaClass javaClass : getPossibleTargetClassesForAccess()) {
                            result.addAll(doWithEachClass.apply(javaClass));
                        }
                        return result.build();
                    }

                    private Set<JavaClass> getPossibleTargetClassesForAccess() {
                        return ImmutableSet.<JavaClass>builder()
                                .add(owner)
                                .addAll(owner.getAllSubClasses())
                                .build();
                    }
                });
            }
 
开发者ID:TNG,项目名称:ArchUnit,代码行数:21,代码来源:DomainObjectCreationContext.java

示例2: completeMembers

import com.google.common.base.Suppliers; //导入方法依赖的package包/类
void completeMembers(final ImportContext context) {
    fields = context.createFields(this);
    methods = context.createMethods(this);
    constructors = context.createConstructors(this);
    staticInitializer = context.createStaticInitializer(this);
    codeUnits = ImmutableSet.<JavaCodeUnit>builder()
            .addAll(methods).addAll(constructors).addAll(staticInitializer.asSet())
            .build();
    members = ImmutableSet.<JavaMember>builder()
            .addAll(fields)
            .addAll(methods)
            .addAll(constructors)
            .build();
    this.annotations = Suppliers.memoize(new Supplier<Map<String, JavaAnnotation>>() {
        @Override
        public Map<String, JavaAnnotation> get() {
            return context.createAnnotations(JavaClass.this);
        }
    });
}
 
开发者ID:TNG,项目名称:ArchUnit,代码行数:21,代码来源:JavaClass.java

示例3: DefaultTopology

import com.google.common.base.Suppliers; //导入方法依赖的package包/类
/**
 * Creates a topology descriptor attributed to the specified provider.
 *
 * @param providerId        identity of the provider
 * @param description       data describing the new topology
 * @param broadcastFunction broadcast point function
 */
public DefaultTopology(ProviderId providerId, GraphDescription description,
                       Function<ConnectPoint, Boolean> broadcastFunction) {
    super(providerId);
    this.broadcastFunction = broadcastFunction;
    this.time = description.timestamp();
    this.creationTime = description.creationTime();

    // Build the graph
    this.graph = new DefaultTopologyGraph(description.vertexes(),
                                          description.edges());

    this.clusterResults = Suppliers.memoize(() -> searchForClusters());
    this.clusters = Suppliers.memoize(() -> buildTopologyClusters());

    this.clusterIndexes = Suppliers.memoize(() -> buildIndexes());

    this.hopCountWeight = new HopCountLinkWeight(graph.getVertexes().size());
    this.broadcastSets = Suppliers.memoize(() -> buildBroadcastSets());
    this.infrastructurePoints = Suppliers.memoize(() -> findInfrastructurePoints());
    this.computeCost = Math.max(0, System.nanoTime() - time);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:29,代码来源:DefaultTopology.java

示例4: main

import com.google.common.base.Suppliers; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
    // {{start:memoize}}
    log.info("Memoized");
    Supplier<String> memoized = Suppliers.memoize(SuppliersExamples::helloWorldSupplier);
    log.info(memoized.get());
    log.info(memoized.get());
    // {{end:memoize}}

    // {{start:memoizeWithExpiration}}
    log.info("Memoized with Expiration");
    Supplier<String> memoizedExpiring = Suppliers.memoizeWithExpiration(
        SuppliersExamples::helloWorldSupplier, 50, TimeUnit.MILLISECONDS);
    log.info(memoizedExpiring.get());
    log.info(memoizedExpiring.get());
    log.info("sleeping");
    TimeUnit.MILLISECONDS.sleep(100);
    log.info(memoizedExpiring.get());
    log.info(memoizedExpiring.get());
    log.info("sleeping");
    TimeUnit.MILLISECONDS.sleep(100);
    log.info(memoizedExpiring.get());
    log.info(memoizedExpiring.get());
    // {{end:memoizeWithExpiration}}
}
 
开发者ID:StubbornJava,项目名称:StubbornJava,代码行数:25,代码来源:SuppliersExamples.java

示例5: DataStoreJobStatusDAO

import com.google.common.base.Suppliers; //导入方法依赖的package包/类
@Inject
public DataStoreJobStatusDAO(@JobsTableName final Supplier<String> tableNameSupplier,
                             @JobsTablePlacement final String placement,
                             DataStore dataStore) {
    _dataStore = dataStore;

    _tableNameSupplier = Suppliers.memoize(
        new Supplier<String>() {
            @Override
            public String get() {
                // Lazily ensure the table exists on the first use.
                String tableName = tableNameSupplier.get();
                if (!_dataStore.getTableExists(tableName)) {
                    _dataStore.createTable(tableName,
                            new TableOptionsBuilder().setPlacement(placement).build(),
                            ImmutableMap.<String, String>of(),
                            new AuditBuilder().setLocalHost().setComment("create table").build()
                    );
                }
                return tableName;
            }
        }
    );
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:25,代码来源:DataStoreJobStatusDAO.java

示例6: TUPackingInfo

import com.google.common.base.Suppliers; //导入方法依赖的package包/类
TUPackingInfo(final I_M_HU tuHU)
{
	Check.assumeNotNull(tuHU, "Parameter tuHU is not null");
	this.tuHU = tuHU;

	huProductStorageSupplier = Suppliers.memoize(() -> {
		final List<IHUProductStorage> productStorages = Services.get(IHandlingUnitsBL.class)
				.getStorageFactory()
				.getStorage(tuHU)
				.getProductStorages();
		if (productStorages.size() == 1)
		{
			return productStorages.get(0);
		}
		else
		{
			return null;
		}
	});
}
 
开发者ID:metasfresh,项目名称:metasfresh-webui-api,代码行数:21,代码来源:TUPackingInfo.java

示例7: VHUPackingInfo

import com.google.common.base.Suppliers; //导入方法依赖的package包/类
VHUPackingInfo(final I_M_HU vhu)
{
	Check.assumeNotNull(vhu, "Parameter vhu is not null");
	huProductStorageSupplier = Suppliers.memoize(() -> {
		final List<IHUProductStorage> productStorages = Services.get(IHandlingUnitsBL.class)
				.getStorageFactory()
				.getStorage(vhu)
				.getProductStorages();
		if (productStorages.size() == 1)
		{
			return productStorages.get(0);
		}
		else
		{
			return null;
		}
	});
}
 
开发者ID:metasfresh,项目名称:metasfresh-webui-api,代码行数:19,代码来源:VHUPackingInfo.java

示例8: AggregatedTUPackingInfo

import com.google.common.base.Suppliers; //导入方法依赖的package包/类
public AggregatedTUPackingInfo(final I_M_HU aggregatedTU)
{
	this.aggregatedTU = aggregatedTU;
	huProductStorageSupplier = Suppliers.memoize(() -> {
		final List<IHUProductStorage> productStorages = Services.get(IHandlingUnitsBL.class)
				.getStorageFactory()
				.getStorage(aggregatedTU)
				.getProductStorages();
		if (productStorages.size() == 1)
		{
			return productStorages.get(0);
		}
		else
		{
			return null;
		}
	});
}
 
开发者ID:metasfresh,项目名称:metasfresh-webui-api,代码行数:19,代码来源:AggregatedTUPackingInfo.java

示例9: createBagUserState

import com.google.common.base.Suppliers; //导入方法依赖的package包/类
private <T> BagUserState<T> createBagUserState(String id, Coder<T> coder) {
  BagUserState rval = new BagUserState<T>(
      beamFnStateClient,
      id,
      coder,
      new Supplier<StateRequest.Builder>() {
        /** Memoizes the partial state key for the lifetime of the {@link BagUserState}. */
        private final Supplier<StateKey.BagUserState> memoizingSupplier =
            Suppliers.memoize(() -> createOrUseCachedBagUserStateKey(id))::get;

        @Override
        public Builder get() {
          return StateRequest.newBuilder()
              .setInstructionReference(processBundleInstructionId.get())
              .setStateKey(StateKey.newBuilder()
                  .setBagUserState(memoizingSupplier.get()));
        }
      });
  stateFinalizers.add(rval::asyncClose);
  return rval;
}
 
开发者ID:apache,项目名称:beam,代码行数:22,代码来源:FnApiDoFnRunner.java

示例10: createSources

import com.google.common.base.Suppliers; //导入方法依赖的package包/类
List<BoundedSource<T>> createSources(List<ResourceId> files, TableSchema schema)
    throws IOException, InterruptedException {

  final String jsonSchema = BigQueryIO.JSON_FACTORY.toString(schema);
  SerializableFunction<GenericRecord, T> fnWrapper =
      new SerializableFunction<GenericRecord, T>() {
        private Supplier<TableSchema> schema = Suppliers.memoize(
            Suppliers.compose(new TableSchemaFunction(), Suppliers.ofInstance(jsonSchema)));

        @Override
        public T apply(GenericRecord input) {
          return parseFn.apply(new SchemaAndRecord(input, schema.get()));
        }
      };
  List<BoundedSource<T>> avroSources = Lists.newArrayList();
  for (ResourceId file : files) {
    avroSources.add(
        AvroSource.from(file.toString()).withParseFn(fnWrapper, getOutputCoder()));
  }
  return ImmutableList.copyOf(avroSources);
}
 
开发者ID:apache,项目名称:beam,代码行数:22,代码来源:BigQuerySourceBase.java

示例11: newAstyanaxStorage

import com.google.common.base.Suppliers; //导入方法依赖的package包/类
private AstyanaxStorage newAstyanaxStorage(long uuid, int shardsLog2, boolean readsAllowed, final String placement,
                                           final String table) {
    // Delay resolving the placement until it's used so we can manipulate table metadata for placements that
    // don't replicate to the current data center.
    return new AstyanaxStorage(uuid, shardsLog2, readsAllowed, placement, Suppliers.memoize(new Supplier<Placement>() {
        @Override
        public Placement get() {
            try {
                return _placementCache.get(placement);
            } catch (UnknownPlacementException e) {
                // Add table information to the exception
                e.setTable(table);
                throw e;
            }
        }
    }));
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:18,代码来源:AstyanaxTableDAO.java

示例12: createCallerSupplier

import com.google.common.base.Suppliers; //导入方法依赖的package包/类
private static Supplier<JavaCodeUnit> createCallerSupplier(final RawAccessRecord record, final ImportedClasses classes) {
    return Suppliers.memoize(new Supplier<JavaCodeUnit>() {
        @Override
        public JavaCodeUnit get() {
            return Factory.getCaller(record.caller, classes);
        }
    });
}
 
开发者ID:TNG,项目名称:ArchUnit,代码行数:9,代码来源:AccessRecord.java

示例13: getAnnotations

import com.google.common.base.Suppliers; //导入方法依赖的package包/类
public Supplier<Map<String, JavaAnnotation>> getAnnotations() {
    return Suppliers.memoize(new Supplier<Map<String, JavaAnnotation>>() {
        @Override
        public Map<String, JavaAnnotation> get() {
            return buildAnnotations(annotations, importedClasses);
        }
    });
}
 
开发者ID:TNG,项目名称:ArchUnit,代码行数:9,代码来源:DomainBuilders.java

示例14: construct

import com.google.common.base.Suppliers; //导入方法依赖的package包/类
@Override
JavaMethod construct(JavaMethodBuilder builder, final ClassesByTypeName importedClasses) {
    if (annotationDefaultValueBuilder.isPresent()) {
        annotationDefaultValue = Suppliers.memoize(new Supplier<Optional<Object>>() {
            @Override
            public Optional<Object> get() {
                return annotationDefaultValueBuilder.get().build(importedClasses);
            }
        });
    }
    return DomainObjectCreationContext.createJavaMethod(builder);
}
 
开发者ID:TNG,项目名称:ArchUnit,代码行数:13,代码来源:DomainBuilders.java

示例15: JavaClass

import com.google.common.base.Suppliers; //导入方法依赖的package包/类
JavaClass(JavaClassBuilder builder) {
    source = checkNotNull(builder.getSource());
    javaType = checkNotNull(builder.getJavaType());
    isInterface = builder.isInterface();
    isEnum = builder.isEnum();
    modifiers = checkNotNull(builder.getModifiers());
    reflectSupplier = Suppliers.memoize(new ReflectClassSupplier());
}
 
开发者ID:TNG,项目名称:ArchUnit,代码行数:9,代码来源:JavaClass.java


注:本文中的com.google.common.base.Suppliers.memoize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。