Ignore:
Timestamp:
2014-10-19T01:27:04+02:00 (10 years ago)
Author:
donvip
Message:

[josm_plugins] fix java 7 warnings / global usage of try-with-resource

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/trustosm/src/tools/NameGenerator.java

    r30737 r30738  
    88/**
    99 * This class is released under GNU general public license
    10  * 
     10 *
    1111 * Description: This class generates random names from syllables, and provides programmer a
    1212 * simple way to set a group of rules for generator to avoid unpronounceable and bizarre names.
    13  * 
     13 *
    1414 * SYLLABLE FILE REQUIREMENTS/FORMAT:
    1515 * 1) all syllables are separated by line break.
     
    1717 * 3) + and - characters are used to set rules, and using them in other way, may result in unpredictable results.
    1818 * 4) Empty lines are ignored.
    19  * 
     19 *
    2020 * SYLLABLE CLASSIFICATION:
    2121 * Name is usually composed from 3 different class of syllables, which include prefix, middle part and suffix.
     
    2323 * To declare syllable as a suffix in the file, insert "+" as a first character of the line.
    2424 * everything else is read as a middle part.
    25  * 
     25 *
    2626 * NUMBER OF SYLLABLES:
    2727 * Names may have any positive number of syllables. In case of 2 syllables, name will be composed from prefix and suffix.
    2828 * In case of 1 syllable, name will be chosen from amongst the prefixes.
    2929 * In case of 3 and more syllables, name will begin with prefix, is filled with middle parts and ended with suffix.
    30  * 
     30 *
    3131 * ASSIGNING RULES:
    3232 * I included a way to set 4 kind of rules for every syllable. To add rules to the syllables, write them right after the
    3333 * syllable and SEPARATE WITH WHITESPACE. (example: "aad +v -c"). The order of rules is not important.
    34  * 
     34 *
    3535 * RULES:
    3636 * 1) +v means that next syllable must definitely start with a vocal.
     
    4141 * Beware of creating logical mistakes, like providing only syllables ending with consonants, but expecting only vocals, which will be detected
    4242 * and RuntimeException will be thrown.
    43  * 
     43 *
    4444 * TO START:
    4545 * Create a new NameGenerator object, provide the syllable file, and create names using compose() method.
    46  * 
     46 *
    4747 * @author Joonas Vali, August 2009.
    4848 *
     
    8585     */
    8686    public void refresh() throws IOException{
    87 
    88         FileReader input = null;
    89         BufferedReader bufRead;
    90         String line;
    91 
    92         input = new FileReader(fileName);
    93 
    94         bufRead = new BufferedReader(input);
    95         line="";
    96 
    97         while(line != null){
    98             line = bufRead.readLine();
    99             if(line != null && !line.equals("")){
    100                 if(line.charAt(0) == '-'){
    101                     pre.add(line.substring(1).toLowerCase());
    102                 }
    103                 else if(line.charAt(0) == '+'){
    104                     sur.add(line.substring(1).toLowerCase());
    105                 }
    106                 else{
    107                     mid.add(line.toLowerCase());
    108                 }
    109             }
    110         }
    111         bufRead.close();
    112     }
    113 
    114     private String upper(String s){
     87        try (
     88                FileReader input = new FileReader(fileName);
     89                BufferedReader bufRead = new BufferedReader(input);
     90        ) {
     91                String line="";
     92
     93                while (line != null) {
     94                    line = bufRead.readLine();
     95                    if (line != null && !line.equals("")) {
     96                        if (line.charAt(0) == '-') {
     97                            pre.add(line.substring(1).toLowerCase());
     98                        } else if (line.charAt(0) == '+') {
     99                            sur.add(line.substring(1).toLowerCase());
     100                        } else{
     101                            mid.add(line.toLowerCase());
     102                        }
     103                    }
     104                }
     105        }
     106    }
     107
     108    private String upper(String s) {
    115109        return s.substring(0,1).toUpperCase().concat(s.substring(1));
    116110    }
    117111
    118     private boolean containsConsFirst(ArrayList<String> array){
    119         for(String s: array){
    120             if(consonantFirst(s)) return true;
     112    private boolean containsConsFirst(ArrayList<String> array) {
     113        for (String s: array) {
     114            if (consonantFirst(s)) return true;
    121115        }
    122116        return false;
Note: See TracChangeset for help on using the changeset viewer.