本文整理匯總了Java中java.util.Properties.entrySet方法的典型用法代碼示例。如果您正苦於以下問題:Java Properties.entrySet方法的具體用法?Java Properties.entrySet怎麽用?Java Properties.entrySet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.Properties
的用法示例。
在下文中一共展示了Properties.entrySet方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: load
import java.util.Properties; //導入方法依賴的package包/類
public void load() {
try {
Logger.getLogger("").setLevel(Level.INFO);
final Properties properties = new Properties();
try { properties.load(new FileInputStream("logging.properties")); }
catch(FileNotFoundException ignored) {}
for(Map.Entry<Object, Object> entry : properties.entrySet()) {
String[] parts = entry.getKey().toString().split("\\.");
if(parts.length == 2 && "level".equals(parts[1])) {
String loggerName = parts[0];
String levelName = (String) entry.getValue();
if("root".equals(loggerName)) {
loggerName = "";
}
Logging.setDefaultLevel(loggerName, Level.parse(levelName));
}
}
Logging.updateFromLoggingProperties();
} catch(IOException | NoSuchFieldException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
logger.log(Level.WARNING, "Error applying logging config", e);
}
}
示例2: getSystemProperties
import java.util.Properties; //導入方法依賴的package包/類
@NonNull
public static Pair<Map<String,String>,Map<String,String>> getSystemProperties(@NonNull final Properties p) {
final Map<String,String> sysProps = new HashMap<>();
final Map<String,String> properties = new HashMap<>();
for (Map.Entry<Object,Object> e : p.entrySet()) {
String key = (String) e.getKey();
String value = (String) e.getValue();
if (key.startsWith(NB_PROP_PREFIX)) {
properties.put(
String.format(
"%s%s", //NOI18N
PLATFROM_PROP_PREFIX,
key.substring(NB_PROP_PREFIX.length())),
value);
} else {
sysProps.put(key, value);
}
}
return Pair.<Map<String,String>,Map<String,String>>of(properties,sysProps);
}
示例3: loadConfiguration
import java.util.Properties; //導入方法依賴的package包/類
/**
* Loads the configuration from the properties.
*
* @param properties the properties to load
*/
private void loadConfiguration(
final Properties properties
) {
for (Entry<Object, Object> entry : properties.entrySet()) {
// run the matcher
Matcher entryMatch = patternConfigurationItem.matcher(entry.getKey().toString());
// result valid?
if (!entryMatch.matches()) {
continue;
}
// load property
loadProperty(
entryMatch.group(1),
entryMatch.group(2),
entry.getValue().toString()
);
}
// log configuration
logConfiguration();
}
示例4: readZKNodes
import java.util.Properties; //導入方法依賴的package包/類
public static ServerName[] readZKNodes(Configuration conf) {
List<ServerName> hosts = new LinkedList<ServerName>();
// Note that we do not simply grab the property
// HConstants.ZOOKEEPER_QUORUM from the HBaseConfiguration because the
// user may be using a zoo.cfg file.
Properties zkProps = ZKConfig.makeZKProps(conf);
for (Entry<Object, Object> entry : zkProps.entrySet()) {
String key = entry.getKey().toString().trim();
String value = entry.getValue().toString().trim();
if (key.startsWith("server.")) {
String[] parts = value.split(":");
String host = parts[0];
int port = HConstants.DEFAULT_ZOOKEPER_CLIENT_PORT;
if (parts.length > 1) {
port = Integer.parseInt(parts[1]);
}
hosts.add(ServerName.valueOf(host, port, -1));
}
}
return hosts.toArray(new ServerName[hosts.size()]);
}
示例5: compareJobProperties
import java.util.Properties; //導入方法依賴的package包/類
private void compareJobProperties(JobProperties jprop1, JobProperties jprop2,
TreePath loc, String eltname)
throws DeepInequalityException {
if (jprop1 == null && jprop2 == null) {
return;
}
if (jprop1 == null || jprop2 == null) {
throw new DeepInequalityException(eltname + " miscompared",
new TreePath(loc, eltname));
}
Properties prop1 = jprop1.getValue();
Properties prop2 = jprop2.getValue();
if (prop1.size() != prop2.size()) {
throw new DeepInequalityException(eltname + " miscompared [size]",
new TreePath(loc, eltname));
}
for (Map.Entry<Object, Object> entry : prop1.entrySet()) {
String v1 = entry.getValue().toString();
String v2 = prop2.get(entry.getKey()).toString();
compare1(v1, v2, new TreePath(loc, eltname), "key:" + entry.getKey());
}
}
示例6: mergeProperties
import java.util.Properties; //導入方法依賴的package包/類
/**
* Adds the incoming properties to the internal properties structure, as long as the internal structure does not
* already contain an entry for the given key.
*
* @param properties The properties to merge
*
* @return this for ethod chaining
*/
public Configuration mergeProperties(Properties properties) {
for ( Map.Entry entry : properties.entrySet() ) {
if ( this.properties.containsKey( entry.getKey() ) ) {
continue;
}
this.properties.setProperty( (String) entry.getKey(), (String) entry.getValue() );
}
return this;
}
示例7: createProperties
import java.util.Properties; //導入方法依賴的package包/類
@Override
protected Properties createProperties() throws IOException {
ConfigCollectionFactory configCollectionFactory = RemoteConfigCollectionFactoryBuilder.getInstance();
if (configApps == null || configApps.size() == 0) {
return super.createProperties();
}
Map<ConfigApp, Map<String, String>> allDatas = WxzConfManager.getInstance().load(configApps);
Properties properties = new Properties();
for (Map.Entry<ConfigApp, Map<String, String>> entry0 : allDatas.entrySet()) {
for (Map.Entry<String, String> entry : entry0.getValue().entrySet()) {
//處理properties文件
if (PropertiesUtils.SUFFIX.equalsIgnoreCase(FilenameUtils.getExtension(entry.getKey()))) {
try {
Properties p = PropertiesUtils.readFromText(entry.getValue());
p.load(new StringReader(entry.getValue()));
for (Map.Entry<Object, Object> objectEntry : p.entrySet()) {
//將配置重複的項打印出來
if (properties.containsKey(objectEntry.getKey())) {
LOGGER.warn("key {} will be overrided,original value {},new value {}", objectEntry.getKey(), properties.get(objectEntry.getKey()), objectEntry.getValue());
}
properties.put(objectEntry.getKey(), objectEntry.getValue());
}
} catch (IOException e) {
LOGGER.error(entry.toString(), e);
}
}
}
}
return properties;
}
示例8: setMediaTypes
import java.util.Properties; //導入方法依賴的package包/類
/**
* Add mappings from file extensions to media types represented as strings.
* <p>When this mapping is not set or when an extension is not found, the Java
* Action Framework, if available, may be used if enabled via
* {@link #setFavorPathExtension(boolean)}.
* @see #addMediaType(String, MediaType)
* @see #addMediaTypes(Map)
*/
public void setMediaTypes(Properties mediaTypes) {
if (!CollectionUtils.isEmpty(mediaTypes)) {
for (Entry<Object, Object> entry : mediaTypes.entrySet()) {
String extension = ((String)entry.getKey()).toLowerCase(Locale.ENGLISH);
this.mediaTypes.put(extension, MediaType.valueOf((String) entry.getValue()));
}
}
}
示例9: extractEntries
import java.util.Properties; //導入方法依賴的package包/類
/**
* Extracts name/value entries from a set of properties based on a given name prefix.
*
* @param properties the properties set to extract from
* @param prefix entries whose names start with this prefix are extracted
* @param stripPrefix specifies whether to remove the prefix from the names in the returned map
*/
public static EconomicMap<String, String> extractEntries(Properties properties, String prefix, boolean stripPrefix) {
EconomicMap<String, String> matches = EconomicMap.create();
for (Map.Entry<Object, Object> e : properties.entrySet()) {
String name = (String) e.getKey();
if (name.startsWith(prefix)) {
String value = (String) e.getValue();
if (stripPrefix) {
name = name.substring(prefix.length());
}
matches.put(name, value);
}
}
return matches;
}
示例10: loadTargetsFromConfig
import java.util.Properties; //導入方法依賴的package包/類
/**
* Loads targets for specific commands from shared config property file.
* @returns map; key=command name; value=array of targets for given command
*/
@NonNull
static Map<String,String[]> loadTargetsFromConfig(
@NonNull final Project project,
@NonNull final PropertyEvaluator evaluator) {
final Map<String,String[]> targets = new HashMap<>(6);
final String config = evaluator.getProperty(ProjectProperties.PROP_PROJECT_CONFIGURATION_CONFIG);
// load targets from shared config
FileObject propFO = project.getProjectDirectory().getFileObject("nbproject/configs/" + config + ".properties");
if (propFO == null) {
return targets;
}
final Properties props = new Properties();
try (InputStream is = propFO.getInputStream()) {
props.load(is);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
return targets;
}
for (Map.Entry<Object,Object> e : props.entrySet()) {
final String propName = (String) e.getKey();
if (propName.startsWith("$target.")) {
final String tNameVal = (String) e.getValue();
if (tNameVal != null && !tNameVal.isEmpty()) {
final String cmdNameKey = propName.substring("$target.".length());
final StringTokenizer stok = new StringTokenizer(tNameVal.trim(), " ");
List<String> targetNames = new ArrayList<>(3);
while (stok.hasMoreTokens()) {
targetNames.add(stok.nextToken());
}
targets.put(cmdNameKey, targetNames.toArray(new String[targetNames.size()]));
}
}
}
return targets;
}
示例11: attributesFor
import java.util.Properties; //導入方法依賴的package包/類
@Override
public Map<String, ?> attributesFor(DataObject template, DataFolder target, String name) {
FileObject dir = FileUtil.getConfigFile("Templates/Properties");
if (dir == null) {
return Collections.emptyMap();
}
Charset set;
InputStream is;
Map<String, Object> ret = new HashMap<>();
for (Enumeration<? extends FileObject> en = dir.getChildren(true); en.hasMoreElements(); ) {
try {
FileObject fo = en.nextElement();
Properties p = new Properties();
is = fo.getInputStream();
p.load(is);
is.close();
for (Map.Entry<Object, Object> entry : p.entrySet()) {
if (entry.getKey() instanceof String) {
String key = (String) entry.getKey();
if (!ret.containsKey(key)) {
ret.put(key, entry.getValue());
}
}
}
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
return ret;
}
示例12: getGroupArtifactVersionMap
import java.util.Properties; //導入方法依賴的package包/類
protected static Map<String, String> getGroupArtifactVersionMap() {
if(groupArtifactVersionMap == null) {
groupArtifactVersionMap = new HashMap<>();
InputStream in = VersionHelper.class.getResourceAsStream("versions.properties");
if(in == null) {
LOG.warn("Could not find versions.properties on the classpath!");
} else {
Properties properties = new Properties();
try {
properties.load(in);
} catch (IOException var7) {
throw new RuntimeException("Failed to load versions.properties: " + var7, var7);
}
Set entries = properties.entrySet();
for (Object entry1 : entries) {
Map.Entry entry = (Map.Entry) entry1;
Object key = entry.getKey();
Object value = entry.getValue();
if (key != null && value != null) {
groupArtifactVersionMap.put(key.toString(), value.toString());
}
}
}
}
return groupArtifactVersionMap;
}
示例13: toCSS
import java.util.Properties; //導入方法依賴的package包/類
public static String toCSS(Properties properties) {
Entry<Object, Object> typeProperty = null;
Entry<Object, Object> indexProperty = null;
Entry<Object, Object> tagNameProperty = null;
StringBuilder sb = new StringBuilder();
Set<Entry<Object, Object>> entries = properties.entrySet();
for (Entry<Object, Object> entry : entries) {
if (entry.getKey().equals("type")) {
typeProperty = entry;
} else if (entry.getKey().equals("indexOfType")) {
indexProperty = entry;
} else if (entry.getKey().equals("tagName")) {
tagNameProperty = entry;
} else {
String value = entry.getValue().toString();
value = value.replaceAll("\\\\", "\\\\\\\\").replaceAll("'", "\\\\'");
sb.append("[").append(entry.getKey().toString()).append("=").append("'").append(value).append("']");
}
}
String r = sb.toString();
if (tagNameProperty != null) {
r = tagNameProperty.getValue().toString();
}
if (typeProperty != null) {
r = "[" + typeProperty.getKey().toString() + "=" + "'" + typeProperty.getValue().toString() + "']" + sb.toString();
}
if (indexProperty != null) {
int index = Integer.parseInt(indexProperty.getValue().toString());
r = r + ":nth(" + (index + 1) + ")";
}
return r;
}
示例14: load
import java.util.Properties; //導入方法依賴的package包/類
public void load(Properties fmProperties) {
for(JwalaPath path : JwalaPath.values()) {
paths.put(path, path.getDefaultPath());
}
for(Map.Entry<Object, Object> e : fmProperties.entrySet()) {
if(e.getKey().toString().startsWith("paths.")) {
for(Map.Entry<JwalaPath, Path> entry : paths.entrySet()) {
if(entry.getKey().getProperty().equalsIgnoreCase(e.getKey().toString())) {
entry.setValue(defaultFs.getPath(e.getValue().toString()));
}
}
}
}
}
示例15: getPluginImplementationViaProperty
import java.util.Properties; //導入方法依賴的package包/類
static Object getPluginImplementationViaProperty(Class<?> pluginClass, Properties props) {
String classSimpleName = pluginClass.getSimpleName();
String pluginPrefix = "rxjava.plugin.";
String implementingClass = props.getProperty("rxjava.plugin." + classSimpleName + ".implementation");
if (implementingClass == null) {
String classSuffix = ".class";
String implSuffix = ".impl";
for (Entry<Object, Object> e : props.entrySet()) {
String key = e.getKey().toString();
if (key.startsWith("rxjava.plugin.") && key.endsWith(".class") && classSimpleName.equals(e.getValue().toString())) {
String implKey = "rxjava.plugin." + key.substring(0, key.length() - ".class".length()).substring("rxjava.plugin.".length()) + ".impl";
implementingClass = props.getProperty(implKey);
if (implementingClass == null) {
throw new RuntimeException("Implementing class declaration for " + classSimpleName + " missing: " + implKey);
}
}
}
}
if (implementingClass == null) {
return null;
}
try {
return Class.forName(implementingClass).asSubclass(pluginClass).newInstance();
} catch (ClassCastException e2) {
throw new RuntimeException(classSimpleName + " implementation is not an instance of " + classSimpleName + ": " + implementingClass);
} catch (ClassNotFoundException e3) {
throw new RuntimeException(classSimpleName + " implementation class not found: " + implementingClass, e3);
} catch (InstantiationException e4) {
throw new RuntimeException(classSimpleName + " implementation not able to be instantiated: " + implementingClass, e4);
} catch (IllegalAccessException e5) {
throw new RuntimeException(classSimpleName + " implementation not able to be accessed: " + implementingClass, e5);
}
}