下面列出了com.google.common.collect.Multimap#keys ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void writeValidationIssues(Multimap<URI, LSPIssue> validationIssues, DataOutput output)
throws IOException {
int numberSources = validationIssues.size();
output.writeInt(numberSources);
for (URI source : validationIssues.keys()) {
Collection<LSPIssue> issues = validationIssues.get(source);
output.writeUTF(source.toString());
int numberIssues = issues.size();
output.writeInt(numberIssues);
for (LSPIssue issue : issues) {
issue.writeExternal(output);
}
}
}
private Address getRichest(Multimap<Address, UnspentTransactionOutput> index) {
Address ret = null;
long maxSum = 0;
for (Address address : index.keys()) {
Collection<UnspentTransactionOutput> unspentTransactionOutputs = index.get(address);
long newSum = sum(unspentTransactionOutputs);
if (newSum > maxSum) {
ret = address;
maxSum = newSum;
}
}
return ret;
}
@Override
public void write(Multimap<BulkIngestKey,Value> entries, TaskInputOutputContext<?,?,OK,OV> context) throws IOException, InterruptedException {
inner.write(entries, context);
for (BulkIngestKey key : entries.keys()) {
counts.add(key.getTableName(), 1);
}
}
private Address getRichest(Multimap<Address, UnspentTransactionOutput> index) {
Address ret = null;
long maxSum = 0;
for (Address address : index.keys()) {
Collection<UnspentTransactionOutput> unspentTransactionOutputs = index.get(address);
long newSum = sum(unspentTransactionOutputs);
if (newSum > maxSum) {
ret = address;
maxSum = newSum;
}
}
return ret;
}
/**
* Initial build reads the project state and resolves changes. Generate output files.
* <p>
* This method assumes that it is only invoked in situations when the client does not have any diagnostics stored,
* e.g. directly after invoking {@link #doClean(CancelIndicator)}, and that therefore no 'publishDiagnostics' events
* with an empty list of diagnostics need to be sent to the client in order to remove obsolete diagnostics. The same
* applies to updates of {@link #issueRegistry}, accordingly.
* <p>
* NOTE: this is not only invoked shortly after server startup but also at various other occasions, for example
* <ul>
* <li>when the client executes the {@link N4JSCommandService#rebuild(ILanguageServerAccess, CancelIndicator)
* rebuild command},
* <li>when the workspace folder is changed in VS Code.
* </ul>
*/
public XBuildResult doInitialBuild(CancelIndicator cancelIndicator) {
ResourceChangeSet changeSet = projectStateHolder.readProjectState(projectConfig);
XBuildResult result = doBuild(
changeSet.getModified(), changeSet.getDeleted(), Collections.emptyList(), false, true, cancelIndicator);
// send issues to client
// (below code won't send empty 'publishDiagnostics' events for resources without validation issues, see API doc
// of this method for details)
Multimap<URI, LSPIssue> validationIssues = projectStateHolder.getValidationIssues();
for (URI location : validationIssues.keys()) {
Collection<LSPIssue> issues = validationIssues.get(location);
publishIssues(location, issues);
}
// clear the resource set to release memory
boolean wasDeliver = resourceSet.eDeliver();
try {
resourceSet.eSetDeliver(false);
resourceSet.getResources().clear();
} finally {
resourceSet.eSetDeliver(wasDeliver);
}
LOG.info("Project built: " + this.projectConfig.getName());
return result;
}
void populateCache(Multimap<QualifiedContent, File> cacheableItems)
throws Exception {
for (QualifiedContent input : cacheableItems.keys()) {
FileCache cache =
getBuildCache(
input.getFile(), isExternalLib(input), userLevelCache);
if (cache != null) {
FileCache.Inputs buildCacheInputs =
AtlasDexArchiveBuilderCacheHander.getBuildCacheInputs(
input.getFile(), dexOptions, dexer, minSdkVersion, isDebuggable);
FileCache.QueryResult result =
cache.createFileInCacheIfAbsent(
buildCacheInputs,
in -> {
Collection<File> dexArchives = cacheableItems.get(input);
logger.verbose(
"Merging %1$s into %2$s",
Joiner.on(',').join(dexArchives), in.getAbsolutePath());
mergeJars(in, cacheableItems.get(input));
});
if (result.getQueryEvent().equals(FileCache.QueryEvent.CORRUPTED)) {
Verify.verifyNotNull(result.getCauseOfCorruption());
logger.info(
"The build cache at '%1$s' contained an invalid cache entry.\n"
+ "Cause: %2$s\n"
+ "We have recreated the cache entry.\n"
+ "%3$s",
cache.getCacheDirectory().getAbsolutePath(),
Throwables.getStackTraceAsString(result.getCauseOfCorruption()),
BuildCacheUtils.BUILD_CACHE_TROUBLESHOOTING_MESSAGE);
}
}
}
}
private Address getRichest(Multimap<Address, UnspentTransactionOutput> index) {
Address ret = null;
long maxSum = 0;
for (Address address : index.keys()) {
Collection<UnspentTransactionOutput> unspentTransactionOutputs = index.get(address);
long newSum = sum(unspentTransactionOutputs);
if (newSum > maxSum) {
ret = address;
maxSum = newSum;
}
}
return ret;
}
/**
* Checks that a check's context types are all unique.
*
* @param check
* the check
*/
// TODO there is no reason for a context type to be unique, except that we are too lazy to generate the right code, right?
@Check
public void checkContextTypeIsUnique(final com.avaloq.tools.ddk.check.check.Check check) {
if (check.getContexts().size() < 1) {
return;
}
Multimap<String, Context> mm = Multimaps.newMultimap(Maps.<String, Collection<Context>> newHashMap(), new Supplier<Collection<Context>>() {
@Override
public Collection<Context> get() {
return Lists.newArrayList();
}
});
for (final Context c : check.getContexts()) {
final ContextVariable var = c.getContextVariable();
if (var != null) {
final JvmTypeReference contextType = var.getType();
if (contextType != null && contextType.getType() != null && !contextType.getType().eIsProxy()) {
mm.put(contextType.getType().getIdentifier(), c);
}
}
}
for (String type : mm.keys()) {
final Collection<Context> duplicatesForType = mm.get(type);
if (duplicatesForType.size() > 1) {
for (final Context duplicateContext : duplicatesForType) {
error(Messages.CheckJavaValidator_CONTEXT_TYPES_UNIQUE, duplicateContext.getContextVariable(), //
CheckPackage.Literals.CONTEXT_VARIABLE__TYPE, IssueCodes.CONTEXT_TYPES_NOT_UNIQUE);
}
}
}
}
private void killPerks(List<Blast> blasts) {
// собираем все перки которые уже есть в радиусе
// надо определить кто кого чем кикнул (ызрывные волны могут пересекаться)
Multimap<Hero, PerkOnBoard> deathMatch = HashMultimap.create();
for (Blast blast : blasts) {
Hero hunter = blast.owner();
int index = perks.indexOf(blast);
if (index != -1) {
PerkOnBoard perk = perks.get(index);
deathMatch.put(hunter, perk);
}
}
// у нас есть два списка, прибитые перки
// и те, благодаря кому
Set<PerkOnBoard> preys = new HashSet<>(deathMatch.values());
Set<Hero> hunters = new HashSet<>(deathMatch.keys());
// вначале прибиваем перки
preys.forEach(perk -> pickPerk(perk));
// а потом все виновники получают свои результаты )
hunters.forEach(hunter -> {
if (!hunter.hasPlayer()) {
return;
}
deathMatch.get(hunter).forEach(perk -> {
hunter.event(Events.DROP_PERK);
// TODO может это делать на этапе, когда balsts развиднеется в removeBlasts
blasts.remove(perk);
walls.add(new MeatChopperHunter(perk, hunter));
});
});
}
public boolean isConnectedToLinkedCompany() {
Multimap<MapHex,Station> lStations;
Multimap<MapHex,Station> iStations;
NetworkGraph nwGraph = NetworkGraph.createMapGraph(getRoot());
NetworkGraph companyGraph =
NetworkGraph.createRouteGraph(nwGraph, this, true, false);
SimpleGraph<NetworkVertex, NetworkEdge> graph =
companyGraph.getGraph();
Set<NetworkVertex> verticies = graph.vertexSet();
PublicCompany_1880 linkedCompany =
(PublicCompany_1880) ((Investor_1880) this).getLinkedCompany();
if (linkedCompany != null) {
NetworkGraph linkedCompanyGraph=NetworkGraph.createRouteGraph(nwGraph, linkedCompany, true, false);
// Creating a list of stations blocked by tokens.
// The connection between investor and Linked Company is NOT blocked by any token of any company.
// A token that is counted as blocked can be reached by the company for which it blocks the route.
// Based on that logic a blocking token is reachable by both actors.
lStations = linkedCompanyGraph.getNonPassableStations();
iStations = companyGraph.getNonPassableStations();
//Case A) the token in Question from a linked Company is actually on the route of the Investor
for (BaseToken token : linkedCompany.getLaidBaseTokens()) {
Owner holder = token.getOwner();
if (!(holder instanceof Stop)) continue;
Stop stop = (Stop) holder;
for (NetworkVertex vertex : verticies) {
if (vertex.getType() == NetworkVertex.VertexType.STATION) {
if ((stop.getRelatedStation() == vertex.getStation())
&& (stop.getParent() == vertex.getHex())) {
return true;
}
}
}
}
// Case B) the Blocking Token is not from the linked Company
// so we need to check if the MapHex of a blocking station is showing up in the
// List of non Passable Stations
for (MapHex blockedHex:lStations.keys()) {
if (iStations.containsKey(blockedHex)) {
//Make sure its not an Offboard Map Hex
if (blockedHex.getCurrentTile().getColour().toString() == "RED" ) continue;
if (blockedHex.getStopName().equals("Beijing")) continue;
return true;
}
}
}
return false;
}
private void killWallsAndChoppers(List<Blast> blasts) {
// собираем все разрушаемые стенки которые уже есть в радиусе
// надо определить кто кого чем кикнул (ызрывные волны могут пересекаться)
List<Wall> all = walls.listSubtypes(Wall.class);
Multimap<Hero, Wall> deathMatch = HashMultimap.create();
for (Blast blast : blasts) {
Hero hunter = blast.owner();
int index = all.indexOf(blast);
if (index != -1) {
Wall wall = all.get(index);
deathMatch.put(hunter, wall);
}
}
// у нас есть два списка, прибитые стенки
// и те, благодаря кому они разрушены
Set<Wall> preys = new HashSet<>(deathMatch.values());
Set<Hero> hunters = new HashSet<>(deathMatch.keys());
// вначале прибиваем стенки
preys.forEach(wall -> {
if (wall instanceof MeatChopperHunter) {
((MeatChopperHunter)wall).die();
} else {
destroyedWalls.add(wall);
}
});
// а потом все виновники получают свои ачивки
hunters.forEach(hunter -> {
if (!hunter.hasPlayer()) {
return;
}
deathMatch.get(hunter).forEach(wall -> {
if (wall instanceof MeatChopper) {
hunter.event(Events.KILL_MEAT_CHOPPER);
} else if (wall instanceof DestroyWall) {
hunter.event(Events.KILL_DESTROY_WALL);
}
});
});
}
private void killHeroes(List<Blast> blasts) {
// беремся за бомберов, если у них только нет иммунитета
// надо определить кто кого чем кикнул (ызрывные волны могут пересекаться)
Multimap<Hero, Hero> deathMatch = HashMultimap.create();
for (Blast blast : blasts) {
Hero hunter = blast.owner();
for (Player player : aliveActive()) {
Hero prey = player.getHero();
if (prey.itsMe(blast)) {
Perk immune = prey.getPerk(Elements.BOMB_IMMUNE);
if (immune == null) {
deathMatch.put(hunter, prey);
}
}
}
}
// у нас есть два списка, те кого прибили
// и те, благодаря кому
Set<Hero> preys = new HashSet<>(deathMatch.values());
Set<Hero> hunters = new HashSet<>(deathMatch.keys());
// вначале прибиваем жертв
preys.forEach(hero -> {
if (!hero.hasPlayer()) {
return;
}
hero.die();
});
// а потом все, кто выжил получают за это очки за всех тех, кого зацепили взрывной волной
// не стоит беспокоиться что они погибли сами - за это есть регулируемые штрафные очки
hunters.forEach(hunter -> {
if (!hunter.hasPlayer()) {
return;
}
deathMatch.get(hunter).forEach(prey -> {
if (hunter != prey) {
hunter.event(Events.KILL_OTHER_HERO);
}
}
);
});
}