use of com.google.common.collect.SetMultimap in project batfish by batfish.
the class CommonUtil method initRemoteIpsecVpns.
public static void initRemoteIpsecVpns(Map<String, Configuration> configurations) {
Map<IpsecVpn, Ip> vpnRemoteIps = new IdentityHashMap<>();
Map<Ip, Set<IpsecVpn>> externalIpVpnMap = new HashMap<>();
SetMultimap<Ip, IpWildcardSetIpSpace> privateIpsByPublicIp = initPrivateIpsByPublicIp(configurations);
for (Configuration c : configurations.values()) {
for (IpsecVpn ipsecVpn : c.getIpsecVpns().values()) {
Ip remoteIp = ipsecVpn.getIkeGateway().getAddress();
vpnRemoteIps.put(ipsecVpn, remoteIp);
Set<InterfaceAddress> externalAddresses = ipsecVpn.getIkeGateway().getExternalInterface().getAllAddresses();
for (InterfaceAddress address : externalAddresses) {
Ip ip = address.getIp();
Set<IpsecVpn> vpnsUsingExternalAddress = externalIpVpnMap.computeIfAbsent(ip, k -> Sets.newIdentityHashSet());
vpnsUsingExternalAddress.add(ipsecVpn);
}
}
}
for (Entry<IpsecVpn, Ip> e : vpnRemoteIps.entrySet()) {
IpsecVpn ipsecVpn = e.getKey();
Ip remoteIp = e.getValue();
Ip localIp = ipsecVpn.getIkeGateway().getLocalIp();
ipsecVpn.initCandidateRemoteVpns();
Set<IpsecVpn> remoteIpsecVpnCandidates = externalIpVpnMap.get(remoteIp);
if (remoteIpsecVpnCandidates != null) {
for (IpsecVpn remoteIpsecVpnCandidate : remoteIpsecVpnCandidates) {
Ip remoteIpsecVpnLocalAddress = remoteIpsecVpnCandidate.getIkeGateway().getLocalIp();
if (remoteIpsecVpnLocalAddress != null && !remoteIpsecVpnLocalAddress.equals(remoteIp)) {
continue;
}
Ip reciprocalRemoteAddress = vpnRemoteIps.get(remoteIpsecVpnCandidate);
Set<IpsecVpn> reciprocalVpns = externalIpVpnMap.get(reciprocalRemoteAddress);
if (reciprocalVpns == null) {
Set<IpWildcardSetIpSpace> privateIpsBehindReciprocalRemoteAddress = privateIpsByPublicIp.get(reciprocalRemoteAddress);
if (privateIpsBehindReciprocalRemoteAddress != null && privateIpsBehindReciprocalRemoteAddress.stream().anyMatch(ipSpace -> ipSpace.containsIp(localIp))) {
reciprocalVpns = externalIpVpnMap.get(localIp);
ipsecVpn.setRemoteIpsecVpn(remoteIpsecVpnCandidate);
ipsecVpn.getCandidateRemoteIpsecVpns().add(remoteIpsecVpnCandidate);
remoteIpsecVpnCandidate.initCandidateRemoteVpns();
remoteIpsecVpnCandidate.setRemoteIpsecVpn(ipsecVpn);
remoteIpsecVpnCandidate.getCandidateRemoteIpsecVpns().add(ipsecVpn);
}
} else if (reciprocalVpns.contains(ipsecVpn)) {
ipsecVpn.setRemoteIpsecVpn(remoteIpsecVpnCandidate);
ipsecVpn.getCandidateRemoteIpsecVpns().add(remoteIpsecVpnCandidate);
}
}
}
}
}
use of com.google.common.collect.SetMultimap in project MinecraftForge by MinecraftForge.
the class ASMDataTable method getAnnotationsFor.
public SetMultimap<String, ASMData> getAnnotationsFor(ModContainer container) {
if (containerAnnotationData == null) {
ImmutableMap.Builder<ModContainer, SetMultimap<String, ASMData>> mapBuilder = ImmutableMap.builder();
for (ModContainer cont : containers) {
Multimap<String, ASMData> values = Multimaps.filterValues(globalAnnotationData, new ModContainerPredicate(cont));
mapBuilder.put(cont, ImmutableSetMultimap.copyOf(values));
}
containerAnnotationData = mapBuilder.build();
}
return containerAnnotationData.get(container);
}
use of com.google.common.collect.SetMultimap in project android by JetBrains.
the class FmHasDependencyMethod method exec.
@Override
public TemplateModel exec(List args) throws TemplateModelException {
if (args.size() < 1 || args.size() > 2) {
throw new TemplateModelException("Wrong arguments");
}
String artifact = ((TemplateScalarModel) args.get(0)).getAsString();
if (artifact.isEmpty()) {
return TemplateBooleanModel.FALSE;
}
// Determine the configuration to check, based on the second argument passed to the function. Defaults to "compile".
String configuration = SdkConstants.GRADLE_COMPILE_CONFIGURATION;
if (args.size() > 1) {
configuration = ((TemplateScalarModel) args.get(1)).getAsString();
}
if (myParamMap.containsKey(TemplateMetadata.ATTR_DEPENDENCIES_MULTIMAP)) {
Object untyped = myParamMap.get(TemplateMetadata.ATTR_DEPENDENCIES_MULTIMAP);
if (untyped instanceof SetMultimap) {
@SuppressWarnings("unchecked") SetMultimap<String, String> dependencies = (SetMultimap<String, String>) untyped;
for (String dependency : dependencies.get(configuration)) {
if (dependency.contains(artifact)) {
return TemplateBooleanModel.TRUE;
}
}
}
}
// Find the corresponding module, if any
String modulePath = (String) myParamMap.get(TemplateMetadata.ATTR_PROJECT_OUT);
if (modulePath != null) {
Module module = FmUtil.findModule(modulePath);
if (module != null) {
AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet != null) {
// TODO: b/23032990
AndroidModuleModel androidModel = AndroidModuleModel.get(facet);
if (androidModel != null) {
boolean dependsOn;
switch(configuration) {
case SdkConstants.GRADLE_COMPILE_CONFIGURATION:
dependsOn = GradleUtil.dependsOn(androidModel, artifact);
break;
case SdkConstants.GRADLE_ANDROID_TEST_COMPILE_CONFIGURATION:
dependsOn = GradleUtil.dependsOnAndroidTest(androidModel, artifact);
break;
default:
throw new TemplateModelException("Unknown dependency configuration " + configuration);
}
return dependsOn ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE;
}
}
}
}
// created project will return true since it will be by virtue of appcompat also being installed.)
if (artifact.contains(SdkConstants.APPCOMPAT_LIB_ARTIFACT) || artifact.contains(SdkConstants.SUPPORT_LIB_ARTIFACT)) {
// No dependencies: Base it off of the minApi and buildApi versions:
// If building with Lollipop, and targeting anything earlier than Lollipop, use appcompat.
// (Also use it if minApi is less than ICS.)
Object buildApiObject = myParamMap.get(TemplateMetadata.ATTR_BUILD_API);
Object minApiObject = myParamMap.get(TemplateMetadata.ATTR_MIN_API_LEVEL);
if (buildApiObject instanceof Integer && minApiObject instanceof Integer) {
int buildApi = (Integer) buildApiObject;
int minApi = (Integer) minApiObject;
return minApi >= 8 && ((buildApi >= 21 && minApi < 21) || minApi < 14) ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE;
}
}
return TemplateBooleanModel.FALSE;
}
use of com.google.common.collect.SetMultimap in project android by JetBrains.
the class NewModuleWizardState method updateDependencies.
/**
* Updates the dependencies stored in the parameters map, to include support libraries required by the extra features selected.
*/
public void updateDependencies() {
@SuppressWarnings("unchecked") SetMultimap<String, String> dependencies = (SetMultimap<String, String>) get(ATTR_DEPENDENCIES_MULTIMAP);
if (dependencies == null) {
dependencies = HashMultimap.create();
}
RepositoryUrlManager urlManager = RepositoryUrlManager.get();
// Support Library
Object fragmentsExtra = get(ATTR_FRAGMENTS_EXTRA);
Object navigationDrawerExtra = get(ATTR_NAVIGATION_DRAWER_EXTRA);
if ((fragmentsExtra != null && Boolean.parseBoolean(fragmentsExtra.toString())) || (navigationDrawerExtra != null && Boolean.parseBoolean(navigationDrawerExtra.toString()))) {
dependencies.put(SdkConstants.GRADLE_COMPILE_CONFIGURATION, urlManager.getLibraryStringCoordinate(SupportLibrary.SUPPORT_V4, true));
}
// AppCompat Library
Object actionBarExtra = get(ATTR_ACTION_BAR_EXTRA);
if (actionBarExtra != null && Boolean.parseBoolean(actionBarExtra.toString())) {
dependencies.put(SdkConstants.GRADLE_COMPILE_CONFIGURATION, urlManager.getLibraryStringCoordinate(SupportLibrary.APP_COMPAT_V7, true));
}
// GridLayout Library
Object gridLayoutExtra = get(ATTR_GRID_LAYOUT_EXTRA);
if (gridLayoutExtra != null && Boolean.parseBoolean(gridLayoutExtra.toString())) {
dependencies.put(SdkConstants.GRADLE_COMPILE_CONFIGURATION, urlManager.getLibraryStringCoordinate(SupportLibrary.GRID_LAYOUT_V7, true));
}
put(ATTR_DEPENDENCIES_MULTIMAP, dependencies);
}
use of com.google.common.collect.SetMultimap in project gerrit by GerritCodeReview.
the class ChangeJson method labelsForClosedChange.
private Map<String, LabelWithStatus> labelsForClosedChange(PermissionBackend.ForChange basePerm, ChangeData cd, LabelTypes labelTypes, boolean standard, boolean detailed) throws OrmException, PermissionBackendException {
Set<Account.Id> allUsers = new HashSet<>();
if (detailed) {
// the latest patch set (in the next loop).
for (PatchSetApproval psa : cd.approvals().values()) {
allUsers.add(psa.getAccountId());
}
}
Set<String> labelNames = new HashSet<>();
SetMultimap<Account.Id, PatchSetApproval> current = MultimapBuilder.hashKeys().hashSetValues().build();
for (PatchSetApproval a : cd.currentApprovals()) {
allUsers.add(a.getAccountId());
LabelType type = labelTypes.byLabel(a.getLabelId());
if (type != null) {
labelNames.add(type.getName());
// Not worth the effort to distinguish between votable/non-votable for 0
// values on closed changes, since they can't vote anyway.
current.put(a.getAccountId(), a);
}
}
Map<String, LabelWithStatus> labels;
if (cd.change().getStatus() == Change.Status.MERGED) {
// Since voting on merged changes is allowed all labels which apply to
// the change must be returned. All applying labels can be retrieved from
// the submit records, which is what initLabels does.
// It's not possible to only compute the labels based on the approvals
// since merged changes may not have approvals for all labels (e.g. if not
// all labels are required for submit or if the change was auto-closed due
// to direct push or if new labels were defined after the change was
// merged).
labels = initLabels(cd, labelTypes, standard);
// it wouldn't be included in the submit records.
for (String name : labelNames) {
if (!labels.containsKey(name)) {
labels.put(name, LabelWithStatus.create(new LabelInfo(), null));
}
}
} else {
// For abandoned changes return only labels for which approvals exist.
// Other labels are not needed since voting on abandoned changes is not
// allowed.
labels = new TreeMap<>(labelTypes.nameComparator());
for (String name : labelNames) {
labels.put(name, LabelWithStatus.create(new LabelInfo(), null));
}
}
if (detailed) {
labels.entrySet().stream().filter(e -> labelTypes.byLabel(e.getKey()) != null).forEach(e -> setLabelValues(labelTypes.byLabel(e.getKey()), e.getValue()));
}
for (Account.Id accountId : allUsers) {
Map<String, ApprovalInfo> byLabel = Maps.newHashMapWithExpectedSize(labels.size());
Map<String, VotingRangeInfo> pvr = Collections.emptyMap();
if (detailed) {
PermissionBackend.ForChange perm = basePerm.user(userFactory.create(accountId));
pvr = getPermittedVotingRanges(permittedLabels(perm, cd));
for (Map.Entry<String, LabelWithStatus> entry : labels.entrySet()) {
ApprovalInfo ai = approvalInfo(accountId, 0, null, null, null);
byLabel.put(entry.getKey(), ai);
addApproval(entry.getValue().label(), ai);
}
}
for (PatchSetApproval psa : current.get(accountId)) {
LabelType type = labelTypes.byLabel(psa.getLabelId());
if (type == null) {
continue;
}
short val = psa.getValue();
ApprovalInfo info = byLabel.get(type.getName());
if (info != null) {
info.value = Integer.valueOf(val);
info.permittedVotingRange = pvr.getOrDefault(type.getName(), null);
info.date = psa.getGranted();
info.tag = psa.getTag();
if (psa.isPostSubmit()) {
info.postSubmit = true;
}
}
if (!standard) {
continue;
}
setLabelScores(type, labels.get(type.getName()), val, accountId);
}
}
return labels;
}
Aggregations