|
Apache CXF example source code file (NameUtil.java)
The Apache CXF NameUtil.java source code/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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 org.apache.cxf.tools.util; import java.util.ArrayList; import java.util.List; import org.apache.cxf.helpers.JavaUtils; public final class NameUtil { static final int UPPER_LETTER = 0; static final int LOWER_LETTER = 1; static final int OTHER_LETTER = 2; static final int DIGIT = 3; static final int OTHER = 4; private static final byte ACTION_CHECK_PUNCT = 0; private static final byte ACTION_CHECK_C2 = 1; private static final byte ACTION_BREAK = 2; private static final byte ACTION_NOBREAK = 3; private static final byte[] ACTION_TABLE = new byte[5 * 5]; private NameUtil() { } static { for (int t0 = 0; t0 < 5; t0++) { for (int t1 = 0; t1 < 5; t1++) { ACTION_TABLE[t0 * 5 + t1] = decideAction(t0, t1); } } } protected static boolean isPunct(char c) { boolean isPunct = c == '-' || c == '.' || c == ':' || c == '_'; boolean isUnicodePunct = c == '\u00b7' || c == '\u0387' || c == '\u06dd' || c == '\u06de'; return isPunct || isUnicodePunct; } protected static boolean isLower(char c) { return c >= 'a' && c <= 'z' || Character.isLowerCase(c); } public static String capitalize(String s) { if (!isLower(s.charAt(0))) { return s; } StringBuilder sb = new StringBuilder(s.length()); sb.append(Character.toUpperCase(s.charAt(0))); sb.append(s.substring(1).toLowerCase()); return sb.toString(); } private static int nextBreak(String s, int start) { int n = s.length(); char c1 = s.charAt(start); int t1 = classify(c1); for (int i = start + 1; i < n; i++) { int t0 = t1; c1 = s.charAt(i); t1 = classify(c1); switch (ACTION_TABLE[t0 * 5 + t1]) { case ACTION_CHECK_PUNCT: if (isPunct(c1)) { return i; } break; case ACTION_CHECK_C2: if (i < n - 1) { char c2 = s.charAt(i + 1); if (isLower(c2)) { return i; } } break; case ACTION_BREAK: return i; default: } } return -1; } private static byte decideAction(int t0, int t1) { if (t0 == OTHER && t1 == OTHER) { return ACTION_CHECK_PUNCT; } if (!xor(t0 == DIGIT, t1 == DIGIT) || (t0 == LOWER_LETTER && t1 != LOWER_LETTER)) { return ACTION_BREAK; } if (!xor(t0 <= OTHER_LETTER, t1 <= OTHER_LETTER)) { return ACTION_BREAK; } if (!xor(t0 == OTHER_LETTER, t1 == OTHER_LETTER)) { return ACTION_BREAK; } if (t0 == UPPER_LETTER && t1 == UPPER_LETTER) { return ACTION_CHECK_C2; } return ACTION_NOBREAK; } private static boolean xor(boolean x, boolean y) { return (x && y) || (!x && !y); } protected static int classify(char c0) { switch (Character.getType(c0)) { case Character.UPPERCASE_LETTER: return UPPER_LETTER; case Character.LOWERCASE_LETTER: return LOWER_LETTER; case Character.TITLECASE_LETTER: case Character.MODIFIER_LETTER: case Character.OTHER_LETTER: return OTHER_LETTER; case Character.DECIMAL_DIGIT_NUMBER: return DIGIT; default: return OTHER; } } public static List<String> toWordList(String s) { List<String> ss = new ArrayList Other Apache CXF examples (source code examples)Here is a short list of links related to this Apache CXF NameUtil.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.