List of usage examples for java.util Map getOrDefault
default V getOrDefault(Object key, V defaultValue)
From source file:com.netflix.spinnaker.orca.clouddriver.tasks.pipeline.UpdateMigratedPipelineTask.java
@Override public TaskResult execute(Stage stage) { Map<String, Object> context = stage.getContext(); Map<String, Object> pipeline = (Map<String, Object>) context.get("source.pipeline"); List<Map> stages = (List<Map>) pipeline.getOrDefault("stages", new ArrayList<>()); List<Map> katoTasks = (List<Map>) context.get("kato.tasks"); List<Map> resultObjects = (List<Map>) katoTasks.get(0).get("resultObjects"); List<Map> replacements = new ArrayList<>( resultObjects.stream().map(o -> (Map) o.get("cluster")).collect(Collectors.toList())); stages.forEach(s -> PipelineClusterExtractor.getExtractor(s, extractors) .ifPresent(e -> e.updateStageClusters(s, replacements))); String newName = (String) context.getOrDefault("newPipelineName", pipeline.get("name") + " - migrated"); pipeline.put("name", newName); pipeline.remove("id"); List<Map> triggers = (List<Map>) pipeline.getOrDefault("triggers", new ArrayList<>()); triggers.forEach(t -> t.put("enabled", false)); front50Service.savePipeline(pipeline); String application = (String) context.get("application"); Optional<Map<String, Object>> newPipeline = front50Service.getPipelines(application).stream() .filter(p -> newName.equals(p.get("name"))).findFirst(); if (!newPipeline.isPresent()) { Map<String, Object> outputs = new HashMap<>(); outputs.put("exception", "Pipeline migration was successful but could not find new pipeline with name " + newName); return new DefaultTaskResult(ExecutionStatus.TERMINAL, outputs); }// w ww. java 2s .c o m Map<String, Object> outputs = new HashMap<>(); outputs.put("newPipelineId", newPipeline.get().get("id")); return new DefaultTaskResult(ExecutionStatus.SUCCEEDED, outputs); }
From source file:org.apache.sling.commons.messaging.mail.internal.SimpleMailBuilder.java
@Override public Email build(@Nonnull final String message, @Nonnull final String recipient, @Nonnull final Map data) throws EmailException { final Map configuration = (Map) data.getOrDefault("mail", Collections.EMPTY_MAP); final String subject = (String) configuration.getOrDefault(SUBJECT_KEY, this.configuration.subject()); final String from = (String) configuration.getOrDefault(FROM_KEY, this.configuration.from()); final String charset = (String) configuration.getOrDefault(CHARSET_KEY, this.configuration.charset()); final String smtpHostname = (String) configuration.getOrDefault(SMTP_HOSTNAME_KEY, this.configuration.smtpHostname()); final int smtpPort = (Integer) configuration.getOrDefault(SMTP_PORT_KEY, this.configuration.smtpPort()); final String smtpUsername = (String) configuration.getOrDefault(SMTP_USERNAME_KEY, this.configuration.smtpUsername()); final String smtpPassword = (String) configuration.getOrDefault(SMTP_PASSWORD_KEY, this.configuration.smtpPassword()); final Email email = new SimpleEmail(); email.setCharset(charset);/*from w w w . ja v a2 s. co m*/ email.setMsg(message); email.addTo(recipient); email.setSubject(subject); email.setFrom(from); email.setHostName(smtpHostname); email.setSmtpPort(smtpPort); email.setAuthentication(smtpUsername, smtpPassword); return email; }
From source file:org.cryptomator.frontend.webdav.mount.LinuxGvfsDavMounter.java
@Override public boolean shouldWork(Map<MountParam, Optional<String>> mountParams) { if (SystemUtils.IS_OS_LINUX) { Optional<String> prefScheme = mountParams.getOrDefault(MountParam.PREFERRED_GVFS_SCHEME, Optional.empty()); boolean prefSchemeIsUnspecifiedOrDav = !prefScheme.isPresent() || prefScheme.get().equalsIgnoreCase("dav"); final Script checkScripts = Script.fromLines("which gvfs-mount xdg-open"); try {/*from w w w .j a v a 2s. c o m*/ checkScripts.execute(); return prefSchemeIsUnspecifiedOrDav; } catch (CommandFailedException e) { return false; } } else { return false; } }
From source file:org.cryptomator.frontend.webdav.mount.LinuxGvfsWebDavMounter.java
@Override public boolean shouldWork(Map<MountParam, Optional<String>> mountParams) { if (SystemUtils.IS_OS_LINUX) { Optional<String> prefScheme = mountParams.getOrDefault(MountParam.PREFERRED_GVFS_SCHEME, Optional.empty()); boolean prefSchemeIsUnspecifiedOrWebDav = !prefScheme.isPresent() || prefScheme.get().equalsIgnoreCase("webdav"); final Script checkScripts = Script.fromLines("which gvfs-mount xdg-open"); try {/*from w w w . j a v a 2 s. c o m*/ checkScripts.execute(); return prefSchemeIsUnspecifiedOrWebDav; } catch (CommandFailedException e) { return false; } } else { return false; } }
From source file:alfio.model.TicketFieldConfigurationAndDescription.java
public List<Pair<String, String>> getTranslatedRestrictedValue() { Map<String, String> description = ticketFieldDescription.getRestrictedValuesDescription(); return ticketFieldConfiguration.getRestrictedValues().stream() .map(val -> Pair.of(val, description.getOrDefault(val, "MISSING_DESCRIPTION"))) .collect(Collectors.toList()); }
From source file:io.cloudslang.lang.compiler.modeller.transformers.SeqStepsTransformer.java
private void validateWaitStep(Map<String, String> stepProps) { String args = stepProps.getOrDefault(SEQ_STEP_ARGS_KEY, stepProps.get(SEQ_STEP_DEFAULT_ARGS_KEY)); if (StringUtils.isEmpty(args)) { throw new RuntimeException(WAIT_PARAM_REQUIRED); }/* ww w. ja v a 2s. c o m*/ if (!WAIT_ARGS.matcher(args).matches()) { throw new RuntimeException(String.format(WAIT_INVALID_ARG, args)); } }
From source file:com.github.drbookings.ui.BookingsByOrigin.java
public Map<BookingOrigin, Collection<T>> getMap() { final Map<BookingOrigin, Collection<T>> result = new LinkedHashMap<>(); for (final T be : bookingEntries) { final Collection<T> value = result.getOrDefault(be.getBookingOrigin(), new ArrayList<>()); value.add(be);/* w ww.j a v a2s. co m*/ result.put(be.getBookingOrigin(), value); } return result; }
From source file:sh.scrap.scrapper.functions.DateFunctionFactory.java
@Override public DataScrapperFunction create(String name, DataScrapperFunctionLibrary library, String pattern, Map<String, Object> annotations) { return context -> subscription -> { Locale locale = parseLocale(annotations.getOrDefault("locale", EN_US)); ZoneId zoneId = ZoneId.of((String) annotations.getOrDefault("timezone", "UTC")); Locale finalLocale = locale; subscription.onSubscribe(new Subscription() { @Override/*from www.j a v a 2 s .c o m*/ public void request(long n) { String data = context.data().toString(); ZonedDateTime parsed; context.objectProcessed(data); try { switch (name) { case "parse": parsed = parse(data, pattern, finalLocale, zoneId); context.objectProcessed(parsed); subscription.onNext(context.withData(format(parsed, ISO8601, EN_US, ZoneId.of("UTC")))); subscription.onComplete(); return; case "format": parsed = parse(data, ISO8601, EN_US, ZoneId.of("UTC")); context.objectProcessed(parsed); subscription.onNext(context.withData(format(parsed, pattern, finalLocale, zoneId))); subscription.onComplete(); return; } } catch (DateTimeParseException e) { subscription.onError(e); subscription.onComplete(); return; } } @Override public void cancel() { } }); }; }
From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.op.handler.KubernetesEventHandler.java
@Override public void addRelationships(Map<KubernetesKind, List<KubernetesManifest>> allResources, Map<KubernetesManifest, List<KubernetesManifest>> relationshipMap) { relationshipMap.putAll(allResources.getOrDefault(EVENT, new ArrayList<>()).stream() .map(m -> ImmutablePair.of(m, KubernetesCacheDataConverter.getResource(m, V1Event.class))) .collect(Collectors.toMap(ImmutablePair::getLeft, p -> Collections.singletonList(involvedManifest(p.getRight()))))); }
From source file:org.apache.metron.enrichment.stellar.ObjectGet.java
@Override public void initialize(Context context) { try {/* w w w. j a v a 2s . co m*/ lock.writeLock().lock(); Map<String, Object> config = getConfig(context); long size = ConversionUtils .convert(config.getOrDefault(OBJECT_CACHE_SIZE_KEY, OBJECT_CACHE_SIZE_DEFAULT), Long.class); long expiryMin = ConversionUtils.convert( config.getOrDefault(OBJECT_CACHE_EXPIRATION_KEY, OBJECT_CACHE_EXPIRATION_MIN_DEFAULT), Long.class); cache = setupCache(size, expiryMin); } catch (IOException e) { throw new IllegalStateException("Unable to initialize: " + e.getMessage(), e); } finally { lock.writeLock().unlock(); } }