Nested generic casting in Java

I am facing some issues while writing an abstract bean container class. I created an interface ImyAppsBean : public interface ImyAppsBean{} Now I want to implement a sort method in my abstract container class. I would like to assume, that the instanc

How to sort a custom linked list in Java?

I am working on a custom Linked List based on Crunchify's implementation to display list of Employee. As of now I can add new Employee or remove existing Employee from the list. However, my project requires adding a sorting method that would not be b

How can I tell Java that an interface implements Comparable?

I have an interface named IDebt, and a class implementing said interface named Debt. I also have a list made of objects implementing the IDebt interface: List<IDebt> debtList = new ArrayList<IDebt>(); The class Debt implements Comparable, but

Legacy comparable to generics

Trying to design a superclass that ensures all sub-classes are inherently Comparable. /** * A base class implementing Comparable with itself by delegation. * @param <T> - The type being wrapped. */ static class Distinct<T extends Comparable<T&

Comparing the values ​​of an object with compareTo ()

I am using a Max-Heap to store objects of type Song. A song has a title and a rating as shown in the Song class. I want the Song object to be compared by rating so that the highest rated songs are displayed first. If songs have the same rating then t

How can I properly extend this abstract class?

Hi I'm inexperience with Java. I understand the concepts of inheritance but I think the syntax is eluding me. I'm seeking some help to get me started in extending this abstract class: I need to create a concrete object from it. What this class should

how do the following generic statements differ in Java?

I have two classes, one in which I have the <T extends Comparable<T> in the class header iteslf as class MaximumTest2 <T extends Comparable<T>> and another in which I have public class MaximumTest but the method extends Comparable as

Java-like object with Priority Queue

I am trying to use a priority queue (java.util.PriorityQueue) on a custom class. I understand that the PriorityQueue class uses the Comparable interface, so I implemented it in my custom class: public class State implements Comparable<State> { publi

ArrayList Natural Ordering

I have a application using a sqlite DB which is put into an ArrayList. I am trying to get the entries to show in alphabetical or from what I understand "natural ordering". I have implemented comparable and have added my collections.sort statemen

Java Hash values: how to make them effectively comparable?

I have pairs of hash values like 128ecf542a35ac5270a87dc740918404;d603ac0c04b9d08974482ae7fd4cf55 a1288b1c7e2257a90bad9bdfb7690fbb;f23828e312d90cb7fdadd6479236119c ................................;................................ I would like to make

When to include what?

I created a class Person (as the book says) to hold the name and last name of a person entered from the keyboard and then there is another class PhoneNumber which encapsulates the country code, area code and the number of a person as a String. Person

Generic Java class that stores comparables

I have a generic java class that stores comparables: public class MyGenericStorage<T extends Comparable<T>> { private T value; public MyGenericStorage(T value) { this.value = value; } //... methods that use T.compareTo() } I also have an abstr

Comparing Long Values ​​Using Collections.sort (Object)

I'm trying to sort a simple list of objects by a long - the below isn't working because one of the long strings is pushed to the top simply because it starts with a lower number. So I'm looking for a way to sort these by the actual long values direct

Java Comparator using .reverseOrder () but with an inner class

I am creating a simple program to learn about the Java Comparator class. I have sorted an Arraylist into order but now I want to sort the list in descending order but am having problems in where to call the .reverseOrder() method as I have used an in

Java: Sort a Collection Using a Collator Key

what I would like to achieve is to sort a colletion of objects by a string value. However in a locale dependant way using a collator. Due to performance reasons I do not want to use the Collator compare() method (as below in the code) rather the Coll