package com.wslfinc.cf.sdk.entities.additional;

import com.wslfinc.cf.sdk.JsonExtractor;
import org.json.JSONObject;

/**
 *
 * @author Wsl_F
 */
public class Contestant {
    
    private static final int DEFAULT_RANK = -1;
    /**
     * Codeforces handle of user.
     */
    String handle;
    /**
     * User's current rank on contest. {@code DEFAULT_RANK} = -1 = unknown =
     * doesn't participate
     */
    int rank;
    /**
     * User's rating before contest.
     */
    int prevRating;
    
    public String getHandle() {
        return handle;
    }
    
    public void setHandle(String handle) {
        this.handle = handle;
    }
    
    public int getRank() {
        return rank;
    }
    
    public void setRank(int rank) {
        this.rank = rank;
    }
    
    public int getPrevRating() {
        return prevRating;
    }
    
    public void setPrevRating(int prevRating) {
        this.prevRating = prevRating;
    }
    
    public final void setAll(String handle, int rank, int prevRating) {
        this.handle = handle;
        this.rank = rank;
        this.prevRating = prevRating;
    }
    
    public final void setAll(JSONObject contestant) {
        this.handle = JsonExtractor.getString(contestant, "handle");
        this.prevRating = JsonExtractor.getInt(contestant, "rating");
        this.rank = Math.max(JsonExtractor.getInt(contestant, "rank"), DEFAULT_RANK);
    }
    
    public Contestant(String handle, int rank, int prevRating) {
        setAll(handle, rank, prevRating);
    }
    
    public Contestant(String handle, int prevRating) {
        this(handle, DEFAULT_RANK, prevRating);
    }
    
    public Contestant(JSONObject contestant) {
        setAll(contestant);
    }
}

@@ -164,22 +164,52 @@
 testant 
-%7B%0A    
+implements Comparable%3CContestant%3E %7B%0A
 %0A    pri
@@ -525,21 +525,17 @@
 Rating;%0A
-    
 %0A
+
     publ
@@ -579,37 +579,33 @@
 n handle;%0A    %7D%0A
-    
 %0A
+
     public void 
@@ -659,37 +659,33 @@
 = handle;%0A    %7D%0A
-    
 %0A
+
     public int g
@@ -714,37 +714,33 @@
 urn rank;%0A    %7D%0A
-    
 %0A
+
     public void 
@@ -783,37 +783,33 @@
 k = rank;%0A    %7D%0A
-    
 %0A
+
     public int g
@@ -850,37 +850,33 @@
 evRating;%0A    %7D%0A
-    
 %0A
+
     public void 
@@ -943,37 +943,33 @@
 evRating;%0A    %7D%0A
-    
 %0A
+
     public final
@@ -1116,37 +1116,33 @@
 evRating;%0A    %7D%0A
-    
 %0A
+
     public final
@@ -1402,37 +1402,33 @@
 LT_RANK);%0A    %7D%0A
-    
 %0A
+
     public Conte
@@ -1516,37 +1516,33 @@
 vRating);%0A    %7D%0A
-    
 %0A
+
     public Conte
@@ -1638,13 +1638,9 @@
   %7D%0A
-    
 %0A
+
     
@@ -1674,32 +1674,32 @@
 t contestant) %7B%0A
-
         setAll(c
@@ -1715,11 +1715,238 @@
 );%0A    %7D
+%0A%0A    @Override%0A    public int compareTo(Contestant o) %7B%0A        if (this.prevRating == o.prevRating) %7B%0A            return this.handle.compareTo(o.handle);%0A        %7D%0A        return this.prevRating %3C o.prevRating ? -1 : 1;%0A    %7D
 %0A%7D%0A

make comparable