Sha256: eff2f0c74b0e95365df9a5b791f6ca5a1f31a00d8d746d1145031f65e056e7b3

Contents?: true

Size: 732 Bytes

Versions: 318

Compression:

Stored size: 732 Bytes

Contents

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

final class HandshakeCalculator {

    private static final int REVERSE_SIGNALS_BIT_POSITION = 4;

    List<Signal> calculateHandshake(final int number) {
        final List<Signal> result = new ArrayList<>();

        for (final Signal signal : Signal.values()) {
            if (isBitSet(signal.ordinal(), number)) {
                result.add(signal);
            }
        }

        if (isBitSet(REVERSE_SIGNALS_BIT_POSITION, number)) {
            Collections.reverse(result);
        }

        return result;
    }

    private boolean isBitSet(final int position, final int number) {
        return ((number >> position) & 1) == 1;
    }

}

Version data entries

318 entries across 318 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.179 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.178 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.177 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.176 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.175 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.174 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.173 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.172 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.171 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.170 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.169 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.167 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.166 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.165 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.164 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.163 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.162 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.161 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.160 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java