Java String Clean cleanStringCamelCase(String in)

Here you can find the source of cleanStringCamelCase(String in)

Description

clean String Camel Case

License

Open Source License

Declaration

public static String cleanStringCamelCase(String in) 

Method Source Code

//package com.java2s;
// "{ configData : { idDataset : \"primoID\", \"tenant\" : \"iotnet\", \"collection\" : \"provaAle\", \"database\": \"db\", \"type\" : \"dataset\", \"subtype\" : \"bulkDataset\", \"entityNameSpace\" : \"it.csi.smartdata.odata.iotnet.iotnetapi002\", \"datasetversion\" : \"1.0.0\", \"current\" : 1, \"archive\" : { \"archiveCollection\" : \"altraCollection\", \"archiveDatabase\": \"altroDB\",  \"archiveInfo\": [ { \"archiveRevision\": 1, \"archiveDate\" : null }, { \"archiveRevision\": 2, \"archiveDate\" : null } ]    }          }, \"metadata\" : { \"name\" : \"primodato\", \"description\" : \"Descrizione\", \"license\" : \"CC BY 4.0\", \"disclaimer\" : null, \"copyright\" : \"Copyright (C) 2014, CSP Innovazione nelle ICT. All rights reserved.\", \"visibility\" : \"public\", \"registrationDate\" : null, \"requestorName\" : \"nomeRichiedente\", \"requestorSurname\" : \"cognomeRichiedente\", \"dataDomain\" : \"ENVIRONMENT\", \"requestornEmail\" : \"ciao@email.it\", \"fps\" : 22,  \"startIngestionDate\" : null, \"endIngestionDate\" : null, \"importFileType\" : \"CSV\", \"datasetStatus\": \"Ok\",  \"tags\" : [{ \"tagCode\" : \"AIR\" }, { \"tagCode\" : \"INDOOR\" }, { \"tagCode\" : \"POLLUTION\" }, { \"tagCode\" : \"QUALITY\" } ], \"fields\" : [{ \"fieldName\" : \"campo_1\", \"fieldAlias\" : \"semantica campo 1\", \"dataType\" : \"int\", \"sourceColumn\" : \"1\", \"isKey\" : 0, \"measureUnit\" : \"ppm\" }, { \"fieldName\" : \"campo_2\", \"fieldAlias\" : \"semantica campo 2\", \"dataType\" : \"string\", \"sourceColumn\" : \"2\", \"isKey\" : 0, \"measureUnit\" : \"metri\" } ] } }";

public class Main {
    public static String cleanStringCamelCase(String in) {
        String out = "";
        if (in != null) {
            in = in.replaceAll("[-]", " ").replaceAll("[.]", " ").replaceAll("[/]", " ");
            String[] words = in.split(" ");
            for (String word : words) {
                out += toProperCase(cleanString(word));
            }/*from w  ww . jav  a 2 s  .co  m*/
        }

        return out;
    }

    public static String cleanStringCamelCase(String in, int length) {
        return safeSubstring(cleanStringCamelCase(in), length);
    }

    static String toProperCase(String in) {
        if (in != null && in.length() > 1)
            return in.substring(0, 1).toUpperCase() + in.substring(1).toLowerCase();
        else if (in != null)
            return in.toUpperCase();
        return "";

    }

    public static String cleanString(String in) {
        if (in != null)
            return in.replaceAll(" ", "").replaceAll("[^\\w\\s]", "");

        return "";
    }

    public static String safeSubstring(String in, int length) {
        String out = in;
        if (in != null && in.length() > length)
            out = in.substring(0, length);

        return out == null ? "" : out;
    }
}

Related

  1. cleanString(String input, char ol, char ne)
  2. cleanString(String statement)
  3. cleanString(String unallowableCharacters, String stringToClean)
  4. cleanStringArrayChar(String value)
  5. cleanStringByLikeWithHSQL(String input)
  6. cleanStringForFilename(String originalString)
  7. cleanStringForFilePath(final String dirty)
  8. cleanStringForJavaName(String original)
  9. cleanStringFromWhitespaces(String text)