All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.kuali.common.util.Ascii Maven / Gradle / Ivy

There is a newer version: 4.4.17
Show newest version
/**
 * Copyright 2010-2014 The Kuali Foundation
 *
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.opensource.org/licenses/ecl2.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.kuali.common.util;

public final class Ascii {

	private Ascii() {
	}

	private static final int LETTER_OFFSET = 13;
	private static final int NUMBER_OFFSET = 5;
	private static final char NUMBER_MIDPOINT = '4';
	private static final char LCASE_MIDPOINT = 'm';
	private static final char UCASE_MIDPOINT = 'M';

	/**
	 * Return true if the character is in the range A-Z or a-z
	 */
	public static boolean isLetter(char c) {
		return isLowerCase(c) || isUpperCase(c);
	}

	/**
	 * Return true if the character is in the range 0-9
	 */
	public static boolean isDigit(char c) {
		return c >= '0' && c <= '9';
	}

	/**
	 * Return true if the character is in the range a-z
	 */
	public static boolean isLowerCase(char c) {
		return c >= 'a' && c <= 'z';
	}

	/**
	 * Return true if the character is in the range A-Z
	 */
	public static boolean isUpperCase(char c) {
		return c >= 'A' && c <= 'Z';
	}

	/**
	 * 

* If the character is a letter or digit, apply the flip algorithm to it, otherwise leave it alone. *

* * The flip algorithm makes the character in the top row become the character in the bottom row, and vice versa. * *
	 *  01234 abcdefghijklm ABCDEFGHIJKLM
	 *  56789 nopqrstuvwxyz NOPQRSTUVWXYZ
	 * 
*/ public static char flip(char c) { if (isLowerCase(c)) { if (c > LCASE_MIDPOINT) { return (char) ((int) c - LETTER_OFFSET); } else { return (char) ((int) c + LETTER_OFFSET); } } else if (isUpperCase(c)) { if (c > UCASE_MIDPOINT) { return (char) ((int) c - LETTER_OFFSET); } else { return (char) ((int) c + LETTER_OFFSET); } } else if (isDigit(c)) { if (c > NUMBER_MIDPOINT) { return (char) ((int) c - NUMBER_OFFSET); } else { return (char) ((int) c + NUMBER_OFFSET); } } else { return c; } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy