Example usage for java.lang Character isUpperCase

List of usage examples for java.lang Character isUpperCase

Introduction

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

Prototype

public static boolean isUpperCase(int codePoint) 

Source Link

Document

Determines if the specified character (Unicode code point) is an uppercase character.

Usage

From source file:KeyEventPost.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    final Text text = new Text(shell, SWT.BORDER);
    text.setSize(text.computeSize(150, SWT.DEFAULT));
    shell.pack();/*from   w  w w . j av  a2  s .com*/
    shell.open();
    new Thread() {
        public void run() {
            String string = "Love the method.";
            for (int i = 0; i < string.length(); i++) {
                char ch = string.charAt(i);
                boolean shift = Character.isUpperCase(ch);
                ch = Character.toLowerCase(ch);
                if (shift) {
                    Event event = new Event();
                    event.type = SWT.KeyDown;
                    event.keyCode = SWT.SHIFT;
                    display.post(event);
                }
                Event event = new Event();
                event.type = SWT.KeyDown;
                event.character = ch;
                display.post(event);
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                }
                event.type = SWT.KeyUp;
                display.post(event);
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                }
                if (shift) {
                    event = new Event();
                    event.type = SWT.KeyUp;
                    event.keyCode = SWT.SHIFT;
                    display.post(event);
                }
            }
        }
    }.start();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:org.eclipse.swt.snippets.Snippet146.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 146");
    final Text text = new Text(shell, SWT.BORDER);
    text.setSize(text.computeSize(150, SWT.DEFAULT));
    shell.pack();/*from  w w  w .  jav  a2  s  . c om*/
    shell.open();
    new Thread() {
        @Override
        public void run() {
            // wait for shell to be opened
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
            }

            String string = "Love the method.";
            for (int i = 0; i < string.length(); i++) {
                char ch = string.charAt(i);
                boolean shift = Character.isUpperCase(ch);
                ch = Character.toLowerCase(ch);
                if (shift) {
                    Event event = new Event();
                    event.type = SWT.KeyDown;
                    event.keyCode = SWT.SHIFT;
                    display.post(event);
                }
                Event event = new Event();
                event.type = SWT.KeyDown;
                event.character = ch;
                display.post(event);
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                }
                event.type = SWT.KeyUp;
                display.post(event);
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                }
                if (shift) {
                    event = new Event();
                    event.type = SWT.KeyUp;
                    event.keyCode = SWT.SHIFT;
                    display.post(event);
                }
            }
        }
    }.start();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:ComputeInitials.java

public static void main(String[] args) {
    String myName = "Fred F. Flintstone";
    StringBuffer myInitials = new StringBuffer();
    int length = myName.length();

    for (int i = 0; i < length; i++) {
        if (Character.isUpperCase(myName.charAt(i))) {
            myInitials.append(myName.charAt(i));
        }/*from  w  ww .j a v  a  2  s. c  o m*/
    }
    System.out.println("My initials are: " + myInitials);
}

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 www.  j av  a 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:MaxVariablesDemo.java

public static void main(String args[]) {

    //integers/*from  ww  w  .  j  a  va 2  s.  c om*/
    byte largestByte = Byte.MAX_VALUE;
    short largestShort = Short.MAX_VALUE;
    int largestInteger = Integer.MAX_VALUE;
    long largestLong = Long.MAX_VALUE;

    //real numbers
    float largestFloat = Float.MAX_VALUE;
    double largestDouble = Double.MAX_VALUE;

    //other primitive types
    char aChar = 'S';
    boolean aBoolean = true;

    //Display them all.
    System.out.println("The largest byte value is " + largestByte + ".");
    System.out.println("The largest short value is " + largestShort + ".");
    System.out.println("The largest integer value is " + largestInteger + ".");
    System.out.println("The largest long value is " + largestLong + ".");

    System.out.println("The largest float value is " + largestFloat + ".");
    System.out.println("The largest double value is " + largestDouble + ".");

    if (Character.isUpperCase(aChar)) {
        System.out.println("The character " + aChar + " is uppercase.");
    } else {
        System.out.println("The character " + aChar + " is lowercase.");
    }
    System.out.println("The value of aBoolean is " + aBoolean + ".");
}

From source file:MaxVariablesDemo.java

public static void main(String args[]) {

    // integers/*from  www. ja va 2 s  .  c  o m*/
    byte largestByte = Byte.MAX_VALUE;
    short largestShort = Short.MAX_VALUE;
    int largestInteger = Integer.MAX_VALUE;
    long largestLong = Long.MAX_VALUE;

    /* real numbers*/
    float largestFloat = Float.MAX_VALUE;
    double largestDouble = Double.MAX_VALUE;

    // other primitive types
    char aChar = 'S';
    boolean aBoolean = true;

    // display them all
    System.out.println("The largest byte value is " + largestByte);
    System.out.println("The largest short value is " + largestShort);
    System.out.println("The largest integer value is " + largestInteger);
    System.out.println("The largest long value is " + largestLong);

    System.out.println("The largest float value is " + largestFloat);
    System.out.println("The largest double value is " + largestDouble);

    if (Character.isUpperCase(aChar)) {
        System.out.println("The character " + aChar + " is upper case.");
    } else {
        System.out.println("The character " + aChar + " is lower case.");
    }
    System.out.println("The value of aBoolean is " + aBoolean);
}

From source file:de.citec.sc.matoll.process.Matoll_CreateMax.java

public static void main(String[] args) throws IOException, ParserConfigurationException, SAXException,
        InstantiationException, IllegalAccessException, ClassNotFoundException, Exception {

    String directory;//  www.  j ava  2s  . c om
    String gold_standard_lexicon;
    String output_lexicon;
    String configFile;
    Language language;
    String output;

    Stopwords stopwords = new Stopwords();

    HashMap<String, Double> maxima;
    maxima = new HashMap<String, Double>();

    if (args.length < 3) {
        System.out.print("Usage: Matoll --mode=train/test <DIRECTORY> <CONFIG>\n");
        return;

    }

    //      Classifier classifier;

    directory = args[1];
    configFile = args[2];

    final Config config = new Config();

    config.loadFromFile(configFile);

    gold_standard_lexicon = config.getGoldStandardLexicon();

    String model_file = config.getModel();

    output_lexicon = config.getOutputLexicon();
    output = config.getOutput();

    language = config.getLanguage();

    LexiconLoader loader = new LexiconLoader();
    Lexicon gold = loader.loadFromFile(gold_standard_lexicon);

    Set<String> uris = new HashSet<>();
    //        Map<Integer,String> sentence_list = new HashMap<>();
    Map<Integer, Set<Integer>> mapping_words_sentences = new HashMap<>();

    //consider only properties
    for (LexicalEntry entry : gold.getEntries()) {
        try {
            for (Sense sense : entry.getSenseBehaviours().keySet()) {
                String tmp_uri = sense.getReference().getURI().replace("http://dbpedia.org/ontology/", "");
                if (!Character.isUpperCase(tmp_uri.charAt(0))) {
                    uris.add(sense.getReference().getURI());
                }
            }
        } catch (Exception e) {
        }
        ;
    }

    ModelPreprocessor preprocessor = new ModelPreprocessor(language);
    preprocessor.setCoreferenceResolution(false);
    Set<String> dep = new HashSet<>();
    dep.add("prep");
    dep.add("appos");
    dep.add("nn");
    dep.add("dobj");
    dep.add("pobj");
    dep.add("num");
    preprocessor.setDEP(dep);

    List<File> list_files = new ArrayList<>();

    if (config.getFiles().isEmpty()) {
        File folder = new File(directory);
        File[] files = folder.listFiles();
        for (File file : files) {
            if (file.toString().contains(".ttl"))
                list_files.add(file);
        }
    } else {
        list_files.addAll(config.getFiles());
    }
    System.out.println(list_files.size());

    int sentence_counter = 0;
    Map<String, Set<Integer>> bag_words_uri = new HashMap<>();
    Map<String, Integer> mapping_word_id = new HashMap<>();
    for (File file : list_files) {
        Model model = RDFDataMgr.loadModel(file.toString());
        for (Model sentence : getSentences(model)) {
            String reference = getReference(sentence);
            reference = reference.replace("http://dbpedia/", "http://dbpedia.org/");
            if (uris.contains(reference)) {
                sentence_counter += 1;
                Set<Integer> words_ids = getBagOfWords(sentence, stopwords, mapping_word_id);
                //TODO: add sentence preprocessing
                String obj = getObject(sentence);
                String subj = getSubject(sentence);
                preprocessor.preprocess(sentence, subj, obj, language);
                //TODO: also return marker if object or subject of property (in SPARQL this has to be optional of course)
                String parsed_sentence = getParsedSentence(sentence);
                try (FileWriter fw = new FileWriter("mapping_sentences_to_ids_goldstandard.tsv", true);
                        BufferedWriter bw = new BufferedWriter(fw);
                        PrintWriter out = new PrintWriter(bw)) {
                    out.println(sentence_counter + "\t" + parsed_sentence);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                for (Integer word_id : words_ids) {
                    if (mapping_words_sentences.containsKey(word_id)) {
                        Set<Integer> tmp_set = mapping_words_sentences.get(word_id);
                        tmp_set.add(sentence_counter);
                        mapping_words_sentences.put(word_id, tmp_set);

                    } else {
                        Set<Integer> tmp_set = new HashSet<>();
                        tmp_set.add(sentence_counter);
                        mapping_words_sentences.put(word_id, tmp_set);
                    }

                }
                if (bag_words_uri.containsKey(reference)) {
                    Set<Integer> tmp = bag_words_uri.get(reference);
                    for (Integer w : words_ids) {
                        tmp.add(w);

                    }
                    bag_words_uri.put(reference, tmp);
                } else {
                    Set<Integer> tmp = new HashSet<>();
                    for (Integer w : words_ids) {
                        tmp.add(w);
                    }
                    bag_words_uri.put(reference, tmp);
                }
            }

        }
        model.close();

    }

    PrintWriter writer = new PrintWriter("bag_of_words_only_goldstandard.tsv");
    StringBuilder string_builder = new StringBuilder();
    for (String r : bag_words_uri.keySet()) {
        string_builder.append(r);
        for (Integer i : bag_words_uri.get(r)) {
            string_builder.append("\t");
            string_builder.append(i);
        }
        string_builder.append("\n");
    }
    writer.write(string_builder.toString());
    writer.close();

    writer = new PrintWriter("mapping_words_to_sentenceids_goldstandard.tsv");
    string_builder = new StringBuilder();
    for (Integer w : mapping_words_sentences.keySet()) {
        string_builder.append(w);
        for (int i : mapping_words_sentences.get(w)) {
            string_builder.append("\t");
            string_builder.append(i);
        }
        string_builder.append("\n");
    }
    writer.write(string_builder.toString());
    writer.close();

}

From source file:Main.java

public static String lowerFirstLetter(String string) {
    if (isEmpty(string) || !Character.isUpperCase(string.charAt(0))) {
        return string;
    }//from   ww w. j  av  a 2  s  .c  om
    return String.valueOf((char) (string.charAt(0) + 32)) + string.substring(1);
}

From source file:Main.java

public static String capitalize(String s) {
    if (s == null || s.length() == 0) {
        return "";
    }//  ww w  . ja va2 s  .  com
    char first = s.charAt(0);
    if (Character.isUpperCase(first)) {
        return s;
    } else {
        return Character.toUpperCase(first) + s.substring(1);
    }
}

From source file:Main.java

private static String capitalize(String s) {
    if (s == null || s.length() == 0) {
        return "";
    }// www . j  a  v a  2 s .c om
    char first = s.charAt(0);
    if (Character.isUpperCase(first)) {
        return s;
    } else {
        return Character.toUpperCase(first) + s.substring(1);
    }
}