src/main/java/MorseCodeDecoder.java
/**
     * Given a string of bits, which may or may not begin or end with '0's,
     * and which may have some variation in the length of the time unit used,
     * returns the Morse Code translation of this message.
     *
     * Accepts 0s and 1s, return dots, dashes and spaces
     *
     * @param bits String of '1's and '0's
     * @return String of '.'s and '-'s
     */
Given a string of bits, which may or may not begin or end with '0's,
and which may have some variation in the length of the time unit used,
returns the Morse Code translation of this message.

Accepts 0s and 1s, return dots, dashes and spaces


Given a string of bits which may or may not begin or end with ' 0 ' s and which may have some variation in the length of the time unit used returns the Morse Code translation of this message . Accepts 0s and 1s return dots dashes and spaces
public static String decodeBitsAdvanced(String bits) {
        System.out.println(bits);
        bits = bits.replaceAll("^0+", "");
        bits = bits.replaceAll("0+$", "");
        if (bits.isEmpty())
            return "";
        List<Integer> ones = Arrays.stream(bits.split("0+"))
                .mapToInt(String::length)
                .boxed()
                .collect(Collectors.toList());
        if (ones.size() == 0)
            return "";
        List<Integer> zeros = Arrays.stream(bits.split("1+"))
                .mapToInt(String::length)
                .boxed()
                .collect(Collectors.toList());
        if (zeros.size() > 0 && zeros.get(0) == 0){
            zeros.remove(0);
        }
        System.out.println(" Ones: " + ones);
        System.out.println("Zeros: " + zeros);
        int longestOne = ones.stream().reduce(0, (m, i) -> m = (i > m) ? i : m);
        int longest = zeros.stream().reduce(longestOne, (m, i) -> m = (i > m) ? i : m);
        int shortest = zeros.stream().reduce(longest, (m, i) -> m = (i < m) ? i : m);
        shortest = ones.stream().reduce(shortest, (m, i) -> m = (i < m) ? i : m);
        decodeMorse(".... . -.--   .--- ..- -.. .");
        String morseCode = "";
        for (int i = shortest * 6; i < 18 * shortest; i++){
            float one = (float) (i / 6.0);
            morseCode = generateMorseCode(ones, zeros, one);
            decodeMorse(morseCode);
            if (checkMorse(morseCode)) {
                System.out.println("Check is true ");
                break;
            }
        }
        return morseCode;
    }
public static String decodeBitsAdvanced ( String bits ) { System . out . println ( bits ) ; bits = bits . replaceAll ( "^0+" , "" ) ; bits = bits . replaceAll ( "0+$" , "" ) ; if ( bits . isEmpty ( ) ) return "" ; List < Integer > ones = Arrays . stream ( bits . split ( "0+" ) ) . mapToInt ( String :: length ) . boxed ( ) . collect ( Collectors . toList ( ) ) ; if ( ones . size ( ) == 0 ) return "" ; List < Integer > zeros = Arrays . stream ( bits . split ( "1+" ) ) . mapToInt ( String :: length ) . boxed ( ) . collect ( Collectors . toList ( ) ) ; if ( zeros . size ( ) > 0 && zeros . get ( 0 ) == 0 ) { zeros . remove ( 0 ) ; } System . out . println ( " Ones: " + ones ) ; System . out . println ( "Zeros: " + zeros ) ; int longestOne = ones . stream ( ) . reduce ( 0 , ( m , i ) -> m = ( i > m ) ? i : m ) ; int longest = zeros . stream ( ) . reduce ( longestOne , ( m , i ) -> m = ( i > m ) ? i : m ) ; int shortest = zeros . stream ( ) . reduce ( longest , ( m , i ) -> m = ( i < m ) ? i : m ) ; shortest = ones . stream ( ) . reduce ( shortest , ( m , i ) -> m = ( i < m ) ? i : m ) ; decodeMorse ( ".... . -.--   .--- ..- -.. ." ) ; String morseCode = "" ; for ( int i = shortest * 6 ; i < 18 * shortest ; i ++ ) { float one = ( float ) ( i / 6.0 ) ; morseCode = generateMorseCode ( ones , zeros , one ) ; decodeMorse ( morseCode ) ; if ( checkMorse ( morseCode ) ) { System . out . println ( "Check is true " ) ; break ; } } return morseCode ; }
Given a string of bits, which may or may not begin or end with '0's,
 and which may have some variation in the length of the time unit used,
 returns the Morse Code translation of this message.
Given a string of bits which may or may not begin or end with ' 0 ' s and which may have some variation in the length of the time unit used returns the Morse Code translation of this message .
//message.append("\n   .... . -.--   .--- ..- -.. ."); //message.append("\n.... . -.--   .--- ..- -.. .");