Java Code Examples for org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation#getCharFromSizeOneString()
The following examples show how to use
org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation#getCharFromSizeOneString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ObjectArrayPutAtMetaMethod.java From groovy with Apache License 2.0 | 6 votes |
private static Object adjustNewValue(Object[] objects, Object newValue) { Class arrayComponentClass = objects.getClass().getComponentType(); Object adjustedNewVal = newValue; if (newValue instanceof Number) { if (!arrayComponentClass.equals(newValue.getClass())) { adjustedNewVal = DefaultTypeTransformation.castToType(newValue, arrayComponentClass); } } else if (Character.class.isAssignableFrom(arrayComponentClass)) { adjustedNewVal = DefaultTypeTransformation.getCharFromSizeOneString(newValue); } else if (Number.class.isAssignableFrom(arrayComponentClass)) { if (newValue instanceof Character || newValue instanceof String || newValue instanceof GString) { Character ch = DefaultTypeTransformation.getCharFromSizeOneString(newValue); adjustedNewVal = DefaultTypeTransformation.castToType(ch, arrayComponentClass); } } else if (arrayComponentClass.isArray()) { adjustedNewVal = DefaultTypeTransformation.castToType(newValue, arrayComponentClass); } return adjustedNewVal; }
Example 2
Source File: LongArrayPutAtMetaMethod.java From groovy with Apache License 2.0 | 5 votes |
public Object invoke(Object object, Object[] args) { final long[] objects = (long[]) object; final int index = normaliseIndex((Integer) args[0], objects.length); Object newValue = args[1]; if (!(newValue instanceof Long)) { if (newValue instanceof Character || newValue instanceof String || newValue instanceof GString) { Character ch = DefaultTypeTransformation.getCharFromSizeOneString(newValue); objects[index] = (Long) DefaultTypeTransformation.castToType(ch, Long.class); } else { objects[index] = ((Number) newValue).longValue(); } } else objects[index] = (Long) args[1]; return null; }
Example 3
Source File: IntegerArrayPutAtMetaMethod.java From groovy with Apache License 2.0 | 5 votes |
public Object invoke(Object object, Object[] args) { final int[] objects = (int[]) object; final int index = normaliseIndex((Integer) args[0], objects.length); Object newValue = args[1]; if (!(newValue instanceof Integer)) { if (newValue instanceof Character || newValue instanceof String || newValue instanceof GString) { Character ch = DefaultTypeTransformation.getCharFromSizeOneString(newValue); objects[index] = (Integer) DefaultTypeTransformation.castToType(ch, Integer.class); } else { objects[index] = ((Number) newValue).intValue(); } } else objects[index] = (Integer) args[1]; return null; }
Example 4
Source File: ShortArrayPutAtMetaMethod.java From groovy with Apache License 2.0 | 5 votes |
public Object invoke(Object object, Object[] args) { final short[] objects = (short[]) object; final int index = normaliseIndex((Integer) args[0], objects.length); Object newValue = args[1]; if (!(newValue instanceof Short)) { if (newValue instanceof Character || newValue instanceof String || newValue instanceof GString) { Character ch = DefaultTypeTransformation.getCharFromSizeOneString(newValue); objects[index] = (Short) DefaultTypeTransformation.castToType(ch, Short.class); } else { objects[index] = ((Number) newValue).shortValue(); } } else objects[index] = (Short) args[1]; return null; }
Example 5
Source File: FloatArrayPutAtMetaMethod.java From groovy with Apache License 2.0 | 5 votes |
public Object invoke(Object object, Object[] args) { final float[] objects = (float[]) object; final int index = normaliseIndex((Integer) args[0], objects.length); Object newValue = args[1]; if (!(newValue instanceof Float)) { if (newValue instanceof Character || newValue instanceof String || newValue instanceof GString) { Character ch = DefaultTypeTransformation.getCharFromSizeOneString(newValue); objects[index] = (Float) DefaultTypeTransformation.castToType(ch, Float.class); } else { objects[index] = ((Number) newValue).floatValue(); } } else objects[index] = (Float) args[1]; return null; }
Example 6
Source File: DoubleArrayPutAtMetaMethod.java From groovy with Apache License 2.0 | 5 votes |
public Object invoke(Object object, Object[] args) { final double[] objects = (double[]) object; final int index = normaliseIndex((Integer) args[0], objects.length); Object newValue = args[1]; if (!(newValue instanceof Double)) { if (newValue instanceof Character || newValue instanceof String || newValue instanceof GString) { Character ch = DefaultTypeTransformation.getCharFromSizeOneString(newValue); objects[index] = (Double) DefaultTypeTransformation.castToType(ch, Double.class); } else { objects[index] = ((Number) newValue).doubleValue(); } } else objects[index] = (Double) args[1]; return null; }
Example 7
Source File: CharacterArrayPutAtMetaMethod.java From groovy with Apache License 2.0 | 4 votes |
public Object invoke(Object object, Object[] args) { final char[] objects = (char[]) object; final int index = normaliseIndex((Integer) args[0], objects.length); objects[index] = DefaultTypeTransformation.getCharFromSizeOneString(args[1]); return null; }