Search Results

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

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

  • Java - Make an object collection friendly

    - by DutrowLLC
    If an object holds a unique primary key, what interfaces does it need to implement in order to be collection friendly especially in terms of being efficiently sortable, hashable, etc...? If the primary key is a string, how are these interfaces best implemented? Thanks!

    Read the article

  • Customs toString in Java not giving desired output and throwing error

    - by user2972048
    I am writing a program in Java to accept and validate dates according to the Gregorian Calendar. My public boolean setDate(String aDate) function for an incorrect entry is suppose to change the boolean goodDate variable to false. That variable is suppose tell the toString function, when called, to output "Invalid Entry" but it does not. My public boolean setDate(int d, int m, int y) function works fine though. I've only included the problem parts as its a long piece of code. Thanks public boolean setDate(int day, int month, int year){ // If 1 <= day <= 31, 1 <= month <= 12, and 0 <= year <= 9999 & the day match with the month // then set object to this date and return true // Otherwise,return false (and do nothing) boolean correct = isTrueDate(day, month, year); if(correct){ this.day = day; this.month = month; this.year = year; return true; }else{ goodDate = false; return false; } //return false; } public boolean setDate(String aDate){ // If aDate is of the form "dd/mm/yyyy" or "d/mm/yyyy" // Then set the object to this date and return true. // Otherwise, return false (and do nothing) Date d = new Date(aDate); boolean correct = isTrueDate(d.day, d.month, d.year); if(correct){ this.day = d.day; this.month = d.month; this.year = d.year; return true; }else{ goodDate = false; return false; } } public String toString(){ // outputs a String of the form "dd/mm/yyyy" // where dd must be 2 digits (with leading zero if needed) // mm must be 2 digits (with leading zero if needed) // yyyy must be 4 digits (with leading zeros if needed) String day1; String month1; String year1; if(day<10){ day1 = "0" + Integer.toString(this.day); } else{ day1 = Integer.toString(this.day); } if(month<10){ month1 = "0" + Integer.toString(this.month); } else{ month1 = Integer.toString(this.month); } if(year<10){ year1 = "00" + Integer.toString(this.year); } else{ year1 = Integer.toString(this.year); } if(goodDate){ return day1 +"/" +month1 +"/" + year1; }else{ goodDate = true; return "Invalid Entry"; } } Thank you

    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

  • Why does Java's TreeSet not specify that its type parameter must extend Comparable?

    - by Tarski
    e.g. The code below throws a ClassCastException when the second Object is added to the TreeSet. Couldn't TreeSet have been written so that the type parameter can only be a Comparable type? i.e. TreeSet would not compile because Object is not Comparable. That way generics actually do their job - of being typesafe. import java.util.TreeSet; public class TreeSetTest { public static void main(String [] args) { TreeSet<Object> t = new TreeSet<Object>(); t.add(new Object()); t.add(new Object()); } }

    Read the article

  • Vim: Fuzzy file search comparable to Sublime Text 2's?

    - by Jed
    I've tried FuzzyFinder, Command-T, and Ctrl-P (which is my finder of choice right now), but none hold a candle to Sublime Text 2. For example, I want to type: Head.php and have it find, among others: app/code/core/Mage/Page/Block/Html/Head.php Currently in Ctrl-P, which has otherwise served me better than Command-T, searching for Head.php gives me these first: downloader/lib/Mage/Connect/Command/Config_Header.php app/code/local/Namespace/Modals/Helper/Reader.php app/code/core/Mage/XMLConnect/Helper/Ipad.php My file is nowhere to be found (and I've never opened any of the above files), so I have to type this instead: pagehtmlhead.php Is there any utility that does smarter scoring/matching?

    Read the article

  • Page expired issue with back button and wicket SortableDataProvider and DataTable

    - by David
    Hi, I've got an issue with SortableDataProvider and DataTable in wicket. I've defined my DataTable as such: IColumn<Column>[] columns = new IColumn[9]; //column values are mapped to the private attributes listed in ColumnImpl.java columns[0] = new PropertyColumn(new Model("#"), "columnPosition", "columnPosition"); columns[1] = new PropertyColumn(new Model("Description"), "description"); columns[2] = new PropertyColumn(new Model("Type"), "dataType", "dataType"); Adding it to the table: DataTable<Column> dataTable = new DataTable<Column>("columnsTable", columns, provider, maxRowsPerPage) { @Override protected Item<Column> newRowItem(String id, int index, IModel<Column> model) { return new OddEvenItem<Column>(id, index, model); } }; My data provider: public class ColumnSortableDataProvider extends SortableDataProvider<Column> { private static final long serialVersionUID = 1L; private List list = null; public ColumnSortableDataProvider(Table table, String sortProperty) { this.list = Arrays.asList(table.getColumns().toArray(new Column[0])); setSort(sortProperty, true); } public ColumnSortableDataProvider(List list, String sortProperty) { this.list = list; setSort(sortProperty, true); } @Override public Iterator iterator(int first, int count) { /* first - first row of data count - minimum number of elements to retrieve So this method returns an iterator capable of iterating over {first, first+count} items */ Iterator iterator = null; try { if(getSort() != null) { Collections.sort(list, new Comparator() { private static final long serialVersionUID = 1L; @Override public int compare(Column c1, Column c2) { int result=1; PropertyModel<Comparable> model1= new PropertyModel<Comparable>(c1, getSort().getProperty()); PropertyModel<Comparable> model2= new PropertyModel<Comparable>(c2, getSort().getProperty()); if(model1.getObject() == null && model2.getObject() == null) result = 0; else if(model1.getObject() == null) result = 1; else if(model2.getObject() == null) result = -1; else result = ((Comparable)model1.getObject()).compareTo(model2.getObject()); result = getSort().isAscending() ? result : -result; return result; } }); } if (list.size() (first+count)) iterator = list.subList(first, first+count).iterator(); else iterator = list.iterator(); } catch (Exception e) { e.printStackTrace(); } return iterator; } The problem is the following: - I click a column header to sort by that column. - I navigate to a different page - I click Back (or Forward if I do the opposite scenario) - Page has expired. It'd be nice to generate the page using PageParameters but I somehow need to intercept the sort event to do so. Any pointers would be greatly appreciated. Thanks a ton!! David

    Read the article

  • Java - Syntax Question: What is <? super T>

    - by aloh
    I'm having trouble understanding the following syntax: public class SortedList< T extends Comparable< ? super T> > extends LinkedList< T > I see that class SortedList extends LinkedList. I just don't know what T extends Comparable< ? super T> means. My understanding of it so far is that type T must be a type that implements Comparable...but what is "< ? super T "?

    Read the article

  • Registrar with good security, DNS hosting, and DNSSEC and IPv6 resolvers?

    - by semenko
    I'm looking to move my domains away from GoDaddy, but I'm having a tough time finding anyone with comparable features at a (even remotely) similar price. I've looked at the usual suggestions (NameCheap, Gandi.net, etc.), but they all seem to lack many of the GoDaddy feature base. I'm looking for: DNSSEC IPv6 Resolvers (dig pdns01.domaincontrol.com AAAA; etc. ) SSL-Logins by default HTTP-only login cookies No stupid password restrictions Two-factor authentications No DNS record limits Rough DNS statistics (queries/day, etc.) Audit trails GoDaddy has all of these, except two-factor, for $3/month. See http://www.godaddy.com/domains/dns-hosting.aspx I can't seem to find any other registrar that supports even a few of these. Is there a registrar that offers comparable features? Or, barring that, a DNS hosting service that offers similar features? (AWS Route53 doesn't offer DNSSEC or IPv6)

    Read the article

  • Estimating costs in a GOAP system

    - by fullwall
    I'm currently developing a GOAP system in Java. An explanation of GOAP can be found at http://web.media.mit.edu/~jorkin/goap.html. Essentially, it's using A* to plot between Actions that mutate the world state. To provide a fair chance for all Actions and Goals to execute, I'm using a heuristic function to estimate the cost of doing something. What is the best way to estimate this cost so that it is comparable to all the other costs? As an example, estimating the cost of running away from an enemy versus attacking it - how should the cost be calculated to be comparable?

    Read the article

  • How do I display a Wicket Datatable, sorted by a specific column by default?

    - by David
    Hello everyone! I have a question regarding Wicket's Datatable. I am currently using DataTable to display a few columns of data. My table is set up as follows: DataTable<Column> dataTable = new DataTable<Column>("columnsTable", columns, provider, maxRowsPerPage) { @Override protected Item<Column> newRowItem(String id, int index, IModel<Column> model) { return new OddEvenItem<Column>(id, index, model); } }; The columns look like so: columns[0] = new PropertyColumn<Column>(new Model<String>("Description"), "description", "description"); columns[1] = new PropertyColumn<Column>(new Model<String>("Logic"), "columnLogic"); columns[2] = new PropertyColumn<Column>(new Model<String>("Type"), "dataType", "dataType"); Here is my column data provider: public class ColumnSortableDataProvider extends SortableDataProvider<Column> { private static final long serialVersionUID = 1L; private List<Column> list = null; public ColumnSortableDataProvider(Table table) { this.list = Arrays.asList(table.getColumns().toArray(new Column[0])); } public ColumnSortableDataProvider(List<Column> list) { this.list = list; } @Override public Iterator<? extends Column> iterator(int first, int count) { /* first - first row of data count - minimum number of elements to retrieve So this method returns an iterator capable of iterating over {first, first+count} items */ Iterator<Column> iterator = null; try { if(getSort() != null) { Collections.sort(list, new Comparator<Column>() { private static final long serialVersionUID = 1L; @Override public int compare(Column c1, Column c2) { int result=1; PropertyModel<Comparable> model1= new PropertyModel<Comparable>(c1, getSort().getProperty()); PropertyModel<Comparable> model2= new PropertyModel<Comparable>(c2, getSort().getProperty()); if(model1.getObject() == null && model2.getObject() == null) result = 0; else if(model1.getObject() == null) result = 1; else if(model2.getObject() == null) result = -1; else result = ((Comparable)model1.getObject()).compareTo(model2.getObject()); result = getSort().isAscending() ? result : -result; return result; } }); } if (list.size() > (first+count)) iterator = list.subList(first, first+count).iterator(); else iterator = list.iterator(); } catch (Exception e) { e.printStackTrace(); } return iterator; } Sorting by clicking a column works perfectly, but I would like the table to initially be sorted, by default, by the Description column. I am at a loss to do this. If you need to see some other code, please let me know. Thank you in advance!!! - D

    Read the article

  • List to TreeSet conversion produces: "java.lang.ClassCastException: MyClass cannot be cast to java.l

    - by Chuck
    List<MyClass> myclassList = (List<MyClass>) rs.get(); TreeSet<MyClass> myclassSet = new TreeSet<MyClass>(myclassList); I don't understand why this code generates this: java.lang.ClassCastException: MyClass cannot be cast to java.lang.Comparable MyClass does not implement Comparable. I just want to use a Set to filter the unique elements of the List since my List contains unncessary duplicates.

    Read the article

  • Autovivification in C#

    - by Terrance
    Trying to wrap my head around perl's Autovivification and based on what it sounds like, It seems to work similar to dynamics in C# as a dynamic object is not assigned a type until runtime or, am I totally off here. If so then is there a comparable idea that I can bridge off of in C# that makes sense? Edit Okay so I'm apparently way off. So as second part of the 2 part question, is there anything conceptually comparable in C#?

    Read the article

  • How do I create a new AnyType[] array?

    - by cb
    Which is the best practice in this situation? I would like an un-initialized array of the same type and length as the original. public static <AnyType extends Comparable<? super AnyType>> void someFunction(AnyType[] someArray) { AnyType[] anotherArray = (AnyType[]) new Comparable[someArray.length]; ...or... AnyType[] anotherArray = (AnyType[]) new Object[someArray.length]; ...some other code... } Thanks, CB

    Read the article

  • Trouble swapping values as keys in generic java BST class

    - by user1729869
    I was given a generic binary search tree class with the following declaration: public class BST<K extends Comparable<K>, V> I was asked to write a method that reverses the BST such that the values become the keys and keys become values. When I call the following method (defined in the class given) reverseDict.put(originalDict.get(key), key); I get the following two error messages from Netbeans: Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: BST.put And also: no suitable method found for put(V,K) method BST.put(BST<K,V>.Node,K,V) is not applicable (actual and formal argument lists differ in length) method BST.put(K,V) is not applicable (actual argument V cannot be converted to K by method invocation conversion) where V,K are type-variables: V extends Object declared in method <K,V>reverseBST(BST<K,V>) K extends Comparable<K> declared in method <K,V>reverseBST(BST<K,V>) From what the error messages are telling me, since my values do not extend Comparable I am unable to use them as keys. If I am right, how can I get around that without changing the class given (maybe a cast)?

    Read the article

  • implementing interface

    - by 1ace1
    hello guys so i have this assignment that i need to implement interface to go over an ArrayList and sort it (ascending or descnding).I dont want "the" answer i just need some suggestions on my approach and why i get this error Exception in thread "main" java.lang.ClassCastException: Week7.Check 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 Week7.TestCheck.main(TestCheck.java:18) This is how i did it: comparable had one method called public int compairTo(Object o) public class Check implements comparable { private Integer checkNumber; public Check(Integer newCheckNumber) { setCheckNumber(newCheckNumber); } public String toString() { return getCheckNumber().toString(); } public void setCheckNumber(Integer checkNumber) { this.checkNumber = checkNumber; } public Integer getCheckNumber() { return checkNumber; } @Override public int compairTo(Object o) { Check compair = (Check)o; int result = 0; if (this.getCheckNumber() > compair.getCheckNumber()) result = 1; else if(this.getCheckNumber() < compair.getCheckNumber()) result = -1; return result; } } in my main i had this import java.util.ArrayList; import java.util.Collections; public class TestCheck { public static void main(String[] args) { ArrayList checkList = new ArrayList(); checkList.add(new Check(445)); checkList.add(new Check(101)); checkList.add(new Check(110)); checkList.add(new Check(553)); checkList.add(new Check(123)); Collections.sort(checkList); for (int i =0; i < checkList.size(); i++){ System.out.println(checkList.get(i)); } } }

    Read the article

  • What else I must do allow my method to handle any type of objects

    - by NewHelpNeeder
    So to allow any type object I must use generics in my code. I have rewrote this method to do so, but then when I create an object, for example Milk, it won't let me pass it to my method. Ether there's something wrong with my generic revision, or Milk object I created is not good. How should I pass my object correctly and add it to linked list? This is a method that causes error when I insert an item: public void insertFirst(T dd) // insert at front of list { Link newLink = new Link(dd); // make new link if( isEmpty() ) // if empty list, last = newLink; // newLink <-- last else first.previous = newLink; // newLink <-- old first newLink.next = first; // newLink --> old first first = newLink; // first --> newLink } This is my class I try to insert into linked list: class Milk { String brand; double size; double price; Milk(String a, double b, double c) { brand = a; size = b; price = c; } } This is test method to insert the data: public static void main(String[] args) { // make a new list DoublyLinkedList theList = new DoublyLinkedList(); // this causes: // The method insertFirst(Comparable) in the type DoublyLinkedList is not applicable for the arguments (Milk) theList.insertFirst(new Milk("brand", 1, 2)); // insert at front theList.displayForward(); // display list forward theList.displayBackward(); // display list backward } // end main() } // end class DoublyLinkedApp Declarations: class Link<T extends Comparable<T>> {} class DoublyLinkedList<T extends Comparable<T>> {}

    Read the article

  • HTML5 game engine for a 2D or 2.5D RPG style "map walk"

    - by stargazer
    please help me to choose a HTML5 game engine or Javascript libraries I want to do the following in the game: when the game starts a part the huge map (full size of the map: about 7 screens) is shown. The map itself is completely designed in the editor mapeditor.org (or in some comparable editor - if you know a good alternative to mapeditor.org - let me know) and loaded at runtime or at design time. The game engine should support loading of isometric maps (well, in worst case only orthogonal maps will be sufficient) both "tile layer" and "object layer" from mapeditor.org should be supported. Scrolling/performance of this map should be fast enough. The map and the game should be either in 2D (orthogonal map) or in 2.5D (isometric map) The game engine should support movement of sprites with animation. Let say I have a sprite for "human" with animation sequences showing "walking" in 8 directions - it should be imported into game engine and should "walk" on the map without writing a lot of Javascript code. Automatic scrolling of the map the "human" nears the screen border. Collision detection, "solid" objects. The mapeditor.org supports properies on tiles. Let say I assign a "solid" property to some tiles in editor. It should be easy to check this "solid" property in the game engine and implement kind of "solid" behavior, so the animanted sprites do not walk through the walls. Collision detection - it should be easy to implement some custom functionality like "when sprite A is close to sprite B - call this function" Showing "dialogs" or popup windows on top of the map - should be easy to implement. Cross-browser audio support - (it is implemented quite well in construct 2 from scirra, so I'm looking for the comparable audio quality) The game itself is a king of RPG but without fighting scenes and without huge "inventory". The main character just walking on the map, discovers some things, there are dialogs and sounds. The functionality of this example from sprite.js http://batiste.dosimple.ch/sprite.js/tests/mapeditor/map_reader.html is very close to what I'm developing. But I'm not a Javascript guru (and a very lazy guy) and would like to write even less Javascript code as in the example...

    Read the article

  • What to expect when creating a style guide?

    - by ted.strauss
    My organization would like to create a full fledged style guide that will be applicable to internal & external web sites, print advertising, trade show design, and overall branding. This article lays out the scope we're aiming for, and has links to many great examples style guide PDFs. The goal is to create a style guide comparable to one of these. I'd like to set realistic expectations within my organization for creating this document. So I have a few of questions pertaining to this: We don't have design staff. Should we be looking for a design firm or freelancer to come in for a 2-6 month contract, or do we need a longer commitment? If we do go with a firm or freelancer, would the pay-scale be comparable to typical design work, or is a style guide a higher order of work? How long should it take a pro to create a style guide? To make estimates more concrete, let's say web only, including all custom graphics. Any red flags to watch out for? (Compare: a new coder who fails to use css properly would be a red flag.)

    Read the article

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