Java Bit Shift shiftLeft(final Character orig, final int shiftDistance)

Here you can find the source of shiftLeft(final Character orig, final int shiftDistance)

Description

shift Left

License

Open Source License

Declaration

public static Character shiftLeft(final Character orig, final int shiftDistance) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static Character shiftLeft(final Character orig, final int shiftDistance) {
        return shiftCharacter(orig, shiftDistance, false);
    }/*  w  ww  .jav a2s.  c om*/

    public static Character shiftCharacter(final Character orig, final int shiftDistance,
            final boolean shiftRight) {
        int actualShiftDistance = shiftDistance % 26;
        char shifted = orig;

        int singleMove = 1;
        if (!shiftRight) {
            singleMove = -1;
        }

        if (Character.isLetter(orig)) {
            for (int i = 0; i < actualShiftDistance; i++) {
                shifted += singleMove;
                if (!Character.isLetter(shifted)) {
                    if (shiftRight) {
                        shifted = (char) (shifted - 26);
                    } else {
                        shifted = (char) (shifted + 26);
                    }

                }
            }
        }

        return shifted;
    }
}

Related

  1. shiftHorizontally(int inkX, int inkXWidth, int textWidth)
  2. shiftIdentifier(StringBuffer buffer, int posBegin, int posEnd)
  3. shiftKeyword(StringBuffer buffer, int posBegin, int posEnd, String keyword, boolean ignoreCase, boolean wholeWord)
  4. shiftLastAlphabets(String id)
  5. shiftLeft(char ch)
  6. shiftPath(String uri)
  7. shiftsForNextPowerOfTwo(final int targetSize)
  8. shiftText(final int pads, final String padding, String textPassed)
  9. shiftUpLeft(long b)