class S2Utils {

    static int getS2SpectralBandIndex(String bandName) {
        // S2 spectralBandIndex:
        // bands B1..B8: spectralBandIndex = 0..7
        // band B8A: spectralBandIndex = 8
        // bands B9: spectralBandIndex = 9
        // bands B10..B12: 10..12
        if (bandName.endsWith("B8A")) {
            return 8;
        } else {
            // shall work for patterns like B12, rho_ng_B12, rBRR_B9, ...
            final int lastIndexOfB = bandName.lastIndexOf("B");
            if (lastIndexOfB >= 0) {
                final int bandNumber = Integer.parseInt(bandName.substring(lastIndexOfB + 1, bandName.length()));
                return bandNumber < 9 ? bandNumber - 1 : bandNumber;
            } else {
                return -1;
            }
        }
    }

}