📄 propertieshelper.java
字号:
/*
* Copyright 2006-2007 Queplix Corp.
*
* Licensed under the Queplix Public License, Version 1.1.1 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.queplix.com/solutions/commercial-open-source/queplix-public-license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.queplix.tools.fkchecker.client.helpers;
import java.text.DecimalFormat;
import java.text.ParsePosition;
import java.util.*;
/**
* @author dmitry.antonov
*/
public class PropertiesHelper {
private static boolean isADigit(String value) {
ParsePosition ps = new ParsePosition(0);
DecimalFormat.getNumberInstance().parse(value, ps);
return ps.getErrorIndex() == -1 && ps.getIndex() == value.length();
}
private static class Property {
public String getPropertyName() {
return propertyName;
}
public String getPropertyValue() {
return propertyValue;
}
public String getPropertySuffix() {
return propertySuffix;
}
private String propertyName;
private String propertyValue;
private String propertySuffix;
public Property(Map.Entry entry) {
propertyValue = entry.getValue().toString();
propertyName = entry.getKey().toString();
int lastPoint = propertyName.lastIndexOf('.');
propertySuffix = new String(propertyName.substring(lastPoint));
propertyName = new String(propertyName.substring(0, lastPoint));
}
}
private static void addPropertyIntoMap(Map<String, List<Property>> map, Map.Entry entry) {
Property property = new Property(entry);
List<Property> list = map.get(property.getPropertySuffix());
if (list == null) {
list = new ArrayList<Property>();
map.put(property.getPropertySuffix(), list);
}
list.add(property);
}
private static Properties createProperties(List<Property> list) {
Properties result = new Properties();
for (Property property : list) {
result.setProperty(property.getPropertyName(), property.getPropertyValue());
}
return result;
}
public static Properties[] splitProperties(Properties properties) {
boolean isMultisource = false;
for (Object o: properties.keySet()) {
String[] key = ("" + o).split("\\.");
if (isADigit(key[key.length - 1])) {
isMultisource = true;
break;
}
}
if (isMultisource) {
Map<String, List<Property>> map = new HashMap<String, List<Property>>();
for (Map.Entry entry: properties.entrySet()) {
addPropertyIntoMap(map, entry);
}
Properties[] result = new Properties[map.size()];
int idx = 0;
for (List<Property> list : map.values()) {
result[idx++] = createProperties(list);
}
return result;
}
else {
return new Properties[]{properties};
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -