Search Results

Search found 359 results on 15 pages for 'comparable'.

Page 4/15 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Why does the Java Collections Framework offer two different ways to sort?

    - by dvanaria
    If I have a list of elements I would like to sort, Java offers two ways to go about this. For example, lets say I have a list of Movie objects and I’d like to sort them by title. One way I could do this is by calling the one-argument version of the static java.util.Collections.sort( ) method with my movie list as the single argument. So I would call Collections.sort(myMovieList). In order for this to work, the Movie class would have to be declared to implement the java.lang.Comparable interface, and the required method compareTo( ) would have to be implemented inside this class. Another way to sort is by calling the two-argument version of the static java.util.Collections.sort( ) method with the movie list and a java.util.Comparator object as it’s arguments. I would call Collections.sort(myMovieList, titleComparator). In this case, the Movie class wouldn’t implement the Comparable interface. Instead, inside the main class that builds and maintains the movie list itself, I would create an inner class that implements the java.util.Comparator interface, and implement the one required method compare( ). Then I'd create an instance of this class and call the two-argument version of sort( ). The benefit of this second method is you can create an unlimited number of these inner class Comparators, so you can sort a list of objects in different ways. In the example above, you could have another Comparator to sort by the year a movie was made, for example. My question is, why bother to learn both ways to sort in Java, when the two-argument version of Collections.sort( ) does everything the first one-argument version does, but with the added benefit of being able to sort the list’s elements based on several different criteria? It would be one less thing to have to keep in your mind while coding. You’d have one basic mechanism of sorting lists in Java to know.

    Read the article

  • using compareTo in Binary Search Tree program

    - by Scott Rogener
    I've been working on this program for a few days now and I've implemented a few of the primary methods in my BinarySearchTree class such as insert and delete. Insert seemed to be working fine, but once I try to delete I kept getting errors. So after playing around with the code I wanted to test my compareTo methods. I created two new nodes and tried to compare them and I get this error: Exception in thread "main" java.lang.ClassCastException: TreeNode cannot be cast to java.lang.Integer at java.lang.Integer.compareTo(Unknown Source) at TreeNode.compareTo(TreeNode.java:16) at BinarySearchTree.myComparision(BinarySearchTree.java:177) at main.main(main.java:14) Here is my class for creating the nodes: public class TreeNode<T> implements Comparable { protected TreeNode<T> left, right; protected Object element; public TreeNode(Object obj) { element=obj; left=null; right=null; } public int compareTo(Object node) { return ((Comparable) this.element).compareTo(node); } } Am I doing the compareTo method all wrong? I would like to create trees that can handle integers and strings (seperatly of course)

    Read the article

  • How to use Comparator in Java to sort

    - by Dan
    I learned how to use the comparable but I'm having difficulty with the Comparator. I am having a error in my code: Exception in thread "main" java.lang.ClassCastException: New.People cannot be cast to java.lang.Comparable at java.util.Arrays.mergeSort(Unknown Source) at java.util.Arrays.sort(Unknown Source) at java.util.Collections.sort(Unknown Source) at New.TestPeople.main(TestPeople.java:18) Here is my code: import java.util.Comparator; public class People implements Comparator{ private int id; private String info; private double price; public People(int newid, String newinfo, double newprice){ setid(newid); setinfo(newinfo); setprice(newprice); } public int getid() { return id; } public void setid(int id) { this.id = id; } public String getinfo() { return info; } public void setinfo(String info) { this.info = info; } public double getprice() { return price; } public void setprice(double price) { this.price = price; } public int compare(Object obj1, Object obj2) { Integer p1 = ((People)obj1).getid(); Integer p2 = ((People)obj2).getid(); if (p1 p2 ){ return 1; } else if (p1 < p2){ return -1; } else return 0; } } import java.util.ArrayList; import java.util.Collections; public class TestPeople { public static void main(String[] args) { ArrayList peps = new ArrayList(); peps.add(new People(123, "M", 14.25)); peps.add(new People(234, "M", 6.21)); peps.add(new People(362, "F", 9.23)); peps.add(new People(111, "M", 65.99)); peps.add(new People(535, "F", 9.23)); Collections.sort(peps); for(int i=0;i I believe it has to do something with the casting in the compare method but I was playing around with it and still could not find the solution

    Read the article

  • What does this Java generics paradigm do and what is it called?

    - by Tom
    I'm looking at some Java classes that have the following form: public abstract class A <E extends A<E>> implements Comparable <E> { public final int compareTo( E other ) { // etc } } public class B extends A <B> { // etc } public class C extends A <C> { // etc } My usage of "Comparable" here is just to illustrate a possible use of the generic parameter "E". Does this usage of generics/inheritance have a name? What is it used for? My impression is that this allows the abstract class to provide a common implementation of a method (such as compareTo) without having to provide it in the subclasses. However, in this example, unlike an inherited method it would restrict subclasses to invoking compareTo on other instances of the same subclass, rather than any "A" subclass. Does this sound right? Anyway, just curious if any gurus out there have seen this before and know what it does. Thanks!

    Read the article

  • Windows Live Messenger for Mac?

    - by studiohack23
    I have a friend who uses a Mac, and was wondering if there is a version of Windows Live Messenger for Mac? Or something comparable that uses/takes advantage of the Windows LIVE ID? I'm interested in recommendations, as well as "is there a Mac version of Live Messenger? Thanks!

    Read the article

  • AAC Sample Rate and Bit Rate for High Quality Audio?

    - by marco.ragogna
    What are the AAC Sample Rate and Bit Rate settings to set in order to encode an audio track with a quality comparable to MP3 320kbps? I need to backup a DVD movie, the default settings for AAC are Bitrate (KB/s) 128 Sample Rate (HZ) 44100 should I set Bitrate (KB/s) 320 Sample Rate (HZ) 48000 or the default are already good?

    Read the article

  • Hotfix entries in event log

    - by Marco Shaw
    Server 2008/2008 R2 I'm trying to remotely monitor these servers to watch the progress of hotfixes being installed. I was able to find this in Server 2003/2003 R2: -Log: System -Source: NtServicePack It seems the above event is written when every hotfix is installed. I can't seem to find a comparable entry in Server 2008/2008 R2 though. Is there anything similar that I can easily monitor for remotely?

    Read the article

  • Best bang for buck, pivotable, non-TN, >= 1920*1200, LCD screen ? [closed]

    - by julien
    I was almost set on getting a Samsung - SyncMaster 2343BW PIVOT, due to the high resolution, pivot and uber-cheapness. But after reading the comment on this SU question, I was bummed to realize it's a TN screen, which apparently would be a pain for my inteded use ; i.e. portrait mode for reading/coding. Do you know of a comparable model that is "IPS or PVA/MVA", but won't break the bank ? cheers

    Read the article

  • Recommend alternative to tripwire?

    - by CarpeNoctem
    Looking for a host-based IDS comparable to tripwire. Preferably one that allows centralized management. Right now I use tripwire and though it works management and reporting through a central server would be ideal. I'm looking for recommendations that have actually been used and not just google results. Thanks!

    Read the article

  • Can the features of Dell OpenManage be replaced by Microsoft System Center?

    - by bwerks
    Hi all, I'm new to both OpenManage and System Center, but it sounds as if they're geared towards similar problems/goals. Are the features comparable enough that OpenManage can be forgone completely in favor of System Center products? Specifically I'm hoping to achieve storage monitoring and remote administration, although if someone with experience with both wants to provide a quick compare/contrast (objective, of course) I won't complain. Thanks!

    Read the article

  • Excel 2007 save import steps on csv file?

    - by Chris Marisic
    I have a csv file that constantly needs opened into Excel and then have the data copied over to a separate workbook. I find the process of having to click through all of the dialogs, setting the text identifier, setting the columns to all be text extremely tedious. In many actions with data like this in regards to MSSQL or Access the program will ask you if you wish to save these steps however Excel doesn't readily ask that. Is there any way to get a comparable usage with Excel?

    Read the article

  • How do implement a breadth first traversal?

    - by not looking for answer
    //This is what I have. I thought pre-order was the same and mixed it up with depth first! import java.util.LinkedList; import java.util.Queue; public class Exercise25_1 { public static void main(String[] args) { BinaryTree tree = new BinaryTree(new Integer[] {10, 5, 15, 12, 4, 8 }); System.out.print("\nInorder: "); tree.inorder(); System.out.print("\nPreorder: "); tree.preorder(); System.out.print("\nPostorder: "); tree.postorder(); //call the breadth method to test it System.out.print("\nBreadthFirst:"); tree.breadth(); } } class BinaryTree { private TreeNode root; /** Create a default binary tree */ public BinaryTree() { } /** Create a binary tree from an array of objects */ public BinaryTree(Object[] objects) { for (int i = 0; i < objects.length; i++) { insert(objects[i]); } } /** Search element o in this binary tree */ public boolean search(Object o) { return search(o, root); } public boolean search(Object o, TreeNode root) { if (root == null) { return false; } if (root.element.equals(o)) { return true; } else { return search(o, root.left) || search(o, root.right); } } /** Return the number of nodes in this binary tree */ public int size() { return size(root); } public int size(TreeNode root) { if (root == null) { return 0; } else { return 1 + size(root.left) + size(root.right); } } /** Return the depth of this binary tree. Depth is the * number of the nodes in the longest path of the tree */ public int depth() { return depth(root); } public int depth(TreeNode root) { if (root == null) { return 0; } else { return 1 + Math.max(depth(root.left), depth(root.right)); } } /** Insert element o into the binary tree * Return true if the element is inserted successfully */ public boolean insert(Object o) { if (root == null) { root = new TreeNode(o); // Create a new root } else { // Locate the parent node TreeNode parent = null; TreeNode current = root; while (current != null) { if (((Comparable)o).compareTo(current.element) < 0) { parent = current; current = current.left; } else if (((Comparable)o).compareTo(current.element) > 0) { parent = current; current = current.right; } else { return false; // Duplicate node not inserted } } // Create the new node and attach it to the parent node if (((Comparable)o).compareTo(parent.element) < 0) { parent.left = new TreeNode(o); } else { parent.right = new TreeNode(o); } } return true; // Element inserted } public void breadth() { breadth(root); } // Implement this method to produce a breadth first // search traversal public void breadth(TreeNode root){ if (root == null) return; System.out.print(root.element + " "); breadth(root.left); breadth(root.right); } /** Inorder traversal */ public void inorder() { inorder(root); } /** Inorder traversal from a subtree */ private void inorder(TreeNode root) { if (root == null) { return; } inorder(root.left); System.out.print(root.element + " "); inorder(root.right); } /** Postorder traversal */ public void postorder() { postorder(root); } /** Postorder traversal from a subtree */ private void postorder(TreeNode root) { if (root == null) { return; } postorder(root.left); postorder(root.right); System.out.print(root.element + " "); } /** Preorder traversal */ public void preorder() { preorder(root); } /** Preorder traversal from a subtree */ private void preorder(TreeNode root) { if (root == null) { return; } System.out.print(root.element + " "); preorder(root.left); preorder(root.right); } /** Inner class tree node */ private class TreeNode { Object element; TreeNode left; TreeNode right; public TreeNode(Object o) { element = o; } } }

    Read the article

  • Java(standard, non standard) or Non Java based Web developement [closed]

    - by LivingThing
    I am new to web development. Initially i thought i would be learning LAMP or WAMP to acquire web developement skills but recently i came across Standard Java based (JSP, servlets) and Non standard Java based (GWT). My question is related to if and how LAMP can be compared with Java (standarad or non stadard) technologies. Is LAMP even comparable to Java based tech or it does something else or something more or less ? what requirement for a web developement projects require the choice that which of these 'technologies' should be choosen ? Thank YOu

    Read the article

  • Sterci today announced it has earned Oracle Exadata and Oracle Exalogic Optimized status

    - by Javier Puerta
    Sterci has announced it has earned Oracle Exadata and Oracle Exalogic Optimized status. (Read full announcement here) "GTExchange from Sterci is a high-performance multi-network and multi-standard financial messaging solution that provides a comprehensive connection hub to SWIFT and other networks, as well as handling internal message transfer. It supports high volume and complex message flows from multiple counterparties, delivering control, transparency and proven efficiencies. By achieving Oracle Exadata Optimized and Oracle Exalogic Optimized status, Sterci has shown that its GTExchange solution has achieved a 3.8 x greater throughput (nearly 4 million messages an hour), than any previous tests on comparable x86 systems." 

    Read the article

  • Does UX matter for enterprise software?

    - by Ryan
    I've come to notice that a lot of software that companies use for managing things like time, expenses, setting up phone systems, etc is very non-intuitive from a user experience point of view. I know personally I waste a lot of time just trying to figure out how to navigate these systems, especially if I don't have a co-worker close by who I can bug to help me out. The help files are usually just as bad as the user interface itself. Are companies that complacent or are there just not any comparable enterprise products out there which do the job for these sorts of tasks? It seems that on the consumer side there is plenty of market opportunity for creating better user experiences, but how about for enterprise software? Obviously a certain level of slickness is not going to matter to a company, but when a better UX design translates to time saved, it's hard to argue against that. Edit: I'm not referring to in-house applications, but rather off the shelf systems from large software companies.

    Read the article

  • Are there programming languages that allow you to do set arithmetic on types?

    - by Will Brown
    Out of curiosity, are there languages that allow you to do set arithmetic on types to create new types? Something like: interface A { void a(); void b(); } interface B { void b(); void c(); } interface C = A & B; // has b() interface D = A | B; // has a(), b() and c() interface E = (A & B) ^ B; // has c() I know that in some languages these ideas can be expressed (i.e., Java has List<Comparable & Serializable> for the union of the interfaces) but I've never heard of a language that supports type arithmetic. Thanks!

    Read the article

  • Best way to handle realtime melee AI in authoritative network environment

    - by PrimeDerektive
    So i've been working on a multiplayer game for a bit; it's a co-op action RPG with real-time combat. If you've seen or played TERA, I'd say it's comparable to that, but not an MMO, heh. I'm currently handling the AI units authoritatively, the server calculates their pathing, movement, and pursue/attack logic, and syncs the movement to the clients 15x per second, and the state changes when they happen. When I emulate 200ms ping, though, the client can perceive being out of range to an AI's attack, but still take the hit, because on the server he hadn't moved that far yet. This also plays hell with my real-time blocking. I don't really want to allow the clients to be allowed to say "that was out of range" or "I blocked that", but I'm not really sure how else to handle it.

    Read the article

  • Handling SMS/email convergence: how does a good business app do it?

    - by Tim Cooper
    I'm writing a school administration software package, but it strikes me that many developers will face this same issue: when communicating with users, should you use email or SMS or both, and should you treat them as fundamentally equivalent channels such that any message can get sent using any media, (with long and short forms of the message template obviously) or should different business functions be specifically tailored to each of the 3? This question got kicked off "StackOverflow" for being overly general, so I'm hoping it's not too general for this site - the answers will no doubt be subjective but "you don't need to write a whole book to answer the question". I'm particularly interested in people who have direct experience of having written comparable business applications. Sub-questions: Do I treat SMS as "moderately secure" and email as less secure? (I'm thinking about booking tokens for parent/teacher nights, permission slips for excursions, absence explanation notes - so high security is not a requirement for us, although medium security is) Is it annoying for users to receive the same message on multiple channels? Should we have a unified framework that reports on delivery or lack thereof of emails and SMS's?

    Read the article

  • What are the differences between Bigloo and ECL from an embedding standpoint? [migrated]

    - by Pubby
    I've been looking to embed Lisp in some C++ code. Two options I'm interested in is Bigloo Scheme and ECL (Common Lisp). Reading through the docs they seem to support a very similar feature set. Obviously Bigloo is Scheme and ECL is CLisp, but what other differences do they have? In particular I'm interested in the following criteria: Ease of embedding (for C++, not just C). I don't want to write a bunch of boilerplate. Performance. Bigloo is performance based and has many compiler optimization options, although I can't find anything comparable for ECL. Style of coding. This one is more for Bigloo - is it more functional than ECL? I'm targeting this question towards someone who has used both.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >