List of usage examples for java.lang Character charValue
@HotSpotIntrinsicCandidate public char charValue()
From source file:org.evosuite.regression.ObjectFields.java
private static char getElementaryValue(Character p) { return p.charValue(); }
From source file:CharUtils.java
/** * <p>Converts the Character to a char handling <code>null</code>.</p> * //from ww w . j a v a 2s .co m * <pre> * CharUtils.toChar(null, 'X') = 'X' * CharUtils.toChar(' ', 'X') = ' ' * CharUtils.toChar('A', 'X') = 'A' * </pre> * * @param ch the character to convert * @param defaultValue the value to use if the Character is null * @return the char value of the Character or the default if null */ public static char toChar(Character ch, char defaultValue) { if (ch == null) { return defaultValue; } return ch.charValue(); }
From source file:CharUtils.java
/** * <p>Converts the Character to a char throwing an exception for <code>null</code>.</p> * /* www . java 2s . c o m*/ * <pre> * CharUtils.toChar(null) = IllegalArgumentException * CharUtils.toChar(' ') = ' ' * CharUtils.toChar('A') = 'A' * </pre> * * @param ch the character to convert * @return the char value of the Character * @throws IllegalArgumentException if the Character is null */ public static char toChar(Character ch) { if (ch == null) { throw new IllegalArgumentException("The Character must not be null"); } return ch.charValue(); }
From source file:org.protorabbit.model.impl.DefaultEngine.java
static IParameter getParameter(String text, Character lastToken) { Object value = null;/*w w w . j a v a2s . c om*/ text = text.trim(); int type = -1; if (lastToken != null && lastToken.charValue() == '\"') { type = IParameter.STRING; // set the value to not include the quotes value = text.substring(1, text.length() - 1); } else if ("true".equals(text) || "false".equals(text)) { type = IParameter.BOOLEAN; value = new Boolean(("true".equals(text))); } else if ("null".equals(text)) { type = IParameter.NULL; } else if (text.startsWith("{") && text.endsWith("}")) { try { value = new JSONObject(text); type = IParameter.OBJECT; } catch (JSONException e) { throw new RuntimeException("Error parsing JSON parameter " + text); } } else if (text.startsWith("[") && text.endsWith("]")) { try { value = new JSONArray(text); type = IParameter.ARRAY; } catch (JSONException e) { throw new RuntimeException("Error parsing JSON parameter " + text); } } else { try { NumberFormat nf = NumberFormat.getInstance(); value = nf.parse(text); type = IParameter.NUMBER; } catch (ParseException pe) { // do nothing } } if (type != -1) { return new Parameter(type, value); } else { throw new RuntimeException("Error parsing parameter " + text); } }
From source file:fr.landel.utils.commons.ObjectUtils.java
/** * Get the primitive value of an {@link Character}. If {@code value} is not * {@code null}, returns the primitive value of {@code value} otherwise returns * {@code defaultValue}/*from w ww .j a v a2 s.c om*/ * * <pre> * Character space = new Character((char) 32); * char value1 = ObjectUtils.toPrimitive(space, '_'); // => value1 = ' ' * char value2 = ObjectUtils.toPrimitive((Character) null, '_'); // => value2 = '_' * </pre> * * @param value * the {@link Character} value * @param defaultValue * the default value * @return a primitive char */ public static char toPrimitive(final Character value, final char defaultValue) { if (value == null) { return defaultValue; } else { return value.charValue(); } }
From source file:net.minecraftforge.common.crafting.CraftingHelper.java
public static ShapedPrimer parseShaped(Object... recipe) { ShapedPrimer ret = new ShapedPrimer(); String shape = ""; int idx = 0;//from w w w . j a v a 2 s. co m if (recipe[idx] instanceof Boolean) { ret.mirrored = (Boolean) recipe[idx]; if (recipe[idx + 1] instanceof Object[]) recipe = (Object[]) recipe[idx + 1]; else idx = 1; } if (recipe[idx] instanceof String[]) { String[] parts = ((String[]) recipe[idx++]); for (String s : parts) { ret.width = s.length(); shape += s; } ret.height = parts.length; } else { while (recipe[idx] instanceof String) { String s = (String) recipe[idx++]; shape += s; ret.width = s.length(); ret.height++; } } if (ret.width * ret.height != shape.length() || shape.length() == 0) { String err = "Invalid shaped recipe: "; for (Object tmp : recipe) { err += tmp + ", "; } throw new RuntimeException(err); } HashMap<Character, Ingredient> itemMap = Maps.newHashMap(); itemMap.put(' ', Ingredient.EMPTY); for (; idx < recipe.length; idx += 2) { Character chr = (Character) recipe[idx]; Object in = recipe[idx + 1]; Ingredient ing = CraftingHelper.getIngredient(in); if (' ' == chr.charValue()) throw new JsonSyntaxException("Invalid key entry: ' ' is a reserved symbol."); if (ing != null) { itemMap.put(chr, ing); } else { String err = "Invalid shaped ore recipe: "; for (Object tmp : recipe) { err += tmp + ", "; } throw new RuntimeException(err); } } ret.input = NonNullList.withSize(ret.width * ret.height, Ingredient.EMPTY); Set<Character> keys = Sets.newHashSet(itemMap.keySet()); keys.remove(' '); int x = 0; for (char chr : shape.toCharArray()) { Ingredient ing = itemMap.get(chr); if (ing == null) throw new IllegalArgumentException( "Pattern references symbol '" + chr + "' but it's not defined in the key"); ret.input.set(x++, ing); keys.remove(chr); } if (!keys.isEmpty()) throw new IllegalArgumentException("Key defines symbols that aren't used in pattern: " + keys); return ret; }
From source file:com.link_intersystems.lang.reflect.MethodInvokingTransformerTest.java
@Test public void invokeMethod() { String testString = "HelloWorld"; Transformer transformer = new MethodInvokingTransformer(charAtMethod, argumentResolver); Object transform = transformer.transform(testString); assertNotNull(transform);//from w w w . j av a 2 s. co m assertTrue(transform instanceof Character); Character charAt1 = (Character) transform; assertEquals('e', charAt1.charValue()); }
From source file:org.jboss.tools.openshift.internal.ui.validator.GitReferenceValidator.java
@Override public IStatus validate(Object value) { if (!(value instanceof String)) { return ValidationStatus.OK_STATUS; }//from w w w. j a v a 2s . c om String ref = (String) value; if (StringUtils.isBlank(ref)) { return ValidationStatus.OK_STATUS; } //Rule 2 (Reference must contain at least one /) is waived as one level is allowed. //Applying rules 3, 4, 5, 6.b, 8,10 for (int i = 0; i < ref.length(); i++) { char c = ref.charAt(i); Integer rule = charactersToExclusionRule.get(c); if (rule != null) { return ValidationStatus.error("Reference cannot contain character '" + c + "'"); } Character next = twoCharacterSequences.get(c); if (next != null && i + 1 < ref.length() && next.charValue() == ref.charAt(i + 1)) { return ValidationStatus.error("Reference cannot contain sequence '" + c + next + "'"); } } //Rule 6.a. Reference cannot begin or end with a slash / if (ref.startsWith("/") || ref.endsWith("/")) { return ValidationStatus.error("Reference cannot begin or end with '/'"); } //Rule 7. Reference cannot end with a dot if (ref.endsWith(".")) { return ValidationStatus.error("Reference cannot end with a dot"); } //Rule 9. Reference cannot be a single character '@' if (ref.equals("@")) { return ValidationStatus.error("Reference cannot be a single character '@'"); } //Rule 1. Reference or its slash-separated component cannot begin with a dot or end with the sequence .lock for (String part : ref.split("/")) { if (part.startsWith(".")) { return ValidationStatus.error("Reference or its slash-separated component cannot start with a dot"); } else if (part.endsWith(".lock")) { return ValidationStatus.error("Reference or its slash-separated component cannot end with '.lock'"); } } return ValidationStatus.OK_STATUS; }
From source file:org.culturegraph.mf.util.tries.CharMap.java
@Override public V put(final Character key, final V value) { put(key.charValue(), value); return null; }
From source file:org.culturegraph.mf.util.tries.CharMap.java
@Override public V get(final Object key) { if (key instanceof Character) { final Character beite = (Character) key; return get(beite.charValue()); }//from w w w. java 2 s.c om return null; }