List of usage examples for java.util Properties containsKey
@Override public boolean containsKey(Object key)
From source file:org.bultreebank.labpipe.converters.LineConverter.java
/** * Converts a Line encoded token into a CoNLL encoded token. * //from ww w .j a v a 2 s . c o m * @param line Line encoded token * @param id ID of the token in CoNLL representation * @param conllMap <code>Map</code> containing connections between full * BTB tags and their respective CoNLL forms. * @return {@link String} - CoNll encoded token * @throws ArrayIndexOutOfBoundsException */ public static String lineTokenToConllToken(String line, int id, Properties conllMap) throws ArrayIndexOutOfBoundsException { ArrayList<String> conll = new ArrayList(10); line = line.replaceAll(" ", "\t"); String[] columns = line.split("\t"); String token = columns[0]; String tag = columns[1]; String lemma = null; if (columns.length > 2) { lemma = columns[2]; } // ID number conll.add(String.valueOf(id)); // Token conll.add(token); // Lemma if (lemma != null) { conll.add(lemma); } else { conll.add("_"); } // Short tag (BTB first letter) if (tag.contains("punct")) { conll.add("Punct"); } else { conll.add(String.valueOf(tag.charAt(0))); } // Long tag if (tag.contains("punct") || tag.contains("Punct")) { conll.add("Punct"); } else if (tag.length() > 2 && tag.charAt(1) != '-') { conll.add(tag.substring(0, 2)); } else if (tag.length() > 2 && tag.charAt(1) == '-') { conll.add(String.valueOf(tag.charAt(0))); } else { conll.add(tag); } // Features (rest of the tag separated with pipe signs) if (conllMap.containsKey(tag)) { // using the map configuration conll.add(conllMap.getProperty(tag)); } else { // tags not listed in the map -- failsafe if (tag.length() > 2 && !tag.contains("unct")) { conll.add(Misc.join(tag.substring(2).split(""), "|").substring(1)); } else { conll.add("_"); } } return Misc.join(conll, "\t"); }
From source file:org.apache.gobblin.service.modules.scheduler.GobblinServiceJobScheduler.java
/** {@inheritDoc} */ @Override/*from w w w.j av a 2s . com*/ public void onAddSpec(Spec addedSpec) { if (this.helixManager.isPresent() && !this.helixManager.get().isConnected()) { // Specs in store will be notified when Scheduler is added as listener to FlowCatalog, so ignore // .. Specs if in cluster mode and Helix is not yet initialized _log.info("System not yet initialized. Skipping Spec Addition: " + addedSpec); return; } _log.info("New Flow Spec detected: " + addedSpec); if (addedSpec instanceof FlowSpec) { try { FlowSpec flowSpec = (FlowSpec) addedSpec; Properties jobConfig = new Properties(); Properties flowSpecProperties = ((FlowSpec) addedSpec).getConfigAsProperties(); jobConfig.putAll(this.properties); jobConfig.setProperty(ConfigurationKeys.JOB_NAME_KEY, addedSpec.getUri().toString()); jobConfig.setProperty(ConfigurationKeys.JOB_GROUP_KEY, flowSpec.getConfig().getValue(ConfigurationKeys.FLOW_GROUP_KEY).toString()); jobConfig.setProperty(ConfigurationKeys.FLOW_RUN_IMMEDIATELY, ConfigUtils .getString((flowSpec).getConfig(), ConfigurationKeys.FLOW_RUN_IMMEDIATELY, "false")); if (flowSpecProperties.containsKey(ConfigurationKeys.JOB_SCHEDULE_KEY) && StringUtils .isNotBlank(flowSpecProperties.getProperty(ConfigurationKeys.JOB_SCHEDULE_KEY))) { jobConfig.setProperty(ConfigurationKeys.JOB_SCHEDULE_KEY, flowSpecProperties.getProperty(ConfigurationKeys.JOB_SCHEDULE_KEY)); } this.scheduledFlowSpecs.put(addedSpec.getUri().toString(), addedSpec); if (jobConfig.containsKey(ConfigurationKeys.JOB_SCHEDULE_KEY)) { _log.info("{} Scheduling flow spec: {} ", this.serviceName, addedSpec); scheduleJob(jobConfig, null); if (PropertiesUtils.getPropAsBoolean(jobConfig, ConfigurationKeys.FLOW_RUN_IMMEDIATELY, "false")) { _log.info("RunImmediately requested, hence executing FlowSpec: " + addedSpec); this.jobExecutor .execute(new NonScheduledJobRunner(flowSpec.getUri(), false, jobConfig, null)); } } else { _log.info("No FlowSpec schedule found, so running FlowSpec: " + addedSpec); this.jobExecutor.execute(new NonScheduledJobRunner(flowSpec.getUri(), true, jobConfig, null)); } } catch (JobException je) { _log.error("{} Failed to schedule or run FlowSpec {}", serviceName, addedSpec, je); } } }
From source file:meta.proyecto.base.ProyectoJava.java
private void addKeys(Properties properties, Set<String> keys) { String id$ = properties.getProperty(DICTIONARY_NEXT_ID_KEY); long id = StringUtils.isNumeric(id$) ? new Long(id$) : 1; for (String key : keys) { if (properties.containsKey(key)) { } else {/*from www .j a va 2 s .c o m*/ properties.setProperty(key, "" + id++); } } properties.setProperty(DICTIONARY_NEXT_ID_KEY, "" + id); }
From source file:com.google.api.ads.adwords.jaxws.extensions.processors.onmemory.ReportProcessorOnMemory.java
/** * Generate all the mapped reports to the given account IDs. * /* w w w.ja va 2s . com*/ * @param dateRangeType * the date range type. * @param dateStart * the starting date. * @param dateEnd * the ending date. * @param accountIdsSet * the account IDs. * @param properties * the properties file * @throws Exception * error reaching the API. */ public void generateReportsForMCC(String userId, String mccAccountId, ReportDefinitionDateRangeType dateRangeType, String dateStart, String dateEnd, Set<Long> accountIdsSet, Properties properties) throws Exception { LOGGER.info("*** Retrieving account IDs ***"); if (accountIdsSet == null || accountIdsSet.size() == 0) { accountIdsSet = this.retrieveAccountIds(userId, mccAccountId); } else { LOGGER.info("Accounts loaded from file."); } AdWordsSession.Builder builder = authenticator.authenticate(userId, mccAccountId, false); LOGGER.info("*** Generating Reports for " + accountIdsSet.size() + " accounts ***"); Stopwatch stopwatch = Stopwatch.createStarted(); Set<ReportDefinitionReportType> reports = this.csvReportEntitiesMapping.getDefinedReports(); // reports for (ReportDefinitionReportType reportType : reports) { if (properties.containsKey(reportType.name())) { this.downloadAndProcess(userId, mccAccountId, builder, reportType, dateRangeType, dateStart, dateEnd, accountIdsSet, properties); } } stopwatch.stop(); LOGGER.info("*** Finished processing all reports in " + (stopwatch.elapsed(TimeUnit.MILLISECONDS) / 1000) + " seconds ***\n"); }
From source file:com.facebook.LinkBench.distributions.ZipfDistribution.java
@Override public void init(long min, long max, Properties props, String keyPrefix) { if (max <= min) { throw new IllegalArgumentException("max = " + max + " <= min = " + min + ": probability distribution cannot have zero or negative domain"); }/* w w w. jav a 2 s. co m*/ this.min = min; this.max = max; String shapeS = props != null ? ConfigUtil.getPropertyRequired(props, keyPrefix + "shape") : null; if (shapeS == null) { throw new IllegalArgumentException( "ZipfDistribution must be provided " + keyPrefix + "shape parameter"); } shape = Double.valueOf(shapeS); if (shape <= 0.0) { throw new IllegalArgumentException("Zipf shape parameter " + shape + " is not positive"); } if (props != null && props.containsKey(keyPrefix + LinkBenchConstants.PROB_MEAN)) { scale = (max - min) * ConfigUtil.getDouble(props, keyPrefix + LinkBenchConstants.PROB_MEAN); } else { scale = 1.0; } // Precompute some values to speed up future method calls long n = max - min; alpha = 1 / (1 - shape); zetan = calcZetan(n); eta = (1 - FastMath.pow(2.0 / n, 1 - shape)) / (1 - Harmonic.generalizedHarmonic(2, shape) / zetan); point5theta = FastMath.pow(0.5, shape); }
From source file:com.mirth.connect.plugins.datapruner.DefaultDataPrunerController.java
private void applyPrunerSettings(Properties properties) { if (StringUtils.isNotEmpty(properties.getProperty("pruningBlockSize"))) { int blockSize = NumberUtils.toInt(properties.getProperty("pruningBlockSize")); if (blockSize < MIN_PRUNING_BLOCK_SIZE) { blockSize = MIN_PRUNING_BLOCK_SIZE; } else if (blockSize > MAX_PRUNING_BLOCK_SIZE) { blockSize = DataPruner.DEFAULT_PRUNING_BLOCK_SIZE; }/*w w w . j a v a2 s.c o m*/ pruner.setPrunerBlockSize(blockSize); } else { pruner.setPrunerBlockSize(DataPruner.DEFAULT_PRUNING_BLOCK_SIZE); } isEnabled = Boolean.parseBoolean(properties.getProperty("enabled")); if (properties.containsKey("pollingProperties")) { pruner.setPollingProperties(serializer.deserialize(properties.getProperty("pollingProperties"), PollConnectorProperties.class)); } else { PollConnectorProperties defaultProperties = new PollConnectorProperties(); defaultProperties.setPollingFrequency(3600000); pruner.setPollingProperties(defaultProperties); } pruner.setArchiveEnabled( Boolean.parseBoolean(properties.getProperty("archiveEnabled", Boolean.FALSE.toString()))); if (pruner.isArchiveEnabled()) { if (properties.contains("archiverOptions")) { pruner.setArchiverOptions(new MessageWriterOptions()); } else { pruner.setArchiverOptions(serializer.deserialize(properties.getProperty("archiverOptions"), MessageWriterOptions.class)); } } if (Boolean.parseBoolean(properties.getProperty("pruneEvents", Boolean.FALSE.toString()))) { pruner.setPruneEvents(true); pruner.setMaxEventAge(Integer.parseInt(properties.getProperty("maxEventAge"))); } else { pruner.setPruneEvents(false); pruner.setMaxEventAge(null); } if (StringUtils.isNotEmpty(properties.getProperty("archiverBlockSize"))) { int blockSize = NumberUtils.toInt(properties.getProperty("archiverBlockSize")); if (blockSize <= 0 || blockSize > MAX_ARCHIVING_BLOCK_SIZE) { blockSize = DataPruner.DEFAULT_ARCHIVING_BLOCK_SIZE; } pruner.setArchiverBlockSize(blockSize); } else { pruner.setArchiverBlockSize(DataPruner.DEFAULT_ARCHIVING_BLOCK_SIZE); } }
From source file:com.baomidou.framework.spring.MutilPropertyPlaceholderConfigurer.java
/** * <p>//from www.j a va 2 s . c o m * ? prop * </p> * @param mergeProperties * spring Properties * @return */ protected Properties convertMergeProperties(Properties mergeProperties) { Properties prop = new Properties(); String runMode = "_" + getRunMode() + "_mode"; Set<Entry<Object, Object>> es = mergeProperties.entrySet(); for (Entry<Object, Object> entry : es) { String key = (String) entry.getKey(); String realKey = key; int idx = key.lastIndexOf("_mode"); if (idx > 0) { if (key.contains(runMode)) { realKey = key.substring(0, key.lastIndexOf(runMode)); } else { /** ?? */ realKey = null; } } /** * ??<br> * ?? */ if (realKey != null && !prop.containsKey(realKey)) { Object value = null; if (idx > 0) { value = mergeProperties.get(realKey + runMode); } else { value = mergeProperties.get(realKey); } if (value != null) { prop.put(realKey, value); } else { throw new SpringWindException("impossible empty property for " + realKey); } } } return prop; }
From source file:com.adito.input.validators.TimeCounterValidator.java
public void validate(PropertyDefinition definition, String value, Properties properties) throws CodedException { // the value is returned in milli seconds, but the validation is done in whatever type the meta data says. int defaultItem = Integer.parseInt(value); if (definition.getTypeMeta().equalsIgnoreCase("s")) { value = String.valueOf(defaultItem / 1000); } else if (definition.getTypeMeta().equalsIgnoreCase("m")) { value = String.valueOf(defaultItem / 1000 / 60); } else if (definition.getTypeMeta().equalsIgnoreCase("h")) { value = String.valueOf(defaultItem / 1000 / 60 / 60); } else if (definition.getTypeMeta().equalsIgnoreCase("d")) { value = String.valueOf(defaultItem / 1000 / 60 / 60 / 24); }/*from w ww . j av a 2 s. co m*/ // Get the range int min = defaultMin; try { if (properties != null && properties.containsKey("minValue")) min = Integer.parseInt(properties.getProperty("minValue")); } catch (NumberFormatException nfe) { log.error("Failed to get minimum value for validator.", nfe); throw new CoreException(ErrorConstants.ERR_INTERNAL_ERROR, ErrorConstants.CATEGORY_NAME, ErrorConstants.BUNDLE_NAME, null, value); } int max = defaultMax; try { if (properties != null && properties.containsKey("maxValue")) max = Integer.parseInt(properties.getProperty("maxValue")); } catch (NumberFormatException nfe) { log.error("Failed to get maximum value for validator.", nfe); throw new CoreException(ErrorConstants.ERR_INTERNAL_ERROR, ErrorConstants.CATEGORY_NAME, ErrorConstants.BUNDLE_NAME, null, value); } /* We may support replacement variables so * to validate we must replace with the minimum value */ if (properties != null && "true".equalsIgnoreCase(properties.getProperty("replacementVariables"))) { Replacer r = new Replacer() { public String getReplacement(Pattern pattern, Matcher matcher, String replacementPattern) { return replacementPattern; } }; ReplacementEngine re = new ReplacementEngine(); re.addPattern(VariableReplacement.VARIABLE_PATTERN, r, String.valueOf(min)); value = re.replace(value); } // Validate try { int i = Integer.parseInt(value); if (i < min || i > max) { throw new CoreException(ErrorConstants.ERR_INTEGER_OUT_OF_RANGE, ErrorConstants.CATEGORY_NAME, ErrorConstants.BUNDLE_NAME, null, String.valueOf(min), String.valueOf(max), value, null); } } catch (NumberFormatException nfe) { throw new CoreException(ErrorConstants.ERR_NOT_AN_INTEGER, ErrorConstants.CATEGORY_NAME, ErrorConstants.BUNDLE_NAME, null, String.valueOf(min), String.valueOf(max), value, null); } }
From source file:org.apache.zeppelin.zeppelin_spark_monitoring.SparkMonitoringInterpreter.java
@Override public void open() { try {/*www . java2 s .com*/ //get connection properties, split prefix for (String propertyKey : property.stringPropertyNames()) { logger.debug("propertyKey: {}", propertyKey); String[] keyValue = propertyKey.split("\\.", 2); if (2 == keyValue.length) { logger.info("key: {}, value: {}", keyValue[0], keyValue[1]); Properties prefixProperties; if (propertiesMap.containsKey(keyValue[0])) { prefixProperties = propertiesMap.get(keyValue[0]); } else { prefixProperties = new Properties(); propertiesMap.put(keyValue[0], prefixProperties); } prefixProperties.put(keyValue[1], property.getProperty(propertyKey)); } } //remove duplicate key Set<String> removeKeySet = new HashSet<>(); for (String key : propertiesMap.keySet()) { Properties properties = propertiesMap.get(key); if (!properties.containsKey(SPARK_MONITORING_HOST) || !properties.containsKey(SPARK_MONITORING_PORT)) { logger.error("{} will be ignored. {} and {} is mandatory.", key, SPARK_MONITORING_HOST, SPARK_MONITORING_PORT); removeKeySet.add(key); } } for (String key : removeKeySet) { propertiesMap.remove(key); } } catch (Exception e) { isMonitoringServerAvailable = false; logger.error("Open connection to Spark Monitoring", e); } }
From source file:com.googlecode.fascinator.redbox.plugins.curation.external.ExternalCurationTransactionManager.java
/** * Get the requested object ready for publication. This would typically just * involve setting a flag/*from www.java 2 s . com*/ * * @param message * The incoming message * @param oid * The object identifier to publish * @return JsonSimple The response object * @throws TransactionException * If an error occurred */ private JsonSimple publish(JsonSimple message, String oid) throws TransactionException { log.debug("Publishing '{}'", oid); JsonSimple response = new JsonSimple(); try { DigitalObject object = storage.getObject(oid); Properties metadata = object.getMetadata(); // Already published? if (!metadata.containsKey(PUBLISH_PROPERTY)) { metadata.setProperty(PUBLISH_PROPERTY, "true"); object.close(); log.info("Publication flag set '{}'", oid); audit(response, oid, "Publication flag set"); } else { log.info("Publication flag is already set '{}'", oid); } } catch (StorageException ex) { throw new TransactionException("Error setting publish property: ", ex); } // Make a final pass through the curation tool(s), // allows for external publication. eg. VITAL JsonSimple itemConfig = getConfigFromStorage(oid); if (itemConfig == null) { log.error("Error accessing item configuration!"); } else { List<String> list = itemConfig.getStringList("transformer", "curation"); if (list != null && !list.isEmpty()) { for (String id : list) { JsonObject order = newTransform(response, id, oid); JsonObject config = (JsonObject) order.get("config"); JsonObject overrides = itemConfig.getObject("transformerOverrides", id); if (overrides != null) { config.putAll(overrides); } } } } // Don't forget to publish children publishRelations(response, oid); return response; }