List of usage examples for java.lang Character valueOf
@HotSpotIntrinsicCandidate public static Character valueOf(char c)
From source file:org.apache.pig.Main.java
static int run(String args[], PigProgressNotificationListener listener) { DateTime startTime = new DateTime(); int rc = 1;//w w w . ja v a 2 s. c o m boolean verbose = false; boolean gruntCalled = false; boolean deleteTempFiles = true; String logFileName = null; boolean printScriptRunTime = true; PigContext pigContext = null; try { Configuration conf = new Configuration(false); GenericOptionsParser parser = new GenericOptionsParser(conf, args); conf = parser.getConfiguration(); Properties properties = new Properties(); PropertiesUtil.loadDefaultProperties(properties); properties.putAll(ConfigurationUtil.toProperties(conf)); if (listener == null) { listener = makeListener(properties); } String[] pigArgs = parser.getRemainingArgs(); boolean userSpecifiedLog = false; boolean checkScriptOnly = false; BufferedReader pin = null; boolean debug = false; boolean dryrun = false; boolean embedded = false; List<String> params = new ArrayList<String>(); List<String> paramFiles = new ArrayList<String>(); HashSet<String> disabledOptimizerRules = new HashSet<String>(); CmdLineParser opts = new CmdLineParser(pigArgs); opts.registerOpt('4', "log4jconf", CmdLineParser.ValueExpected.REQUIRED); opts.registerOpt('b', "brief", CmdLineParser.ValueExpected.NOT_ACCEPTED); opts.registerOpt('c', "check", CmdLineParser.ValueExpected.NOT_ACCEPTED); opts.registerOpt('d', "debug", CmdLineParser.ValueExpected.REQUIRED); opts.registerOpt('e', "execute", CmdLineParser.ValueExpected.NOT_ACCEPTED); opts.registerOpt('f', "file", CmdLineParser.ValueExpected.REQUIRED); opts.registerOpt('g', "embedded", CmdLineParser.ValueExpected.REQUIRED); opts.registerOpt('h', "help", CmdLineParser.ValueExpected.OPTIONAL); opts.registerOpt('i', "version", CmdLineParser.ValueExpected.OPTIONAL); opts.registerOpt('l', "logfile", CmdLineParser.ValueExpected.REQUIRED); opts.registerOpt('m', "param_file", CmdLineParser.ValueExpected.OPTIONAL); opts.registerOpt('p', "param", CmdLineParser.ValueExpected.OPTIONAL); opts.registerOpt('r', "dryrun", CmdLineParser.ValueExpected.NOT_ACCEPTED); opts.registerOpt('t', "optimizer_off", CmdLineParser.ValueExpected.REQUIRED); opts.registerOpt('v', "verbose", CmdLineParser.ValueExpected.NOT_ACCEPTED); opts.registerOpt('w', "warning", CmdLineParser.ValueExpected.NOT_ACCEPTED); opts.registerOpt('x', "exectype", CmdLineParser.ValueExpected.REQUIRED); opts.registerOpt('F', "stop_on_failure", CmdLineParser.ValueExpected.NOT_ACCEPTED); opts.registerOpt('M', "no_multiquery", CmdLineParser.ValueExpected.NOT_ACCEPTED); opts.registerOpt('N', "no_fetch", CmdLineParser.ValueExpected.NOT_ACCEPTED); opts.registerOpt('P', "propertyFile", CmdLineParser.ValueExpected.REQUIRED); ExecMode mode = ExecMode.UNKNOWN; String file = null; String engine = null; // set up client side system properties in UDF context UDFContext.getUDFContext().setClientSystemProps(properties); char opt; while ((opt = opts.getNextOpt()) != CmdLineParser.EndOfOpts) { switch (opt) { case '4': String log4jconf = opts.getValStr(); if (log4jconf != null) { properties.setProperty(LOG4J_CONF, log4jconf); } break; case 'b': properties.setProperty(BRIEF, "true"); break; case 'c': checkScriptOnly = true; break; case 'd': String logLevel = opts.getValStr(); if (logLevel != null) { properties.setProperty(DEBUG, logLevel); } debug = true; break; case 'e': mode = ExecMode.STRING; break; case 'f': mode = ExecMode.FILE; file = opts.getValStr(); break; case 'g': embedded = true; engine = opts.getValStr(); break; case 'F': properties.setProperty("stop.on.failure", "" + true); break; case 'h': String topic = opts.getValStr(); if (topic != null) if (topic.equalsIgnoreCase("properties")) printProperties(); else { System.out.println("Invalide help topic - " + topic); usage(); } else usage(); return ReturnCode.SUCCESS; case 'i': printScriptRunTime = false; System.out.println(getVersionString()); return ReturnCode.SUCCESS; case 'l': //call to method that validates the path to the log file //and sets up the file to store the client side log file String logFileParameter = opts.getValStr(); if (logFileParameter != null && logFileParameter.length() > 0) { logFileName = validateLogFile(logFileParameter, null); } else { logFileName = validateLogFile(logFileName, null); } userSpecifiedLog = true; properties.setProperty("pig.logfile", (logFileName == null ? "" : logFileName)); break; case 'm': paramFiles.add(opts.getValStr()); break; case 'M': // turns off multiquery optimization properties.setProperty(PigConfiguration.PIG_OPT_MULTIQUERY, "" + false); break; case 'N': properties.setProperty(PigConfiguration.PIG_OPT_FETCH, "" + false); break; case 'p': params.add(opts.getValStr()); break; case 'r': // currently only used for parameter substitution // will be extended in the future dryrun = true; break; case 't': disabledOptimizerRules.add(opts.getValStr()); break; case 'v': properties.setProperty(VERBOSE, "" + true); verbose = true; break; case 'w': properties.setProperty("aggregate.warning", "" + false); break; case 'x': properties.setProperty("exectype", opts.getValStr()); if (opts.getValStr().toLowerCase().contains("local")) { UserGroupInformation.setConfiguration(new Configuration(false)); } break; case 'P': { InputStream inputStream = null; try { FileLocalizer.FetchFileRet localFileRet = FileLocalizer.fetchFile(properties, opts.getValStr()); inputStream = new BufferedInputStream(new FileInputStream(localFileRet.file)); properties.load(inputStream); } catch (IOException e) { throw new RuntimeException("Unable to parse properties file '" + opts.getValStr() + "'"); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { } } } } break; default: { Character cc = Character.valueOf(opt); throw new AssertionError("Unhandled option " + cc.toString()); } } } // create the context with the parameter pigContext = new PigContext(properties); // create the static script state object ScriptState scriptState = pigContext.getExecutionEngine().instantiateScriptState(); String commandLine = LoadFunc.join((AbstractList<String>) Arrays.asList(args), " "); scriptState.setCommandLine(commandLine); if (listener != null) { scriptState.registerListener(listener); } ScriptState.start(scriptState); pigContext.getProperties().setProperty("pig.cmd.args", commandLine); if (logFileName == null && !userSpecifiedLog) { logFileName = validateLogFile(properties.getProperty("pig.logfile"), null); } pigContext.getProperties().setProperty("pig.logfile", (logFileName == null ? "" : logFileName)); // configure logging configureLog4J(properties, pigContext); log.info(getVersionString().replace("\n", "")); if (logFileName != null) { log.info("Logging error messages to: " + logFileName); } deleteTempFiles = Boolean .valueOf(properties.getProperty(PigConfiguration.PIG_DELETE_TEMP_FILE, "true")); pigContext.getProperties().setProperty(PigImplConstants.PIG_OPTIMIZER_RULES_KEY, ObjectSerializer.serialize(disabledOptimizerRules)); PigContext.setClassLoader(pigContext.createCl(null)); // construct the parameter substitution preprocessor Grunt grunt = null; BufferedReader in; String substFile = null; paramFiles = fetchRemoteParamFiles(paramFiles, properties); pigContext.setParams(params); pigContext.setParamFiles(paramFiles); switch (mode) { case FILE: { String remainders[] = opts.getRemainingArgs(); if (remainders != null) { pigContext.getProperties().setProperty(PigContext.PIG_CMD_ARGS_REMAINDERS, ObjectSerializer.serialize(remainders)); } FileLocalizer.FetchFileRet localFileRet = FileLocalizer.fetchFile(properties, file); if (localFileRet.didFetch) { properties.setProperty("pig.jars.relative.to.dfs", "true"); } scriptState.setFileName(file); if (embedded) { return runEmbeddedScript(pigContext, localFileRet.file.getPath(), engine); } else { SupportedScriptLang type = determineScriptType(localFileRet.file.getPath()); if (type != null) { return runEmbeddedScript(pigContext, localFileRet.file.getPath(), type.name().toLowerCase()); } } //Reader is created by first loading "pig.load.default.statements" or .pigbootup file if available in = new BufferedReader(new InputStreamReader( Utils.getCompositeStream(new FileInputStream(localFileRet.file), properties))); // run parameter substitution preprocessor first substFile = file + ".substituted"; pin = runParamPreprocessor(pigContext, in, substFile, debug || dryrun || checkScriptOnly); if (dryrun) { if (dryrun(substFile, pigContext)) { log.info("Dry run completed. Substituted pig script is at " + substFile + ". Expanded pig script is at " + file + ".expanded"); } else { log.info("Dry run completed. Substituted pig script is at " + substFile); } return ReturnCode.SUCCESS; } logFileName = validateLogFile(logFileName, localFileRet.file); pigContext.getProperties().setProperty("pig.logfile", (logFileName == null ? "" : logFileName)); // Set job name based on name of the script pigContext.getProperties().setProperty(PigContext.JOB_NAME, "PigLatin:" + new File(file).getName()); if (!debug) { new File(substFile).deleteOnExit(); } scriptState.setScript(localFileRet.file); grunt = new Grunt(pin, pigContext); gruntCalled = true; if (checkScriptOnly) { grunt.checkScript(substFile); System.err.println(file + " syntax OK"); rc = ReturnCode.SUCCESS; } else { int results[] = grunt.exec(); rc = getReturnCodeForStats(results); } return rc; } case STRING: { if (checkScriptOnly) { System.err.println("ERROR:" + "-c (-check) option is only valid " + "when executing pig with a pig script file)"); return ReturnCode.ILLEGAL_ARGS; } // Gather up all the remaining arguments into a string and pass them into // grunt. StringBuffer sb = new StringBuffer(); String remainders[] = opts.getRemainingArgs(); for (int i = 0; i < remainders.length; i++) { if (i != 0) sb.append(' '); sb.append(remainders[i]); } sb.append('\n'); scriptState.setScript(sb.toString()); in = new BufferedReader(new StringReader(sb.toString())); grunt = new Grunt(in, pigContext); gruntCalled = true; int results[] = grunt.exec(); return getReturnCodeForStats(results); } default: break; } // If we're here, we don't know yet what they want. They may have just // given us a jar to execute, they might have given us a pig script to // execute, or they might have given us a dash (or nothing) which means to // run grunt interactive. String remainders[] = opts.getRemainingArgs(); if (remainders == null) { if (checkScriptOnly) { System.err.println("ERROR:" + "-c (-check) option is only valid " + "when executing pig with a pig script file)"); return ReturnCode.ILLEGAL_ARGS; } // Interactive mode = ExecMode.SHELL; //Reader is created by first loading "pig.load.default.statements" or .pigbootup file if available ConsoleReader reader = new ConsoleReader(Utils.getCompositeStream(System.in, properties), new OutputStreamWriter(System.out)); reader.setDefaultPrompt("grunt> "); final String HISTORYFILE = ".pig_history"; String historyFile = System.getProperty("user.home") + File.separator + HISTORYFILE; reader.setHistory(new History(new File(historyFile))); ConsoleReaderInputStream inputStream = new ConsoleReaderInputStream(reader); grunt = new Grunt(new BufferedReader(new InputStreamReader(inputStream)), pigContext); grunt.setConsoleReader(reader); gruntCalled = true; grunt.run(); return ReturnCode.SUCCESS; } else { pigContext.getProperties().setProperty(PigContext.PIG_CMD_ARGS_REMAINDERS, ObjectSerializer.serialize(remainders)); // They have a pig script they want us to run. mode = ExecMode.FILE; FileLocalizer.FetchFileRet localFileRet = FileLocalizer.fetchFile(properties, remainders[0]); if (localFileRet.didFetch) { properties.setProperty("pig.jars.relative.to.dfs", "true"); } scriptState.setFileName(remainders[0]); if (embedded) { return runEmbeddedScript(pigContext, localFileRet.file.getPath(), engine); } else { SupportedScriptLang type = determineScriptType(localFileRet.file.getPath()); if (type != null) { return runEmbeddedScript(pigContext, localFileRet.file.getPath(), type.name().toLowerCase()); } } //Reader is created by first loading "pig.load.default.statements" or .pigbootup file if available InputStream seqInputStream = Utils.getCompositeStream(new FileInputStream(localFileRet.file), properties); in = new BufferedReader(new InputStreamReader(seqInputStream)); // run parameter substitution preprocessor first substFile = remainders[0] + ".substituted"; pin = runParamPreprocessor(pigContext, in, substFile, debug || dryrun || checkScriptOnly); if (dryrun) { if (dryrun(substFile, pigContext)) { log.info("Dry run completed. Substituted pig script is at " + substFile + ". Expanded pig script is at " + remainders[0] + ".expanded"); } else { log.info("Dry run completed. Substituted pig script is at " + substFile); } return ReturnCode.SUCCESS; } logFileName = validateLogFile(logFileName, localFileRet.file); pigContext.getProperties().setProperty("pig.logfile", (logFileName == null ? "" : logFileName)); if (!debug) { new File(substFile).deleteOnExit(); } // Set job name based on name of the script pigContext.getProperties().setProperty(PigContext.JOB_NAME, "PigLatin:" + new File(remainders[0]).getName()); scriptState.setScript(localFileRet.file); grunt = new Grunt(pin, pigContext); gruntCalled = true; if (checkScriptOnly) { grunt.checkScript(substFile); System.err.println(remainders[0] + " syntax OK"); rc = ReturnCode.SUCCESS; } else { int results[] = grunt.exec(); rc = getReturnCodeForStats(results); } return rc; } // Per Utkarsh and Chris invocation of jar file via pig depricated. } catch (ParseException e) { usage(); rc = ReturnCode.PARSE_EXCEPTION; PigStatsUtil.setErrorMessage(e.getMessage()); PigStatsUtil.setErrorThrowable(e); } catch (org.apache.pig.tools.parameters.ParseException e) { // usage(); rc = ReturnCode.PARSE_EXCEPTION; PigStatsUtil.setErrorMessage(e.getMessage()); PigStatsUtil.setErrorThrowable(e); } catch (IOException e) { if (e instanceof PigException) { PigException pe = (PigException) e; rc = (pe.retriable()) ? ReturnCode.RETRIABLE_EXCEPTION : ReturnCode.PIG_EXCEPTION; PigStatsUtil.setErrorMessage(pe.getMessage()); PigStatsUtil.setErrorCode(pe.getErrorCode()); } else { rc = ReturnCode.IO_EXCEPTION; PigStatsUtil.setErrorMessage(e.getMessage()); } PigStatsUtil.setErrorThrowable(e); if (!gruntCalled) { LogUtils.writeLog(e, logFileName, log, verbose, "Error before Pig is launched"); } } catch (Throwable e) { rc = ReturnCode.THROWABLE_EXCEPTION; PigStatsUtil.setErrorMessage(e.getMessage()); PigStatsUtil.setErrorThrowable(e); if (!gruntCalled) { LogUtils.writeLog(e, logFileName, log, verbose, "Error before Pig is launched"); } } finally { if (printScriptRunTime) { printScriptRunTime(startTime); } if (deleteTempFiles) { // clear temp files FileLocalizer.deleteTempFiles(); } if (pigContext != null) { pigContext.getExecutionEngine().destroy(); } PerformanceTimerFactory.getPerfTimerFactory().dumpTimers(); } return rc; }
From source file:de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderTest.java
@DataProvider(name = "typesAsSessionAttributesProvider") protected Object[][] createTypesAsSessionAttributesData() { return new Object[][] { { int.class, 42 }, { long.class, 42 }, { Boolean.class, Boolean.TRUE }, { String.class, "42" }, { StringBuilder.class, new StringBuilder("42") }, { StringBuffer.class, new StringBuffer("42") }, { Class.class, String.class }, { Long.class, Long.valueOf(42) }, { Integer.class, Integer.valueOf(42) }, { Character.class, Character.valueOf('c') }, { Byte.class, Byte.valueOf("b".getBytes()[0]) }, { Double.class, Double.valueOf(42d) }, { Float.class, Float.valueOf(42f) }, { Short.class, Short.valueOf((short) 42) }, { BigDecimal.class, new BigDecimal(42) }, { AtomicInteger.class, new AtomicInteger(42) }, { AtomicLong.class, new AtomicLong(42) }, { MutableInt.class, new MutableInt(42) }, { Integer[].class, new Integer[] { 42 } }, { Date.class, new Date(System.currentTimeMillis() - 10000) }, { Calendar.class, Calendar.getInstance() }, { Currency.class, Currency.getInstance("EUR") }, { ArrayList.class, new ArrayList<String>(Arrays.asList("foo")) }, { int[].class, new int[] { 1, 2 } }, { long[].class, new long[] { 1, 2 } }, { short[].class, new short[] { 1, 2 } }, { float[].class, new float[] { 1, 2 } }, { double[].class, new double[] { 1, 2 } }, { int[].class, new int[] { 1, 2 } }, { byte[].class, "42".getBytes() }, { char[].class, "42".toCharArray() }, { String[].class, new String[] { "23", "42" } }, { Person[].class, new Person[] { createPerson("foo bar", Gender.MALE, 42) } } }; }
From source file:Main.java
/** * <p>Inserts the specified element at the specified position in the array. * Shifts the element currently at that position (if any) and any subsequent * elements to the right (adds one to their indices).</p> * * <p>This method returns a new array with the same elements of the input * array plus the given element on the specified position. The component * type of the returned array is always the same as that of the input * array.</p>/* www . ja v a 2 s. com*/ * * <p>If the input array is {@code null}, a new one element array is returned * whose component type is the same as the element.</p> * * <pre> * ArrayUtils.add(null, 0, 'a') = ['a'] * ArrayUtils.add(['a'], 0, 'b') = ['b', 'a'] * ArrayUtils.add(['a', 'b'], 0, 'c') = ['c', 'a', 'b'] * ArrayUtils.add(['a', 'b'], 1, 'k') = ['a', 'k', 'b'] * ArrayUtils.add(['a', 'b', 'c'], 1, 't') = ['a', 't', 'b', 'c'] * </pre> * * @param array the array to add the element to, may be {@code null} * @param index the position of the new object * @param element the object to add * @return A new array containing the existing elements and the new element * @throws IndexOutOfBoundsException if the index is out of range * (index < 0 || index > array.length). */ public static char[] add(char[] array, int index, char element) { return (char[]) add(array, index, Character.valueOf(element), Character.TYPE); }
From source file:Main.java
/** * <p>Inserts the specified element at the specified position in the array. * Shifts the element currently at that position (if any) and any subsequent * elements to the right (adds one to their indices).</p> * * <p>This method returns a new array with the same elements of the input * array plus the given element on the specified position. The component * type of the returned array is always the same as that of the input * array.</p>/*from w w w . j a va 2 s. co m*/ * * <p>If the input array is {@code null}, a new one element array is returned * whose component type is the same as the element.</p> * * <pre> * ArrayUtils.add(null, 0, 'a') = ['a'] * ArrayUtils.add(['a'], 0, 'b') = ['b', 'a'] * ArrayUtils.add(['a', 'b'], 0, 'c') = ['c', 'a', 'b'] * ArrayUtils.add(['a', 'b'], 1, 'k') = ['a', 'k', 'b'] * ArrayUtils.add(['a', 'b', 'c'], 1, 't') = ['a', 't', 'b', 'c'] * </pre> * * @param array the array to add the element to, may be {@code null} * @param index the position of the new object * @param element the object to add * @return A new array containing the existing elements and the new element * @throws IndexOutOfBoundsException if the index is out of range * (index < 0 || index > array.length). */ public static char[] add(final char[] array, final int index, final char element) { return (char[]) add(array, index, Character.valueOf(element), Character.TYPE); }
From source file:org.seasar.cubby.internal.controller.impl.RequestParameterBinderImplTest.java
@Test public void converters() { final Map<String, Object[]> map = new HashMap<String, Object[]>(); map.put("decimal", new Object[] { "12.3" }); map.put("decimals", new Object[] { "45.6", "78.9" }); map.put("bigint", new Object[] { "9876" }); map.put("bigints", new Object[] { "5432", "10" }); map.put("bool1", new Object[] { "true" }); map.put("bools1", new Object[] { "true", "false" }); map.put("bool2", new Object[] { "false" }); map.put("bools2", new Object[] { "false", "true", "false" }); map.put("byte1", new Object[] { "12" }); map.put("bytes1", new Object[] { "34", "56" }); map.put("byte2", new Object[] { "98" }); map.put("bytes2", new Object[] { "76", "54" }); map.put("char1", new Object[] { "a" }); map.put("chars1", new Object[] { "b", "c" }); map.put("char2", new Object[] { "d" }); map.put("chars2", new Object[] { "e", "f" }); map.put("date", new Object[] { "2008-7-28" }); map.put("dates", new Object[] { "2008-8-14", "2008-10-30" }); map.put("double1", new Object[] { "1.2" }); map.put("doubles1", new Object[] { "3.4", "5.6" }); map.put("double2", new Object[] { "9.8" }); map.put("doubles2", new Object[] { "7.6", "5.4" }); map.put("en", new Object[] { "VALUE1" }); map.put("ens", new Object[] { "VALUE2", "VALUE3" }); map.put("float1", new Object[] { "1.2" }); map.put("floats1", new Object[] { "3.4", "5.6" }); map.put("float2", new Object[] { "9.8" }); map.put("floats2", new Object[] { "7.6", "5.4" }); map.put("int1", new Object[] { "12" }); map.put("ints1", new Object[] { "34", "56" }); map.put("int2", new Object[] { "98" }); map.put("ints2", new Object[] { "76", "54" }); map.put("long1", new Object[] { "12" }); map.put("longs1", new Object[] { "34", "56" }); map.put("long2", new Object[] { "98" }); map.put("longs2", new Object[] { "76", "54" }); map.put("short1", new Object[] { "12" }); map.put("shorts1", new Object[] { "34", "56" }); map.put("short2", new Object[] { "98" }); map.put("shorts2", new Object[] { "76", "54" }); map.put("sqldate", new Object[] { "2008-7-28" }); map.put("sqldates", new Object[] { "2008-8-14", "2008-10-30" }); map.put("sqltime", new Object[] { "12:34:56" }); map.put("sqltimes", new Object[] { "13:45:24", "23:44:00" }); map.put("sqltimestamp", new Object[] { "2008-7-28 12:34:56" }); map.put("sqltimestamps", new Object[] { "2008-8-14 13:45:24", "2008-10-30 23:44:00" }); final ConvertersDto dto = new ConvertersDto(); final ActionContext actionContext = new MockActionContext(null, MockAction.class, actionMethod(MockAction.class, "all")); final List<ConversionFailure> conversionFailures = requestParameterBinder.bind(map, dto, actionContext); assertNotNull(dto.getDecimal());//from w w w .ja v a 2 s.c om assertTrue(new BigDecimal("12.3").compareTo(dto.getDecimal()) == 0); assertNotNull(dto.getDecimals()); assertEquals(2, dto.getDecimals().length); assertTrue(new BigDecimal("45.6").compareTo(dto.getDecimals()[0]) == 0); assertTrue(new BigDecimal("78.9").compareTo(dto.getDecimals()[1]) == 0); assertNotNull(dto.getBigint()); assertTrue(new BigInteger("9876").compareTo(dto.getBigint()) == 0); assertNotNull(dto.getBigints()); assertEquals(2, dto.getBigints().length); assertTrue(new BigInteger("5432").compareTo(dto.getBigints()[0]) == 0); assertTrue(new BigInteger("10").compareTo(dto.getBigints()[1]) == 0); assertNotNull(dto.getBool1()); assertTrue(dto.getBool1()); assertNotNull(dto.getBools1()); assertEquals(2, dto.getBools1().length); assertTrue(dto.getBools1()[0]); assertFalse(dto.getBools1()[1]); assertFalse(dto.isBool2()); assertNotNull(dto.getBools2()); assertEquals(3, dto.getBools2().length); assertFalse(dto.getBools2()[0]); assertTrue(dto.getBools2()[1]); assertFalse(dto.getBools2()[2]); assertNotNull(dto.getByte1()); assertEquals(Byte.valueOf((byte) 12), dto.getByte1()); assertNotNull(dto.getBytes1()); assertEquals(2, dto.getBytes1().length); assertEquals(Byte.valueOf((byte) 34), dto.getBytes1()[0]); assertEquals(Byte.valueOf((byte) 56), dto.getBytes1()[1]); assertEquals((byte) 98, dto.getByte2()); assertNotNull(dto.getBytes2()); assertEquals(2, dto.getBytes2().length); assertEquals((byte) 76, dto.getBytes2()[0]); assertEquals((byte) 54, dto.getBytes2()[1]); assertNotNull(dto.getChar1()); assertEquals(Character.valueOf('a'), dto.getChar1()); assertNotNull(dto.getChars1()); assertEquals(2, dto.getChars1().length); assertEquals(Character.valueOf('b'), dto.getChars1()[0]); assertEquals(Character.valueOf('c'), dto.getChars1()[1]); assertNotNull(dto.getChar2()); assertEquals('d', dto.getChar2()); assertNotNull(dto.getChars2()); assertEquals(2, dto.getChars2().length); assertEquals('e', dto.getChars2()[0]); assertEquals('f', dto.getChars2()[1]); assertNotNull(dto.getDate()); assertEquals(new Date(fromDateToMillis(2008, 7, 28)), dto.getDate()); assertNotNull(dto.getDates()); assertEquals(2, dto.getDates().length); assertEquals(new Date(fromDateToMillis(2008, 8, 14)), dto.getDates()[0]); assertEquals(new Date(fromDateToMillis(2008, 10, 30)), dto.getDates()[1]); assertNotNull(dto.getDouble1()); assertEquals(new Double(1.2d), dto.getDouble1()); assertNotNull(dto.getDoubles1()); assertEquals(2, dto.getDoubles1().length); assertEquals(new Double(3.4d), dto.getDoubles1()[0]); assertEquals(new Double(5.6d), dto.getDoubles1()[1]); assertEquals(9.8d, dto.getDouble2(), 0.0d); assertNotNull(dto.getDoubles2()); assertEquals(2, dto.getDoubles2().length); assertEquals(7.6d, dto.getDoubles2()[0], 0.0d); assertEquals(5.4d, dto.getDoubles2()[1], 0.0d); assertNotNull(dto.getEn()); assertSame(ExEnum.VALUE1, dto.getEn()); assertNotNull(dto.getEns()); assertEquals(2, dto.getEns().length); assertSame(ExEnum.VALUE2, dto.getEns()[0]); assertSame(ExEnum.VALUE3, dto.getEns()[1]); assertNotNull(dto.getFloat1()); assertEquals(new Float(1.2f), dto.getFloat1()); assertNotNull(dto.getFloats1()); assertEquals(2, dto.getFloats1().length); assertEquals(new Float(3.4f), dto.getFloats1()[0]); assertEquals(new Float(5.6f), dto.getFloats1()[1]); assertEquals(9.8f, dto.getFloat2(), 0.0f); assertNotNull(dto.getFloats2()); assertEquals(2, dto.getFloats2().length); assertEquals(7.6f, dto.getFloats2()[0], 0.0f); assertEquals(5.4f, dto.getFloats2()[1], 0.0f); assertNotNull(dto.getInt1()); assertEquals(Integer.valueOf(12), dto.getInt1()); assertNotNull(dto.getInts1()); assertEquals(2, dto.getInts1().length); assertEquals(Integer.valueOf(34), dto.getInts1()[0]); assertEquals(Integer.valueOf(56), dto.getInts1()[1]); assertEquals(98, dto.getInt2()); assertNotNull(dto.getInts2()); assertEquals(2, dto.getInts2().length); assertEquals(76, dto.getInts2()[0]); assertEquals(54, dto.getInts2()[1]); assertNotNull(dto.getLong1()); assertEquals(Long.valueOf(12l), dto.getLong1()); assertNotNull(dto.getLongs1()); assertEquals(2, dto.getLongs1().length); assertEquals(Long.valueOf(34l), dto.getLongs1()[0]); assertEquals(Long.valueOf(56l), dto.getLongs1()[1]); assertEquals(98l, dto.getLong2()); assertNotNull(dto.getLongs2()); assertEquals(2, dto.getLongs2().length); assertEquals(76l, dto.getLongs2()[0]); assertEquals(54l, dto.getLongs2()[1]); assertNotNull(dto.getShort1()); assertEquals(Short.valueOf((short) 12), dto.getShort1()); assertNotNull(dto.getShorts1()); assertEquals(2, dto.getShorts1().length); assertEquals(Short.valueOf((short) 34), dto.getShorts1()[0]); assertEquals(Short.valueOf((short) 56), dto.getShorts1()[1]); assertEquals((short) 98, dto.getShort2()); assertNotNull(dto.getShorts2()); assertEquals(2, dto.getShorts2().length); assertEquals((short) 76, dto.getShorts2()[0]); assertEquals((short) 54, dto.getShorts2()[1]); assertNotNull(dto.getSqldate()); assertEquals(new java.sql.Date(fromDateToMillis(2008, 7, 28)), dto.getSqldate()); assertNotNull(dto.getSqldates()); assertEquals(2, dto.getSqldates().length); assertEquals(new java.sql.Date(fromDateToMillis(2008, 8, 14)), dto.getSqldates()[0]); assertEquals(new java.sql.Date(fromDateToMillis(2008, 10, 30)), dto.getSqldates()[1]); assertNotNull(dto.getSqltime()); assertEquals(new Time(fromTimeToMillis(12, 34, 56)), dto.getSqltime()); assertNotNull(dto.getSqltimes()); assertEquals(2, dto.getSqltimes().length); assertEquals(new Time(fromTimeToMillis(13, 45, 24)), dto.getSqltimes()[0]); assertEquals(new Time(fromTimeToMillis(23, 44, 00)), dto.getSqltimes()[1]); assertNotNull(dto.getSqltimestamp()); assertEquals(new Timestamp(fromTimestampToMillis(2008, 7, 28, 12, 34, 56)), dto.getSqltimestamp()); assertNotNull(dto.getSqltimestamps()); assertEquals(2, dto.getSqltimestamps().length); assertEquals(new Timestamp(fromTimestampToMillis(2008, 8, 14, 13, 45, 24)), dto.getSqltimestamps()[0]); assertEquals(new Timestamp(fromTimestampToMillis(2008, 10, 30, 23, 44, 00)), dto.getSqltimestamps()[1]); assertTrue(conversionFailures.isEmpty()); System.out.println(dto); }
From source file:com.xhsoft.framework.common.utils.ClassUtil.java
/** * @param type/*from w w w. j a v a 2s .c o m*/ * @param s * @return Object * @author lizj */ public static Object cast(Class<?> type, String s) { if (s == null || type == null) { return null; } Object value = null; if (type == char.class || type == Character.class) { value = (s.length() > 0 ? Character.valueOf(s.charAt(0)) : null); } else if (type == boolean.class || type == Boolean.class) { String x = s.toLowerCase(); boolean b = ("1".equals(x) || "y".equals(x) || "on".equals(x) || "yes".equals(x) || "true".equals(x)); value = new Boolean(b); } else if (type == byte.class || type == Byte.class) { try { value = Byte.parseByte(s); } catch (NumberFormatException e) { } } else if (type == short.class || type == Short.class) { try { value = Short.parseShort(s); } catch (NumberFormatException e) { } } else if (type == int.class || type == Integer.class) { try { value = Integer.parseInt(s); } catch (NumberFormatException e) { } } else if (type == float.class || type == Float.class) { try { value = Float.parseFloat(s); } catch (NumberFormatException e) { } } else if (type == double.class || type == Double.class) { try { value = Double.parseDouble(s); } catch (NumberFormatException e) { } } else if (type == long.class || type == Long.class) { try { value = Long.parseLong(s); } catch (NumberFormatException e) { } } else if (type == String.class) { value = s; } else if (type == StringBuilder.class) { value = new StringBuilder(s); } else if (type == StringBuffer.class) { value = new StringBuffer(s); } else if (type == java.io.Reader.class) { value = new java.io.StringReader(s); } else if (type == java.util.Date.class) { if (s.length() > 0) { try { String format = (s.length() == "yyyy-MM-dd".length() ? "yyyy-MM-dd" : "yyyy-MM-dd HH:mm:ss SSS"); SimpleDateFormat dateFormat = new SimpleDateFormat(format); value = dateFormat.parse(s); } catch (java.text.ParseException e) { if (DEBUG) { log.debug("Exception: " + e.getMessage()); } } } } else if (type == java.sql.Date.class) { if (s.length() > 0) { try { String format = (s.length() == "yyyy-MM-dd".length() ? "yyyy-MM-dd" : "yyyy-MM-dd HH:mm:ss SSS"); SimpleDateFormat dateFormat = new SimpleDateFormat(format); java.util.Date date = dateFormat.parse(s); value = new java.sql.Date(date.getTime()); } catch (java.text.ParseException e) { if (DEBUG) { log.debug("Exception: " + e.getMessage()); } } } } else if (type == java.sql.Timestamp.class) { if (s.length() > 0) { try { String format = (s.length() == "yyyy-MM-dd".length() ? "yyyy-MM-dd" : "yyyy-MM-dd HH:mm:ss SSS"); SimpleDateFormat dateFormat = new SimpleDateFormat(format); java.util.Date date = dateFormat.parse(s); value = new java.sql.Timestamp(date.getTime()); } catch (java.text.ParseException e) { if (DEBUG) { log.debug("Exception: " + e.getMessage()); } } } } return value; }
From source file:eionet.gdem.utils.MultipartFileUpload.java
/** * Removes strange symbols from file name * * @param fileName File name//from w w w . j a v a 2s . co m * @return Processed file name */ private String parseFileName(String fileName) { StringBuffer ret = new StringBuffer(); int code = 0; int lastCode = 0; for (int i = 0; i < fileName.length(); i++) { char c = fileName.charAt(i); code = Character.valueOf(fileName.charAt(i)); if (code == 63 && lastCode == 65533) { ret.append("s"); } else if (fileNameEscapes.containsKey(new Integer(code))) { ret.append(fileNameEscapes.get(code)); } else if (code > 127 || isRestrictedChar(c)) { ret.append("-"); } else { ret.append(c); } // System.out.println(c + "=" + code); lastCode = code; } return ret.toString(); }
From source file:stg.utils.RandomStringGenerator.java
/** * Returns a unique character from the given character list. * The generated character is then removed from the list. * /*from ww w . jav a 2 s. c om*/ * @param c * @return list */ private String generateUniqueCharacter(char c, List<Character> list) { if (list.size() == 0) { StringBuilder ssb = new StringBuilder(); ssb.append("Format supplied "); ssb.append(format); ssb.append(" has more number of "); ssb.append(c); ssb.append(" than the supplied "); ssb.append(decode(c)); throw new IllegalArgumentException(ssb.toString()); } String str = RandomStringUtils.random(1, toCharArray(list)); list.remove(Character.valueOf(str.charAt(0))); return str; }
From source file:org.thymeleaf.util.EvaluationUtilTest.java
@Test public void convertToListTest() { {//from w w w . j a v a 2 s. c o m final List<Object> result = EvaluationUtil.evaluateAsList(null); Assert.assertTrue(result != null && result.size() == 0); } { final Set<Object> set = new LinkedHashSet<Object>(); set.add(Integer.valueOf(2)); set.add(Integer.valueOf(43)); final List<Object> list = new ArrayList<Object>(); list.add(Integer.valueOf(2)); list.add(Integer.valueOf(43)); final List<Object> result = EvaluationUtil.evaluateAsList(set); Assert.assertTrue(result != null && result instanceof List && list.equals(result)); } { final Map<Object, Object> map = new LinkedHashMap<Object, Object>(); map.put("a", Integer.valueOf(2)); map.put("b", Integer.valueOf(43)); final List<Object> list = new ArrayList<Object>(); list.add(new EvaluationUtil.MapEntry<Object, Object>("a", Integer.valueOf(2))); list.add(new EvaluationUtil.MapEntry<Object, Object>("b", Integer.valueOf(43))); final List<Object> result = EvaluationUtil.evaluateAsList(map); Assert.assertTrue(result != null && result instanceof List && list.equals(result)); } { final byte[] arr0 = new byte[0]; final List<Object> list0 = new ArrayList<Object>(); final List<Object> result0 = EvaluationUtil.evaluateAsList(arr0); Assert.assertTrue(result0 != null && result0 instanceof List && list0.equals(result0)); final byte[] arr = new byte[2]; arr[0] = (byte) 23; arr[1] = (byte) -127; final List<Object> list = new ArrayList<Object>(); list.add(Byte.valueOf((byte) 23)); list.add(Byte.valueOf((byte) -127)); final List<Object> result = EvaluationUtil.evaluateAsList(arr); Assert.assertTrue(result != null && result instanceof List && list.equals(result)); } { final short[] arr0 = new short[0]; final List<Object> list0 = new ArrayList<Object>(); final List<Object> result0 = EvaluationUtil.evaluateAsList(arr0); Assert.assertTrue(result0 != null && result0 instanceof List && list0.equals(result0)); final short[] arr = new short[2]; arr[0] = (short) 23; arr[1] = (short) -127; final List<Object> list = new ArrayList<Object>(); list.add(Short.valueOf((short) 23)); list.add(Short.valueOf((short) -127)); final List<Object> result = EvaluationUtil.evaluateAsList(arr); Assert.assertTrue(result != null && result instanceof List && list.equals(result)); } { final int[] arr0 = new int[0]; final List<Object> list0 = new ArrayList<Object>(); final List<Object> result0 = EvaluationUtil.evaluateAsList(arr0); Assert.assertTrue(result0 != null && result0 instanceof List && list0.equals(result0)); final int[] arr = new int[2]; arr[0] = 23; arr[1] = -127; final List<Object> list = new ArrayList<Object>(); list.add(Integer.valueOf(23)); list.add(Integer.valueOf(-127)); final List<Object> result = EvaluationUtil.evaluateAsList(arr); Assert.assertTrue(result != null && result instanceof List && list.equals(result)); } { final long[] arr0 = new long[0]; final List<Object> list0 = new ArrayList<Object>(); final List<Object> result0 = EvaluationUtil.evaluateAsList(arr0); Assert.assertTrue(result0 != null && result0 instanceof List && list0.equals(result0)); final long[] arr = new long[2]; arr[0] = 23L; arr[1] = -127L; final List<Object> list = new ArrayList<Object>(); list.add(Long.valueOf(23L)); list.add(Long.valueOf(-127L)); final List<Object> result = EvaluationUtil.evaluateAsList(arr); Assert.assertTrue(result != null && result instanceof List && list.equals(result)); } { final float[] arr0 = new float[0]; final List<Object> list0 = new ArrayList<Object>(); final List<Object> result0 = EvaluationUtil.evaluateAsList(arr0); Assert.assertTrue(result0 != null && result0 instanceof List && list0.equals(result0)); final float[] arr = new float[2]; arr[0] = 23.0f; arr[1] = -127.1f; final List<Object> list = new ArrayList<Object>(); list.add(Float.valueOf(23.0f)); list.add(Float.valueOf(-127.1f)); final List<Object> result = EvaluationUtil.evaluateAsList(arr); Assert.assertTrue(result != null && result instanceof List && result.size() == list.size()); for (int i = 0; i < result.size(); i++) { Assert.assertTrue(result.get(i) != null && result.get(i) instanceof Float && (((Float) result.get(i)).compareTo((Float) list.get(i)) == 0)); } } { final double[] arr0 = new double[0]; final List<Object> list0 = new ArrayList<Object>(); final List<Object> result0 = EvaluationUtil.evaluateAsList(arr0); Assert.assertTrue(result0 != null && result0 instanceof List && list0.equals(result0)); final double[] arr = new double[2]; arr[0] = 23.0d; arr[1] = -127.1d; final List<Object> list = new ArrayList<Object>(); list.add(Double.valueOf(23.0d)); list.add(Double.valueOf(-127.1d)); final List<Object> result = EvaluationUtil.evaluateAsList(arr); Assert.assertTrue(result != null && result instanceof List && result.size() == list.size()); for (int i = 0; i < result.size(); i++) { Assert.assertTrue(result.get(i) != null && result.get(i) instanceof Double && (((Double) result.get(i)).compareTo((Double) list.get(i)) == 0)); } } { final boolean[] arr0 = new boolean[0]; final List<Object> list0 = new ArrayList<Object>(); final List<Object> result0 = EvaluationUtil.evaluateAsList(arr0); Assert.assertTrue(result0 != null && result0 instanceof List && list0.equals(result0)); final boolean[] arr = new boolean[2]; arr[0] = true; arr[1] = false; final List<Object> list = new ArrayList<Object>(); list.add(Boolean.TRUE); list.add(Boolean.FALSE); final List<Object> result = EvaluationUtil.evaluateAsList(arr); Assert.assertTrue(result != null && result instanceof List && list.equals(result)); } { final char[] arr0 = new char[0]; final List<Object> list0 = new ArrayList<Object>(); final List<Object> result0 = EvaluationUtil.evaluateAsList(arr0); Assert.assertTrue(result0 != null && result0 instanceof List && list0.equals(result0)); final char[] arr = new char[3]; arr[0] = 'a'; arr[1] = 'x'; arr[2] = (char) 0; final List<Object> list = new ArrayList<Object>(); list.add(Character.valueOf('a')); list.add(Character.valueOf('x')); list.add(Character.valueOf((char) 0)); final List<Object> result = EvaluationUtil.evaluateAsList(arr); Assert.assertTrue(result != null && result instanceof List && list.equals(result)); } { final Class<?>[] arr0 = new Class<?>[0]; final List<Object> list0 = new ArrayList<Object>(); final List<Object> result0 = EvaluationUtil.evaluateAsList(arr0); Assert.assertTrue(result0 != null && result0 instanceof List && list0.equals(result0)); final Class<?>[] arr = new Class<?>[2]; arr[0] = EvaluationUtil.class; arr[1] = EvaluationUtilTest.class; final List<Object> list = new ArrayList<Object>(); list.add(EvaluationUtil.class); list.add(EvaluationUtilTest.class); final List<Object> result = EvaluationUtil.evaluateAsList(arr); Assert.assertTrue(result != null && result instanceof List && list.equals(result)); } { final List<Object> list = new ArrayList<Object>(); list.add(EvaluationUtil.class); final List<Object> result = EvaluationUtil.evaluateAsList(EvaluationUtil.class); Assert.assertTrue(result != null && result instanceof List && list.equals(result)); } }
From source file:asmlib.Type.java
/** Devolve o nome do tipo bsico (int, long, ...). * til para por exemplo chamar intValue() sobre Integer, longValue() sobre Long, ... **///from w w w. j a v a 2 s. c om public String primitiveTypeName() { if (!isPrimitive()) throw new InstrumentationException("Type doesn't represent a Primitive Type"); String c = Character.valueOf(bytecodeName().charAt(0)).toString(); for (String[] typeMapping : primitiveTypeNames) { if (typeMapping[1].equals(c)) return typeMapping[0]; } throw new AssertionError("This should never happen"); }