Search Results

Search found 58 results on 3 pages for 'treemap'.

Page 1/3 | 1 2 3  | Next Page >

  • Scala 2.8 TreeMap and custom Ordering

    - by Dave
    I'm switching from scala 2.7 and ordered to scala 2.8 and using ordering. It looks quite straight forward but I was wondering could I make it a little less verbose. For example: scala> case class A(i: Int) defined class A scala> object A extends Ordering[A] { def compare(o1: A, o2: A) = o1.i - o2.i} defined module A If I then try to create a TreeMap I get an error scala> new collection.immutable.TreeMap[A, String]() <console>:10: error: could not find implicit value for parameter ordering: Ordering[A] new collection.immutable.TreeMap[A, String]() ^ However if I explicitly specify the object A as the ordering it works fine. scala> new collection.immutable.TreeMap[A, String]()(A) res34: scala.collection.immutable.TreeMap[A,String] = Map() Do I always have to explicitly specify the ordering or is there a shorter format? Thanks

    Read the article

  • Disk usage treemap software for headless Linux

    - by CyberShadow
    There are some programs which can display used disk space using a treemap, such as WinDirStat for Windows and KDirStat for KDE/Linux: I'm looking for something similar, but for a headless Linux box. Alternatively, what are other good ways to visualize used disk space with just SSH access?

    Read the article

  • Consistent Equals() results, but inconsistent TreeMap.containsKey() result

    - by smessing
    I have the following object Node: private class Node implements Comparable<Node>(){ private String guid(); ... public boolean equals(Node o){ return (this == o); } public int hashCode(){ return guid.hashCode(); } ... } And I use it in the following TreeMap: TreeMap<Node, TreeSet<Edge>> nodes = new TreeMap<Node, TreeSet<Edge>>(); Now, the tree map is used in a class called Graph to store nodes currently in the graph, along with a set of their edges (from the class Edge). My problem is when I try to execute: public containsNode(n){ for (Node x : nodes.keySet()) { System.out.println("HASH CODE: "); System.out.print(x.hashCode() == n.hashCode()); System.out.println("EQUALS: "); System.out.print(x.equals(n)); System.out.println("CONTAINS: "); System.out.print(nodes.containsKey(n)); System.out.println("N: " + n); System.out.println("X: " + x); } } I sometimes get the following: HASHCODE: true EQUALS: true CONTAINS: false N: foo X: foo Anyone have an idea as to what I'm doing wrong? I'm still new to all this, so I apologize in advance if I'm overlooking something simple (I know hashCode() doesn't really matter for TreeMap, but I figured I'd include it).

    Read the article

  • Consistent HashCode() and Equals() results, but inconsistent TreeMap.containsKey() result

    - by smessing
    I have the following object Node: private class Node implements Comparable<Node>(){ private String guid(); ... public boolean equals(Node o){ return (this == o); } public int hashCode(){ return guid.hashCode(); } ... } And I use it in the following TreeMap: TreeMap<Node, TreeSet<Edge>> nodes = new TreeMap<Node, TreeSet<Edge>>(); Now, the tree map is used in a class called Graph to store nodes currently in the graph, along with a set of their edges (from the class Edge). My problem is when I try to execute: public containsNode(n){ for (Node x : nodes.keySet()) { System.out.println("HASH CODE: "); System.out.print(x.hashCode() == n.hashCode()); System.out.println("EQUALS: "); System.out.print(x.equals(n)); System.out.println("CONTAINS: "); System.out.print(nodes.containsKey(n)); System.out.println("N: " + n); System.out.println("X: " + x); } } I sometimes get the following: HASHCODE: true EQUALS: true CONTAINS: false N: foo X: foo Anyone have an idea as to what I'm doing wrong? I'm still new to all this, so I apologize in advance if I'm overlooking something simple (I know hashCode() doesn't really matter for TreeMap, but I figured I'd include it).

    Read the article

  • TreeMap not properly returning values

    - by smessing
    I have the following TreeMap: TreeMap<String, Integer> distances = new TreeMap<String, Integer>(); and it contains both strings, "Face" and "Foo", with appropriate values, such that: System.out.println(distances); Yields: {Face=12, Foo=2} However, distances.get(Face) returns null, even though distances.get(Foo) properly returns 2. Previously, distances.get(Face) worked, but for some reason, it stopped working. Note I print out the map right before calling get() for both keys, so I haven't accidentally changed Face's value to null. Has anyone else every encountered this problem? Is there anything I can do? I'm having a terrible time simply trying to figure out how to debug this problem.

    Read the article

  • TreeMap randomly stops properly returning values

    - by smessing
    I have the following TreeMap: TreeMap<String, Integer> distances = new TreeMap<String, Integer>(); and it contains both strings, "Face" and "Foo", with appropriate values, such that: System.out.println(distances); Yields: {Face=12, Foo=2} However, distances.get(Face) returns null, even though distances.get(Foo) properly returns 2. Previously, distances.get(Face) worked, but for some reason, it stopped working. Note I print out the map right before calling get() for both keys, so I haven't accidentally changed Face's value to null. Has anyone else ever encountered this problem? Is there anything I can do? I'm having a terrible time simply trying to figure out how to debug this problem.

    Read the article

  • JButton and next/previous object of treemap

    - by supacat
    I have this problem: 1) There are objects placed in the TreeMap through the JTextField. (Phonebook-like program). 2)There are buttons that implement view of available records in TreeMap. When you click on these buttons next / previous available objects of TreeMap displaying in JTextField. (scroll through the available records). I tried this code, but I didn't work :/ btn[4].addActionListener(new ActionListener(){ Iterator iter = tree.keySet().iterator(); public void actionPerformed(ActionEvent e) { if (iter.hasNext()){ String str = iter.next().toString(); fldFio.setText(str); fldNumber.setText(tree.get(str)); } } });

    Read the article

  • Using Comparable to compare objects and sorting them in a TreeMap

    - by arjacsoh
    II cannot understand how should the natural ordering of class be "consistent with equals" when implementing the Comparable interface. I deteted a flaw in my program and therefore I deteced that in the documentantion of the interface Comparable. My problem is that although two Objects are considered as distinct on the base of equals method, the TreeMap structure treats them as equal and consequently does not accept the second insert. The sample code is: public class Car implements Comparable<Car> { int weight; String name; public Car(int w, String n) { weight=w; name=n; } public boolean equals(Object o){ if(o instanceof Car){ Car d = (Car)o; return ((d.name.equals(name)) && (d.weight==weight)); } return false; } public int hashCode(){ return weight/2 + 17; } public String toString(){ return "I am " +name+ " !!!"; } public int compareTo(Car d){ if(this.weight>d.weight) return 1; else if(this.weight<d.weight) return -1; else return 0; } /*public int compareTo(Car d){ return this.name.compareTo(d.name); }*/ } public static void main(String[] args) { Car d1 = new Car(100, "a"); Car d2 = new Car(110, "b"); Car d3 = new Car(110, "c"); Car d4 = new Car(100, "a"); Map<Car, Integer> m = new HashMap<Car, Integer>(); m.put(d1, 1); m.put(d2, 2); m.put(d3, 3); m.put(d4, 16); for(Map.Entry<Car, Integer> me : m.entrySet()) System.out.println(me.getKey().toString() + " " +me.getValue()); TreeMap<Car, Integer> tm = new TreeMap<Car, Integer>(m); System.out.println("After Sorting: "); for(Map.Entry<Car, Integer> me : tm.entrySet()) System.out.println(me.getKey().toString() + " " +me.getValue()); } The output is : I am a !!! 16 I am c !!! 3 I am b !!! 2 After Sorting: I am a !!! 16 I am c !!! 2 That is, that the object c has replaced (somewhat) object b. If I comment the original equals method and uncomment the second equals method, which compares the objects according name, the output is the expected: I am a !!! 16 I am c !!! 3 I am b !!! 2 After Sorting: I am a !!! 16 I am b !!! 2 I am c !!! 3 Why does it come around in this way and what should I alter in order to insert and sort different objects with some attributes of equal value in a TreeMap?

    Read the article

  • how to sort a treemap using bubble sort?

    - by Tsuna Sawada
    27527-683 27525-1179 27525-1571 27525-1813 27525-4911 27526-1303 27526-3641 27525-3989 27525-4083 27525-4670 27526-4102 27526-558 27527-2411 27527-4342 this is the list of key where it is declared as string in a map then i want to sort it in ascending order. how can i use a bubble sorting method inside a map? where the value of the key is a list. in order to get : 27525-1179 27525-1571 27525-1813 27525-3989 27525-4083 27525-4670 27525-4911 27526-558 27526-1303 27526-3641 27526-4102 27527-683 27527-2411 27527-4342

    Read the article

  • Searching in a TreeMap (Java)

    - by Kronen
    I need to do a search in a map of maps and return the keys this element belong. I think this implementation is very slow, can you help me to optimize it?. I need to use TreeSet and I can't use contains because they use compareTo, and equals/compareTo pair are implemented in an incompatible way and I can't change that. (sorry my bad english) Map m = new TreeSet(); public String getKeys(Element element) { for(Entry e : m.entrySet()) { mapSubKey = e.getValue(); for(Entry e2 : mapSubKey.entrySet()) { setElements = e2.getValue(); for(Element elem : setElements) if(elem.equals(element)) return "Key: " + e.getKey() + " SubKey: " + e2.getKey(); } } }

    Read the article

  • Manual metrics and treemap components

    - by Greg
    I have a problem with SonarQube. I use web API to inject manual metrics values for a project like this : curl -u nom:password -d "resource=<projet>&metric=<key de la metric>&val=<valeur>" http://localhost:8081/sonar/api/manual_measures One of these metrics is a percentage and this metric is declared as a Percentage value in Sonar in Settings = Manual Metrics window. I have a project with components and each project and components have this metric value. When I want to show this metric as a color metric in a "treemap of components" of widget, all the treemap is grey (as if values are not defined). But if I put mouse on the name of component in treemap, I saw the color metric value as a percentage value like this : myComponent - ncloc: 800 - myMetric: 84,0% Moreover, scale metric color does not appear in treemap title (after Size ncloc Color <my metric>).

    Read the article

  • What Can A 'TreeDict' (Or Treemap) Be Used For In Practice?

    - by Seun Osewa
    I'm developing a 'TreeDict' class in Python. This is a basically a dict that allows you to retrieve its key-value pairs in sorted order, just like the Treemap collection class in Java. I've implemented some functionality based on the way unique indexes in relational databases can be used, e.g. functions to let you retrieve values corresponding to a range of keys, keys greater than, less than or equal to a particular value in sorted order, strings or tuples that have a specific prefix in sorted order, etc. Unfortunately, I can't think of any real life problem that will require a class like this. I suspect that the reason we don't have sorted dicts in Python is that in practice they aren't required often enough to be worth it, but I want to be proved wrong. Can you think of any specific applications of a 'TreeDict'? Any real life problem that would be best solved by this data structure? I just want to know for sure whether this is worth it.

    Read the article

  • Java List Sorting: Is there a way to keep a list permantly sorted automatically like TreeMap?

    - by david
    In Java you can build up an ArrayList with items and then call: Collections.sort(list, comparator); Is there anyway to pass in the Comparator at the time of List creation like you can do with TreeMap? The goal is to be able add an element to the list and instead of having it automatically appended to the end of the list, the list would keep itself sorted based on the Comparator and insert the new element at the index determined by the Comparator. So basically the list might have to re-sort upon every new element added. Is there anyway to achieve this in this way with the Comparator or by some other similar means? Thanks.

    Read the article

  • Java SortedMap to Scala TreeMap

    - by Dave
    I'm having trouble converting a java SortedMap into a scala TreeMap. The SortedMap comes from deserialization and needs to be converted into a scala structure before being used. Some background, for the curious, is that the serialized structure is written through XStream and on desializing I register a converter that says anything that can be assigned to SortedMap[Comparable[_],_] should be given to me. So my convert method gets called and is given an Object that I can safely cast because I know it's of type SortedMap[Comparable[_],_]. That's where it gets interesting. Here's some sample code that might help explain it. // a conversion from comparable to ordering scala> implicit def comparable2ordering[A <: Comparable[A]](x: A): Ordering[A] = new Ordering[A] { | def compare(x: A, y: A) = x.compareTo(y) | } comparable2ordering: [A <: java.lang.Comparable[A]](x: A)Ordering[A] // jm is how I see the map in the converter. Just as an object. I know the key // is of type Comparable[_] scala> val jm : Object = new java.util.TreeMap[Comparable[_], String]() jm: java.lang.Object = {} // It's safe to cast as the converter only gets called for SortedMap[Comparable[_],_] scala> val b = jm.asInstanceOf[java.util.SortedMap[Comparable[_],_]] b: java.util.SortedMap[java.lang.Comparable[_], _] = {} // Now I want to convert this to a tree map scala> collection.immutable.TreeMap() ++ (for(k <- b.keySet) yield { (k, b.get(k)) }) <console>:15: error: diverging implicit expansion for type Ordering[A] starting with method Tuple9 in object Ordering collection.immutable.TreeMap() ++ (for(k <- b.keySet) yield { (k, b.get(k)) })

    Read the article

  • Disk usage treemap software for headless Linux

    - by CyberShadow
    There are some programs which can display used disk space using a treemap, such as WinDirStat for Windows and KDirStat for KDE/Linux: I'm looking for something similar, but for a headless Linux box. (E.g. run console data collection program on the server, then load the file in a graphical program in a GUI environment.) Alternatively, what are other good ways to get a structured used disk space representation, with just SSH access?

    Read the article

  • TreeMap sort by value

    - by vito huang
    I'm new to java, i want to write an comparator to that will let me sort TreeMap by value instead of the default natural sorting. i tried something like this, but can't find out what went wrong: import java.util.*; class treeMap { public static void main(String[] args) { System.out.println("the main"); byValue cmp = new byValue(); Map<String, Integer> map = new TreeMap<String, Integer>(cmp); map.put("de",10); map.put("ab", 20); map.put("a",5); for (Map.Entry<String,Integer> pair: map.entrySet()) { System.out.println(pair.getKey()+":"+pair.getValue()); } } } class byValue implements Comparator<Map.Entry<String,Integer>> { public int compare(Map.Entry<String,Integer> e1, Map.Entry<String,Integer> e2) { if (e1.getValue() < e2.getValue()){ return 1; } else if (e1.getValue() == e2.getValue()) { return 0; } else { return -1; } } } I guess what am i asking is what controls what get pass to comparator function, can i get an Map.Entry pass to comparator?

    Read the article

  • jQuery Treemap Plugin

    - by Revert
    Hello, I am trying to get the Treemap plugin (http://www.jquery.info/spip.php?article40) working with jQuery v1.3.x. The plugin works with jQuery v1.1 and v1.2 but for some reason it fails with the v1.3 base. This is the browser error "Error: uncaught exception: Syntax error, unrecognized expression: " Does anyone know changes occurred between JQuery v1.2 and v1.3 that could cause this? Cheers, D

    Read the article

  • Dojo 1.8 : introduction de nouveaux composants dont le calendrier, la jauge et le treemap pour le framework JavaScript

    Dojo 1.8 : introduction de nouveaux composants dont le calendrier, la jauge et le treemap pour mobile et pour navigateur La version 1.8 de Dojo amène avec elle de nouveaux composants que vous pouvez déjà découvrir dans la version beta sortie dernièrement. Le calendrier Le composant calendrier dispose d'une belle interface utilisateur et permet une vision par jour, par semaine, par mois ou bien par année. Bien entendu, ce composant est compatible avec les APIs Dojo et peut être manié sans problème. Il en est de même au niveau des CSS. Des adaptations sont réalisables facilement. [IMG]http://dojotoolkit.org/blog/wp-content/uploads/2012/05/calendar-e13364...

    Read the article

1 2 3  | Next Page >