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.159 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.158 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.157 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.156 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.155 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.154 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.153 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.152 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.151 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.150 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.149 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.148 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.147 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.146 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.145 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.144 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.143 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.142 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.141 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java
trackler-2.2.1.140 tracks/java/exercises/secret-handshake/.meta/src/reference/java/HandshakeCalculator.java