/* 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
{
{
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 int myCategory2;
private int myValue1;
private double myValue2;
int value1, double value2)
{
myCategory1 = category1;
myCategory2 = category2;
myCategory3 = category3;
myCategory4 = category4;
myValue1 = value1;
myValue2 = value2;
}
{
return myCategory1;
}
public int getCategory2( )
{
return myCategory2;
}
{
return myCategory3;
}
{
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.
*/
{
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 ( ) ;
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS51dGlsLmNvbmN1cnJlbnQuKjsKaW1wb3J0IGphdmEudXRpbC5zdHJlYW0uKjsKaW1wb3J0IGphdmEubGFuZy4qOwppbXBvcnQgamF2YS5pby4qOwoKLyogTmFtZSBvZiB0aGUgY2xhc3MgaGFzIHRvIGJlICJNYWluIiBvbmx5IGlmIHRoZSBjbGFzcyBpcyBwdWJsaWMuICovCmNsYXNzIElkZW9uZQp7CglwdWJsaWMgc3RhdGljIHZvaWQgbWFpbiAoU3RyaW5nW10gYXJncykgdGhyb3dzIGphdmEubGFuZy5FeGNlcHRpb24KCXsKCQlUaHJlYWRQb29sRXhlY3V0b3IgcG9vbCA9IG5ldyBUaHJlYWRQb29sRXhlY3V0b3IoOCwgOCwgMCwgVGltZVVuaXQuU0VDT05EUywgbmV3IEFycmF5QmxvY2tpbmdRdWV1ZTw+KDEwKSk7CiAgICAgICAgLy9FeGVjdXRvclNlcnZpY2UgcG9vbCA9IEV4ZWN1dG9ycy5uZXdGaXhlZFRocmVhZFBvb2woMik7CiAgICAgICAgLy9Gb3JrSm9pblBvb2wgcG9vbCA9IG5ldyBGb3JrSm9pblBvb2woOCk7CiAgICAgICAgCiAgICAgICAgTGlzdDxSZWNvcmQ+IGxpc3QgPSBuZXcgQXJyYXlMaXN0PD4oKTsKICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IDExNTAwMDsgaSsrKQogICAgICAgIHsKICAgICAgICAgICAgbGlzdC5hZGQobmV3IFJlY29yZCgiQSIsIGkgLyAxMDAwMCwgIkIiLCAiQyIsIGksIChkb3VibGUpIGkgLyAxMDAgKyAxKSk7CiAgICAgICAgfQogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiQXJyYXlMaXN0J3Mgc3BsaXRlcmF0b3IgaXMgT1JERVJFRDogIiArCiAgICAgICAgICAgICAgICAoKGxpc3Quc3BsaXRlcmF0b3IoKS5jaGFyYWN0ZXJpc3RpY3MoKSAmIFNwbGl0ZXJhdG9yLk9SREVSRUQpICE9IDApKTsKICAgICAgICAgICAgICAgIAogICAgICAgIFN0cmVhbTxSZWNvcmQ+IHN0cmVhbSA9IGxpc3QucGFyYWxsZWxTdHJlYW0oKQogICAgICAgICAgIC8vLnBhcmFsbGVsKCkKICAgICAgICAgICAuc29ydGVkKAogICAgICAgICAgICAgICAgICAgKHIxLCByMikgLT4gSW50ZWdlci5jb21wYXJlKHIxLmdldENhdGVnb3J5MigpLCByMi5nZXRDYXRlZ29yeTIoKSkKICAgICAgICAgICApCiAgICAgICAgICAgLy8ucGFyYWxsZWwoKQogICAgICAgICAgIDsKICAgICAgICAgICAKICAgICAgICBMaXN0PFJlY29yZD4gb3V0cHV0ID0gc3RyZWFtLmNvbGxlY3QoQ29sbGVjdG9ycy50b0xpc3QoKSk7CiAgICAgICAgCiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKG91dHB1dC5zaXplKCkpOwogICAgICAgIGludCBwcmV2ID0gLTE7CiAgICAgICAgYm9vbGVhbiB2ZXJpZmllZCA9IHRydWU7CiAgICAgICAgZm9yIChSZWNvcmQgcmVjb3JkIDogb3V0cHV0KQogICAgICAgIHsKICAgICAgICAgICAgaW50IGN1cnIgPSByZWNvcmQuZ2V0VmFsdWUxKCk7CiAgICAgICAgICAgIGlmIChwcmV2ICE9IC0xKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBpZiAocHJldiArIDEgIT0gY3VycikKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIldhcm5pbmc6ICIgKyBwcmV2ICsgIiBmb2xsb3dlZCBieSAiICsgY3VyciArICIhIik7CiAgICAgICAgICAgICAgICAgICAgdmVyaWZpZWQgPSBmYWxzZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBwcmV2ID0gY3VycjsKICAgICAgICB9CiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCJWZXJpZmllZDogIiArIHZlcmlmaWVkKTsKCX0KfQoKY2xhc3MgUmVjb3JkIGltcGxlbWVudHMgQ29tcGFyYWJsZTxSZWNvcmQ+CnsKICAgcHJpdmF0ZSBTdHJpbmcgbXlDYXRlZ29yeTE7CiAgIHByaXZhdGUgaW50ICAgIG15Q2F0ZWdvcnkyOwogICBwcml2YXRlIFN0cmluZyBteUNhdGVnb3J5MzsKICAgcHJpdmF0ZSBTdHJpbmcgbXlDYXRlZ29yeTQ7CiAgIHByaXZhdGUgaW50ICAgIG15VmFsdWUxOwogICBwcml2YXRlIGRvdWJsZSBteVZhbHVlMjsKCiAgIHB1YmxpYyBSZWNvcmQoU3RyaW5nIGNhdGVnb3J5MSwgaW50IGNhdGVnb3J5MiwgU3RyaW5nIGNhdGVnb3J5MywgU3RyaW5nIGNhdGVnb3J5NCwKICAgICAgaW50IHZhbHVlMSwgZG91YmxlIHZhbHVlMikKICAgewogICAgICBteUNhdGVnb3J5MSA9IGNhdGVnb3J5MTsKICAgICAgbXlDYXRlZ29yeTIgPSBjYXRlZ29yeTI7CiAgICAgIG15Q2F0ZWdvcnkzID0gY2F0ZWdvcnkzOwogICAgICBteUNhdGVnb3J5NCA9IGNhdGVnb3J5NDsKICAgICAgbXlWYWx1ZTEgPSB2YWx1ZTE7CiAgICAgIG15VmFsdWUyID0gdmFsdWUyOwogICB9CgogICBwdWJsaWMgU3RyaW5nIGdldENhdGVnb3J5MSgpCiAgIHsKICAgICAgcmV0dXJuIG15Q2F0ZWdvcnkxOwogICB9CgogICBwdWJsaWMgaW50IGdldENhdGVnb3J5MigpCiAgIHsKICAgICAgcmV0dXJuIG15Q2F0ZWdvcnkyOwogICB9CgogICBwdWJsaWMgU3RyaW5nIGdldENhdGVnb3J5MygpCiAgIHsKICAgICAgcmV0dXJuIG15Q2F0ZWdvcnkzOwogICB9CgogICBwdWJsaWMgU3RyaW5nIGdldENhdGVnb3J5NCgpCiAgIHsKICAgICAgcmV0dXJuIG15Q2F0ZWdvcnk0OwogICB9CgogICBwdWJsaWMgaW50IGdldFZhbHVlMSgpCiAgIHsKICAgICAgcmV0dXJuIG15VmFsdWUxOwogICB9CgogICBwdWJsaWMgZG91YmxlIGdldFZhbHVlMigpCiAgIHsKICAgICAgcmV0dXJuIG15VmFsdWUyOwogICB9CgogICAgcHVibGljIGludCBjb21wYXJlVG8oUmVjb3JkIG90aGVyKQogICAgewogICAgICAgIGludCBjb21wID0gbXlDYXRlZ29yeTEuY29tcGFyZVRvKG90aGVyLm15Q2F0ZWdvcnkxKTsKICAgICAgICBpZiAoY29tcCAhPSAwKSByZXR1cm4gY29tcDsKICAgICAgICBjb21wID0gbXlDYXRlZ29yeTIgLSBvdGhlci5teUNhdGVnb3J5MjsKICAgICAgICBpZiAoY29tcCAhPSAwKSByZXR1cm4gY29tcDsKICAgICAgICBjb21wID0gbXlDYXRlZ29yeTMuY29tcGFyZVRvKG90aGVyLm15Q2F0ZWdvcnkzKTsKICAgICAgICBpZiAoY29tcCAhPSAwKSByZXR1cm4gY29tcDsKICAgICAgICBjb21wID0gbXlDYXRlZ29yeTQuY29tcGFyZVRvKG90aGVyLm15Q2F0ZWdvcnk0KTsKICAgICAgICBy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