本文整理匯總了Java中java.util.TreeMap類的典型用法代碼示例。如果您正苦於以下問題:Java TreeMap類的具體用法?Java TreeMap怎麽用?Java TreeMap使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TreeMap類屬於java.util包,在下文中一共展示了TreeMap類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: toMultimap
import java.util.TreeMap; //導入依賴的package包/類
public static Map<String, List<String>> toMultimap(Headers headers, String valueForNullKey) {
Map<String, List<String>> result = new TreeMap(FIELD_NAME_COMPARATOR);
int size = headers.size();
for (int i = 0; i < size; i++) {
String fieldName = headers.name(i);
String value = headers.value(i);
List<String> allValues = new ArrayList();
List<String> otherValues = (List) result.get(fieldName);
if (otherValues != null) {
allValues.addAll(otherValues);
}
allValues.add(value);
result.put(fieldName, Collections.unmodifiableList(allValues));
}
if (valueForNullKey != null) {
result.put(null, Collections.unmodifiableList(Collections.singletonList
(valueForNullKey)));
}
return Collections.unmodifiableMap(result);
}
示例2: getServices
import java.util.TreeMap; //導入依賴的package包/類
/**
* Retrieves the services that are available for use with the description for each service.
* The Services are determined by looking up all of the implementations of the
* Customer Service interface that are using the DataService qualifier annotation.
* The DataService annotation contains the service name and description information.
* @return Map containing a list of services available and a description of each one.
*/
public Map<String,String> getServices (){
TreeMap<String,String> services = new TreeMap<String,String>();
logger.fine("Getting CustomerService Impls");
Set<Bean<?>> beans = beanManager.getBeans(CustomerService.class,new AnnotationLiteral<Any>() {
private static final long serialVersionUID = 1L;});
for (Bean<?> bean : beans) {
for (Annotation qualifer: bean.getQualifiers()){
if(DataService.class.getName().equalsIgnoreCase(qualifer.annotationType().getName())){
DataService service = (DataService) qualifer;
logger.fine(" name="+service.name()+" description="+service.description());
services.put(service.name(), service.description());
}
}
}
return services;
}
示例3: calculate
import java.util.TreeMap; //導入依賴的package包/類
public static final String calculate(Map<String, ? extends Object> parameters, String appsecret) {
TreeMap<String, Object> params = new TreeMap(parameters);
params.remove("sign");
params.put("appsecret", appsecret);
StringBuilder stringBuilder = new StringBuilder();
Iterator var4 = params.entrySet().iterator();
while(var4.hasNext()) {
Map.Entry<String, Object> entry = (Map.Entry)var4.next();
stringBuilder.append(((String)entry.getKey()).trim());
stringBuilder.append("=");
stringBuilder.append(entry.getValue().toString().trim());
stringBuilder.append("&");
}
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
return DigestUtils.sha1Hex(stringBuilder.toString());
}
示例4: makeMap
import java.util.TreeMap; //導入依賴的package包/類
private static SortedMap<String, Object> makeMap(
String[] itemNames, Object[] itemValues)
throws OpenDataException {
if (itemNames == null || itemValues == null)
throw new IllegalArgumentException("Null itemNames or itemValues");
if (itemNames.length == 0 || itemValues.length == 0)
throw new IllegalArgumentException("Empty itemNames or itemValues");
if (itemNames.length != itemValues.length) {
throw new IllegalArgumentException(
"Different lengths: itemNames[" + itemNames.length +
"], itemValues[" + itemValues.length + "]");
}
SortedMap<String, Object> map = new TreeMap<String, Object>();
for (int i = 0; i < itemNames.length; i++) {
String name = itemNames[i];
if (name == null || name.equals(""))
throw new IllegalArgumentException("Null or empty item name");
if (map.containsKey(name))
throw new OpenDataException("Duplicate item name " + name);
map.put(itemNames[i], itemValues[i]);
}
return map;
}
示例5: getAllDBFiles
import java.util.TreeMap; //導入依賴的package包/類
public static TreeMap<String, MassBank> getAllDBFiles(File[] inputFiles, String ser, boolean forceRecalculation, boolean withPeaks)throws Exception {
TreeMap<String, MassBank> dbFiles=null;
if(!forceRecalculation){
try{
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(ser));
dbFiles = (TreeMap<String, MassBank>) ois.readObject();
ois.close();
}catch(Exception e){
System.err.println(e);
}
}
if(dbFiles==null){
System.out.println("calculating database file...");
dbFiles=new TreeMap<String,MassBank>();
for(File f:inputFiles){
getAllDBFiles(f, dbFiles, withPeaks);
}
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(ser));
oos.writeObject(dbFiles);
oos.flush();
oos.close();
System.out.println("...finished");
}
return dbFiles;
}
示例6: getSitesForUser
import java.util.TreeMap; //導入依賴的package包/類
public Map<String, TestSite> getSitesForUser(String username)
{
if(username == null)
{
username = AuthenticationUtil.getAdminUserName();
}
List<SiteInfo> sites = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<SiteInfo>>()
{
@Override
public List<SiteInfo> doWork() throws Exception
{
List<SiteInfo> results = siteService.listSites(null, null);
return results;
}
}, username, getId());
TreeMap<String, TestSite> ret = new TreeMap<String, TestSite>();
for(SiteInfo siteInfo : sites)
{
TestSite site = new TestSite(TestNetwork.this, siteInfo/*, null*/);
ret.put(site.getSiteId(), site);
}
return ret;
}
示例7: write
import java.util.TreeMap; //導入依賴的package包/類
void write(File outputFile) throws IOException {
IoActions.writeTextFile(outputFile, new ErroringAction<BufferedWriter>() {
@Override
protected void doExecute(BufferedWriter writer) throws Exception {
final Map<String, JavadocOptionFileOption<?>> options = new TreeMap<String, JavadocOptionFileOption<?>>(optionFile.getOptions());
JavadocOptionFileWriterContext writerContext = new JavadocOptionFileWriterContext(writer);
JavadocOptionFileOption<?> localeOption = options.remove("locale");
if (localeOption != null) {
localeOption.write(writerContext);
}
for (final String option : options.keySet()) {
options.get(option).write(writerContext);
}
optionFile.getSourceNames().write(writerContext);
}
});
}
示例8: putBuffer
import java.util.TreeMap; //導入依賴的package包/類
@Override
public synchronized void putBuffer(ByteBuffer buffer) {
TreeMap<Key, ByteBuffer> tree = getBufferTree(buffer.isDirect());
while (true) {
Key key = new Key(buffer.capacity(), System.nanoTime());
if (!tree.containsKey(key)) {
tree.put(key, buffer);
return;
}
// Buffers are indexed by (capacity, time).
// If our key is not unique on the first try, we try again, since the
// time will be different. Since we use nanoseconds, it's pretty
// unlikely that we'll loop even once, unless the system clock has a
// poor granularity.
}
}
示例9: combine
import java.util.TreeMap; //導入依賴的package包/類
/** Combine results */
static <T extends Combinable<T>> Map<Parameter, T> combine(Map<Parameter, List<T>> m) {
final Map<Parameter, T> combined = new TreeMap<Parameter, T>();
for(Parameter p : Parameter.values()) {
//note: results would never be null due to the design of Util.combine
final List<T> results = Util.combine(m.get(p));
Util.out.format("%-6s => ", p);
if (results.size() != 1)
Util.out.println(results.toString().replace(", ", ",\n "));
else {
final T r = results.get(0);
combined.put(p, r);
Util.out.println(r);
}
}
return combined;
}
示例10: ConditionVertex
import java.util.TreeMap; //導入依賴的package包/類
/**
* The constructor for chaining nodes inside of ConditionVertex.
*
* @param state the actual CollisionAtPosition
* @param scene the actual SimulatedLevelScene (has to updated befor)
* @param knowledge (not actually used in this constructor) knowledge is extracted from the scene (?)
* @param effects the known effects
* @param depth the depth of the actual node (incremented in everytime a node is expanded)
* @param previousInteraction the goal which was reached in the previous node in the simulation
* @param relevantEffect the relevant Effect
* @param topProbability the maximum probability
*/
public ConditionVertex(CollisionAtPosition state,
SimulatedLevelScene scene,
TreeMap<ConditionDirectionPair, TreeMap<Effect, Double>> knowledge,
TreeMap<Effect, Double> effects,
int depth,
Goal previousInteraction, Effect relevantEffect, double topProbability)
{
this.scene = scene;
this.depth = depth;
this.effects = effects;
this.previousInteraction = previousInteraction;
this.state = state;
this.knowledge = scene.getKnowledge();
this.importantEffect = relevantEffect;
this.topProbability = topProbability;
}
示例11: fastScrollVertical
import java.util.TreeMap; //導入依賴的package包/類
static void fastScrollVertical(int amountAxis, RecyclerView recyclerView) {
LinearLayoutManager linearLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
if (indexHeight == null) {
indexHeight = new TreeMap<>();
//call this method the OnScrollListener's onScrolled will be called,but dx and dy always be zero.
linearLayoutManager.scrollToPositionWithOffset(0, -amountAxis);
} else {
int total = 0, count = 0;
Iterator<Integer> iterator = indexHeight.keySet().iterator();
while (null != iterator && iterator.hasNext()) {
int height = indexHeight.get(iterator.next());
if (total + height >= amountAxis) {
break;
}
total += height;
count++;
}
linearLayoutManager.scrollToPositionWithOffset(count, -(amountAxis - total));
}
}
示例12: testHigherKey
import java.util.TreeMap; //導入依賴的package包/類
/**
* higherKey returns next element
*/
public void testHigherKey() {
TreeMap q = map5();
Object e1 = q.higherKey(three);
assertEquals(four, e1);
Object e2 = q.higherKey(zero);
assertEquals(one, e2);
Object e3 = q.higherKey(five);
assertNull(e3);
Object e4 = q.higherKey(six);
assertNull(e4);
}
示例13: findMinLightsCount
import java.util.TreeMap; //導入依賴的package包/類
static void findMinLightsCount(Node[] nodes, int curr, TreeMap<Integer, Integer> lightsToVariantsCount) {
if (curr == nodes.length) {
if (allEdgesHighlighted(nodes[0])) {
int amountOfSwitchedOnNodes = calculateSwitchedOnNodes(nodes);
Integer variantsCount = lightsToVariantsCount.getOrDefault(amountOfSwitchedOnNodes, 0);
lightsToVariantsCount.put(amountOfSwitchedOnNodes, variantsCount + 1);
}
return;
}
nodes[curr].isSwitchedOn = true;
findMinLightsCount(nodes, curr + 1, lightsToVariantsCount);
nodes[curr].isSwitchedOn = false;
findMinLightsCount(nodes, curr + 1, lightsToVariantsCount);
}
示例14: getRequestProperties
import java.util.TreeMap; //導入依賴的package包/類
/**
* Returns an unmodifiable map of general request properties used by this
* connection.
*/
@Override
public Map<String, List<String>> getRequestProperties() {
if (connected) {
throw new IllegalStateException(
"Cannot access request headers after connection is set.");
}
Map<String, List<String>> map = new TreeMap<String, List<String>>(
String.CASE_INSENSITIVE_ORDER);
for (Pair<String, String> entry : mRequestHeaders) {
if (map.containsKey(entry.first)) {
// This should not happen due to setRequestPropertyInternal.
throw new IllegalStateException(
"Should not have multiple values.");
} else {
List<String> values = new ArrayList<String>();
values.add(entry.second);
map.put(entry.first, Collections.unmodifiableList(values));
}
}
return Collections.unmodifiableMap(map);
}
示例15: index
import java.util.TreeMap; //導入依賴的package包/類
public void index(Map<String, Object> context) throws Exception {
Map<String, String> properties = new TreeMap<String, String>();
StringBuilder msg = new StringBuilder();
msg.append("Version: ");
msg.append(Version.getVersion(Envs.class, "2.2.0"));
properties.put("Registry", msg.toString());
String address = NetUtils.getLocalHost();
properties.put("Host", NetUtils.getHostName(address) + "/" + address);
properties.put("Java", System.getProperty("java.runtime.name") + " " + System.getProperty("java.runtime.version"));
properties.put("OS", System.getProperty("os.name") + " "
+ System.getProperty("os.version"));
properties.put("CPU", System.getProperty("os.arch", "") + ", "
+ String.valueOf(Runtime.getRuntime().availableProcessors()) + " cores");
properties.put("Locale", Locale.getDefault().toString() + "/"
+ System.getProperty("file.encoding"));
properties.put("Uptime", formatUptime(ManagementFactory.getRuntimeMXBean().getUptime())
+ " From " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z").format(new Date(ManagementFactory.getRuntimeMXBean().getStartTime()))
+ " To " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z").format(new Date()));
context.put("properties", properties);
}