Java Code Examples for java.util.Properties#contains()

The following examples show how to use java.util.Properties#contains() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Configuration.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Sets all deprecated properties that are not currently set but have a
 * corresponding new property that is set. Useful for iterating the
 * properties when all deprecated properties for currently set properties
 * need to be present.
 */
public void setDeprecatedProperties() {
	DeprecationContext deprecations = deprecationContext.get();
	Properties props = getProps();
	Properties overlay = getOverlay();
	for (Map.Entry<String, DeprecatedKeyInfo> entry :
			deprecations.getDeprecatedKeyMap().entrySet()) {
		String depKey = entry.getKey();
		if (!overlay.contains(depKey)) {
			for (String newKey : entry.getValue().newKeys) {
				String val = overlay.getProperty(newKey);
				if (val != null) {
					props.setProperty(depKey, val);
					overlay.setProperty(depKey, val);
					break;
				}
			}
		}
	}
}
 
Example 2
Source File: Configuration.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Sets all deprecated properties that are not currently set but have a
 * corresponding new property that is set. Useful for iterating the
 * properties when all deprecated properties for currently set properties
 * need to be present.
 */
public void setDeprecatedProperties() {
	DeprecationContext deprecations = deprecationContext.get();
	Properties props = getProps();
	Properties overlay = getOverlay();
	for (Map.Entry<String, DeprecatedKeyInfo> entry :
			deprecations.getDeprecatedKeyMap().entrySet()) {
		String depKey = entry.getKey();
		if (!overlay.contains(depKey)) {
			for (String newKey : entry.getValue().newKeys) {
				String val = overlay.getProperty(newKey);
				if (val != null) {
					props.setProperty(depKey, val);
					overlay.setProperty(depKey, val);
					break;
				}
			}
		}
	}
}
 
Example 3
Source File: ResourceMojo.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
private void lateInit() {
    RuntimeMode runtimeMode = getRuntimeMode();
    jkubeServiceHub.setPlatformMode(runtimeMode);
    if (runtimeMode.equals(RuntimeMode.OPENSHIFT)) {
        Properties properties = project.getProperties();
        if (!properties.contains(DOCKER_IMAGE_USER)) {
            String namespaceToBeUsed = this.namespace != null && !this.namespace.isEmpty() ?
                    this.namespace: clusterAccess.getNamespace();
            log.info("Using docker image name of namespace: " + namespaceToBeUsed);
            properties.setProperty(DOCKER_IMAGE_USER, namespaceToBeUsed);
        }
        if (!properties.contains(RuntimeMode.JKUBE_EFFECTIVE_PLATFORM_MODE)) {
            properties.setProperty(RuntimeMode.JKUBE_EFFECTIVE_PLATFORM_MODE, runtimeMode.toString());
        }
    }
}
 
Example 4
Source File: Configuration.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Sets all deprecated properties that are not currently set but have a
 * corresponding new property that is set. Useful for iterating the
 * properties when all deprecated properties for currently set properties
 * need to be present.
 */
public void setDeprecatedProperties() {
  DeprecationContext deprecations = deprecationContext.get();
  Properties props = getProps();
  Properties overlay = getOverlay();
  for (Map.Entry<String, DeprecatedKeyInfo> entry :
      deprecations.getDeprecatedKeyMap().entrySet()) {
    String depKey = entry.getKey();
    if (!overlay.contains(depKey)) {
      for (String newKey : entry.getValue().newKeys) {
        String val = overlay.getProperty(newKey);
        if (val != null) {
          props.setProperty(depKey, val);
          overlay.setProperty(depKey, val);
          break;
        }
      }
    }
  }
}
 
Example 5
Source File: DistributedTestCase.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public final Properties getAllDistributedSystemProperties(Properties props) {
  Properties p = DUnitEnv.get().getDistributedSystemProperties();
  
  // our tests do not expect auto-reconnect to be on by default
  if (!p.contains(DistributionConfig.DISABLE_AUTO_RECONNECT_NAME)) {
    p.put(DistributionConfig.DISABLE_AUTO_RECONNECT_NAME, "true");
  }
      
  for (Iterator iter = props.entrySet().iterator();
  iter.hasNext(); ) {
    Map.Entry entry = (Map.Entry) iter.next();
    String key = (String) entry.getKey();
    Object value = entry.getValue();
    p.put(key, value);
  }
  return p;
}
 
Example 6
Source File: DataSourceFactory.java    From tomee with Apache License 2.0 6 votes vote down vote up
private static void convert(final Properties properties, final Duration duration, final String key, final String oldKey) {
    properties.remove(key);

    // If someone is using the legacy property, use it
    if (properties.contains(oldKey)) {
        return;
    }
    properties.remove(oldKey);

    if (duration == null) {
        return;
    }
    if (duration.getUnit() == null) {
        duration.setUnit(TimeUnit.MILLISECONDS);
    }

    final long milliseconds = TimeUnit.MILLISECONDS.convert(duration.getTime(), duration.getUnit());
    properties.put(oldKey, String.valueOf(milliseconds));
}
 
Example 7
Source File: Configuration.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Sets all deprecated properties that are not currently set but have a
 * corresponding new property that is set. Useful for iterating the
 * properties when all deprecated properties for currently set properties
 * need to be present.
 */
public void setDeprecatedProperties() {
	DeprecationContext deprecations = deprecationContext.get();
	Properties props = getProps();
	Properties overlay = getOverlay();
	for (Map.Entry<String, DeprecatedKeyInfo> entry :
			deprecations.getDeprecatedKeyMap().entrySet()) {
		String depKey = entry.getKey();
		if (!overlay.contains(depKey)) {
			for (String newKey : entry.getValue().newKeys) {
				String val = overlay.getProperty(newKey);
				if (val != null) {
					props.setProperty(depKey, val);
					overlay.setProperty(depKey, val);
					break;
				}
			}
		}
	}
}
 
Example 8
Source File: Storage.java    From spork with Apache License 2.0 6 votes vote down vote up
/**
 * reset the store and get the Data object to access it
 * @param context
 * @return data as Data
 */
public static Data resetData(PigContext context) {
  Properties properties = context.getProperties();

  // cleaning up previous data
  try {
    if (properties.contains(PIG_CONTEXT_KEY)) {
      Integer previousId = new Integer(properties.getProperty(PIG_CONTEXT_KEY));
      idToData.remove(previousId);
    }
  } catch (RuntimeException e) {
    LOG.warn("invalid id in context properties for "+PIG_CONTEXT_KEY, e);
  }

  // setting new Store
  int id = nextId++;
  properties.setProperty(PIG_CONTEXT_KEY, String.valueOf(id));
  Data data = new Data();
  idToData.put(id, data);
  return data;
}
 
Example 9
Source File: DistributedTestCase.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public final Properties getAllDistributedSystemProperties(Properties props) {
  Properties p = DUnitEnv.get().getDistributedSystemProperties();
  
  // our tests do not expect auto-reconnect to be on by default
  if (!p.contains(DistributionConfig.DISABLE_AUTO_RECONNECT_NAME)) {
    p.put(DistributionConfig.DISABLE_AUTO_RECONNECT_NAME, "true");
  }
      
  for (Iterator iter = props.entrySet().iterator();
  iter.hasNext(); ) {
    Map.Entry entry = (Map.Entry) iter.next();
    String key = (String) entry.getKey();
    Object value = entry.getValue();
    p.put(key, value);
  }
  return p;
}
 
Example 10
Source File: TestUtils.java    From digdag with Apache License 2.0 6 votes vote down vote up
public static void withSystemProperties(Map<String, String> props, Action a)
        throws Exception
{
    Properties systemProperties = System.getProperties();
    Map<String, Object> prev = new HashMap<>();
    for (String key : props.keySet()) {
        if (systemProperties.contains(key)) {
            prev.put(key, systemProperties.getProperty(key));
        } else {
            prev.put(key, NOT_PRESENT);
        }
    }
    try {
        systemProperties.putAll(props);
        a.run();
    }
    finally {
        for (Map.Entry<String, Object> e : prev.entrySet()) {
            if (e.getValue() == NOT_PRESENT) {
                systemProperties.remove(e.getKey());
            } else {
                systemProperties.put(e.getKey(), e.getValue());
            }
        }
    }
}
 
Example 11
Source File: PropertiesUtils.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * <p>
 * In addition to overriding file properties from System Properties, System properties are added to the returned
 * Properties.
 * </p><p>
 * {@see #systemPropertiesOverride}
 * </p>
 *
 *
 * @param props Properties with System Properties added and Overriding file properties
 * @param arg filter System Properties added to Properties by the Property key starting with arg
 * @return
 */
public Properties systemPropertiesAndOverride(Properties props, String arg) {
    PropertiesUtils propUtils = new PropertiesUtils();
    props = propUtils.systemPropertiesOverride(props, arg);

    Iterator iter = System.getProperties().stringPropertyNames().iterator();
    while (iter.hasNext()) {
        String key = (String) iter.next();
        if (arg == null || arg.equals("")) {
            if (!props.contains(key)) {
                props.setProperty(key, System.getProperty(key));
            }
        } else {
            if (key.startsWith(arg) && !props.contains(key)) {
                props.setProperty(key, System.getProperty(key));
            }
        }
    }
    return props;
}
 
Example 12
Source File: PropertiesCallbackHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void verifyProperties(Properties properties) throws IOException {
    final String admin = "admin";
    if (properties.contains(admin) && admin.equals(properties.get(admin))) {
        ROOT_LOGGER.userAndPasswordWarning();
    }
}
 
Example 13
Source File: GobblinClusterManager.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
/**
 * Create the service based application launcher and other associated services
 * @throws Exception
 */
private void initializeAppLauncherAndServices() throws Exception {
  // Done to preserve backwards compatibility with the previously hard-coded timeout of 5 minutes
  Properties properties = ConfigUtils.configToProperties(this.config);
  if (!properties.contains(ServiceBasedAppLauncher.APP_STOP_TIME_SECONDS)) {
    properties.setProperty(ServiceBasedAppLauncher.APP_STOP_TIME_SECONDS, Long.toString(300));
  }
  this.applicationLauncher = new ServiceBasedAppLauncher(properties, this.clusterName);

  // create a job catalog for keeping track of received jobs if a job config path is specified
  if (this.config.hasPath(GobblinClusterConfigurationKeys.GOBBLIN_CLUSTER_PREFIX
      + ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY)) {
    String jobCatalogClassName = ConfigUtils.getString(config, GobblinClusterConfigurationKeys.JOB_CATALOG_KEY,
        GobblinClusterConfigurationKeys.DEFAULT_JOB_CATALOG);

    this.jobCatalog =
        (MutableJobCatalog) GobblinConstructorUtils.invokeFirstConstructor(Class.forName(jobCatalogClassName),
        ImmutableList.of(config
            .getConfig(StringUtils.removeEnd(GobblinClusterConfigurationKeys.GOBBLIN_CLUSTER_PREFIX, "."))
            .withFallback(this.config)));
  } else {
    this.jobCatalog = null;
  }

  SchedulerService schedulerService = new SchedulerService(properties);
  this.applicationLauncher.addService(schedulerService);
  this.jobScheduler = buildGobblinHelixJobScheduler(config, this.appWorkDir, getMetadataTags(clusterName, applicationId),
      schedulerService);
  this.applicationLauncher.addService(this.jobScheduler);
  this.jobConfigurationManager = buildJobConfigurationManager(config);
  this.applicationLauncher.addService(this.jobConfigurationManager);

  if (ConfigUtils.getBoolean(this.config, GobblinClusterConfigurationKeys.CONTAINER_HEALTH_METRICS_SERVICE_ENABLED,
      GobblinClusterConfigurationKeys.DEFAULT_CONTAINER_HEALTH_METRICS_SERVICE_ENABLED)) {
    this.applicationLauncher.addService(new ContainerHealthMetricsService(config));
  }
}
 
Example 14
Source File: CliClientParamsFactory.java    From tajo with Apache License 2.0 5 votes vote down vote up
public static Properties get(@Nullable Properties connParam) {
  Properties copy = connParam == null ? new Properties() : (Properties) connParam.clone();
  for (Map.Entry<String, String> entry : DEFAULT_PARAMS.entrySet()) {
    if (!copy.contains(entry.getKey())) {
      copy.setProperty(entry.getKey(), entry.getValue());
    }
  }
  return copy;
}
 
Example 15
Source File: RemoteTestServer.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
    public void init(final Properties props) {
        properties = props;
        if (props.contains("java.naming.security.principal"))
            throw new IllegalArgumentException("Not allowed 'java.naming.security.principal'");
//        props.put("test.server.class","org.apache.openejb.test.RemoteTestServer");
        props.put("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory");
        props.put("java.naming.provider.url", "127.0.0.1:4201");
//        props.put("java.naming.security.principal", "testuser");
//        props.put("java.naming.security.credentials", "testpassword");
    }
 
Example 16
Source File: FulltextSearchServiceFactory.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Resolves the endpoint type, which is either a constant or a variable to
 * be looked up in the binding set.
 * @return Class name for the endpoint type or null if none found
 */
private String resolveEndpointType(IBindingSet bs) {

   String endpointTypeStr = resolveAsString(endpointType, bs);

   // try override with system default, if not set
   if (endpointTypeStr==null) {
      endpointTypeStr = defaults.getDefaultEndpointType();
   }
   
   if (endpointTypeStr != null && !endpointTypeStr.isEmpty()) {
        final String endpointName = FTS.FTS_CUSTOM_TYPE + endpointTypeStr;
        final Properties props = getStoreProps(serviceCallParams);
        try {
            if (props.contains(endpointName)) {
               return props.getProperty(endpointName);
            }
            switch(EndpointType.valueOf(endpointTypeStr)) {
                case SOLR:
                    return SolrFulltextSearchImpl.class.getName();
            }
      } catch (Exception e) {

         // illegal, ignore and proceed
         if (log.isDebugEnabled()) {
            log.warn("Illegal endpoint type: " + endpointTypeStr + 
                  " -> will be ignored, using default.");
         }

      }
   }

   return null; // fallback to default
}
 
Example 17
Source File: PulsarKafkaSimpleConsumer.java    From pulsar with Apache License 2.0 5 votes vote down vote up
private SubscriptionType getSubscriptionType(Properties properties) {
    String subType = properties != null && properties.contains(SUBSCRIPTION_TYPE)
            ? properties.getProperty(SUBSCRIPTION_TYPE)
            : SubscriptionType.Failover.toString();
    try {
        return SubscriptionType.valueOf(subType);
    } catch (IllegalArgumentException ie) {
        return SubscriptionType.Failover;
    }
}
 
Example 18
Source File: PropsUtil.java    From Zebra with MIT License 5 votes vote down vote up
public static int getInt(Properties props, String key, int defaultValue){
	int value = defaultValue;
	if(props.contains(key)){
		value = Integer.valueOf(props.getProperty(key));
	}
	return value;
}
 
Example 19
Source File: PropsUtil.java    From Zebra with MIT License 5 votes vote down vote up
public static String getString(Properties props, String key, String defaultValue){
	String value = defaultValue;
	if( props.contains(key)){
		value = props.getProperty(key);
	}
	return value;
}
 
Example 20
Source File: SpacedLogbackSystem.java    From spring-cloud-formula with Apache License 2.0 5 votes vote down vote up
protected Appender<ILoggingEvent> fileAppender(Space space) {
    RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<>();
    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    String logPattern = this.patterns.getProperty("logging.pattern.file", FILE_LOG_PATTERN);
    encoder.setPattern(OptionHelper.substVars(logPattern, context));
    encoder.setCharset(DEFAULT_CHARSET);
    appender.setEncoder(encoder);
    start(encoder);

    // parse path and file
    // first consider spec.path, second, default_spec.path, third logging.path
    LogFile logFile = LogFile.get(patterns);
    Properties defaultProperties = new Properties();
    if (logFile != null) {
        logFile.applyTo(defaultProperties);
    }
    String path = space.getSpec().getPath() != null ? space.getSpec().getPath() :
            space.getDefaultSpec().getPath() != null ? space.getDefaultSpec().getPath() :
                    defaultProperties.contains(LoggingSystemProperties.LOG_PATH)
                            ? defaultProperties.getProperty(LoggingSystemProperties.LOG_PATH) :
                            DEFAULT_PATH;
    path = patterns.resolvePlaceholders(path);
    String file = space.getSpec().getFile() != null
            ? fileName(space.getSpec().getFile()) : fileName(space.getName());
    file = patterns.resolvePlaceholders(file);
    appender.setFile(path + "/" + file);
    setRollingPolicy(appender, space, path, file);

    //  threshold config
    ThresholdFilter thresholdFilter = new ThresholdFilter();
    if (space.getSpec().getThreshold() != null) {
        thresholdFilter.setLevel(space.getSpec().getThreshold());
        start(thresholdFilter);
        appender.addFilter(thresholdFilter);
    }

    appender("SPACE-" + space.getName(), appender);
    return appender;
}