Repository: commons-text Updated Branches: refs/heads/master a6690773e -> 6bbe66feb
Fixing checkstyle errors Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/6bbe66fe Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/6bbe66fe Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/6bbe66fe Branch: refs/heads/master Commit: 6bbe66feb6d8dc69a0464085dd4117e6e23aa389 Parents: a669077 Author: Bruno P. Kinoshita <[email protected]> Authored: Tue Nov 8 21:40:18 2016 +1300 Committer: Bruno P. Kinoshita <[email protected]> Committed: Tue Nov 8 21:40:18 2016 +1300 ---------------------------------------------------------------------- .../apache/commons/text/AlphabetConverter.java | 51 +++++++++++++++----- .../commons/text/names/HumanNameParser.java | 22 ++++++--- .../org/apache/commons/text/names/Name.java | 50 +++++++++++++++---- .../org/apache/commons/text/package-info.java | 22 +++++++++ 4 files changed, 114 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-text/blob/6bbe66fe/src/main/java/org/apache/commons/text/AlphabetConverter.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/text/AlphabetConverter.java b/src/main/java/org/apache/commons/text/AlphabetConverter.java index 5fc3528..db3d2a8 100644 --- a/src/main/java/org/apache/commons/text/AlphabetConverter.java +++ b/src/main/java/org/apache/commons/text/AlphabetConverter.java @@ -64,14 +64,27 @@ import java.util.Set; * * @since 0.1 */ -public class AlphabetConverter { +public final class AlphabetConverter { + /** + * Original string to be encoded. + */ private final Map<Integer, String> originalToEncoded; + /** + * Encoding alphabet. + */ private final Map<String, String> encodedToOriginal; - + /** + * Length of the encoded letter. + */ private final int encodedLetterLength; - + /** + * Arrow constant, used for converting the object into a string. + */ private static final String ARROW = " -> "; + /** + * Line separator, used for converting the object into a string. + */ private static final String LINE_SEPARATOR = System.getProperty("line.separator"); /** @@ -123,7 +136,7 @@ public class AlphabetConverter { } /** - * Decodes a given string + * Decode a given string. * * @param encoded a string that has been encoded using this AlphabetConverter * @return the decoded string, {@code null} if the given string is null @@ -175,7 +188,7 @@ public class AlphabetConverter { /** * Get the mapping from integer code point of source language to encoded string. Use to reconstruct converter from - * serialized map + * serialized map. * * @return the original map */ @@ -184,7 +197,13 @@ public class AlphabetConverter { } /** - * Recursive method used when creating encoder/decoder + * Recursive method used when creating encoder/decoder. + * + * @param level at which point it should add a single encoding + * @param currentEncoding current encoding + * @param encoding letters encoding + * @param originals original values + * @param doNotEncodeMap map of values that should not be encoded */ private void addSingleEncoding(int level, String currentEncoding, Collection<Integer> encoding, Iterator<Integer> originals, Map<Integer, String> doNotEncodeMap) { @@ -245,7 +264,7 @@ public class AlphabetConverter { if (obj == this) { return true; } - if (obj instanceof AlphabetConverter == false) { + if (!(obj instanceof AlphabetConverter)) { return false; } final AlphabetConverter other = (AlphabetConverter) obj; @@ -294,8 +313,8 @@ public class AlphabetConverter { /** * Create an alphabet converter, for converting from the original alphabet, to the encoded alphabet, while leaving * the characters in <em>doNotEncode</em> as they are (if possible). - * - * Duplicate letters in either original or encoding will be ignored. + * + * <p>Duplicate letters in either original or encoding will be ignored.</p> * * @param original an array of chars representing the original alphabet * @param encoding an array of chars representing the alphabet to be used for encoding @@ -310,6 +329,12 @@ public class AlphabetConverter { convertCharsToIntegers(doNotEncode)); } + /** + * Convert characters to integers. + * + * @param chars array of characters + * @return an equivalent array of integers + */ private static Integer[] convertCharsToIntegers(Character[] chars) { if (chars == null || chars.length == 0) { return new Integer[0]; @@ -323,9 +348,9 @@ public class AlphabetConverter { /** * Create an alphabet converter, for converting from the original alphabet, to the encoded alphabet, while leaving - * the characters in <em>doNotEncode</em> as they are (if possible) - * - * Duplicate letters in either original or encoding will be ignored + * the characters in <em>doNotEncode</em> as they are (if possible). + * + * <p>Duplicate letters in either original or encoding will be ignored.</p> * * @param original an array of ints representing the original alphabet in codepoints * @param encoding an array of ints representing the alphabet to be used for encoding, in codepoints @@ -391,7 +416,7 @@ public class AlphabetConverter { } else if (encodingCopy.size() - doNotEncodeCopy.size() < 2) { throw new IllegalArgumentException( - "Must have at least two encoding characters (not counting those in the 'do not encode' list), but has " + "Must have at least two encoding characters (excluding those in the 'do not encode' list), but has " + (encodingCopy.size() - doNotEncodeCopy.size())); } else { // we start with one which is our minimum, and because we do the http://git-wip-us.apache.org/repos/asf/commons-text/blob/6bbe66fe/src/main/java/org/apache/commons/text/names/HumanNameParser.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/text/names/HumanNameParser.java b/src/main/java/org/apache/commons/text/names/HumanNameParser.java index d713e9f..f97f162 100644 --- a/src/main/java/org/apache/commons/text/names/HumanNameParser.java +++ b/src/main/java/org/apache/commons/text/names/HumanNameParser.java @@ -27,7 +27,7 @@ import org.apache.commons.lang3.StringUtils; * A parser capable of parsing name parts out of a single string. * * <h3>Parsing examples</h3> - * + * * <p>The code works by basically applying several Regexes in a certain order * and removing (chopping) tokens off the original string. The parser creates * a {@link Name} object representing the parse result. Note that passing null @@ -73,25 +73,25 @@ import org.apache.commons.lang3.StringUtils; * </table> * * <h3>Sample usage</h3> - * + * * <p>HumanNameParser instances are immutable and can be reused for parsing multiple names:</p> - * + * * <pre> * HumanNameParser parser = new HumanNameParser(); * Name parsedName = parser.parse("S�rgio Vieira de Mello") * String firstName = parsedName.getFirstName(); * String nickname = parsedName.getNickName(); * // ... - * + * * Name nextName = parser.parse("James C. ('Jimmy') O'Dell, Jr.") * String firstName = nextName.getFirstName(); * String nickname = nextName.getNickName(); * </pre> * * <h3>Further notes</h3> - * + * * <p>The original code was written in <a href="http://jasonpriem.com/human-name-parse">PHP</a> - * and ported to <a href="http://tupilabs.github.io/HumanNameParser.java/">Java</a>. This + * and ported to <a href="http://tupilabs.github.io/HumanNameParser.java/">Java</a>. This * implementation is based on the Java implementation, with additions * suggested in <a href="https://issues.apache.org/jira/browse/TEXT-15">TEXT-15</a> * and <a href="https://issues.apache.org/jira/browse/TEXT-16">TEXT-16</a>.</p> @@ -100,7 +100,13 @@ import org.apache.commons.lang3.StringUtils; */ public final class HumanNameParser { + /** + * List of suffixes. Not exposed to users or children classes. + */ private final List<String> suffixes; + /** + * List of prefixes. Not exposed to users or children classes. + */ private final List<String> prefixes; /** @@ -115,7 +121,7 @@ public final class HumanNameParser { "bar", "ben", "bin", "da", "dal", "de la", "de", "del", "der", "di", "ibn", "la", "le", "san", "st", "ste", "van", "van der", "van den", "vel", - "von" ); + "von"); } /** @@ -168,7 +174,7 @@ public final class HumanNameParser { // if anything's left, that's the middle name String middle = nameString.getWrappedString(); - + return new Name(leadingInit, first, nickname, middle, last, suffix); } http://git-wip-us.apache.org/repos/asf/commons-text/blob/6bbe66fe/src/main/java/org/apache/commons/text/names/Name.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/text/names/Name.java b/src/main/java/org/apache/commons/text/names/Name.java index 7e32de4..fefefd5 100644 --- a/src/main/java/org/apache/commons/text/names/Name.java +++ b/src/main/java/org/apache/commons/text/names/Name.java @@ -25,13 +25,41 @@ import java.util.Objects; */ public final class Name { + /** + * Leading initial. e.g. <em>F.</em>, as in <em>Francisco ('Chico') Silva Zhao II</em>. + */ private final String leadingInitial; + /** + * The first name, e.g. <em>Francisco</em>, as in <em>Francisco ('Chico') Silva Zhao II</em>. + */ private final String firstName; + /** + * The nickname, e.g. <em>Chico</em>, as in <em>Francisco ('Chico') Silva Zhao II</em>. + */ private final String nickName; + /** + * The middle name, e.g. <em>Silva</em>, as in <em>Francisco ('Chico') Silva Zhao II</em>. + */ private final String middleName; + /** + * The last name, e.g. <em>Zhao</em>, as in <em>Francisco ('Chico') Silva Zhao II</em>. + */ private final String lastName; + /** + * The suffix, e.g. <em>II</em>, as in <em>Francisco ('Chico') Silva Zhao II</em>. + */ private final String suffix; + /** + * Create a Name. + * + * @param leadingInitial the leading initial + * @param firstName the first name + * @param nickName the nickname + * @param middleName the middle name + * @param lastName the last name + * @param suffix a suffix + */ Name(String leadingInitial, String firstName, String nickName, String middleName, String lastName, String suffix) { this.leadingInitial = leadingInitial; this.firstName = firstName; @@ -41,8 +69,6 @@ public final class Name { this.suffix = suffix; } - // TODO Add an example to each getter - /** * Gets the leading init part of the name. * @@ -99,15 +125,19 @@ public final class Name { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } Name name = (Name) o; - return Objects.equals(leadingInitial, name.leadingInitial) && - Objects.equals(firstName, name.firstName) && - Objects.equals(nickName, name.nickName) && - Objects.equals(middleName, name.middleName) && - Objects.equals(lastName, name.lastName) && - Objects.equals(suffix, name.suffix); + return Objects.equals(leadingInitial, name.leadingInitial) + && Objects.equals(firstName, name.firstName) + && Objects.equals(nickName, name.nickName) + && Objects.equals(middleName, name.middleName) + && Objects.equals(lastName, name.lastName) + && Objects.equals(suffix, name.suffix); } @Override http://git-wip-us.apache.org/repos/asf/commons-text/blob/6bbe66fe/src/main/java/org/apache/commons/text/package-info.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/text/package-info.java b/src/main/java/org/apache/commons/text/package-info.java new file mode 100644 index 0000000..f36b6dc --- /dev/null +++ b/src/main/java/org/apache/commons/text/package-info.java @@ -0,0 +1,22 @@ +/* + * 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. + */ +/** + * <p>Basic classes for text handling.</p> + * + * @since 1.0 + */ +package org.apache.commons.text;
