/* package whatever; // don't place package name! */

import java.util.*;
import java.util.concurrent.*;
import java.util.stream.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		ThreadPoolExecutor pool = new ThreadPoolExecutor(8, 8, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<>(10));
        //ExecutorService pool = Executors.newFixedThreadPool(2);
        //ForkJoinPool pool = new ForkJoinPool(8);
        
        List<Record> list = new ArrayList<>();
        for (int i = 0; i < 115000; i++)
        {
            list.add(new Record("A", i / 10000, "B", "C", i, (double) i / 100 + 1));
        }
        System.out.println("ArrayList's spliterator is ORDERED: " +
                ((list.spliterator().characteristics() & Spliterator.ORDERED) != 0));
                
        Stream<Record> stream = list.parallelStream()
           //.parallel()
           .sorted(
                   (r1, r2) -> Integer.compare(r1.getCategory2(), r2.getCategory2())
           )
           //.parallel()
           ;
           
        List<Record> output = stream.collect(Collectors.toList());
        
        System.out.println(output.size());
        int prev = -1;
        boolean verified = true;
        for (Record record : output)
        {
            int curr = record.getValue1();
            if (prev != -1)
            {
                if (prev + 1 != curr)
                {
                    System.out.println("Warning: " + prev + " followed by " + curr + "!");
                    verified = false;
                }
            }
            prev = curr;
        }
        System.out.println("Verified: " + verified);
	}
}

class Record implements Comparable<Record>
{
   private String myCategory1;
   private int    myCategory2;
   private String myCategory3;
   private String myCategory4;
   private int    myValue1;
   private double myValue2;

   public Record(String category1, int category2, String category3, String category4,
      int value1, double value2)
   {
      myCategory1 = category1;
      myCategory2 = category2;
      myCategory3 = category3;
      myCategory4 = category4;
      myValue1 = value1;
      myValue2 = value2;
   }

   public String getCategory1()
   {
      return myCategory1;
   }

   public int getCategory2()
   {
      return myCategory2;
   }

   public String getCategory3()
   {
      return myCategory3;
   }

   public String getCategory4()
   {
      return myCategory4;
   }

   public int getValue1()
   {
      return myValue1;
   }

   public double getValue2()
   {
      return myValue2;
   }

    public int compareTo(Record other)
    {
        int comp = myCategory1.compareTo(other.myCategory1);
        if (comp != 0) return comp;
        comp = myCategory2 - other.myCategory2;
        if (comp != 0) return comp;
        comp = myCategory3.compareTo(other.myCategory3);
        if (comp != 0) return comp;
        comp = myCategory4.compareTo(other.myCategory4);
        return comp;
    }

   /**
    * Returns the string representation.
    * @return The string representation.
    */
   public String toString()
   {
      StringBuilder buf = new StringBuilder();
      buf.append("Record(");
      buf.append(myCategory1);
      buf.append(",");
      buf.append(myCategory2);
      buf.append(",");
      buf.append(myCategory3);
      buf.append(",");
      buf.append(myCategory4);
      buf.append(",");
      buf.append(myValue1);
      buf.append(",");
      buf.append(myValue2);
      buf.append(")");
      return buf.toString();
   }
}