'How to change UnicodeCategory in java?

I'm trying to migrate this C# code to Java.

Is there any possibility to migrate the unicodeCategory to a regex in Java, or is there a possibility to do the Unicode category by Java directly?

foreach (var currentChar in preNormalizedString)
{
    var unicodeCategory = CharUnicodeInfo.GetUnicodeCategory(currentChar);

    //https://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k(System.Globalization.UnicodeCategory.LowercaseLetter);k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.6);k(DevLang-csharp)&rd=true
    switch (unicodeCategory)
    {
        //case UnicodeCategory.NonSpacingMark:
        //case UnicodeCategory.SpacingCombiningMark:
        //case UnicodeCategory.EnclosingMark:
        case UnicodeCategory.DashPunctuation:
        case UnicodeCategory.ConnectorPunctuation:
        case UnicodeCategory.OpenPunctuation:
        case UnicodeCategory.ClosePunctuation:
        case UnicodeCategory.OtherPunctuation:
        case UnicodeCategory.LineSeparator:
        case UnicodeCategory.MathSymbol:
        case UnicodeCategory.ModifierSymbol:
        case UnicodeCategory.OtherSymbol:
        case UnicodeCategory.SpaceSeparator:
        case UnicodeCategory.ParagraphSeparator:
            if (!isPreviousSpaceChar)
                builder.Append(" ");
            isPreviousSpaceChar = true;
            break;

        case UnicodeCategory.Control:
        case UnicodeCategory.CurrencySymbol:
        case UnicodeCategory.EnclosingMark:
        case UnicodeCategory.NonSpacingMark:
        case UnicodeCategory.SpacingCombiningMark:
        case UnicodeCategory.InitialQuotePunctuation:
        case UnicodeCategory.FinalQuotePunctuation:
        case UnicodeCategory.Format:
        case UnicodeCategory.ModifierLetter:
        case UnicodeCategory.OtherNotAssigned:
        case UnicodeCategory.PrivateUse:
        case UnicodeCategory.Surrogate:
            // Caratères ignorés.
            break;

        case UnicodeCategory.LowercaseLetter:
        case UnicodeCategory.UppercaseLetter:
        case UnicodeCategory.LetterNumber:
        case UnicodeCategory.DecimalDigitNumber:
        case UnicodeCategory.OtherLetter:
        case UnicodeCategory.OtherNumber:
        case UnicodeCategory.TitlecaseLetter:
        default:
            builder.Append(currentChar);
            isPreviousSpaceChar = false;
            break;
    }
}

var normalizedString = builder.ToString() ?? string.Empty;
normalizedString = normalizedString.ToUpper();
normalizedString = normalizedString.Trim();
return normalizedString;


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source