本文整理汇总了Java中com.google.common.collect.ImmutableList.isEmpty方法的典型用法代码示例。如果您正苦于以下问题:Java ImmutableList.isEmpty方法的具体用法?Java ImmutableList.isEmpty怎么用?Java ImmutableList.isEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.ImmutableList
的用法示例。
在下文中一共展示了ImmutableList.isEmpty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.google.common.collect.ImmutableList; //导入方法依赖的package包/类
public static void main(String... args) {
Parser templateParser = Parboiled.createParser(Parser.class);
ParsingResult<Object> result = new ReportingParseRunner<>(templateParser.Unit()).run(input2);
ImmutableList<Object> copy = ImmutableList.copyOf(result.valueStack.iterator());
if (!copy.isEmpty()) {
Unit unit = (Unit) copy.get(0);
Unit balance = Balancing.balance(unit);
System.out.println(balance);
}
if (result.hasErrors()) {
System.err.println(ErrorUtils.printParseErrors(result.parseErrors));
}
// System.out.println(ParseTreeUtils.printNodeTree(result));
}
示例2: computeDependencyGraph
import com.google.common.collect.ImmutableList; //导入方法依赖的package包/类
/**
* Recursive part of {@link #computeDependencyGraph(Set, Multimap, Multimap, Collection)}. The given project is
* processed only if it has not been processed already. If that is the case, it will either be added to the given
* list of independent projects, or a dependency from the given project to each of the projects it depends on is
* added. Finally, the algorithm calls itself for each dependency.
*
* @param project
* the project being processed
* @param visitedProjects
* set of projects already processed
* @param pendencies
* maps projects to the projects that depend on them
* @param dependencies
* maps projects to the projects they depend on
* @param independent
* projects without dependencies
*/
private static void computeDependencyGraph(IN4JSProject project, Set<IN4JSProject> visitedProjects,
Multimap<IN4JSProject, IN4JSProject> pendencies,
Multimap<IN4JSProject, IN4JSProject> dependencies, Collection<IN4JSProject> independent) {
if (!visitedProjects.add(project))
return;
ImmutableList<? extends IN4JSProject> pendingProjects = project.getDependenciesAndImplementedApis();
if (pendingProjects.isEmpty()) {
independent.add(project);
} else {
for (IN4JSProject pendingProject : pendingProjects) {
pendencies.put(pendingProject, project);
dependencies.put(project, pendingProject);
computeDependencyGraph(pendingProject, visitedProjects, pendencies, dependencies, independent);
}
}
}
示例3: ServiceManager
import com.google.common.collect.ImmutableList; //导入方法依赖的package包/类
/**
* Constructs a new instance for managing the given services.
*
* @param services The services to manage
*
* @throws IllegalArgumentException if not all services are {@linkplain State#NEW new} or if there
* are any duplicate services.
*/
public ServiceManager(Iterable<? extends Service> services) {
ImmutableList<Service> copy = ImmutableList.copyOf(services);
if (copy.isEmpty()) {
// Having no services causes the manager to behave strangely. Notably, listeners are never
// fired. To avoid this we substitute a placeholder service.
logger.log(
Level.WARNING,
"ServiceManager configured with no services. Is your application configured properly?",
new EmptyServiceManagerWarning());
copy = ImmutableList.<Service>of(new NoOpService());
}
this.state = new ServiceManagerState(copy);
this.services = copy;
WeakReference<ServiceManagerState> stateReference =
new WeakReference<ServiceManagerState>(state);
for (Service service : copy) {
service.addListener(new ServiceListener(service, stateReference), directExecutor());
// We check the state after adding the listener as a way to ensure that our listener was added
// to a NEW service.
checkArgument(service.state() == NEW, "Can only manage NEW services, %s", service);
}
// We have installed all of our listeners and after this point any state transition should be
// correct.
this.state.markReady();
}
示例4: parse
import com.google.common.collect.ImmutableList; //导入方法依赖的package包/类
public static KillRewardModule parse(MapModuleContext context, Logger logger, Document doc) throws InvalidXMLException {
ImmutableList.Builder<KillReward> rewards = ImmutableList.builder();
final ItemParser itemParser = context.needModule(ItemParser.class);
final Optional<ItemModifyModule> itemModifier = context.module(ItemModifyModule.class);
// Must allow top-level children for legacy support
for(Element elKillReward : XMLUtils.flattenElements(doc.getRootElement(), ImmutableSet.of("kill-rewards"), ImmutableSet.of("kill-reward", "killreward"), 0)) {
ImmutableList.Builder<ItemStack> items = ImmutableList.builder();
for(Element itemEl : elKillReward.getChildren("item")) {
final ItemStack item = itemParser.parseItem(itemEl, false);
itemModifier.ifPresent(imm -> imm.applyRules(item));
items.add(item.immutableCopy());
}
Filter filter = context.needModule(FilterParser.class).property(elKillReward, "filter").optional(StaticFilter.ALLOW);
Kit kit = context.needModule(KitParser.class).property(elKillReward, "kit").optional(KitNode.EMPTY);
rewards.add(new KillReward(items.build(), filter, kit));
}
ImmutableList<KillReward> list = rewards.build();
if(list.isEmpty()) {
return null;
} else {
return new KillRewardModule(list);
}
}
示例5: accept
import com.google.common.collect.ImmutableList; //导入方法依赖的package包/类
@Override
public void accept(SiteConfig siteConfig, ImmutableList<Document> documents) {
if (!documents.isEmpty()) {
System.out.println("-------------------------");
System.out.println("Documents: ");
documents.forEach(d -> {
System.out.println(" - "+d.path());
});
System.out.println("-------------------------");
if (showContent) {
documents.forEach(d -> {
if (d.content() instanceof Text) {
System.out.println(" - "+d.path());
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println(((Text) d.content()).text());
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
});
}
} else {
System.out.println("-------------------------");
System.out.println("No generated Documents.");
System.out.println("-------------------------");
}
}
示例6: doInsert
import com.google.common.collect.ImmutableList; //导入方法依赖的package包/类
protected final FluentFuture<Integer> doInsert(final ImmutableList<T> documents) {
if (documents.isEmpty()) {
return FluentFutures.from(Futures.immediateFuture(0));
}
return submit(new Callable<Integer>() {
@Override
public Integer call() {
collection().insertMany(documents);
return 0; // java driver for mongo returns 0 anyway
}
});
}
示例7: asToml
import com.google.common.collect.ImmutableList; //导入方法依赖的package包/类
private static void asToml(StringBuilder sb, ImmutableList<String> parentKey, int skipIndent, String key, List<Either<Object, ? extends PropertyTree>> values) {
ImmutableList<String> currentKey = append(parentKey, key);
if (values.size()==1) {
Either<Object, ? extends PropertyTree> either = values.get(0);
if (either.isLeft()) {
Object value = either.left();
sb.append(indent(parentKey, skipIndent)).append(key).append(" = ").append(valueAsToml(value)).append("\n");
} else {
PropertyTree propertyTree = either.right();
boolean renderTreeKey = !containsOnlyOtherPropertyTrees(propertyTree);
if (renderTreeKey) {
sb.append(indent(parentKey, skipIndent)).append("[").append(Joiner.on(".").join(currentKey)).append("]").append("\n");
}
asToml(sb, propertyTree, currentKey, renderTreeKey ? skipIndent : skipIndent+1);
}
} else {
ImmutableList<Object> onlyValues = values.stream().filter(Either::isLeft).map(e -> e.left()).collect(ImmutableList.toImmutableList());
ImmutableList<? extends PropertyTree> onlyTrees = values.stream().filter(e -> !e.isLeft()).map(e -> e.right()).collect(ImmutableList.toImmutableList());
if (!onlyValues.isEmpty() && onlyTrees.isEmpty()) {
sb.append(indent(parentKey, skipIndent)).append(key).append(" = ").append("[")
.append(onlyValues.stream().map(v -> valueAsToml(v)).collect(Collectors.joining(", ")))
.append("]\n");
} else {
if (onlyValues.isEmpty() && !onlyTrees.isEmpty()) {
onlyTrees.forEach(t -> {
asToml(sb, t, currentKey, skipIndent);
});
} else {
throw new IllegalArgumentException("not supported: "+key+" = "+values);
}
}
}
}
示例8: initFreshKey
import com.google.common.collect.ImmutableList; //导入方法依赖的package包/类
private void initFreshKey() {
//no local metadata found, fresh key
final ImmutableList<String> siaPaths = loadMetaData();
final Map<String, String> filenameLookup;
if (siaPaths == null) {
//case FreshUnreachable
LOGGER.error("metadata was fresh but unreachable, erroring out");
throw new IllegalStateException("fresh key, unable to locate metadata ");
} else if (siaPaths.isEmpty()) {
//case FreshEmpty
LOGGER.info("metadata was fresh but empty, assuming a fresh file system");
initializedDownloadService = new NothingTodoDownloadService();
filenameLookup = Maps.newHashMap();
} else {
LOGGER.info("metadata was fresh and nonempty, we have work to do to restore up to {} files", siaPaths.size());
//stopping siad here. extractSiaLookupMap will add new files. then restart / init the seed
siaProcessController.stopProcess();
filenameLookup = extractSiaLookupMap(siaPaths);
siaProcessController.startProcess();
siaUtil.waitForConsensus();
siaUtil.unlockWallet(siaSeedService.getSiaSeed());
//todo init the seed. this will take a while. nevertheless we don't want to assign initializedDownloadService just yet, because it would not be ready.
initializedDownloadService = buildSiaDownload(filenameLookup);
}
LOGGER.info("writing out info about metadata so we can later start up even if offline");
final MetaDataStatus toWrite = new MetaDataStatus();
toWrite.lookup = filenameLookup;
metaDataStatusProvider.write(toWrite);
}
示例9: hasDataSetForLabels
import com.google.common.collect.ImmutableList; //导入方法依赖的package包/类
/**
* Asserts that the distribution for the given label can be constructed from the given data set.
*
* <p>Note that this only tests that the distribution has the same binned histogram, along with
* the same mean, and sum of squared deviation as it would if it had recorded the specified data
* points. It could have in fact collected different data points that resulted in the same
* distribution, but that information is lost to us and cannot be tested.
*/
public And<DistributionMetricSubject> hasDataSetForLabels(
ImmutableSet<? extends Number> dataSet, String... labels) {
ImmutableList<MetricPoint<Distribution>> metricPoints = actual().getTimestampedValues();
if (metricPoints.isEmpty()) {
failWithBadResults(
"has a distribution for labels", Joiner.on(':').join(labels), "has", "no values");
}
MutableDistribution targetDistribution =
new MutableDistribution(metricPoints.get(0).value().distributionFitter());
dataSet.forEach(data -> targetDistribution.add(data.doubleValue()));
return hasValueForLabels(ImmutableDistribution.copyOf(targetDistribution), labels);
}
示例10: loadFrom
import com.google.common.collect.ImmutableList; //导入方法依赖的package包/类
public static QuoteFilter loadFrom(ByteSource source) throws IOException {
final ImmutableList<String> input = source.asCharSource(Charsets.UTF_8).readLines();
if (input.isEmpty()) {
throw new IOException("Attempted to load QuoteFilter from empty file");
}
final int numEntries = Integer.parseInt(input.get(0));
final int expectedLines = 2 * numEntries + 1;
if (input.size() != expectedLines) {
throw new IOException(String.format(
"Invalid number of lines when loading QuoteFiler. Expected %d, got %d",
expectedLines, input.size()));
}
final ImmutableMap.Builder<Symbol, ImmutableRangeSet<Integer>> ret = ImmutableMap.builder();
int curLine = 1;
for (int i = 0; i < numEntries; ++i) {
final Symbol docid = Symbol.from(input.get(curLine++));
final ImmutableRangeSet.Builder<Integer> ranges = ImmutableRangeSet.builder();
for (final String part : StringUtils.OnSpaces.split(input.get(curLine++))) {
final List<String> endPointStrings = DASH_SPLITTER.splitToList(part);
if (endPointStrings.size() != 2) {
throw new IOException(String.format("Invalid range serialization %s", part));
}
ranges.add(Range.closed(Integer.parseInt(endPointStrings.get(0)),
Integer.parseInt(endPointStrings.get(1))));
}
ret.put(docid, ranges.build());
}
return QuoteFilter.createFromBannedRegions(ret.build());
}
示例11: validate
import com.google.common.collect.ImmutableList; //导入方法依赖的package包/类
public void validate(final Set<TransactionConfigEntityData> transactionConfigEntityData, final Set<MatchingServiceConfigEntityData> matchingServiceConfigEntityData) {
Collection<CertificateDetails> certificateDetails = certificateDtoTransformer.transform(transactionConfigEntityData, matchingServiceConfigEntityData);
ImmutableList<InvalidCertificateDto> invalidCertificates = certificateValidityChecker.getInvalidCertificates(certificateDetails);
if (!invalidCertificates.isEmpty()) {
throw createInvalidCertificatesException(invalidCertificates);
}
}
示例12: parsePost
import com.google.common.collect.ImmutableList; //导入方法依赖的package包/类
public Post parsePost(Element el) throws InvalidXMLException {
checkDeprecatedFilter(el);
final Optional<TeamFactory> owner = teamParser.property(el, "owner").optional();
boolean sequential = XMLUtils.parseBoolean(el.getAttribute("sequential"), false);
boolean permanent = XMLUtils.parseBoolean(el.getAttribute("permanent"), false);
double pointsPerSecond = XMLUtils.parseNumber(el.getAttribute("points-rate"), Double.class, 0D);
Filter pickupFilter = filterParser.property(el, "pickup-filter").optional(StaticFilter.ALLOW);
Duration recoverTime = XMLUtils.parseDuration(Node.fromAttr(el, "recover-time", "return-time"), Post.DEFAULT_RETURN_TIME);
Duration respawnTime = XMLUtils.parseDuration(el.getAttribute("respawn-time"), null);
Double respawnSpeed = XMLUtils.parseNumber(el.getAttribute("respawn-speed"), Double.class, (Double) null);
ImmutableList<PointProvider> returnPoints = ImmutableList.copyOf(pointParser.parse(el, new PointProviderAttributes()));
if(respawnTime == null && respawnSpeed == null) {
respawnSpeed = Post.DEFAULT_RESPAWN_SPEED;
}
if(respawnTime != null && respawnSpeed != null) {
throw new InvalidXMLException("post cannot have both respawn-time and respawn-speed", el);
}
if(returnPoints.isEmpty()) {
throw new InvalidXMLException("post must have at least one point provider", el);
}
return context.features().define(el, Post.class, new PostImpl(owner, recoverTime, respawnTime, respawnSpeed, returnPoints, sequential, permanent, pointsPerSecond, pickupFilter));
}
示例13: checkKeyPresence
import com.google.common.collect.ImmutableList; //导入方法依赖的package包/类
/**
* Checks that an element which is supposed to have a key does have one.
* @param mergingReport report to log warnings and errors.
* @param xmlElement xml element to check for key presence.
* @return true if the element has a valid key or false it does not need one or it is invalid.
*/
private static boolean checkKeyPresence(
MergingReport.Builder mergingReport,
XmlElement xmlElement) {
ManifestModel.NodeKeyResolver nodeKeyResolver = xmlElement.getType().getNodeKeyResolver();
ImmutableList<String> keyAttributesNames = nodeKeyResolver.getKeyAttributesNames();
if (keyAttributesNames.isEmpty()) {
return false;
}
if (Strings.isNullOrEmpty(xmlElement.getKey())) {
// we should have a key but we don't.
String message = keyAttributesNames.size() > 1
? String.format(
"Missing one of the key attributes '%1$s' on element %2$s at %3$s",
Joiner.on(',').join(keyAttributesNames),
xmlElement.getId(),
xmlElement.printPosition())
: String.format(
"Missing '%1$s' key attribute on element %2$s at %3$s",
keyAttributesNames.get(0),
xmlElement.getId(),
xmlElement.printPosition());
xmlElement.addMessage(mergingReport, ERROR, message);
return false;
}
return true;
}
示例14: write
import com.google.common.collect.ImmutableList; //导入方法依赖的package包/类
public Map2D<T> write(final int x, final int y, final ImmutableList<T> xs) {
Preconditions.checkArgument(isInBounds(x, y));
Preconditions.checkNotNull(xs);
if (xs.isEmpty()) {
return this;
}
final T[][] nextValues = Arrays2D.copy(valueType, values);
for (int i = 0; i < xs.size(); i++) {
if (x + i >= width) {
break;
}
nextValues[x + i][y] = xs.get(i);
}
return Map2D.of(width, height, valueType, nextValues);
}
示例15: create
import com.google.common.collect.ImmutableList; //导入方法依赖的package包/类
public static FileSelection create(final FileSystemWrapper fs, Path combined) throws IOException {
Stopwatch timer = Stopwatch.createStarted();
final ImmutableList<FileStatus> statuses = fs.listRecursive(combined, false);
if (statuses == null || statuses.isEmpty()) {
return null;
}
final FileSelection fileSel = create(StatusType.EXPANDED, statuses, combined.toUri().getPath());
logger.debug("FileSelection.create() took {} ms ", timer.elapsed(TimeUnit.MILLISECONDS));
return fileSel;
}