本文整理匯總了Java中com.google.common.collect.ImmutableSet.Builder.build方法的典型用法代碼示例。如果您正苦於以下問題:Java Builder.build方法的具體用法?Java Builder.build怎麽用?Java Builder.build使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.collect.ImmutableSet.Builder
的用法示例。
在下文中一共展示了Builder.build方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: adaptMIPResult
import com.google.common.collect.ImmutableSet.Builder; //導入方法依賴的package包/類
protected XORAllocation<T> adaptMIPResult(IMIPResult mipResult) {
Map<Bidder<T>, BidderAllocation<T>> trades = new HashMap<>();
for (Bidder<T> bidder : auction.getBidders()) {
double totalValue = 0;
Builder<Good> goodsBuilder = ImmutableSet.<Good>builder();
Builder<XORValue<T>> bundleBids = ImmutableSet.<XORValue<T>>builder();
for (XORValue<T> bundleBid : auction.getBid(bidder).getValues()) {
if (DoubleMath.fuzzyEquals(mipResult.getValue(getBidVariable(bundleBid)), 1, 1e-3)) {
goodsBuilder.addAll(bundleBid.getLicenses());
bundleBids.add(bundleBid);
totalValue += bundleBid.value().doubleValue();
}
}
Set<Good> goods = goodsBuilder.build();
if (!goods.isEmpty()) {
trades.put(bidder, new BidderAllocation<>(totalValue, new Bundle<>(goods), bundleBids.build()));
}
}
return new XORAllocation<>(trades);
}
示例2: getClassesToCheck
import com.google.common.collect.ImmutableSet.Builder; //導入方法依賴的package包/類
private synchronized Collection<Class<?>> getClassesToCheck()
{
if( classesToCheck == null )
{
Builder<Class<?>> builder = ImmutableSet.builder();
builder.addAll(STATIC_CLASSES_TO_CHECK);
List<Extension> extensions = domainParamTracker.getExtensions();
for( Extension extension : extensions )
{
Collection<Parameter> clazzes = extension.getParameters("class");
for( Parameter clazzParam : clazzes )
{
builder.add(domainParamTracker.getClassForName(extension, clazzParam.valueAsString()));
}
}
classesToCheck = builder.build();
}
return classesToCheck;
}
示例3: getDrillUserConfigurableLogicalRules
import com.google.common.collect.ImmutableSet.Builder; //導入方法依賴的package包/類
/**
* Get a list of logical rules that can be turned on or off by session/system options.
*
* If a rule is intended to always be included with the logical set, it should be added
* to the immutable list created in the getDrillBasicRules() method below.
*
* @param optimizerRulesContext - used to get the list of planner settings, other rules may
* also in the future need to get other query state from this,
* such as the available list of UDFs (as is used by the
* DrillMergeProjectRule created in getDrillBasicRules())
* @return - a list of rules that have been filtered to leave out
* rules that have been turned off by system or session settings
*/
public static RuleSet getDrillUserConfigurableLogicalRules(OptimizerRulesContext optimizerRulesContext) {
final PlannerSettings ps = optimizerRulesContext.getPlannerSettings();
// This list is used to store rules that can be turned on an off
// by user facing planning options
final Builder<RelOptRule> userConfigurableRules = ImmutableSet.<RelOptRule>builder();
if (ps.isConstantFoldingEnabled()) {
// TODO - DRILL-2218
userConfigurableRules.add(ReduceExpressionsRule.PROJECT_INSTANCE);
userConfigurableRules.add(DrillReduceExpressionsRule.FILTER_INSTANCE_DRILL);
userConfigurableRules.add(DrillReduceExpressionsRule.CALC_INSTANCE_DRILL);
}
return new DrillRuleSet(userConfigurableRules.build());
}
示例4: listNodesByIds
import com.google.common.collect.ImmutableSet.Builder; //導入方法依賴的package包/類
@Override
public Iterable<NodeMetadata> listNodesByIds(Iterable<String> ids) {
List<Instance> instances = new ArrayList<Instance>();
for (String id : ids) {
IAcsClient client = api.getAcsClient(api.decodeToRegion(id));
DescribeInstancesRequest req = new DescribeInstancesRequest();
Gson gson = new GsonBuilder().create();
String iids = gson.toJson(new String[] { api.decodeToId(id) });
req.setInstanceIds(iids);
try {
DescribeInstancesResponse resp = client.getAcsResponse(req);
instances.addAll(resp.getInstances());
} catch (Exception e) {
logger.warn(e.getMessage());
}
}
Builder<NodeMetadata> builder = ImmutableSet.builder();
builder.addAll(transform(instances, new InstanceToNodeMetadata(api, nodeStatus)));
return builder.build();
}
示例5: listNodes
import com.google.common.collect.ImmutableSet.Builder; //導入方法依賴的package包/類
@Override
public Iterable<NodeMetadata> listNodes() {
Builder<NodeMetadata> builder = ImmutableSet.builder();
Set<String> regions = api.getAvailableRegions();
for (String region : regions) {
try {
IAcsClient client = api.getAcsClient(region);
DescribeInstancesRequest req = new DescribeInstancesRequest();
DescribeInstancesResponse resp = client.getAcsResponse(req);
builder.addAll(transform(resp.getInstances(), new InstanceToNodeMetadata(api, nodeStatus)));
} catch (Exception e) {
logger.warn(e.getMessage());
}
}
return builder.build();
}
示例6: listImages
import com.google.common.collect.ImmutableSet.Builder; //導入方法依賴的package包/類
@Override
public Iterable<Image> listImages() {
Builder<Image> builder = ImmutableSet.builder();
Set<String> regions = api.getAvailableRegions();
for (String region : regions) {
try {
IAcsClient client = api.getAcsClient(region);
DescribeImagesRequest req = new DescribeImagesRequest();
DescribeImagesResponse resp = client.getAcsResponse(req);
builder.addAll(transform(resp.getImages(), new ImageToImage(api, region)));
} catch (Exception e) {
logger.warn(e.getMessage());
}
}
return builder.build();
}
示例7: getIncomingChannels
import com.google.common.collect.ImmutableSet.Builder; //導入方法依賴的package包/類
public Set<String> getIncomingChannels(Plugin plugin) {
if (plugin == null) {
throw new IllegalArgumentException("Plugin cannot be null");
}
synchronized (incomingLock) {
Set<PluginMessageListenerRegistration> registrations = incomingByPlugin.get(plugin);
if (registrations != null) {
Builder<String> builder = ImmutableSet.builder();
for (PluginMessageListenerRegistration registration : registrations) {
builder.add(registration.getChannel());
}
return builder.build();
} else {
return ImmutableSet.of();
}
}
}
示例8: getIncomingChannelRegistrations
import com.google.common.collect.ImmutableSet.Builder; //導入方法依賴的package包/類
public Set<PluginMessageListenerRegistration> getIncomingChannelRegistrations(Plugin plugin, String channel) {
if (plugin == null) {
throw new IllegalArgumentException("Plugin cannot be null");
}
validateChannel(channel);
synchronized (incomingLock) {
Set<PluginMessageListenerRegistration> registrations = incomingByPlugin.get(plugin);
if (registrations != null) {
Builder<PluginMessageListenerRegistration> builder = ImmutableSet.builder();
for (PluginMessageListenerRegistration registration : registrations) {
if (registration.getChannel().equals(channel)) {
builder.add(registration);
}
}
return builder.build();
} else {
return ImmutableSet.of();
}
}
}
示例9: testUpdateEndpointGroup
import com.google.common.collect.ImmutableSet.Builder; //導入方法依賴的package包/類
@Test
public void testUpdateEndpointGroup() throws Throwable {
Set<Endpoint> expected = ImmutableSet.of(Endpoint.of("127.0.0.1", 8001, 2),
Endpoint.of("127.0.0.1", 8002, 3));
switch (mode) {
case IN_NODE_VALUE:
setNodeValue(NodeValueCodec.DEFAULT.encodeAll(expected));
break;
case IN_CHILD_NODES:
//add two more node
setNodeChild(expected);
//construct the final expected node list
Builder<Endpoint> builder = ImmutableSet.builder();
builder.addAll(sampleEndpoints).addAll(expected);
expected = builder.build();
break;
}
try (CloseableZooKeeper zk = connection()) {
zk.sync(zNode, (rc, path, ctx) -> {
}, null);
}
final Set<Endpoint> finalExpected = expected;
await().untilAsserted(() -> assertThat(endpointGroup.endpoints()).hasSameElementsAs(finalExpected));
}
示例10: adaptArgumentValue
import com.google.common.collect.ImmutableSet.Builder; //導入方法依賴的package包/類
@Override
public Collection<SchemaNodeIdentifier> adaptArgumentValue(
final StmtContext<Collection<SchemaNodeIdentifier>, KeyStatement,
EffectiveStatement<Collection<SchemaNodeIdentifier>, KeyStatement>> ctx,
final QNameModule targetModule) {
final Builder<SchemaNodeIdentifier> builder = ImmutableSet.builder();
boolean replaced = false;
for (final SchemaNodeIdentifier arg : ctx.getStatementArgument()) {
final QName qname = arg.getLastComponent();
if (!targetModule.equals(qname.getModule())) {
final QName newQname = ctx.getFromNamespace(QNameCacheNamespace.class,
QName.create(targetModule, qname.getLocalName()));
builder.add(SchemaNodeIdentifier.SAME.createChild(newQname));
replaced = true;
} else {
builder.add(arg);
}
}
// This makes sure we reuse the collection when a grouping is
// instantiated in the same module
return replaced ? builder.build() : ctx.getStatementArgument();
}
示例11: download
import com.google.common.collect.ImmutableSet.Builder; //導入方法依賴的package包/類
@GET
@Path("{id}/download")
@RequiresRoles(UserRole.ROLE_ADMIN)
@Produces(MediaType.TEXT_PLAIN)
public Response download(@PathParam("id") long id) {
Course course = courseDao.findById(id);
Builder<String> setBuilder = ImmutableSet.builder();
if (course.getProjects().isEmpty()) {
return Response.status(Status.NO_CONTENT).entity("This course doesn't have any projects").build();
} else {
for (Project project : course.getProjects()) {
if (project.getSourceCodeUrl() == null) {
LOG.warn("This project doesnt have a source code URL: {}", project);
} else {
setBuilder.add(project.getSourceCodeUrl());
}
}
Set<String> sourceCodeurls = setBuilder.build();
return Response.ok(repoDownloader.prepareDownload(sourceCodeurls)).build();
}
}
示例12: allCandidatesThatReachedTheQuorum
import com.google.common.collect.ImmutableSet.Builder; //導入方法依賴的package包/類
private ImmutableSet<CANDIDATE> allCandidatesThatReachedTheQuorum(BigFraction quorum,
ImmutableCollection<VoteState<CANDIDATE>> voteStates,
CandidateStates<CANDIDATE> candidateStates) {
VoteDistribution<CANDIDATE> voteDistribution = new VoteDistribution<>(candidateStates.getHopefulCandidates(),
voteStates);
// We use a sorted set here, to provide Unit tests a predictable execution order.
Builder<CANDIDATE> candidatesThatReachedTheQuorum = ImmutableSortedSet.orderedBy(comparing(o -> o.name));
voteDistribution.votesByCandidate.entrySet().stream()
.filter(votesForCandidate -> quorumIsReached(quorum, votesForCandidate))
.forEach(votesForCandidate -> candidatesThatReachedTheQuorum.add(votesForCandidate.getKey()));
return candidatesThatReachedTheQuorum.build();
}
示例13: nextBroadcast
import com.google.common.collect.ImmutableSet.Builder; //導入方法依賴的package包/類
private Iterable<Broadcast> nextBroadcast(Iterable<Broadcast> broadcasts) {
DateTime now = clock.now();
DateTime earliest = null;
Builder<Broadcast> filteredBroadcasts = ImmutableSet.builder();
for (Broadcast broadcast : broadcasts) {
DateTime transmissionTime = broadcast.getTransmissionTime();
if (transmissionTime.isAfter(now) && (earliest == null || transmissionTime.isBefore(
earliest))) {
earliest = transmissionTime;
filteredBroadcasts = ImmutableSet.<Broadcast>builder().add(broadcast);
} else if (transmissionTime.isEqual(earliest)) {
filteredBroadcasts.add(broadcast);
}
}
return filteredBroadcasts.build();
}
示例14: getPermutationsConditions
import com.google.common.collect.ImmutableSet.Builder; //導入方法依賴的package包/類
private Set<String> getPermutationsConditions(ResourceContext context,
List<String> permutationAxes) {
Builder<String> setBuilder = ImmutableSet.builder();
PropertyOracle oracle = context.getGeneratorContext().getPropertyOracle();
for (String permutationAxis : permutationAxes) {
String propValue = null;
try {
SelectionProperty selProp = oracle.getSelectionProperty(null,
permutationAxis);
propValue = selProp.getCurrentValue();
} catch (BadPropertyValueException e) {
try {
ConfigurationProperty confProp = oracle.getConfigurationProperty(permutationAxis);
propValue = confProp.getValues().get(0);
} catch (BadPropertyValueException e1) {
e1.printStackTrace();
}
}
if (propValue != null) {
setBuilder.add(permutationAxis + ":" + propValue);
}
}
return setBuilder.build();
}
示例15: getSelectedDays
import com.google.common.collect.ImmutableSet.Builder; //導入方法依賴的package包/類
public ImmutableSet<Day> getSelectedDays() {
final Builder<Day> selectedDays = ImmutableSet.<Day> builder();
ViewVisitor.visitAll(this, new ViewVisitorCallback() {
@Override
public void onViewVisited(View view) {
if (view instanceof CheckBox && view.getTag() instanceof Day) {
CheckBox checkbox = (CheckBox) view;
Day day = (Day) checkbox.getTag();
if (checkbox.isChecked()) {
selectedDays.add(day);
}
}
}
});
return selectedDays.build();
}