com.iofairy.string.CaseConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of functional Show documentation
Show all versions of functional Show documentation
Functional Programming for Java 8+ and compatible with the modular system of Java 9+.
/*
* Copyright (C) 2021 iofairy,
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.iofairy.string;
import static com.iofairy.string.StringCase.*;
/**
* CaseConverter
*
* @since 0.3.0
*/
public enum CaseConverter implements StringConverter {
/**
* {@link StringCase#LOWER_SPACE} to {@link StringCase#UPPER_SPACE}
e.g. lower space to UPPER SPACE
*/
LS_US(LOWER_SPACE, UPPER_SPACE),
/**
* {@link StringCase#LOWER_SPACE} to {@link StringCase#LOWER_HYPHEN}
e.g. lower space to lower-hyphen
*/
LS_LH(LOWER_SPACE, LOWER_HYPHEN),
/**
* {@link StringCase#LOWER_SPACE} to {@link StringCase#UPPER_HYPHEN}
e.g. lower space to UPPER-HYPHEN
*/
LS_UH(LOWER_SPACE, UPPER_HYPHEN),
/**
* {@link StringCase#LOWER_SPACE} to {@link StringCase#LOWER_UNDERSCORE}
e.g. lower space to lower_underscore
*/
LS_LU(LOWER_SPACE, LOWER_UNDERSCORE),
/**
* {@link StringCase#LOWER_SPACE} to {@link StringCase#UPPER_UNDERSCORE}
e.g. lower space to UPPER_UNDERSCORE
*/
LS_UU(LOWER_SPACE, UPPER_UNDERSCORE),
/**
* {@link StringCase#LOWER_SPACE} to {@link StringCase#LOWER_CAMEL}
e.g. lower space to lowerCamel
*/
LS_LC(LOWER_SPACE, LOWER_CAMEL),
/**
* {@link StringCase#LOWER_SPACE} to {@link StringCase#UPPER_CAMEL}
e.g. lower space to UpperCamel
*/
LS_UC(LOWER_SPACE, UPPER_CAMEL),
/**
* {@link StringCase#UPPER_SPACE} to {@link StringCase#LOWER_HYPHEN}
e.g. UPPER SPACE to lower-hyphen
*/
US_LH(UPPER_SPACE, LOWER_HYPHEN),
/**
* {@link StringCase#UPPER_SPACE} to {@link StringCase#UPPER_HYPHEN}
e.g. UPPER SPACE to UPPER-HYPHEN
*/
US_UH(UPPER_SPACE, UPPER_HYPHEN),
/**
* {@link StringCase#UPPER_SPACE} to {@link StringCase#LOWER_UNDERSCORE}
e.g. UPPER SPACE to lower_underscore
*/
US_LU(UPPER_SPACE, LOWER_UNDERSCORE),
/**
* {@link StringCase#UPPER_SPACE} to {@link StringCase#UPPER_UNDERSCORE}
e.g. UPPER SPACE to UPPER_UNDERSCORE
*/
US_UU(UPPER_SPACE, UPPER_UNDERSCORE),
/**
* {@link StringCase#UPPER_SPACE} to {@link StringCase#LOWER_CAMEL}
e.g. UPPER SPACE to lowerCamel
*/
US_LC(UPPER_SPACE, LOWER_CAMEL),
/**
* {@link StringCase#UPPER_SPACE} to {@link StringCase#UPPER_CAMEL}
e.g. UPPER SPACE to UpperCamel
*/
US_UC(UPPER_SPACE, UPPER_CAMEL),
/**
* {@link StringCase#LOWER_HYPHEN} to {@link StringCase#UPPER_HYPHEN}
e.g. lower-hyphen to UPPER-HYPHEN
*/
LH_UH(LOWER_HYPHEN, UPPER_HYPHEN),
/**
* {@link StringCase#LOWER_HYPHEN} to {@link StringCase#LOWER_UNDERSCORE}
e.g. lower-hyphen to lower_underscore
*/
LH_LU(LOWER_HYPHEN, LOWER_UNDERSCORE),
/**
* {@link StringCase#LOWER_HYPHEN} to {@link StringCase#UPPER_UNDERSCORE}
e.g. lower-hyphen to UPPER_UNDERSCORE
*/
LH_UU(LOWER_HYPHEN, UPPER_UNDERSCORE),
/**
* {@link StringCase#LOWER_HYPHEN} to {@link StringCase#LOWER_CAMEL}
e.g. lower-hyphen to lowerCamel
*/
LH_LC(LOWER_HYPHEN, LOWER_CAMEL),
/**
* {@link StringCase#LOWER_HYPHEN} to {@link StringCase#UPPER_CAMEL}
e.g. lower-hyphen to UpperCamel
*/
LH_UC(LOWER_HYPHEN, UPPER_CAMEL),
/**
* {@link StringCase#UPPER_HYPHEN} to {@link StringCase#LOWER_UNDERSCORE}
e.g. UPPER-HYPHEN to lower_underscore
*/
UH_LU(UPPER_HYPHEN, LOWER_UNDERSCORE),
/**
* {@link StringCase#UPPER_HYPHEN} to {@link StringCase#UPPER_UNDERSCORE}
e.g. UPPER-HYPHEN to UPPER_UNDERSCORE
*/
UH_UU(UPPER_HYPHEN, UPPER_UNDERSCORE),
/**
* {@link StringCase#UPPER_HYPHEN} to {@link StringCase#LOWER_CAMEL}
e.g. UPPER-HYPHEN to lowerCamel
*/
UH_LC(UPPER_HYPHEN, LOWER_CAMEL),
/**
* {@link StringCase#UPPER_HYPHEN} to {@link StringCase#UPPER_CAMEL}
e.g. UPPER-HYPHEN to UpperCamel
*/
UH_UC(UPPER_HYPHEN, UPPER_CAMEL),
/**
* {@link StringCase#LOWER_UNDERSCORE} to {@link StringCase#UPPER_UNDERSCORE}
e.g. lower_underscore to UPPER_UNDERSCORE
*/
LU_UU(LOWER_UNDERSCORE, UPPER_UNDERSCORE),
/**
* {@link StringCase#LOWER_UNDERSCORE} to {@link StringCase#LOWER_CAMEL}
e.g. lower_underscore to lowerCamel
*/
LU_LC(LOWER_UNDERSCORE, LOWER_CAMEL),
/**
* {@link StringCase#LOWER_UNDERSCORE} to {@link StringCase#UPPER_CAMEL}
e.g. lower_underscore to UpperCamel
*/
LU_UC(LOWER_UNDERSCORE, UPPER_CAMEL),
/**
* {@link StringCase#UPPER_UNDERSCORE} to {@link StringCase#LOWER_CAMEL}
e.g. UPPER_UNDERSCORE to lowerCamel
*/
UU_LC(UPPER_UNDERSCORE, LOWER_CAMEL),
/**
* {@link StringCase#UPPER_UNDERSCORE} to {@link StringCase#UPPER_CAMEL}
e.g. UPPER_UNDERSCORE to UpperCamel
*/
UU_UC(UPPER_UNDERSCORE, UPPER_CAMEL),
/**
* {@link StringCase#LOWER_CAMEL} to {@link StringCase#UPPER_CAMEL}
e.g. lowerCamel to UpperCamel
*/
LC_UC(LOWER_CAMEL, UPPER_CAMEL),
/**
* {@link StringCase#UPPER_CAMEL} to {@link StringCase#LOWER_CAMEL}
e.g. UpperCamel to lowerCamel
*/
UC_LC(UPPER_CAMEL, LOWER_CAMEL),
/**
* {@link StringCase#UPPER_CAMEL} to {@link StringCase#UPPER_UNDERSCORE}
e.g. UpperCamel to UPPER_UNDERSCORE
*/
UC_UU(UPPER_CAMEL, UPPER_UNDERSCORE),
/**
* {@link StringCase#UPPER_CAMEL} to {@link StringCase#LOWER_UNDERSCORE}
e.g. UpperCamel to lower_underscore
*/
UC_LU(UPPER_CAMEL, LOWER_UNDERSCORE),
/**
* {@link StringCase#UPPER_CAMEL} to {@link StringCase#UPPER_HYPHEN}
e.g. UpperCamel to UPPER-HYPHEN
*/
UC_UH(UPPER_CAMEL, UPPER_HYPHEN),
/**
* {@link StringCase#UPPER_CAMEL} to {@link StringCase#LOWER_HYPHEN}
e.g. UpperCamel to lower-hyphen
*/
UC_LH(UPPER_CAMEL, LOWER_HYPHEN),
/**
* {@link StringCase#UPPER_CAMEL} to {@link StringCase#UPPER_SPACE}
e.g. UpperCamel to UPPER SPACE
*/
UC_US(UPPER_CAMEL, UPPER_SPACE),
/**
* {@link StringCase#UPPER_CAMEL} to {@link StringCase#LOWER_SPACE}
e.g. UpperCamel to lower space
*/
UC_LS(UPPER_CAMEL, LOWER_SPACE),
/**
* {@link StringCase#LOWER_CAMEL} to {@link StringCase#UPPER_UNDERSCORE}
e.g. lowerCamel to UPPER_UNDERSCORE
*/
LC_UU(LOWER_CAMEL, UPPER_UNDERSCORE),
/**
* {@link StringCase#LOWER_CAMEL} to {@link StringCase#LOWER_UNDERSCORE}
e.g. lowerCamel to lower_underscore
*/
LC_LU(LOWER_CAMEL, LOWER_UNDERSCORE),
/**
* {@link StringCase#LOWER_CAMEL} to {@link StringCase#UPPER_HYPHEN}
e.g. lowerCamel to UPPER-HYPHEN
*/
LC_UH(LOWER_CAMEL, UPPER_HYPHEN),
/**
* {@link StringCase#LOWER_CAMEL} to {@link StringCase#LOWER_HYPHEN}
e.g. lowerCamel to lower-hyphen
*/
LC_LH(LOWER_CAMEL, LOWER_HYPHEN),
/**
* {@link StringCase#LOWER_CAMEL} to {@link StringCase#UPPER_SPACE}
e.g. lowerCamel to UPPER SPACE
*/
LC_US(LOWER_CAMEL, UPPER_SPACE),
/**
* {@link StringCase#LOWER_CAMEL} to {@link StringCase#LOWER_SPACE}
e.g. lowerCamel to lower space
*/
LC_LS(LOWER_CAMEL, LOWER_SPACE),
/**
* {@link StringCase#UPPER_UNDERSCORE} to {@link StringCase#LOWER_UNDERSCORE}
e.g. UPPER_UNDERSCORE to lower_underscore
*/
UU_LU(UPPER_UNDERSCORE, LOWER_UNDERSCORE),
/**
* {@link StringCase#UPPER_UNDERSCORE} to {@link StringCase#UPPER_HYPHEN}
e.g. UPPER_UNDERSCORE to UPPER-HYPHEN
*/
UU_UH(UPPER_UNDERSCORE, UPPER_HYPHEN),
/**
* {@link StringCase#UPPER_UNDERSCORE} to {@link StringCase#LOWER_HYPHEN}
e.g. UPPER_UNDERSCORE to lower-hyphen
*/
UU_LH(UPPER_UNDERSCORE, LOWER_HYPHEN),
/**
* {@link StringCase#UPPER_UNDERSCORE} to {@link StringCase#UPPER_SPACE}
e.g. UPPER_UNDERSCORE to UPPER SPACE
*/
UU_US(UPPER_UNDERSCORE, UPPER_SPACE),
/**
* {@link StringCase#UPPER_UNDERSCORE} to {@link StringCase#LOWER_SPACE}
e.g. UPPER_UNDERSCORE to lower space
*/
UU_LS(UPPER_UNDERSCORE, LOWER_SPACE),
/**
* {@link StringCase#LOWER_UNDERSCORE} to {@link StringCase#UPPER_HYPHEN}
e.g. lower_underscore to UPPER-HYPHEN
*/
LU_UH(LOWER_UNDERSCORE, UPPER_HYPHEN),
/**
* {@link StringCase#LOWER_UNDERSCORE} to {@link StringCase#LOWER_HYPHEN}
e.g. lower_underscore to lower-hyphen
*/
LU_LH(LOWER_UNDERSCORE, LOWER_HYPHEN),
/**
* {@link StringCase#LOWER_UNDERSCORE} to {@link StringCase#UPPER_SPACE}
e.g. lower_underscore to UPPER SPACE
*/
LU_US(LOWER_UNDERSCORE, UPPER_SPACE),
/**
* {@link StringCase#LOWER_UNDERSCORE} to {@link StringCase#LOWER_SPACE}
e.g. lower_underscore to lower space
*/
LU_LS(LOWER_UNDERSCORE, LOWER_SPACE),
/**
* {@link StringCase#UPPER_HYPHEN} to {@link StringCase#LOWER_HYPHEN}
e.g. UPPER-HYPHEN to lower-hyphen
*/
UH_LH(UPPER_HYPHEN, LOWER_HYPHEN),
/**
* {@link StringCase#UPPER_HYPHEN} to {@link StringCase#UPPER_SPACE}
e.g. UPPER-HYPHEN to UPPER SPACE
*/
UH_US(UPPER_HYPHEN, UPPER_SPACE),
/**
* {@link StringCase#UPPER_HYPHEN} to {@link StringCase#LOWER_SPACE}
e.g. UPPER-HYPHEN to lower space
*/
UH_LS(UPPER_HYPHEN, LOWER_SPACE),
/**
* {@link StringCase#LOWER_HYPHEN} to {@link StringCase#UPPER_SPACE}
e.g. lower-hyphen to UPPER SPACE
*/
LH_US(LOWER_HYPHEN, UPPER_SPACE),
/**
* {@link StringCase#LOWER_HYPHEN} to {@link StringCase#LOWER_SPACE}
e.g. lower-hyphen to lower space
*/
LH_LS(LOWER_HYPHEN, LOWER_SPACE),
/**
* {@link StringCase#UPPER_SPACE} to {@link StringCase#LOWER_SPACE}
e.g. UPPER SPACE to lower space
*/
US_LS(UPPER_SPACE, LOWER_SPACE),
/**
* {@link StringCase#ALL_SEPARATORS} to {@link StringCase#UPPER_CAMEL}
*/
AS_UC(ALL_SEPARATORS, UPPER_CAMEL),
/**
* {@link StringCase#ALL_SEPARATORS} to {@link StringCase#LOWER_CAMEL}
*/
AS_LC(ALL_SEPARATORS, LOWER_CAMEL),
/**
* {@link StringCase#ALL_SEPARATORS} to {@link StringCase#UPPER_UNDERSCORE}
*/
AS_UU(ALL_SEPARATORS, UPPER_UNDERSCORE),
/**
* {@link StringCase#ALL_SEPARATORS} to {@link StringCase#LOWER_UNDERSCORE}
*/
AS_LU(ALL_SEPARATORS, LOWER_UNDERSCORE),
/**
* {@link StringCase#ALL_SEPARATORS} to {@link StringCase#UPPER_SPACE}
*/
AS_US(ALL_SEPARATORS, UPPER_SPACE),
/**
* {@link StringCase#ALL_SEPARATORS} to {@link StringCase#LOWER_SPACE}
*/
AS_LS(ALL_SEPARATORS, LOWER_SPACE),
/**
* {@link StringCase#ALL_SEPARATORS} to {@link StringCase#UPPER_HYPHEN}
*/
AS_UH(ALL_SEPARATORS, UPPER_HYPHEN),
/**
* {@link StringCase#ALL_SEPARATORS} to {@link StringCase#LOWER_HYPHEN}
*/
AS_LH(ALL_SEPARATORS, LOWER_HYPHEN);
/*=======================================================*/
public final StringCase fromCase;
public final StringCase toCase;
CaseConverter(StringCase fromCase, StringCase toCase) {
this.fromCase = fromCase;
this.toCase = toCase;
}
@Override
public String convert(String inputStr) {
return fromCase.to(toCase, inputStr);
}
}