本文整理匯總了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)));
}