本文整理汇总了Java中java.util.TreeMap.keySet方法的典型用法代码示例。如果您正苦于以下问题:Java TreeMap.keySet方法的具体用法?Java TreeMap.keySet怎么用?Java TreeMap.keySet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.TreeMap
的用法示例。
在下文中一共展示了TreeMap.keySet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createMyListmenu
import java.util.TreeMap; //导入方法依赖的package包/类
private JMenu createMyListmenu() {
if (myListMenu == null) {
myListMenu = new JMenu("My Lists");
}
myListMenu.removeAll();
JMenuItem item;
TreeMap<String, TreeSet<String>> pls = MFMPlayLists.getInstance().getMyPlayListsTree();
for (String name : pls.keySet()) {
item = myListMenu.add(mfmActionShowList);
item.setActionCommand("Show List");
item.setText(name);
}
myListMenu.repaint();
myListMenu.validate();
return myListMenu;
}
示例2: testKeySetOrder
import java.util.TreeMap; //导入方法依赖的package包/类
/**
* keySet is ordered
*/
public void testKeySetOrder() {
TreeMap map = map5();
Set s = map.keySet();
Iterator i = s.iterator();
Integer last = (Integer)i.next();
assertEquals(last, one);
int count = 1;
while (i.hasNext()) {
Integer k = (Integer)i.next();
assertTrue(last.compareTo(k) < 0);
last = k;
++count;
}
assertEquals(5, count);
}
示例3: hasEqualComponentTypeSettings
import java.util.TreeMap; //导入方法依赖的package包/类
/**
* Checks for equal component type settings.
*
* @param ggsToCompare the GeneralGraphSettings4MAS to compare
* @return true, if successful
*/
public boolean hasEqualComponentTypeSettings(GeneralGraphSettings4MAS ggsToCompare) {
boolean isEqual = true;
TreeMap<String, ComponentTypeSettings> ctsTreeMapToCompare = ggsToCompare.getCurrentCTS();
isEqual = (ctsTreeMapToCompare.size()==this.getCurrentCTS().size());
if (isEqual==true) {
// --- Compare each element in the TreeMap ----
Vector<String> keyVector = new Vector<String>(ctsTreeMapToCompare.keySet());
for (int i = 0; i < keyVector.size(); i++) {
String key = keyVector.get(i);
ComponentTypeSettings cts2Comp = ctsTreeMapToCompare.get(key);
ComponentTypeSettings ctsLocal = this.getCurrentCTS().get(key);
if (ctsLocal==null) return false;
if (isEqualComponentTypeSettings(cts2Comp, ctsLocal)==false) return false;
}
}
return isEqual;
}
示例4: selectLikelyEntry
import java.util.TreeMap; //导入方法依赖的package包/类
static <A> Entry<A, Double> selectLikelyEntry(TreeMap<A, Double> entries)
{
ArrayList<A> keys = new ArrayList<A>(entries.keySet());
Double value;
A randomKey;
do
{
randomKey = keys.get(random.nextInt(keys.size()));
value = entries.get(randomKey);
//System.out.println("thinking to talk about " + randomKey + " + " + value + "("+keys.size()+" keys)");
}
while(value==null || (Math.random() > value.doubleValue()));
return new SimpleEntry<A, Double>(randomKey, value);
}
示例5: getMostImportantEffect
import java.util.TreeMap; //导入方法依赖的package包/类
/**
* select the most important effect of a collision
* @param simulatedEffectList of the collision
* @return max important of the effects, with importance := probability * relevance
*/
private Effect getMostImportantEffect(TreeMap<Effect,Double> simulatedEffectList){
// select most important effect
// note: likelihood != importance!
double topImportance = 0.0;
Effect topEffect = null;
for(Effect e : simulatedEffectList.keySet())
{
double importance = simulatedEffectList.get(e) * getEffectRelevance(e);
// System.out.println("SD: Effect: " + e.getType() +"evaluated; probability: " + simulatedEffectList.get(e) + ", relevance: " + getEffectRelevance(e));
if (importance > topImportance){
topEffect = e;
topImportance = importance;
}
}
return topEffect;
}
示例6: buildParamStr
import java.util.TreeMap; //导入方法依赖的package包/类
protected static String buildParamStr(TreeMap<String, Object> requestParams, String requestMethod) {
String retStr = "";
for(String key: requestParams.keySet()) {
//排除上传文件的参数
if(requestMethod == "POST" && requestParams.get(key).toString().substring(0, 1).equals("@")){
continue;
}
if (retStr.length()==0) {
retStr += '?';
} else {
retStr += '&';
}
retStr += key.replace("_", ".") + '=' + requestParams.get(key).toString();
}
return retStr;
}
示例7: service
import java.util.TreeMap; //导入方法依赖的package包/类
/**
* Only interested in the parameters and values for requests.
* Note: echos parameters in alphabetical order.
*/
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// Just echo the parameters and values back as plain text
resp.setContentType("text/plain");
resp.setCharacterEncoding("UTF-8");
PrintWriter out = resp.getWriter();
TreeMap<String,String[]> parameters = new TreeMap<String,String[]>(req.getParameterMap());
boolean first = true;
for(String name: parameters.keySet()) {
String[] values = req.getParameterValues(name);
java.util.Arrays.sort(values);
for(int i=0; i<values.length; ++i)
{
if(first)
first = false;
else
out.print(",");
out.print(name + "=" + values[i]);
}
}
}
示例8: ScheduleSelectAdapter
import java.util.TreeMap; //导入方法依赖的package包/类
public ScheduleSelectAdapter(TreeMap<Integer, List<ScheduleType>> schedules) {
minutesList = new ArrayList<>();
for (Integer integer : schedules.keySet()) {
minutesList.add(integer);
}
this.schedules = schedules;
}
示例9: testKeySet
import java.util.TreeMap; //导入方法依赖的package包/类
/**
* keySet returns a Set containing all the keys
*/
public void testKeySet() {
TreeMap map = map5();
Set s = map.keySet();
assertEquals(5, s.size());
assertTrue(s.contains(one));
assertTrue(s.contains(two));
assertTrue(s.contains(three));
assertTrue(s.contains(four));
assertTrue(s.contains(five));
}
示例10: choose_size
import java.util.TreeMap; //导入方法依赖的package包/类
private int choose_size(TreeMap<Integer, Double> wheel) {
double choice = rand.nextDouble() * 100;
for (Integer key : wheel.keySet()) {
if (choice < wheel.get(key)) {
return key;
}
}
return 0;
}
示例11: selectRandomEntry
import java.util.TreeMap; //导入方法依赖的package包/类
static <A, B> Entry<A, B> selectRandomEntry(TreeMap<A, B> entries)
{
ArrayList<A> keys = new ArrayList<A>(entries.keySet());
A randomKey = keys.get(random.nextInt(keys.size()));
B value = entries.get(randomKey);
return new SimpleEntry<A, B>(randomKey, value);
}
示例12: selectInterestingEntryWithEffect
import java.util.TreeMap; //导入方法依赖的package包/类
static SimpleEntry<ConditionDirectionPair, TreeMap<Effect, Double>> selectInterestingEntryWithEffect(TreeMap<ConditionDirectionPair, TreeMap<Effect, Double>> entries, Effect effect)
{
TreeMap<ConditionDirectionPair, TreeMap<Effect, Double>> entriesclone = new TreeMap<ConditionDirectionPair, TreeMap<Effect, java.lang.Double>>();
//filter knowledge
for(ConditionDirectionPair cdp : entries.keySet())
{
for(Entry<Effect, Double> e : entries.get(cdp).entrySet())
{
if(e.getKey().equals(effect))
{
TreeMap<Effect,Double> tmp = new TreeMap<Effect,Double>();
tmp.put(e.getKey(),e.getValue());
entriesclone.put(cdp,tmp);
}
}
/*if(entries.get(cdp).keySet().contains(effect))
{
entriesclone.put(cdp,entries.get(cdp));
}*/
}
if(entriesclone.isEmpty())
return null;
return selectInterestingEntry(entriesclone);
}
示例13: main
import java.util.TreeMap; //导入方法依赖的package包/类
public static void main(String[] args) {
HashMap<Agencia, Cliente[]> hm = new HashMap<Agencia, Cliente[]>();
// adiciona chave - agência e valor = array Cliente
hm.put(new Agencia("ag01"), new Cliente[] { new Cliente("Enricando Cardoso"), new Cliente("Inacio Estole"), new Cliente("Luiz Ladrum"), });
hm.put(new Agencia("ag02"), new Cliente[] { new Cliente("Henri Cando"), new Cliente("Stolin Lu La"), new Cliente("Lara Pio"), });
hm.put(new Agencia("ag03"), new Cliente[] { new Cliente("Sony Gando"), new Cliente("Leiro Pisto"), new Cliente("Waga Oubum Du"), });
// criando TreeMap
TreeMap<Agencia, Cliente[]> tm = new TreeMap<Agencia, Cliente[]>(hm);
// imprime a coleção
System.out.println(tm);
// pega as chaves
Set chaves = tm.keySet();
// imprime as chaves
System.out.println(chaves);
// pega os valores
Collection<Cliente[]> valores = tm.values();
// imprime os valores
for (Cliente[] cs : valores) {
for (Cliente c : cs) {
System.out.println(c);
}
}
}
示例14: handleEncapsulatedPacket
import java.util.TreeMap; //导入方法依赖的package包/类
private void handleEncapsulatedPacket(EncapsulatedPacket packet) throws Exception {
if (packet.messageIndex == null) {
this.handleEncapsulatedPacketRoute(packet);
} else {
if (packet.messageIndex < this.reliableWindowStart || packet.messageIndex > this.reliableWindowEnd) {
return;
}
if ((packet.messageIndex - this.lastReliableIndex) == 1) {
this.lastReliableIndex++;
this.reliableWindowStart++;
this.reliableWindowEnd++;
this.handleEncapsulatedPacketRoute(packet);
if (!this.reliableWindow.isEmpty()) {
TreeMap<Integer, EncapsulatedPacket> sortedMap = new TreeMap<>(this.reliableWindow);
for (int index : sortedMap.keySet()) {
EncapsulatedPacket pk = this.reliableWindow.get(index);
if ((index - this.lastReliableIndex) != 1) {
break;
}
this.lastReliableIndex++;
this.reliableWindowStart++;
this.reliableWindowEnd++;
this.handleEncapsulatedPacketRoute(pk);
this.reliableWindow.remove(index);
}
}
} else {
this.reliableWindow.put(packet.messageIndex, packet);
}
}
}
示例15: testKeySetToArray
import java.util.TreeMap; //导入方法依赖的package包/类
/**
* keySet.toArray returns contains all keys
*/
public void testKeySetToArray() {
TreeMap map = map5();
Set s = map.keySet();
Object[] ar = s.toArray();
assertTrue(s.containsAll(Arrays.asList(ar)));
assertEquals(5, ar.length);
ar[0] = m10;
assertFalse(s.containsAll(Arrays.asList(ar)));
}