Skip to content

Commit

Permalink
Retranslate Java.
Browse files Browse the repository at this point in the history
  • Loading branch information
shunter committed Jan 4, 2017
1 parent 3048f23 commit aa226a3
Show file tree
Hide file tree
Showing 30 changed files with 805 additions and 411 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,43 @@ public static String toString(int value, String format, Locale locale) {
return FormatHelper.buildFormat(locale, format).format(value);
}

/**
* Converts the string representation of a number to its 32-bit signed integer
* equivalent.
*
* @param s
* A string containing a number to convert.
* @return A 32-bit signed integer equivalent to the number contained in s.
*/
public static int parse(String s) {
return parse(s, defaultNumberStyle, null);
}

/**
* Converts the string representation of a number in a specified style and
* culture-specific format to its 32-bit signed integer equivalent.
*
* @param s
* A string containing a number to convert.
* @param style
* A bitwise combination of the enumeration values that indicates the style
* elements that can be present in s. A typical value to specify is
* Integer.
* @param locale
* An object that supplies culture-specific formatting information about s.
* @return A 32-bit signed integer equivalent to the number contained in s.
*/
public static int parse(String s, NumberStyles style, Locale locale) {
if (locale == null)
locale = CultureInfoHelper.getCurrentCulture();

int[] out_result = new int[1];
if (tryParse(s, style, locale, out_result))
return out_result[0];

throw new NumberFormatException("Input string was not in a correct format.");
}

/**
* Converts the string representation of a number to its 32-bit signed integer
* equivalent. A return value indicates whether the operation succeeded.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package agi.foundation.compatibility;

import java.text.DecimalFormatSymbols;
import java.util.Locale;

/**
* Defines how numeric values are formatted and displayed, depending on the culture.
*/
public final class NumberFormatInfo {
private final DecimalFormatSymbols decimalFormatSymbols;

/**
* Returns the NumberFormatInfo associated with the specified Locale.
*/
public static NumberFormatInfo getInstance(Locale locale) {
if (locale == null)
locale = CultureInfoHelper.getCurrentCulture();
return new NumberFormatInfo(locale, DecimalFormatSymbols.getInstance(locale));
}

/**
* Gets the default read-only NumberFormatInfo that is culture-independent
* (invariant).
*/
public static NumberFormatInfo getInvariantInfo() {
return getInstance(CultureInfoHelper.getInvariantCulture());
}

private NumberFormatInfo(Locale locale, DecimalFormatSymbols decimalFormatSymbols) {
this.decimalFormatSymbols = decimalFormatSymbols;
}

/**
* Gets the string to use as the decimal separator in numeric values.
*/
public String getNumberDecimalSeparator() {
return String.valueOf(decimalFormatSymbols.getDecimalSeparator());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;
import java.util.Scanner;
import java.util.regex.MatchResult;
Expand Down Expand Up @@ -92,6 +93,22 @@ private enum PaddingType {

private StringHelper() {}

/**
* Initializes a new instance of the String class to the value indicated by a
* specified Unicode character repeated a specified number of times.
*
* @param c
* A Unicode character.
* @param count
* The number of times c occurs.
* @return the new String.
*/
public static String create(char c, int count) {
char[] array = new char[count];
Arrays.fill(array, c);
return new String(array);
}

/**
* Indicates whether the specified string is null or an Empty string.
*
Expand Down Expand Up @@ -182,40 +199,6 @@ public static String[] split(String string, char[] separator, int count, StringS
return split(string, regex, options, count);
}

/**
* Returns a string array that contains the substrings in this string that are
* delimited by elements of a specified string array. Parameters specify the maximum
* number of substrings to return and whether to return empty array elements.
*
* @param string
* the String to split.
* @param separator
* An array of strings that delimit the substrings in this string, an empty
* array that contains no delimiters, or null.
* @param count
* The maximum number of substrings to return.
* @param options
* Specify <code>RemoveEmptyEntries</code> to omit empty array elements
* from the array returned, or <code>None</code> to include empty array
* elements in the array returned.
* @return An array whose elements contain the substrings in this string that are
* delimited by one or more strings in separator.
*/
public static String[] split(String string, String[] separator, int count, StringSplitOptions options) {
String regex = null;
if (separator != null && separator.length > 0) {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < separator.length; i++) {
builder.append(separator[i]);
if (i < separator.length - 1)
builder.append("|");
}
regex = builder.toString();
}

return split(string, regex, options, count);
}

/**
* Do the work of splitting the string according to the specified regex and options.
*/
Expand Down Expand Up @@ -283,6 +266,35 @@ private static String[] split(String string, String regex, StringSplitOptions op
return result.toArray(new String[result.size()]);
}

/**
* Deletes a specified number of characters from this instance beginning at a
* specified position.
*
* @param str
* The string.
* @param startIndex
* The zero-based position to begin deleting characters.
* @param count
* The number of characters to delete.
* @return A new string that is equivalent to this string except for the removed
* characters.
*/
public static String remove(String str, int startIndex, int count) {
if (startIndex < 0)
throw new ArgumentOutOfRangeException("startIndex", "startIndex cannot be less than zero.");
if (count < 0)
throw new ArgumentOutOfRangeException("count", "count cannot be less than zero.");

int strLength = str.length();
if (startIndex > strLength - count)
throw new ArgumentOutOfRangeException("startIndex", "startIndex must be less than length of string minus count.");

StringBuilder result = new StringBuilder(strLength - count);
result.append(str.substring(0, startIndex));
result.append(str.substring(startIndex + count));
return result.toString();
}

/**
* Returns a new string that right-aligns the characters in this instance by padding
* them on the left with a specified Unicode character, for a specified total length.
Expand All @@ -303,6 +315,26 @@ public static String padLeft(String str, int totalWidth, char paddingChar) {
return pad(str, totalWidth, paddingChar, PaddingType.LEFT);
}

/**
* Returns a new string that left-aligns the characters in this string by padding them
* on the right with a specified Unicode character, for a specified total length.
*
* @param str
* The string.
* @param totalWidth
* The number of characters in the resulting string, equal to the number of
* original characters plus any additional padding characters.
* @param paddingChar
* A Unicode padding character.
* @return A new string that is equivalent to this instance, but left-aligned and
* padded on the right with as many paddingChar characters as needed to create
* a length of totalWidth. Or, if totalWidth is less than the length of this
* instance, a new string that is identical to this instance.
*/
public static String padRight(String str, int totalWidth, char paddingChar) {
return pad(str, totalWidth, paddingChar, PaddingType.RIGHT);
}

private static String pad(String str, int totalWidth, char paddingChar, PaddingType paddingType) {
if (totalWidth < 0)
throw new ArgumentOutOfRangeException("totalWidth", "Non-negative number required.");
Expand Down Expand Up @@ -691,6 +723,31 @@ private static boolean isAsciiDigit(char c) {
}
}

/**
* Reports the index of the first occurrence of the specified string in the current
* String object. A parameter specifies the type of search to use for the specified
* string.
*
* @param string
* @param value
* The String object to seek.
* @param comparisonType
* One of the StringComparison values.
* @return The index position of the value parameter if that string is found, or -1 if
* it is not. If value is Empty, the return value is 0.
*/
public static int indexOf(String string, String value, StringComparison comparisonType) {
if (getIgnoreCase(comparisonType)) {
Locale locale = getLocale(comparisonType);

String stringLowerCase = string.toLowerCase(locale);
String valueLowerCase = value.toLowerCase(locale);
return stringLowerCase.indexOf(valueLowerCase);
} else {
return string.indexOf(value);
}
}

/**
* Returns a copy of this String object converted to lowercase using the casing rules
* of the invariant culture.
Expand Down Expand Up @@ -720,6 +777,60 @@ public static boolean startsWith(String str, String value) {
return str.startsWith(value);
}

/**
* Retrieves a substring from this instance. The substring starts at a specified
* character position.
*
* @param str
* The string.
* @param startIndex
* The zero-based starting character position of a substring in this
* instance.
* @return A string that is equivalent to the substring that begins at startIndex in
* this instance, or Empty if startIndex is equal to the length of this
* instance.
*/
public static String substring(String str, int startIndex) {
return substring(str, startIndex, str.length() - startIndex);
}

/**
* Retrieves a substring from this instance. The substring starts at a specified
* character position and has a specified length.
*
* @param str
* The string.
* @param startIndex
* The zero-based starting character position of a substring in this
* instance.
* @param length
* The number of characters in the substring.
* @return A string that is equivalent to the substring of length length that begins
* at startIndex in this instance, or Empty if startIndex is equal to the
* length of this instance and length is zero.
*/
public static String substring(String str, int startIndex, int length) {
if (startIndex < 0)
throw new ArgumentOutOfRangeException("startIndex", "startIndex cannot be less than zero.");

int strLen = str.length();
if (startIndex > strLen)
throw new ArgumentOutOfRangeException("startIndex", "startIndex cannot be larger than length of string.");

if (length < 0)
throw new ArgumentOutOfRangeException("length", "Length cannot be less than zero.");

int endIndex = startIndex + length;
if (endIndex > strLen) {
throw new ArgumentOutOfRangeException("length", "Index and length must refer to a location within the string.");
}

if (length == 0)
return "";

return str.substring(startIndex, endIndex);
}

/**
* Returns a new string in which all occurrences of a specified string in the current
* instance are replaced with another specified string.
Expand Down Expand Up @@ -769,6 +880,24 @@ public static String trimStart(String str, char... trimChars) {
return str.substring(index);
}

/**
* Appends a copy of a specified substring to the given StringBuilder object.
*
* @param builder
* The StringBuilder.
* @param value
* The string that contains the substring to append.
* @param startIndex
* The starting position of the substring within value.
* @param count
* The number of characters in value to append.
* @return A reference to the StringBuilder object after the append operation has
* completed.
*/
public static StringBuilder append(StringBuilder builder, String value, int startIndex, int count) {
return builder.append(value, startIndex, startIndex + count);
}

private static boolean arrayContains(char[] array, char charToFind) {
for (char c : array) {
if (c == charToFind)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public enum CesiumVerticalOrigin implements Enumeration {
*/
BOTTOM(0), /**
*
The item is vertically centered at the position.
The item is at the vertical center between {@link #Baseline} and {@link #Top}.
*/
Expand All @@ -29,7 +29,13 @@ public enum CesiumVerticalOrigin implements Enumeration {
*/
TOP(2);
TOP(2), /**
*
If the object contains text, the origin is at the baseline of the text, otherwise the origin is at the bottom of the object.
*/
BASELINE(3);
private final int value;

CesiumVerticalOrigin(int value) {
Expand Down Expand Up @@ -57,6 +63,8 @@ public static CesiumVerticalOrigin getFromValue(int value) {
return CENTER;
case 2:
return TOP;
case 3:
return BASELINE;
default:
throw new IllegalArgumentException("Undefined enum value.");
}
Expand Down
Loading

0 comments on commit aa226a3

Please sign in to comment.