Example usage for java.lang Character equals

List of usage examples for java.lang Character equals

Introduction

In this page you can find the example usage for java.lang Character equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Compares this object against the specified object.

Usage

From source file:Main.java

public static void main(String[] args) {
    Character c1 = new Character('a');
    Character c2 = new Character('a');

    String str1 = "Equal ";

    if (c1.equals(c2)) {
        System.out.println(str1);
    }/*from www  .  ja  va  2  s . c o  m*/
}

From source file:CharacterDemo.java

public static void main(String args[]) {
    Character a = new Character('a');
    Character a2 = new Character('a');
    Character b = new Character('b');

    int difference = a.compareTo(b);

    if (difference == 0) {
        System.out.println("a is equal to b.");
    } else if (difference < 0) {
        System.out.println("a is less than b.");
    } else if (difference > 0) {
        System.out.println("a is greater than b.");
    }//from   w ww  .  ja  va  2 s .c  o  m

    System.out.println("a is " + ((a.equals(a2)) ? "equal" : "not equal") + " to a2.");

    System.out.println("The character " + a.toString() + " is "
            + (Character.isUpperCase(a.charValue()) ? "upper" : "lower") + "case.");
}

From source file:Main.java

public static boolean isWhiteSpace(char c) {
    boolean out = Boolean.TRUE;
    for (Character cr : WHITE_SPACE) {
        if (cr.equals(c)) {
            out = Boolean.FALSE;/*from  w w w.  j a  va 2 s . co m*/
            break;
        }
    }
    return out;
}

From source file:Main.java

/**
 * Freaking Java trim won't work!!! This is an own implementation of trim.
 * //  w  w w . j  a  va  2 s  . com
 * @return String with all fields separated by ":"
 */
public static String trimmer(String line) {
    String retval = "";
    Boolean series = false;

    for (Character a : line.toCharArray()) {
        if (!a.equals(' ') && !series)
            retval += a;

        if (!a.equals(' ') && series) {
            retval += ":" + a;
            series = false;
        }

        if (a.equals(' ')) {
            series = true;
        }
    }

    return retval;
}

From source file:com.woonoz.proxy.servlet.UrlRewriterImpl.java

private static String removeTrailingSlashes(final String text) {
    if (text.isEmpty()) {
        return text;
    }//from w w w. j a  v a 2 s  .  c  om
    final CharacterIterator it = new StringCharacterIterator(text);
    Character c = it.last();
    while (c.equals('/')) {
        c = it.previous();
    }
    return text.substring(0, it.getIndex() + 1);
}

From source file:com.woonoz.proxy.servlet.UrlRewriterImpl.java

private static String removeLeadingSlashes(final String text) {
    if (text.isEmpty()) {
        return text;
    }//from   w  w  w.  jav  a  2 s  .com
    final CharacterIterator it = new StringCharacterIterator(text);
    Character c = it.first();
    while (c.equals('/')) {
        c = it.next();
    }
    return text.substring(it.getIndex());
}

From source file:Main.java

private static String getNumericPrefix(String string) {
    StringBuffer numeric = new StringBuffer();

    if (string != null) {
        string = string.trim();/*from  w w w .j  a  v a 2  s .c om*/

        if (string.length() > 0) {

            StringBuffer buffer = new StringBuffer(string);
            char first = buffer.charAt(0);

            if (Character.isDigit(first)) {
                numeric.append(first);

                for (int i = 1; i < buffer.length(); i++) {
                    Character next = buffer.charAt(i);

                    if (Character.isDigit(next)) {
                        numeric.append(next);

                        // skip commas within numbers
                    } else if (next.equals(',')) {
                        continue;

                    } else {
                        break;
                    }
                }
            }
        }
    }

    return numeric.length() == 0 ? null : numeric.toString();
}

From source file:Main.java

public static boolean charsEqual(@Nullable Character one, @Nullable Character another, boolean ignoreCase) {
    if (ignoreCase) {
        one = one != null ? Character.toUpperCase(one) : null;
        another = another != null ? Character.toUpperCase(another) : null;
    }/*from   www  .ja va  2s. c  o  m*/
    return !(one != null ? !one.equals(another) : another != null);
}

From source file:com.legstar.codegen.tasks.SourceToXsdCobolTask.java

/**
 * Converts a URI into a package name. We assume a hierarchical,
 * server-based URI with the following syntax:
 * [scheme:][//host[:port]][path][?query][#fragment]
 * The package name is derived from host, path and fragment.
 * //from ww  w  . jav  a2  s . co m
 * @param namespaceURI the input namespace URI
 * @return the result package name
 */
public static String packageFromURI(final URI namespaceURI) {

    StringBuilder result = new StringBuilder();
    URI nURI = namespaceURI.normalize();
    boolean firstToken = true;

    /*
     * First part of package name is built from host with tokens in
     * reverse order.
     */
    if (nURI.getHost() != null && nURI.getHost().length() != 0) {
        Vector<String> v = new Vector<String>();
        StringTokenizer t = new StringTokenizer(nURI.getHost(), ".");
        while (t.hasMoreTokens()) {
            v.addElement(t.nextToken());
        }

        for (int i = v.size(); i > 0; i--) {
            if (!firstToken) {
                result.append('.');
            } else {
                firstToken = false;
            }
            result.append(v.get(i - 1));
        }
    }

    /* Next part of package is built from the path tokens */
    if (nURI.getPath() != null && nURI.getPath().length() != 0) {
        Vector<String> v = new Vector<String>();
        StringTokenizer t = new StringTokenizer(nURI.getPath(), "/");
        while (t.hasMoreTokens()) {
            v.addElement(t.nextToken());
        }

        for (int i = 0; i < v.size(); i++) {
            String token = v.get(i);
            /* ignore situations such as /./../ */
            if (token.equals(".") || token.equals("..")) {
                continue;
            }
            if (!firstToken) {
                result.append('.');
            } else {
                firstToken = false;
            }
            result.append(v.get(i));
        }
    }

    /* Finally append any fragment */
    if (nURI.getFragment() != null && nURI.getFragment().length() != 0) {
        if (!firstToken) {
            result.append('.');
        } else {
            firstToken = false;
        }
        result.append(nURI.getFragment());
    }

    /*
     * By convention, namespaces are lowercase and should not contain
     * invalid Java identifiers
     */
    String s = result.toString().toLowerCase();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < s.length(); i++) {
        Character c = s.charAt(i);
        if (Character.isJavaIdentifierPart(c) || c.equals('.')) {
            sb.append(c);
        } else {
            sb.append("_");
        }
    }
    return sb.toString();
}

From source file:edu.jhu.hlt.concrete.ingesters.webposts.WebPostIngester.java

private static boolean isSpaceOrUnixNewline(final Character c) {
    return c.equals(' ') || c.equals('\n');
}