List of usage examples for com.google.common.collect Maps difference
public static <K, V> SortedMapDifference<K, V> difference(SortedMap<K, ? extends V> left, Map<? extends K, ? extends V> right)
From source file:org.jfrog.hudson.BuildInfoDeployer.java
private Build gatherBuildInfo(MavenModuleSetBuild build) throws IOException, InterruptedException { BuildInfoBuilder infoBuilder = new BuildInfoBuilder(build.getParent().getDisplayName()) .number(build.getNumber() + "") .buildAgent(new BuildAgent("Maven", build.getParent().getMaven().getName())) .agent(new Agent("hudson", build.getHudsonVersion())).type(BuildType.MAVEN); if (Hudson.getInstance().getRootUrl() != null) { infoBuilder.url(Hudson.getInstance().getRootUrl() + build.getUrl()); }/*from www . j a v a2 s. co m*/ Calendar startedTimestamp = build.getTimestamp(); infoBuilder.startedDate(startedTimestamp.getTime()); long duration = System.currentTimeMillis() - startedTimestamp.getTimeInMillis(); infoBuilder.durationMillis(duration); ArtifactoryServer server = publisher.getArtifactoryServer(); infoBuilder.artifactoryPrincipal(server.getUserName()); CauseAction action = ActionableHelper.getLatestAction(build, CauseAction.class); if (action != null) { for (Cause cause : action.getCauses()) { if (cause instanceof Cause.UserCause) { infoBuilder.principal(((Cause.UserCause) cause).getUserName()); } } } Cause.UpstreamCause parent = ActionableHelper.getUpstreamCause(build); if (parent != null) { String parentProject = parent.getUpstreamProject(); int buildNumber = parent.getUpstreamBuild(); infoBuilder.parentName(parentProject); infoBuilder.parentNumber(buildNumber + ""); } gatherModuleAndDependencyInfo(infoBuilder, build); gatherSysPropInfo(infoBuilder); addBuildInfoVariables(infoBuilder); EnvVars envVars = build.getEnvironment(listener); String revision = envVars.get("SVN_REVISION"); if (StringUtils.isNotBlank(revision)) { infoBuilder.vcsRevision(revision); } if (publisher.isIncludeEnvVars()) { for (Map.Entry<String, String> entry : envVars.entrySet()) { infoBuilder.addProperty(BuildInfoProperties.BUILD_INFO_ENVIRONMENT_PREFIX + entry.getKey(), entry.getValue()); } } else { MapDifference<String, String> difference = Maps.difference(envVars, System.getenv()); Map<String, String> filteredEnvVars = difference.entriesOnlyOnLeft(); for (Map.Entry<String, String> entry : filteredEnvVars.entrySet()) { infoBuilder.addProperty(BuildInfoProperties.BUILD_INFO_ENVIRONMENT_PREFIX + entry.getKey(), entry.getValue()); } } Build buildInfo = infoBuilder.build(); // for backwards compatibility for Artifactory 2.2.3 if (parent != null) { buildInfo.setParentBuildId(parent.getUpstreamProject()); } return buildInfo; }
From source file:com.thinkbiganalytics.metadata.rest.model.nifi.NiFiFlowCacheSync.java
public Map<String, String> getProcessorIdToFeedNameMapUpdatedSinceLastSync( Map<String, String> processorIdToFeedNameMap) { MapDifference<String, String> diff = Maps.difference(snapshot.getProcessorIdToFeedNameMap(), processorIdToFeedNameMap);//from ww w . j av a2s . c o m return diff.entriesOnlyOnRight(); }
From source file:eu.numberfour.n4js.ui.workingsets.GitRepositoryAwareWorkingSetManager.java
/** * Sole constructor for creating the working set manager. Internally initializes the cache for repositories. *///from w ww . ja v a 2s . c om public GitRepositoryAwareWorkingSetManager() { repositoryCache = Activator.getDefault().getRepositoryCache(); // might not be initialized yet. repositoryChangeListener = new IPreferenceChangeListener() { @SuppressWarnings("deprecation") // keep deprecated RepositoryUtil.PREFS_DIRECTORIES for backward-compatibility @Override public void preferenceChange(final PreferenceChangeEvent event) { if (!RepositoryUtil.PREFS_DIRECTORIES_REL.equals(event.getKey()) && !RepositoryUtil.PREFS_DIRECTORIES.equals(event.getKey())) { return; } if (!orderedWorkingSetIds.isEmpty() && !visibleWorkingSetIds.isEmpty()) { MapDifference<String, String> diff = calculateDifference(event); if (!diff.areEqual()) { // Deletions final Set<String> deletions = diff.entriesOnlyOnLeft().keySet(); for (String deletedUrl : deletions) { orderedWorkingSetIds.remove(deletedUrl); visibleWorkingSetIds.remove(deletedUrl); } // Additions final Set<String> additions = diff.entriesOnlyOnRight().keySet(); for (String addedUrl : additions) { orderedWorkingSetIds.add(addedUrl); visibleWorkingSetIds.add(addedUrl); } } } discardWorkingSetCaches(); saveState(new NullProgressMonitor()); WorkingSetManagerBroker workingSetManagerBroker = getWorkingSetManagerBroker(); if (workingSetManagerBroker.isWorkingSetTopLevel()) { final WorkingSetManager activeManager = workingSetManagerBroker.getActiveManager(); if (activeManager != null) { if (activeManager.getId().equals(getId())) { workingSetManagerBroker.refreshNavigator(); } } } } private MapDifference<String, String> calculateDifference(PreferenceChangeEvent event) { String oldValue = Strings.nullToEmpty((String) event.getOldValue()); String newValue = Strings.nullToEmpty((String) event.getNewValue()); Map<String, String> oldMappings = toMap(newHashSet(Splitter.on(pathSeparator).split(oldValue)), i -> i); Map<String, String> newMappings = toMap(newHashSet(Splitter.on(pathSeparator).split(newValue)), i -> i); return Maps.difference(oldMappings, newMappings); } }; final IEclipsePreferences gitNode = InstanceScope.INSTANCE.getNode(Activator.getPluginId()); gitNode.addPreferenceChangeListener(repositoryChangeListener); final BundleContext context = Activator.getDefault().getBundle().getBundleContext(); context.addBundleListener(new BundleListener() { @Override public void bundleChanged(final BundleEvent event) { if (BundleEvent.STOPPING == event.getType()) { gitNode.removePreferenceChangeListener(repositoryChangeListener); } } }); }
From source file:org.jfrog.hudson.maven2.BuildInfoDeployer.java
private Build gatherBuildInfo(MavenModuleSetBuild build) throws IOException, InterruptedException { BuildInfoBuilder infoBuilder = new BuildInfoBuilder(build.getParent().getDisplayName()) .number(build.getNumber() + "") .buildAgent(new BuildAgent("Maven", build.getParent().getMaven().getName())) .agent(new Agent("hudson", build.getHudsonVersion())).type(BuildType.MAVEN); String buildUrl = ActionableHelper.getBuildUrl(build); if (StringUtils.isNotBlank(buildUrl)) { infoBuilder.url(buildUrl);/*w ww . j a va2 s . c o m*/ } Calendar startedTimestamp = build.getTimestamp(); infoBuilder.startedDate(startedTimestamp.getTime()); long duration = System.currentTimeMillis() - startedTimestamp.getTimeInMillis(); infoBuilder.durationMillis(duration); ArtifactoryServer server = publisher.getArtifactoryServer(); String artifactoryPrincipal = server.getResolvingCredentials().getUsername(); if (StringUtils.isBlank(artifactoryPrincipal)) { artifactoryPrincipal = ""; } infoBuilder.artifactoryPrincipal(artifactoryPrincipal); String userCause = ActionableHelper.getUserCausePrincipal(build); if (userCause != null) { infoBuilder.principal(userCause); } Cause.UpstreamCause parent = ActionableHelper.getUpstreamCause(build); if (parent != null) { String parentProject = parent.getUpstreamProject(); int buildNumber = parent.getUpstreamBuild(); infoBuilder.parentName(parentProject); infoBuilder.parentNumber(buildNumber + ""); if (StringUtils.isBlank(userCause)) { infoBuilder.principal("auto"); } } gatherModuleAndDependencyInfo(infoBuilder, build); gatherSysPropInfo(infoBuilder); addBuildInfoVariables(infoBuilder); EnvVars envVars = build.getEnvironment(listener); String revision = ExtractorUtils.getVcsRevision(envVars); if (StringUtils.isNotBlank(revision)) { infoBuilder.vcsRevision(revision); } if (publisher.isIncludeEnvVars()) { for (Map.Entry<String, String> entry : envVars.entrySet()) { infoBuilder.addProperty(BuildInfoProperties.BUILD_INFO_ENVIRONMENT_PREFIX + entry.getKey(), entry.getValue()); } } else { MapDifference<String, String> difference = Maps.difference(envVars, System.getenv()); Map<String, String> filteredEnvVars = difference.entriesOnlyOnLeft(); for (Map.Entry<String, String> entry : filteredEnvVars.entrySet()) { infoBuilder.addProperty(BuildInfoProperties.BUILD_INFO_ENVIRONMENT_PREFIX + entry.getKey(), entry.getValue()); } } LicenseControl licenseControl = new LicenseControl(publisher.isRunChecks()); if (publisher.isRunChecks()) { if (StringUtils.isNotBlank(publisher.getViolationRecipients())) { licenseControl.setLicenseViolationsRecipientsList(publisher.getViolationRecipients()); } if (StringUtils.isNotBlank(publisher.getScopes())) { licenseControl.setScopesList(publisher.getScopes()); } } licenseControl.setIncludePublishedArtifacts(publisher.isIncludePublishArtifacts()); licenseControl.setAutoDiscover(publisher.isLicenseAutoDiscovery()); infoBuilder.licenseControl(licenseControl); BuildRetention buildRetention = new BuildRetention(publisher.isDiscardBuildArtifacts()); if (publisher.isDiscardOldBuilds()) { buildRetention = BuildRetentionFactory.createBuildRetention(build, publisher.isDiscardBuildArtifacts()); } infoBuilder.buildRetention(buildRetention); // add staging status if it is a release build ReleaseAction release = ActionableHelper.getLatestAction(build, ReleaseAction.class); if (release != null) { String stagingRepoKey = release.getStagingRepositoryKey(); if (StringUtils.isBlank(stagingRepoKey)) { stagingRepoKey = publisher.getRepositoryKey(); } infoBuilder.addStatus(new PromotionStatusBuilder(Promotion.STAGED) .timestampDate(startedTimestamp.getTime()).comment(release.getStagingComment()) .repository(stagingRepoKey).ciUser(userCause).user(artifactoryPrincipal).build()); } Build buildInfo = infoBuilder.build(); // for backwards compatibility for Artifactory 2.2.3 if (parent != null) { buildInfo.setParentBuildId(parent.getUpstreamProject()); } return buildInfo; }
From source file:org.netxilia.api.impl.dependencies.SheetAliasDependencyManager.java
public void saveSheet(SheetData sheetData, Collection<SheetData.Property> properties) { if (properties != null && properties.contains(SheetData.Property.aliases)) { // check which alias changed // make a diff between the stored version of aliases and the new list MapDifference<Alias, AreaReference> diff = Maps.difference(previousAliases, sheetData.getAliases()); previousAliases = new HashMap<Alias, AreaReference>(sheetData.getAliases()); workbookAliasDependencyManager.refreshAliases(sheet.getName(), diff.entriesDiffering().keySet(), diff.entriesOnlyOnLeft().keySet()); }/*w w w . jav a 2 s .c o m*/ }
From source file:org.lisapark.octopus.core.ProcessorBean.java
/** /*from www .ja v a2s . co m*/ * * @param bean * @param threshold * @return */ public Double compare(ProcessorBean bean) { Double tolerance = null; if (this.getClassName().equalsIgnoreCase(bean.getClassName())) { Map<String, Object> thisParams = Maps.newHashMap(this.getParams()); Map<String, Object> thatParams = Maps.newHashMap(bean.getParams()); MapDifference<String, Object> diff = Maps.difference(thisParams, thatParams); int different = diff.entriesDiffering().size(); int inCommon = diff.entriesInCommon().size(); tolerance = ((double) different / (double) (thisParams.size() + thatParams.size() - inCommon)); } return tolerance; }
From source file:com.addthis.hydra.job.alert.JobAlertRunner.java
/** * Iterate over alert map, checking the status of each alert and sending emails as needed. *//* www .ja va2 s .co m*/ public void scanAlerts() { if (alertsEnabled) { log.info("Started alert scan of {} alerts...", alertMap.size()); try { for (Map.Entry<String, AbstractJobAlert> entry : alertMap.entrySet()) { AbstractJobAlert oldAlert = entry.getValue(); Map<String, String> currentErrors = oldAlert.getActiveJobs(); // entry may be concurrently deleted, so only recompute if still present, and while locked AbstractJobAlert alert = alertMap.computeIfPresent(entry.getKey(), (id, currentAlert) -> { currentAlert.checkAlertForJobs(currentAlert.getAlertJobs(spawn), meshyClient); if (!currentAlert.getActiveJobs().equals(currentErrors)) { storeAlert(currentAlert.alertId, currentAlert); } return currentAlert; }); // null if it was concurrently removed from the map. Does not catch all removals, but might as well // make a best effort attempt to send clears when convenient (should probably move clear emails to // the removal method at some point) if (alert == null) { emailAlert(oldAlert, "[CLEAR] ", currentErrors); } else { Map<String, String> newErrors = alert.getActiveJobs(); MapDifference<String, String> difference = Maps.difference(currentErrors, newErrors); emailAlert(oldAlert, "[CLEAR] ", difference.entriesOnlyOnLeft()); emailAlert(alert, "[TRIGGER] ", difference.entriesOnlyOnRight()); Map<String, String> errorsChanged = new HashMap<>(); for (Map.Entry<String, MapDifference.ValueDifference<String>> differing : difference .entriesDiffering().entrySet()) { String oldValue = differing.getValue().leftValue(); String newValue = differing.getValue().rightValue(); if (!alert.suppressChanges.suppress(oldValue, newValue)) { errorsChanged.put(differing.getKey(), newValue); } } emailAlert(alert, "[ERROR CHANGED] ", errorsChanged); } } lastAlertScanFailed = false; log.info("Finished alert scan"); } catch (Exception e) { lastAlertScanFailed = true; log.error("Unexpected error while scanning alerts: {}", e.getMessage(), e); } } }
From source file:org.ecloudmanager.deployment.vm.infrastructure.InfrastructureDeployerImpl.java
@Override public boolean isRecreateActionRequired(VMDeployment before, VMDeployment after) { Map<String, String> beforeParams = getNodeParameters(before); Map<String, String> afterParams = getNodeParameters(after); List<NodeParameter> params; try {/*from w ww . j a v a2s . c o m*/ params = nodeAPIProvider.getAPI(apiName).getNodeParameters(credentials); } catch (Exception e) { throw new RuntimeException("Can't get node parameters", e); } Map<String, MapDifference.ValueDifference<String>> diff = Maps.difference(beforeParams, afterParams) .entriesDiffering(); return diff.entrySet().stream().anyMatch(entry -> params.stream() .anyMatch(parameter -> parameter.getName().equals(entry.getKey()) && !parameter.getConfigure())); // AWSInstanceType beforeInstanceType = AWSInstanceType.get(getAwsInstanceType(before)); // AWSInstanceType afterInstanceType = AWSInstanceType.get(getAwsInstanceType(after)); // if (beforeInstanceType == null || afterInstanceType == null || !afterInstanceType.isCompatible(beforeInstanceType)) { // return true; // } // // if (before.getVirtualMachineTemplate().getStorage() != after.getVirtualMachineTemplate().getStorage()) { // if ( // !(beforeInstanceType.isEbs() && afterInstanceType.isEbs()) || // before.getVirtualMachineTemplate().getStorage() > after.getVirtualMachineTemplate().getStorage() // ) { // return true; // } // } // // return !getAwsRegion(after).equals(getAwsRegion(before)) || // !getAwsSubnet(after).equals(getAwsSubnet(before)) || // !getAwsAmi(after).equals(getAwsAmi(before)) || // !getAwsKeypair(after).equals(getAwsKeypair(before)); }
From source file:com.auditbucket.engine.service.WhatService.java
public AuditDeltaBean getDelta(MetaHeader header, ChangeLog from, ChangeLog to) { if (header == null || from == null || to == null) throw new IllegalArgumentException("Unable to compute delta due to missing arguments"); LogWhat source = getWhat(header, from); LogWhat dest = getWhat(header, to);/*from w ww .j a va 2s.com*/ MapDifference<String, Object> diffMap = Maps.difference(source.getWhatMap(), dest.getWhatMap()); AuditDeltaBean result = new AuditDeltaBean(); result.setAdded(new HashMap<>(diffMap.entriesOnlyOnRight())); result.setRemoved(new HashMap<>(diffMap.entriesOnlyOnLeft())); HashMap<String, Object> differences = new HashMap<>(); Set<String> keys = diffMap.entriesDiffering().keySet(); for (String key : keys) { differences.put(key, diffMap.entriesDiffering().get(key).toString()); } result.setChanged(differences); result.setUnchanged(diffMap.entriesInCommon()); return result; }
From source file:io.druid.firehose.rabbitmq.JacksonifiedConnectionFactory.java
@Override public boolean equals(Object o) { if (this == o) { return true; }/*w w w. j a v a 2s . co m*/ if (o == null || getClass() != o.getClass()) { return false; } JacksonifiedConnectionFactory that = (JacksonifiedConnectionFactory) o; if (connectionTimeout != that.connectionTimeout) { return false; } if (port != that.port) { return false; } if (requestedChannelMax != that.requestedChannelMax) { return false; } if (requestedFrameMax != that.requestedFrameMax) { return false; } if (requestedHeartbeat != that.requestedHeartbeat) { return false; } if (clientProperties != null ? !Maps.difference(getSerializableClientProperties(clientProperties), getSerializableClientProperties(that.clientProperties)).areEqual() : that.clientProperties != null) { return false; } if (host != null ? !host.equals(that.host) : that.host != null) { return false; } if (password != null ? !password.equals(that.password) : that.password != null) { return false; } if (uri != null ? !uri.equals(that.uri) : that.uri != null) { return false; } if (username != null ? !username.equals(that.username) : that.username != null) { return false; } if (virtualHost != null ? !virtualHost.equals(that.virtualHost) : that.virtualHost != null) { return false; } return true; }