aboutsummaryrefslogtreecommitdiff
path: root/challenge-277/luca-ferrari/pljava/src/main/java/Task1.java
blob: 157decedd70b7ebb5e6871b2f8ef62650f143931 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public static int task1_pljava( String[] words1, String[] words2 ) throws SQLException {
    logger.log( Level.INFO, "Entering pwc277.task1_pljava" );

    final Map<String, Integer[]> counting = new HashMap<String, Integer[]>();

    Stream.of( words1 ).forEach( current -> {
    	Integer[] count = { 0, 0 };
    	counting.putIfAbsent( current, count );
    	count = counting.get( current );
    	count[ 0 ]++;
    	counting.put( current, count );
    } );


    Stream.of( words2 ).forEach( current -> {
    	Integer[] count = { 0, 0 };
    	counting.putIfAbsent( current, count );
    	count = counting.get( current );
    	count[ 1 ]++;
    	counting.put( current, count );
    } );

    return (int) counting.entrySet().stream().filter( current -> {
    	Integer[] count = current.getValue();
    	return count[ 0 ] == count[ 1 ] && count[ 0 ] == 1;
    } ).count();
}