Example usage for org.apache.commons.lang WordUtils capitalize

List of usage examples for org.apache.commons.lang WordUtils capitalize

Introduction

In this page you can find the example usage for org.apache.commons.lang WordUtils capitalize.

Prototype

public static String capitalize(String str) 

Source Link

Document

Capitalizes all the whitespace separated words in a String.

Usage

From source file:net.firejack.platform.model.service.reverse.ReverseEngineeringService.java

private RelationshipModel convertToOneToManyRelationship(Constraint constraint,
        Map<String, EntityModel> entityModels) {
    RelationshipModel relationshipModel = new RelationshipModel();
    String relationshipName = constraint.getName().replaceAll("\\p{Punct}", " ").replaceAll("\\s+", " ").trim();
    relationshipName = WordUtils.capitalize(relationshipName.toLowerCase());
    relationshipModel.setName(relationshipName);

    Column sourceColumn = constraint.getSourceColumn();
    Table sourceTable = sourceColumn.getTable();
    EntityModel sourceEntityModel = entityModels.get(sourceTable.getName());
    relationshipModel.setSourceEntity(sourceEntityModel);

    Column destinationColumn = constraint.getDestinationColumn();
    Table destinationTable = destinationColumn.getTable();
    EntityModel destinationEntityModel = entityModels.get(destinationTable.getName());
    relationshipModel.setTargetEntity(destinationEntityModel);

    relationshipModel.setPath(sourceEntityModel.getLookup());
    relationshipModel.setLookup(sourceEntityModel.getLookup() + "." + StringUtils.normalize(relationshipName));
    if (sourceTable.equals(destinationTable) && "id_parent".equals(sourceColumn.getName())) { //TODO hard code for OPF schemas
        relationshipModel.setRelationshipType(TREE);
        relationshipModel.setDescription(
                "Relationship with type: TREE created by constraint: '" + constraint.getName() + "'");
    } else {//from www .  ja  v a  2  s.  c  o m
        relationshipModel.setRelationshipType(TYPE);
        relationshipModel.setDescription(
                "Relationship with type: TYPE created by constraint: '" + constraint.getName() + "'");
        relationshipModel.setTargetConstraintName(constraint.getName());
        relationshipModel.setOnDeleteOption(convertToRelationshipOption(constraint.getOnDelete()));
        relationshipModel.setOnUpdateOption(convertToRelationshipOption(constraint.getOnUpdate()));
    }
    relationshipModel.setParent(sourceEntityModel);

    String sourceColumnName = sourceColumn.getName();
    if (relationshipModel.getRelationshipType() == PARENT_CHILD) {
        relationshipModel.setSourceConstraintName(sourceColumnName);
    } else {
        relationshipModel.setTargetEntityRefName(sourceColumnName);
    }
    relationshipModel.setReverseEngineer(true);

    return relationshipModel;
}

From source file:gdv.xport.feld.Feld.java

private static String toBezeichnung(final String name) {
    String converted = name.replaceAll("_", " ");
    ByteBuffer outputBuffer = Config.DEFAULT_ENCODING.encode(converted);
    String convertedISO = new String(outputBuffer.array(), Config.DEFAULT_ENCODING);
    return WordUtils.capitalize(convertedISO.toLowerCase());
}

From source file:com.tgn.ProjectApex.DestroyTheMonument.Monument.java

public void onSecond() {
    long time = timer.getTime();

    if (time == -5L) {

        String winner = voting.getWinner();
        voting.end();/*from w w w . ja v  a 2 s  .c om*/
        getServer().broadcastMessage(ChatColor.GOLD + "Voting is now closed!");
        maps.selectMap(winner);
        getServer().broadcastMessage(ChatColor.GREEN + WordUtils.capitalize(winner) + " was chosen!");
        loadMap(winner);

        for (Player p : Bukkit.getOnlinePlayers()) {
            p.playSound(p.getLocation(), Sound.ENDERDRAGON_WINGS, 10, 1);
            p.playSound(p.getLocation(), Sound.ENDERDRAGON_GROWL, 10, 1);
        }
    }

    if (time <= -5L) {
        for (Player p : Bukkit.getOnlinePlayers()) {
            p.playSound(p.getLocation(), Sound.ENDERDRAGON_WINGS, 10, 1);
            p.playSound(p.getLocation(), Sound.ENDERDRAGON_GROWL, 10, 1);
            p.playSound(p.getLocation(), Sound.NOTE_PLING, 10, 2F);
            p.playSound(p.getLocation(), Sound.NOTE_BASS_GUITAR, 10, 2F);
            p.playSound(p.getLocation(), Sound.NOTE_PIANO, 10, 2F);
        }
    }

    if (time == 0L)
        startGame();
}

From source file:net.firejack.platform.model.service.reverse.ReverseEngineeringService.java

private RelationshipModel convertToManyToManyRelationship(Table table, Map<String, EntityModel> entityModels) {
    RelationshipModel relationshipModel = new RelationshipModel();
    String relationshipName = table.getName().replaceAll("\\p{Punct}", " ").replaceAll("\\s+", " ").trim();
    relationshipName = WordUtils.capitalize(relationshipName.toLowerCase());
    relationshipModel.setName(relationshipName);

    List<Constraint> constraints = table.getConstraints();

    Constraint constraint1 = constraints.get(1);
    Column source1Column = constraint1.getSourceColumn();
    Column destination1Column = constraint1.getDestinationColumn();
    Table destination1Table = destination1Column.getTable();
    EntityModel destination1EntityModel = entityModels.get(destination1Table.getName());
    relationshipModel.setSourceEntity(destination1EntityModel);
    relationshipModel.setSourceConstraintName(constraint1.getName());
    relationshipModel.setSourceEntityRefName(source1Column.getName());

    Constraint constraint2 = constraints.get(0);
    Column source2Column = constraint2.getSourceColumn();
    Column destination2Column = constraint2.getDestinationColumn();
    Table destination2Table = destination2Column.getTable();
    EntityModel destination2EntityModel = entityModels.get(destination2Table.getName());
    relationshipModel.setTargetEntity(destination2EntityModel);
    relationshipModel.setTargetConstraintName(constraint2.getName());
    relationshipModel.setTargetEntityRefName(source2Column.getName());
    relationshipModel.setPath(destination1EntityModel.getLookup());
    relationshipModel//from w  ww .  j av  a  2 s  . co m
            .setLookup(destination1EntityModel.getLookup() + "." + StringUtils.normalize(relationshipName));
    relationshipModel.setRelationshipType(RelationshipType.ASSOCIATION);
    relationshipModel.setParent(destination1EntityModel);

    relationshipModel.setOnDeleteOption(convertToRelationshipOption(constraint2.getOnDelete()));
    relationshipModel.setOnUpdateOption(convertToRelationshipOption(constraint2.getOnUpdate()));

    relationshipModel.setDescription(
            "Relationship between tables: '" + destination1Table.getName() + " (" + destination1Column.getName()
                    + ")' and " + destination2Table.getName() + " (" + destination2Column.getName() + ")'");
    relationshipModel.setReverseEngineer(true);

    return relationshipModel;
}

From source file:net.dmulloy2.ultimatearena.arenas.Arena.java

private final void conclude() {
    // API - conclude event
    ArenaConcludeEvent event = new ArenaConcludeEvent(this);
    plugin.getServer().getPluginManager().callEvent(event);

    if (!disabled)
        this.gameMode = Mode.IDLE;

    plugin.removeActiveArena(this);
    plugin.broadcast(getMessage("concluded"), WordUtils.capitalize(name));

    plugin.getSignHandler().onArenaCompletion(this);
    plugin.getSignHandler().updateSigns(az);
}

From source file:canreg.client.gui.management.CanReg4MigrationInternalFrame.java

@Action
public void MigrationAction() {
    okButton.setEnabled(false);/*from   w ww  .ja  v a 2 s.  com*/
    doneButton.setEnabled(false);
    cancelButton.setEnabled(true);
    jList1.setEnabled(false);
    EditDatabaseVariableTableAssociationInternalFrame edvif = new EditDatabaseVariableTableAssociationInternalFrame();
    int addServer = JOptionPane.showInternalConfirmDialog(
            CanRegClientApp.getApplication().getMainFrame().getContentPane(),
            java.util.ResourceBundle
                    .getBundle("canreg/client/gui/management/resources/CanReg4SystemConverterInternalFrame")
                    .getString("SUCCESSFULLY_CREATED_XML: ") + "\'" + Globals.CANREG_SERVER_SYSTEM_CONFIG_FOLDER
                    + Globals.FILE_SEPARATOR + regcode + "\'.\n"
                    + java.util.ResourceBundle.getBundle(
                            "canreg/client/gui/management/resources/CanReg4SystemConverterInternalFrame")
                            .getString("ADD_IT_TO_FAV_SERVERS?"),
            "Success", JOptionPane.YES_NO_OPTION);
    if (addServer == JOptionPane.YES_OPTION) {
        localSettings = CanRegClientApp.getApplication().getLocalSettings();
        localSettings.addServerToServerList(dlm.get(list.getSelectedIndex()), "localhost", Globals.DEFAULT_PORT,
                regcode);
        localSettings.writeSettings();
    }
    try {
        edvif.setTitle("Variables and Tables for "
                + WordUtils.capitalize(dlm.get(list.getSelectedIndex()).toLowerCase()));
        edvif.loadSystemDefinition(
                Globals.CANREG_SERVER_SYSTEM_CONFIG_FOLDER + Globals.FILE_SEPARATOR + regcode + ".xml");
        edvif.setDesktopPane(desktopPane);
        CanRegClientView.showAndPositionInternalFrame(desktopPane, edvif);
    } catch (IOException ex) {
        Logger.getLogger(CanReg4SystemConverterInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ParserConfigurationException ex) {
        Logger.getLogger(CanReg4SystemConverterInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SAXException ex) {
        Logger.getLogger(CanReg4SystemConverterInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
    }

    edvif.saveButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            //logout from canreg system before conversion
            if (CanRegClientApp.getApplication().loggedIn) {
                try {
                    CanRegClientApp.getApplication().logOut();
                } catch (RemoteException ex) {
                    Logger.getLogger(CanReg4MigrationInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            //check to see if there is a database already - rename it
            File databaseFolder = new File(
                    Globals.CANREG_SERVER_DATABASE_FOLDER + Globals.FILE_SEPARATOR + regcode);
            if (databaseFolder.exists()) {
                int i = 0;
                File folder2 = databaseFolder;
                while (folder2.exists()) {
                    i++;
                    folder2 = new File(
                            Globals.CANREG_SERVER_DATABASE_FOLDER + Globals.FILE_SEPARATOR + regcode + i);
                }
                databaseFolder.renameTo(folder2);
                debugOut("database: " + databaseFolder);
                try {
                    canreg.common.Tools.fileCopy(
                            Globals.CANREG_SERVER_SYSTEM_CONFIG_FOLDER + Globals.FILE_SEPARATOR + regcode
                                    + ".xml",
                            Globals.CANREG_SERVER_SYSTEM_CONFIG_FOLDER + Globals.FILE_SEPARATOR + regcode + i
                                    + ".xml");
                } catch (IOException ex) {
                    Logger.getLogger(CanReg4MigrationInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            ProgressBar.setStringPainted(true);
            cTask = new ProgressTask(
                    org.jdesktop.application.Application.getInstance(canreg.client.CanRegClientApp.class));
            cTask.execute();
            cTask.addPropertyChangeListener(new PropertyChangeListener() {
                @Override
                public void propertyChange(PropertyChangeEvent evt) {
                    if ("progress".equals(evt.getPropertyName())) {
                        ProgressBar.setValue((Integer) evt.getNewValue());
                        ProgressBar.setString(evt.getNewValue().toString() + "%");
                    }
                }
            });
        }
    });
}

From source file:com.sfs.whichdoctor.dao.onlineapplication.BasicTrainingOnlineApplicationHandler.java

/**
 * Load the phone details from the XML application.
 *
 * @param root the root of the XML application
 * @param type the type// w  ww.  j av  a2s. com
 * @param guid the guid
 * @return the phone bean
 */
private PhoneBean loadPhoneDetails(final Element root, final String type, final int guid) {
    PhoneBean phone = new PhoneBean();

    Element pd = root.getChild("personaldetails");

    phone.setReferenceGUID(guid);

    if (StringUtils.equalsIgnoreCase(type, "work")) {
        phone = loadWorkPhoneDetails(root, phone);
    }
    if (StringUtils.equalsIgnoreCase(type, "workfax")) {
        phone = loadWorkFaxDetails(root, phone);
    }
    if (StringUtils.equalsIgnoreCase(type, "home")) {
        phone = loadHomePhoneDetails(root, phone);
    }
    if (StringUtils.equalsIgnoreCase(type, "homefax")) {
        phone = loadHomeFaxDetails(root, phone);
    }
    if (StringUtils.equalsIgnoreCase(type, "mobile")) {
        phone = loadMobilePhoneDetails(root, phone);
    }

    if (StringUtils.isNotBlank(phone.getNumber())) {
        // Load the country code for the phone number
        try {
            String ctry = WordUtils.capitalize(pd.getChildText("countryid")).trim();
            phone.setCountryCode(this.phoneDAO.getCountryCode(ctry));
        } catch (Exception e) {
            dataLogger.error("Error getting country code: " + e.getMessage());
        }
    } else {
        // The phone number is not valid, return null
        phone = null;
    }

    return phone;
}

From source file:com.ikanow.infinit.e.harvest.enrichment.legacy.alchemyapi.AlchemyEntityGeoCleanser.java

public boolean cleanseGeoInDocu(DocumentPojo doc) {

    boolean bChangedAnything = false;

    Map<String, Candidate> dubiousLocations = new HashMap<String, Candidate>();

    Set<String> otherRegions = new HashSet<String>();
    Set<String> otherCountries = new HashSet<String>();
    Set<String> otherCountriesOrRegionsReferenced = new HashSet<String>();

    //Debug//from w w w  .j av  a  2 s  .  c o  m
    if (_nDebugLevel >= 2) {
        System.out.println(
                "+++++++ Doc: " + doc.getTitle() + " / " + doc.getId() + " / " + doc.getEntities().size());
    }

    // 1] First off, let's find anything location-based and also determine if it's bad or not 

    if (null != doc.getEntities())
        for (EntityPojo ent : doc.getEntities()) {

            boolean bStrongCandidate = false;

            // People: decompose names
            if (EntityPojo.Dimension.Where == ent.getDimension()) {

                // So locations get disambiguated to one of:
                // "<city-etc>, <region-or-country>", or "<region-or-country>"
                // though can also just be left as they are.

                String sActualName = ent.getActual_name().toLowerCase();
                if (!ent.getDisambiguatedName().toLowerCase().equals(sActualName)) {
                    // It's been disambiguated

                    //Debug
                    if (_nDebugLevel >= 3) {
                        System.out.println("disambiguous candidate: " + ent.getDisambiguatedName() + " VS "
                                + ent.getActual_name() + " ("
                                + ((null != ent.getSemanticLinks()) ? ent.getSemanticLinks().size() : 0) + ")");
                    }

                    // OK next step, is it a disambiguation to a US town?
                    String splitMe[] = ent.getDisambiguatedName().split(", ");
                    if (2 == splitMe.length) {

                        String stateOrCountry = splitMe[1];
                        Matcher m = _statesRegex.matcher(stateOrCountry);
                        if (m.find()) { // This is a US disambiguation - high risk case
                            // Short cut if state is already directly mentioned?
                            stateOrCountry = stateOrCountry.toLowerCase();

                            if (!otherRegions.contains(stateOrCountry)) { // See list below - no need to go any further

                                // OK next step - is it a possible ambiguity:
                                ArrayList<BasicDBObject> x = new ArrayList<BasicDBObject>();
                                BasicDBObject inner0_0 = new BasicDBObject(MongoDbManager.not_,
                                        Pattern.compile("US"));
                                BasicDBObject inner1_0 = new BasicDBObject("country_code", inner0_0);
                                x.add(inner1_0);

                                BasicDBObject inner0_1 = new BasicDBObject(MongoDbManager.gte_, 400000);
                                BasicDBObject inner1_1 = new BasicDBObject("population", inner0_1);
                                x.add(inner1_1);

                                BasicDBObject dbo = new BasicDBObject();
                                dbo.append("search_field", sActualName);
                                dbo.append(MongoDbManager.or_, x);

                                DBCursor dbc = _georefDB.find(dbo);
                                if (dbc.size() >= 1) { // Problems!

                                    //Create list of candidates

                                    Type listType = new TypeToken<LinkedList<GeoFeaturePojo>>() {
                                    }.getType();
                                    LinkedList<GeoFeaturePojo> grpl = new Gson()
                                            .fromJson(dbc.toArray().toString(), listType);

                                    //Debug
                                    if (_nDebugLevel >= 2) {
                                        System.out.println("\tERROR CANDIDATE: " + ent.getDisambiguatedName()
                                                + " VS " + ent.getActual_name() + " (" + dbc.count() + ")");

                                        if (_nDebugLevel >= 3) {
                                            for (GeoFeaturePojo grp : grpl) {
                                                System.out.println("\t\tCandidate:" + grp.getCity() + " / "
                                                        + grp.getRegion() + " / " + grp.getCountry());
                                            }
                                        }
                                    }

                                    Candidate candidate = new Candidate(ent, grpl, stateOrCountry);
                                    dubiousLocations.put(ent.getIndex(), candidate);
                                    bStrongCandidate = true;

                                } // if strong candidate
                            } //TESTED ("reston, virginia" after "virginia/stateorcounty" mention)
                              // (end if can't shortcut past all this)

                        } // end if a US town
                    } // end if in the format "A, B"

                } // if weak candidate
                  //TESTED

                if (!bStrongCandidate) { // Obv can't count on a disambiguous candidate:               
                    String type = ent.getType().toLowerCase();

                    if (type.equals("stateorcounty")) {
                        String disName = ent.getDisambiguatedName().toLowerCase();
                        if (_abbrStateRegex.matcher(disName).matches()) {
                            otherRegions.add(getStateFromAbbr(disName));
                        } else {
                            otherRegions.add(ent.getDisambiguatedName().toLowerCase());
                        }
                        otherCountriesOrRegionsReferenced.add("united states");
                    } //TESTED: "mich./stateorcounty"
                    else if (type.equals("country")) {
                        String disName = ent.getDisambiguatedName().toLowerCase();

                        // Translation of known badly transcribed countries:
                        // (England->UK)
                        if (disName.equals("england")) {
                            otherCountries.add("united kingdom");
                        } //TESTED
                        else {
                            otherCountries.add(ent.getDisambiguatedName().toLowerCase());
                        }
                    } else if (type.equals("region")) {
                        otherRegions.add(ent.getDisambiguatedName().toLowerCase());
                    } else if (type.equals("city")) {
                        String splitMe[] = ent.getDisambiguatedName().split(",\\s*");
                        if (2 == splitMe.length) {
                            otherCountriesOrRegionsReferenced.add(splitMe[1].toLowerCase());
                            if (this._statesRegex.matcher(splitMe[1]).find()) {
                                otherCountriesOrRegionsReferenced.add("united states");
                            } //TESTED: "lexingon, kentucky/city"
                        }
                    }
                } //TESTED: just above clauses

            } // if location

        } // (end loop over entities)

    // Debug:
    if ((_nDebugLevel >= 3) && (!dubiousLocations.isEmpty())) {
        for (String s : otherRegions) {
            System.out.println("Strong region: " + s);
        }
        for (String s : otherCountries) {
            System.out.println("Strong countries: " + s);
        }
        for (String s : otherCountriesOrRegionsReferenced) {
            System.out.println("Weak regionscountries: " + s);
        }
    }

    // 2] The requirements and algorithm are discussed in 
    // http://ikanow.jira.com/wiki/display/INF/Beta...+improving+AlchemyAPI+extraction+%28geo%29
    // Canonical cases:
    // Darfur -> Darfur, MN even though Sudan and sometimes Darfur, Sudan are present
    // Shanghai -> Shanghai, WV even though China is mentioned (and not WV)
    // Manchester -> Manchester village, NY (not Manchester, UK)
    // Philadelphia -> Philadelphia (village), NY (though NY is mentioned and not PA) 

    // We're generating the following order
    //       10] Sitting tenant with strong direct
    //       15] Large city with strong direct      
    //       20] Region with direct
    //       30] Large city with strong indirect
    //       40] Sitting tenant with strong indirect 
    //       50] Region with indirect
    //       60] Another foreign possibility with strong direct 
    //       70] Large city with weak direct
    //       72] Large city with weak indirect
    //       75] Large city with no reference 
    //       78] Another foreign possibility with strong indirect (>100K population - ie not insignificant) 
    //       80] Sitting tenant with any weak (US) direct or indirect 
    //       90] Another foreign possibility with strong indirect 
    //      100] Another foreign possibility with weak direct 
    //      110] Another foreign possibility with weak indirect 
    //      120] Region with no reference, if there is only 1
    //      130] Sitting tenant with none of the above (ie default)
    //      140] Anything else!

    for (Map.Entry<String, Candidate> pair : dubiousLocations.entrySet()) {
        EntityPojo ent = pair.getValue().entity;
        Candidate candidate = pair.getValue();

        // 2.1] Let's analyse the "sitting tenant"

        int nPrio = 130;
        GeoFeaturePojo currLeader = null;
        int nCase = 0; // (just for debugging, 0=st, 1=large city, 2=region, 3=other)

        if (otherRegions.contains(candidate.state)) { // Strong direct ref, winner!
            nPrio = 10; // winner!
        } //TESTED: "san antonio, texas/city" vs "texas"
        else if (otherCountriesOrRegionsReferenced.contains(candidate.state)) {
            // Indirect ref
            nPrio = 40; // good, but beatable...
        } //TESTED: "philadelphia (village), new york/city" 
        else if (otherCountries.contains("united states")) { // Weak direct ref
            nPrio = 80; // better than nothing...            
        } //TESTED: "apache, oklahoma/city"
        else if (otherCountriesOrRegionsReferenced.contains("united states")) { // Weak indirect ref
            nPrio = 80; // better than nothing...            
        } //TESTED: "washington, d.c." have DC as stateorcounty, but US in countries list

        // Special case: we don't like "village":
        if ((80 != nPrio) && ent.getDisambiguatedName().contains("village")
                && !ent.getActual_name().contains("village")) {
            nPrio = 80;
        } //TESTED: "Downvoted: Philadelphia (village), New York from Philadelphia"

        // Debug
        if (_nDebugLevel >= 2) {
            System.out.println(pair.getKey() + " SittingTenantScore=" + nPrio);
        }

        // Alternatives
        if (nPrio > 10) {

            LinkedList<GeoFeaturePojo> geos = pair.getValue().candidates;
            for (GeoFeaturePojo geo : geos) {

                int nAltPrio = 140;
                int nAltCase = -1;
                String city = (null != geo.getCity()) ? geo.getCity().toLowerCase() : null;
                String region = (null != geo.getRegion()) ? geo.getRegion().toLowerCase() : null;
                String country = (null != geo.getCountry()) ? geo.getCountry().toLowerCase() : null;

                // 2.2] CASE 1: I'm a city with pop > 1M (best score 15)
                //                15] Large city with strong direct      
                //                30] Large city with strong indirect
                //                70] Large city with weak direct
                //                72] Large city with weak indirect
                //                75] Large city with no reference                

                if ((null != city) && (geo.getPopulation() >= 400000) && (nPrio > 15)) {
                    nAltCase = 1;

                    if ((null != region) && (otherRegions.contains(region))) {
                        nAltPrio = 15; // strong direct
                    } //TESTED: "dallas / Texas / United States = 15"
                    else if ((null != region) && (otherCountriesOrRegionsReferenced.contains(region))) {
                        nAltPrio = 30; // strong indirect
                    } //TESTED: "sacramento / California / United State"
                    else if ((null != country) && (otherCountries.contains(country))) {
                        nAltPrio = 70; // weak direct 
                    } //TESTED: "berlin, germany", with "germany" directly mentioned
                    else if ((null != country) && (otherCountriesOrRegionsReferenced.contains(country))) {
                        nAltPrio = 72; // weak indirect 
                    } //TESTED: "los angeles / California / United States = 72"
                    else {
                        nAltPrio = 75; // just for being big!
                    } //TESTED: "barcelona, spain"
                }

                // 2.3] CASE 2: I'm a region (best score=20, can beat current score)
                //                20] Region with direct
                //                50] Region with indirect
                //               120] Region with no reference, if there is only 1

                else if ((null == city) && (nPrio > 20)) {
                    nAltCase = 2;

                    if ((null != country) && (otherCountries.contains(country))) {
                        nAltPrio = 20; // strong direct 
                    } //TESTED: (region) "Berlin, Germany" with "Germany" mentioned
                    else if ((null != country) && (otherCountriesOrRegionsReferenced.contains(country))) {
                        nAltPrio = 50; // strong indirect 
                    } //(haven't seen, but we'll live)
                    else {
                        nAltPrio = 120; // (just for being there)
                    } //TESTED: "null / Portland / Jamaica = 120", also "Shanghai / China"
                }

                // 2.4] CASE 3: I'm any foreign possibility (best score=60)
                //                60] Another foreign possibility with strong direct 
                //                78] Another foreign possibility with strong indirect (>100K population - ie not insignificant) 
                //                90] Another foreign possibility with strong indirect 
                //               100] Another foreign possibility with weak direct 
                //               110] Another foreign possibility with weak indirect 

                else if (nPrio > 60) {
                    nAltCase = 3;

                    if ((null != region) && (otherRegions.contains(region))) {
                        nAltPrio = 60; // strong direct

                        // Double check we're not falling into the trap below:
                        if (!geo.getCountry_code().equals("US")) {
                            Matcher m = this._statesRegex.matcher(geo.getRegion());
                            if (m.matches()) { // non US state matching against (probably) US state, disregard)
                                nAltPrio = 140;
                            }
                        } //TESTED (same clause as below)

                    } //TESTED: lol "philadelphia / Maryland / Liberia = 60" (before above extra clause)

                    if (nAltPrio > 60) { // (may need to re-run test)
                        if ((null != country) && (otherCountries.contains(country))) {
                            if (geo.getPopulation() < 100000) {
                                nAltPrio = 90; // strong indirect
                            } //TESTED: "washington / Villa Clara / Cuba"
                            else {
                                nAltPrio = 78; // strong indirect, with boost!                        
                            } //TESTED: "geneva, Geneve, Switzerland", pop 180K
                        } else if ((null != region) && (otherCountriesOrRegionsReferenced.contains(region))) {
                            nAltPrio = 100; // weak direct
                        } //TESTED: "lincoln / Lincolnshire / United Kingdom = 100"
                        else if ((null != country) && (otherCountriesOrRegionsReferenced.contains(country))) {
                            nAltPrio = 110; // weak indirect
                        } //(haven't seen, but we'll live)                  
                    }
                }
                // Debug:
                if ((_nDebugLevel >= 2) && (nAltPrio < 140)) {
                    System.out.println("----Alternative: " + geo.getCity() + " / " + geo.getRegion() + " / "
                            + geo.getCountry() + " score=" + nAltPrio);
                }

                // Outcome of results:

                if (nAltPrio < nPrio) {
                    currLeader = geo;
                    nPrio = nAltPrio;
                    nCase = nAltCase;
                }
            } // end loop over alternativse

            if (null != currLeader) { // Need to change

                if (1 == nCase) {
                    this._nMovedToLargeCity++;

                    //(Cities are lower case in georef DB for some reason)
                    String city = WordUtils.capitalize(currLeader.getCity());

                    if (currLeader.getCountry_code().equals("US")) { // Special case: is this just the original?

                        String region = currLeader.getRegion();
                        if (region.equals("District of Columbia")) { // Special special case
                            region = "D.C.";
                        }
                        String sCandidate = city + ", " + region;

                        if (!sCandidate.equals(ent.getDisambiguatedName())) {
                            ent.setDisambiguatedName(sCandidate);
                            ent.setIndex(ent.getDisambiguatedName() + "/city");
                            ent.setSemanticLinks(null);
                            bChangedAnything = true;
                        } //TESTED (lots, eg "Philadelphia (village), New York" -> "Philadelphia, PA"; Wash, Ill. -> Wash DC)
                        else {
                            this._nMovedToLargeCity--;
                            _nStayedWithOriginal++;
                        } //TESTED ("Washington DC", "San Juan, Puerto Rico")
                    } //TESTED (see above)
                    else {
                        ent.setDisambiguatedName(city + ", " + currLeader.getCountry());
                        ent.setIndex(ent.getDisambiguatedName() + "/city");
                        ent.setSemanticLinks(null);
                        bChangedAnything = true;
                    } //TESTED: "london, california/city to London, United Kingdom"
                } else if (2 == nCase) {
                    this._nMovedToRegion++;
                    ent.setDisambiguatedName(currLeader.getRegion() + ", " + currLeader.getCountry());
                    ent.setIndex(ent.getDisambiguatedName() + "/region");
                    ent.setSemanticLinks(null);
                    bChangedAnything = true;

                } //TESTED: "Moved madrid, new york/city to Madrid, Spain" (treats Madrid as region, like Berlin see above)
                else {
                    //(Cities are lower case in georef DB for some reason)
                    String city = WordUtils.capitalize(currLeader.getCity());

                    this._nMovedToForeignCity++;
                    ent.setDisambiguatedName(city + ", " + currLeader.getCountry());
                    ent.setIndex(ent.getDisambiguatedName() + "/city");
                    ent.setSemanticLinks(null);
                    bChangedAnything = true;

                } //TESTED: "Moved geneva, new york/city to Geneva, Switzerland"

                if ((_nDebugLevel >= 1) && (null == ent.getSemanticLinks())) {
                    System.out.println("++++ Moved " + pair.getKey() + " to " + ent.getDisambiguatedName());
                }
            } else {
                _nStayedWithOriginal++;
            }

        } // (if sitting tenant not holder)

    } // (end loop over candidates)      

    if ((_nDebugLevel >= 1) && bChangedAnything) {
        System.out.println("\t(((Doc: " + doc.getTitle() + " / " + doc.getId() + " / " + doc.getUrl() + ")))");
    }

    return bChangedAnything;
}

From source file:net.firejack.platform.core.config.meta.construct.ConfigElementFactory.java

/**
 * @param element/* w ww. j a  v a 2s .c  o  m*/
 */
public void normalizeName(IPackageDescriptorElement element) {
    if (true) {
        return;
    }
    if (element instanceof INameProvider) {
        INameProvider namedElement = (INameProvider) element;
        String name = namedElement.getName();
        if (element instanceof IPackageDescriptor || element instanceof IDomainElement
                || element instanceof ActionElement || element instanceof FolderElement
                || element instanceof NavigationConfigElement) {
            name = StringUtils.changeWhiteSpacesWithSymbol(name, "-");
            namedElement.setName(name.toLowerCase());
        } else if (element instanceof IEntityElement || element instanceof IRelationshipElement) {
            name = WordUtils.capitalize(name);
            namedElement.setName(name);
        } else if (element instanceof DirectoryElement) {
            namedElement.setName(name.toLowerCase());
        } else if (element instanceof IFieldElement) {
            name = StringUtils.changeWhiteSpacesWithSymbol(name, "_");
            namedElement.setName(name);
        }
    }
}

From source file:net.firejack.platform.core.config.meta.construct.ConfigElementFactory.java

private RelationshipConfigElement populateRelationship(String name, String hint, RelationshipType relType,
        Reference source, Reference target, IFieldElement... fields) {
    name = WordUtils.capitalize(name);
    RelationshipConfigElement rel = new RelationshipConfigElement(name);
    //checkElementName(rel);
    normalizeName(rel);/*w ww . j a v  a  2s  . c om*/
    rel.setHint(hint);
    rel.setType(relType);
    rel.setSource(source);
    rel.setTarget(target);
    if (fields.length != 0) {
        List<IFieldElement> fieldList = new ArrayList<IFieldElement>();
        Collections.addAll(fieldList, fields);
        rel.setFields(fieldList);
    }
    return rel;
}