Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6057127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:27:14+00:00 2026-05-23T08:27:14+00:00

@Override public int compareTo(final myRow another) { final int BEFORE =-1; final int EQUAL

  • 0
  @Override
      public int compareTo(final myRow another) {

        final int BEFORE    =-1;
        final int EQUAL     = 0;
        final int AFTER     = 1;

        if (this==another) return EQUAL;

        if (sorttype==sort_type.SORT_ABC) {

            int rv      =0;
            int sorted  =row.toLowerCase().compareTo(another.getRow().toLowerCase());

            if (this.getUserType()==user_type.USER_TYPE_BANNED) rv=AFTER;
            if (this.getUserType()==user_type.USER_TYPE_NORMAL) rv=sorted;
            if (this.getUserType()==user_type.USER_TYPE_FRIEND) rv=BEFORE;

            Log.e("sorted", row+" "+this.getUserType()+" - "+rv+" ");

            return rv;

        } else if (sorttype==sort_type.SORT_LOGINTIME) {

            if (this.getUserType()==user_type.USER_TYPE_BANNED) {
                return AFTER;
            }
            if (this.getUserType()==user_type.USER_TYPE_NORMAL) return EQUAL;
            if (this.getUserType()==user_type.USER_TYPE_FRIEND) {
                //int sorted    =row.toLowerCase().compareTo(another.getRow().toLowerCase());
                return BEFORE;
            }

            //return 0;
        }

        return 0;

        //return row.toLowerCase().compareTo(another.getRow().toLowerCase());
      }

I have a String userlist, with nick names. I have banned users, normal users, and friend users.

I d like to sort my friend users to the top of the list, and the banned users to the bottom of the list, and I d like to showing them is ASC style.

How can i do that?

So the structure is:

Abc  (friend)
abrt (friend)
dfgh (friend)

abdfg (normal user)
bnmm  (normal user)
wert  (normal user)

Andgh  (banned user)
Dfghhj (banned user)
Qwer   (banned user)

I get this:

06-19 14:43:46.586: ERROR/AndroidRuntime(23434): java.lang.IllegalArgumentException: Comparison method violates its general contract!
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:27:15+00:00Added an answer on May 23, 2026 at 8:27 am

    Your code looks a bit complex. The simplest way would be to start from the highest priority field and move down to other fields. An example code would be:

    public class Member implements Comparable<Member> {
    
        static enum Status {
            NORMAL(1), FRIEND(2), BANNED(3);
    
            private final int order;
    
            Status(int order) {
                this.order = order;
            }
    
            public int getOrder() {
                return this.order;
            }
    
        };
    
        private final String name;
    
        private final Status status;
    
        public Member(final String name, final Status status) {
            this.name = name;
            this.status = status;
        }
    
        @Override
        public int compareTo(Member o) {
            if (this.status.equals(o.status)) {
                return this.name.compareTo(o.name);
            } else {
                return this.status.compareTo(o.status);
            }
        }
    
        @Override
        public String toString() {
            return "Member [name=" + name + ", status=" + status + "]";
        }
    
        public static void main(String[] args) throws Throwable {
            Member[] members = {
                            new Member("abrt", Status.FRIEND),
                            new Member("dfgh", Status.FRIEND),
                            new Member("abdf", Status.NORMAL),
                            new Member("wert", Status.NORMAL),
                            new Member("andgh", Status.BANNED),
                            new Member("qwer", Status.BANNED)
            };
            List<Member> lst = Arrays.asList(members);
            Collections.sort(lst);
            System.out.println(lst);
        }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It does not seem straighforward. I am trying this: @Override public int compare(Period o1,
Example private static final Comparator<A> PRODUCT_CODE_COMPARATOR = new Comparator<A>() { @Override public int compare(final
protected override Boolean IsValid(String propertyValue) { return !String.IsNullOrEmpty(propertyValue) && propertyValue.Trim().Length > 0; } This
My SSCE: public class ComparableItem implements Comparable<ComparableItem> { private final int itemNo; public ComparableItem(final
Consider this class. public class DynamicField implements Comparable<DynamicField> { String title; int position; int
My Program overrides public void paint(Graphics g, int x, int y); in order to
I am doing the following class RuleObject implements Comparable{ @Override public String toString() {
colLabels[i].addMouseListener(new MyAdapter()); private class MyAdapter extends MouseAdapter { @Override public void mouseClicked(MouseEvent event) {
Basically, I have the following so far: class Foo { public override bool Equals(object
According to http://www.codeguru.com/forum/showthread.php?t=463663 , C#'s getHashCode function in 3.5 is implemented as: public override

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.