List of usage examples for java.lang Byte valueOf
public static Byte valueOf(String s) throws NumberFormatException
From source file:org.apache.hive.jdbc.BaseJdbcWithMiniLlap.java
@Test(timeout = 60000) public void testDataTypes() throws Exception { createDataTypesTable("datatypes"); RowCollector2 rowCollector = new RowCollector2(); String query = "select * from datatypes"; int rowCount = processQuery(query, 1, rowCollector); assertEquals(3, rowCount);/*from w w w .j ava 2 s .co m*/ // Verify schema String[][] colNameTypes = new String[][] { { "datatypes.c1", "int" }, { "datatypes.c2", "boolean" }, { "datatypes.c3", "double" }, { "datatypes.c4", "string" }, { "datatypes.c5", "array<int>" }, { "datatypes.c6", "map<int,string>" }, { "datatypes.c7", "map<string,string>" }, { "datatypes.c8", "struct<r:string,s:int,t:double>" }, { "datatypes.c9", "tinyint" }, { "datatypes.c10", "smallint" }, { "datatypes.c11", "float" }, { "datatypes.c12", "bigint" }, { "datatypes.c13", "array<array<string>>" }, { "datatypes.c14", "map<int,map<int,int>>" }, { "datatypes.c15", "struct<r:int,s:struct<a:int,b:string>>" }, { "datatypes.c16", "array<struct<m:map<string,string>,n:int>>" }, { "datatypes.c17", "timestamp" }, { "datatypes.c18", "decimal(16,7)" }, { "datatypes.c19", "binary" }, { "datatypes.c20", "date" }, { "datatypes.c21", "varchar(20)" }, { "datatypes.c22", "char(15)" }, { "datatypes.c23", "binary" }, }; FieldDesc fieldDesc; assertEquals(23, rowCollector.numColumns); for (int idx = 0; idx < rowCollector.numColumns; ++idx) { fieldDesc = rowCollector.schema.getColumns().get(idx); assertEquals("ColName idx=" + idx, colNameTypes[idx][0], fieldDesc.getName()); assertEquals("ColType idx=" + idx, colNameTypes[idx][1], fieldDesc.getTypeInfo().getTypeName()); } // First row is all nulls Object[] rowValues = rowCollector.rows.get(0); for (int idx = 0; idx < rowCollector.numColumns; ++idx) { assertEquals("idx=" + idx, null, rowValues[idx]); } // Second Row rowValues = rowCollector.rows.get(1); assertEquals(Integer.valueOf(-1), rowValues[0]); assertEquals(Boolean.FALSE, rowValues[1]); assertEquals(Double.valueOf(-1.1d), rowValues[2]); assertEquals("", rowValues[3]); List<?> c5Value = (List<?>) rowValues[4]; assertEquals(0, c5Value.size()); Map<?, ?> c6Value = (Map<?, ?>) rowValues[5]; assertEquals(0, c6Value.size()); Map<?, ?> c7Value = (Map<?, ?>) rowValues[6]; assertEquals(0, c7Value.size()); List<?> c8Value = (List<?>) rowValues[7]; assertEquals(null, c8Value.get(0)); assertEquals(null, c8Value.get(1)); assertEquals(null, c8Value.get(2)); assertEquals(Byte.valueOf((byte) -1), rowValues[8]); assertEquals(Short.valueOf((short) -1), rowValues[9]); assertEquals(Float.valueOf(-1.0f), rowValues[10]); assertEquals(Long.valueOf(-1l), rowValues[11]); List<?> c13Value = (List<?>) rowValues[12]; assertEquals(0, c13Value.size()); Map<?, ?> c14Value = (Map<?, ?>) rowValues[13]; assertEquals(0, c14Value.size()); List<?> c15Value = (List<?>) rowValues[14]; assertEquals(null, c15Value.get(0)); assertEquals(null, c15Value.get(1)); List<?> c16Value = (List<?>) rowValues[15]; assertEquals(0, c16Value.size()); assertEquals(null, rowValues[16]); assertEquals(null, rowValues[17]); assertEquals(null, rowValues[18]); assertEquals(null, rowValues[19]); assertEquals(null, rowValues[20]); assertEquals(null, rowValues[21]); assertEquals(null, rowValues[22]); // Third row rowValues = rowCollector.rows.get(2); assertEquals(Integer.valueOf(1), rowValues[0]); assertEquals(Boolean.TRUE, rowValues[1]); assertEquals(Double.valueOf(1.1d), rowValues[2]); assertEquals("1", rowValues[3]); c5Value = (List<?>) rowValues[4]; assertEquals(2, c5Value.size()); assertEquals(Integer.valueOf(1), c5Value.get(0)); assertEquals(Integer.valueOf(2), c5Value.get(1)); c6Value = (Map<?, ?>) rowValues[5]; assertEquals(2, c6Value.size()); assertEquals("x", c6Value.get(Integer.valueOf(1))); assertEquals("y", c6Value.get(Integer.valueOf(2))); c7Value = (Map<?, ?>) rowValues[6]; assertEquals(1, c7Value.size()); assertEquals("v", c7Value.get("k")); c8Value = (List<?>) rowValues[7]; assertEquals("a", c8Value.get(0)); assertEquals(Integer.valueOf(9), c8Value.get(1)); assertEquals(Double.valueOf(2.2d), c8Value.get(2)); assertEquals(Byte.valueOf((byte) 1), rowValues[8]); assertEquals(Short.valueOf((short) 1), rowValues[9]); assertEquals(Float.valueOf(1.0f), rowValues[10]); assertEquals(Long.valueOf(1l), rowValues[11]); c13Value = (List<?>) rowValues[12]; assertEquals(2, c13Value.size()); List<?> listVal = (List<?>) c13Value.get(0); assertEquals("a", listVal.get(0)); assertEquals("b", listVal.get(1)); listVal = (List<?>) c13Value.get(1); assertEquals("c", listVal.get(0)); assertEquals("d", listVal.get(1)); c14Value = (Map<?, ?>) rowValues[13]; assertEquals(2, c14Value.size()); Map<?, ?> mapVal = (Map<?, ?>) c14Value.get(Integer.valueOf(1)); assertEquals(2, mapVal.size()); assertEquals(Integer.valueOf(12), mapVal.get(Integer.valueOf(11))); assertEquals(Integer.valueOf(14), mapVal.get(Integer.valueOf(13))); mapVal = (Map<?, ?>) c14Value.get(Integer.valueOf(2)); assertEquals(1, mapVal.size()); assertEquals(Integer.valueOf(22), mapVal.get(Integer.valueOf(21))); c15Value = (List<?>) rowValues[14]; assertEquals(Integer.valueOf(1), c15Value.get(0)); listVal = (List<?>) c15Value.get(1); assertEquals(2, listVal.size()); assertEquals(Integer.valueOf(2), listVal.get(0)); assertEquals("x", listVal.get(1)); c16Value = (List<?>) rowValues[15]; assertEquals(2, c16Value.size()); listVal = (List<?>) c16Value.get(0); assertEquals(2, listVal.size()); mapVal = (Map<?, ?>) listVal.get(0); assertEquals(0, mapVal.size()); assertEquals(Integer.valueOf(1), listVal.get(1)); listVal = (List<?>) c16Value.get(1); mapVal = (Map<?, ?>) listVal.get(0); assertEquals(2, mapVal.size()); assertEquals("b", mapVal.get("a")); assertEquals("d", mapVal.get("c")); assertEquals(Integer.valueOf(2), listVal.get(1)); assertEquals(Timestamp.valueOf("2012-04-22 09:00:00.123456789"), rowValues[16]); assertEquals(new BigDecimal("123456789.123456"), rowValues[17]); assertArrayEquals("abcd".getBytes("UTF-8"), (byte[]) rowValues[18]); assertEquals(Date.valueOf("2013-01-01"), rowValues[19]); assertEquals("abc123", rowValues[20]); assertEquals("abc123 ", rowValues[21]); assertArrayEquals("X'01FF'".getBytes("UTF-8"), (byte[]) rowValues[22]); }
From source file:com.ebay.nest.io.sede.thrift.TCTLSeparatedProtocol.java
protected String getByteValue(String altValue, String defaultVal) { if (altValue != null && altValue.length() > 0) { try {/*from w ww. j a v a2 s . co m*/ byte[] b = new byte[1]; b[0] = Byte.valueOf(altValue).byteValue(); return new String(b); } catch (NumberFormatException e) { return altValue; } } return defaultVal; }
From source file:org.entrystore.repository.config.PropertiesConfiguration.java
/** * @see se.kth.cid.config.Config#getByte(java.lang.String) */// w ww . ja va 2s .c o m public byte getByte(String key) { String strValue = config.getProperty(key); byte byteValue = 0; if (strValue != null) { byteValue = Byte.valueOf(strValue).byteValue(); } return byteValue; }
From source file:org.op4j.functions.FnObject.java
/** * <p>//w ww . jav a 2s . c om * Determines whether the target object and the specified object are NOT equal * by calling the <tt>equals</tt> method on the target object. * </p> * * @param object the object to compare to the target * @return false if both objects are equal, true if not. */ public static final Function<Object, Boolean> notEq(final byte object) { return new NotEquals(Byte.valueOf(object)); }
From source file:com.vmware.o11n.plugin.powershell.model.RemotePsType.java
private Object convertPrimitiveType(String type, String value) { if (type.equals("C")) { //Char return (char) Integer.valueOf(value).intValue(); }//from www.j a v a 2 s . co m if (type.equals("B")) { //Boolean return Boolean.valueOf(value); } if (type.equals("By")) { //UnsignedByte return Short.valueOf(value); } if (type.equals("SB")) { //SignedByte return Byte.valueOf(value); } if (type.equals("U16")) { //UnsignedShort return Integer.valueOf(value); } if (type.equals("I16")) { //SignedShort return Short.valueOf(value); } if (type.equals("U32")) { //UnsignedInt return Long.valueOf(value); } if (type.equals("I32")) { //SignedInt return Integer.valueOf(value); } if (type.equals("I64")) { //SignedLong return Long.valueOf(value); } if (type.equals("Sg")) { //Float return Float.valueOf(value); } if (type.equals("Db")) { //Double return Double.valueOf(value); } else { return value; } }
From source file:org.entrystore.repository.config.PropertiesConfiguration.java
/** * @see se.kth.cid.config.Config#getByte(java.lang.String, byte) *//*from www.j ava 2 s .c om*/ public byte getByte(String key, byte defaultValue) { String strValue = config.getProperty(key); byte byteValue = 0; if (strValue != null) { byteValue = Byte.valueOf(strValue).byteValue(); } else { byteValue = defaultValue; } return byteValue; }
From source file:org.apache.pig.data.BinInterSedes.java
/** * Expects binInterSedes data types (NOT DataType types!) * <p>// w w w.jav a2s. c o m * * @see org.apache.pig.data.InterSedes#readDatum(java.io.DataInput, byte) */ @Override public Object readDatum(DataInput in, byte type) throws IOException, ExecException { switch (type) { case TUPLE_0: case TUPLE_1: case TUPLE_2: case TUPLE_3: case TUPLE_4: case TUPLE_5: case TUPLE_6: case TUPLE_7: case TUPLE_8: case TUPLE_9: case TUPLE: case TINYTUPLE: case SMALLTUPLE: return SedesHelper.readGenericTuple(in, type); case BAG: case TINYBAG: case SMALLBAG: return readBag(in, type); case MAP: case TINYMAP: case SMALLMAP: return readMap(in, type); case INTERNALMAP: return readInternalMap(in); case INTEGER_0: return Integer.valueOf(0); case INTEGER_1: return Integer.valueOf(1); case INTEGER_INBYTE: return Integer.valueOf(in.readByte()); case INTEGER_INSHORT: return Integer.valueOf(in.readShort()); case INTEGER: return Integer.valueOf(in.readInt()); case LONG_0: return Long.valueOf(0); case LONG_1: return Long.valueOf(1); case LONG_INBYTE: return Long.valueOf(in.readByte()); case LONG_INSHORT: return Long.valueOf(in.readShort()); case LONG_ININT: return Long.valueOf(in.readInt()); case LONG: return Long.valueOf(in.readLong()); case DATETIME: return new DateTime(in.readLong(), DateTimeZone.forOffsetMillis(in.readShort() * ONE_MINUTE)); case FLOAT: return Float.valueOf(in.readFloat()); case DOUBLE: return Double.valueOf(in.readDouble()); case BIGINTEGER: return readBigInteger(in); case BIGDECIMAL: return readBigDecimal(in); case BOOLEAN_TRUE: return Boolean.valueOf(true); case BOOLEAN_FALSE: return Boolean.valueOf(false); case BYTE: return Byte.valueOf(in.readByte()); case TINYBYTEARRAY: case SMALLBYTEARRAY: case BYTEARRAY: return new DataByteArray(SedesHelper.readBytes(in, type)); case CHARARRAY: case SMALLCHARARRAY: return SedesHelper.readChararray(in, type); case GENERIC_WRITABLECOMPARABLE: return readWritable(in); case SCHEMA_TUPLE_BYTE_INDEX: case SCHEMA_TUPLE_SHORT_INDEX: case SCHEMA_TUPLE: return readSchemaTuple(in, type); case NULL: return null; default: throw new RuntimeException("Unexpected data type " + type + " found in stream."); } }
From source file:cn.jsprun.struts.action.BasicSettingsAction.java
@SuppressWarnings("unchecked") public ActionForward styles(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {/* w w w . j a va2 s. c om*/ try { if (submitCheck(request, "settingsubmit")) { String variables[] = { "styleid", "stylejump", "frameon", "framewidth", "subforumsindex", "forumlinkstatus", "maxbdays", "moddisplay", "whosonlinestatus", "whosonline_contract", "maxonlinelist", "topicperpage", "threadmaxpages", "hottopic", "fastpost", "fastreply", "globalstick", "threadsticky", "postperpage", "starthreshold", "maxsigrows", "ratelogrecord", "showsettings", "showjavacode", "zoomstatus", "vtonlinestatus", "userstatusby", "postno", "postnocustom", "maxsmilies", "memberperpage", "membermaxpages", "hideprivate", "visitedforums" }; Map<String, String> oldSettings = ForumInit.settings; Map<String, String> settings = new HashMap<String, String>(); for (String variable : variables) { if ("showsettings".equals(variable)) { int showsignatures = Integer.valueOf(request.getParameter("showsignatures")); int showavatars = Integer.valueOf(request.getParameter("showavatars")); int showimages = Integer.valueOf(request.getParameter("showimages")); if (showsignatures > 0) { showsignatures = 4; } if (showavatars > 0) { showavatars = 2; } this.putValue(variable, String.valueOf(showsignatures + showavatars + showimages), oldSettings, settings); this.putValue("showimages", String.valueOf(showimages), oldSettings, settings); } else if (Common.matches(variable, "^(maxonlinelist|threadmaxpages|hottopic|starthreshold|maxsigrows|maxsmilies|membermaxpages|visitedforums)$")) { this.putValue(variable, String.valueOf(Common.toDigit(request.getParameter(variable))), oldSettings, settings); } else if (Common.matches(variable, "^(topicperpage|postperpage|memberperpage)$")) { Long value = Long.valueOf(Common.toDigit(request.getParameter(variable))); if (value > 0) { this.putValue(variable, value.toString(), oldSettings, settings); } } else { this.putValue(variable, request.getParameter(variable), oldSettings, settings); } } Map<String, Map<String, String>> customauthorinfo = new HashMap<String, Map<String, String>>(); String[] items = request.getParameter("item").split(","); String types[] = { "left", "special", "menu" }; for (String item : items) { Map<String, String> authorinfo = new HashMap<String, String>(); for (String type : types) { String value = request.getParameter("customauthorinfo[" + item + "][" + type + "]"); if ("1".equals(value)) { authorinfo.put(type, value); } } if (authorinfo.size() > 0) { customauthorinfo.put(item, authorinfo); } } Map data = new HashMap(); data.put(0, customauthorinfo); this.putValue("customauthorinfo", dataParse.combinationChar(data), oldSettings, settings); byte msgquick = Byte.valueOf(request.getParameter("msgforward[quick]")); String message = request.getParameter("msgforward[messages]"); String refreshtime = String .valueOf(Common.toDigit(request.getParameter("msgforward[refreshtime]"))); Map<Integer, String> messages = new TreeMap<Integer, String>(); String mess[] = message.split("\n"); for (int j = 0; j < mess.length; j++) { if (!"".equals(mess[j].trim())) { messages.put(j, mess[j].trim()); } } Map msgforward = new TreeMap(); msgforward.put("messages", messages); msgforward.put("quick", msgquick); msgforward.put("refreshtime", refreshtime); this.putValue("msgforward", dataParse.combinationChar(msgforward), oldSettings, settings); this.updateSettings(settings, oldSettings); servlet.getServletContext().setAttribute("msgforward", msgforward); return this.getForward(mapping, request); } } catch (Exception e) { request.setAttribute("message", e.getMessage()); return mapping.findForward("message"); } Map<String, String> settings = ForumInit.settings; List<Map<String, String>> styleTemplages = dataBaseService .executeQuery("SELECT styleid, name FROM jrun_styles WHERE available=1"); request.setAttribute("styleTemplages", styleTemplages); int showsettings = Integer.valueOf(settings.get("showsettings")); request.setAttribute("showsignatures", (showsettings & 4) == 0); request.setAttribute("showavatars", (showsettings & 2) == 0); request.setAttribute("showimages", (showsettings & 1) == 0); StringBuffer items = new StringBuffer(); Map<String, String> authorinfoitems = new TreeMap<String, String>(); authorinfoitems.put("uid", getMessage(request, "a_setting_uid")); authorinfoitems.put("posts", getMessage(request, "a_setting_posts")); authorinfoitems.put("digest", getMessage(request, "digest")); authorinfoitems.put("credits", getMessage(request, "credits")); items.append("uid,posts,digest,credits"); Map<Integer, Map> extcredits = dataParse.characterParse(settings.get("extcredits_bak"), true); Iterator<Entry<Integer, Map>> extcreditids = extcredits.entrySet().iterator(); while (extcreditids.hasNext()) { Entry<Integer, Map> e = extcreditids.next(); Map extcredit = e.getValue(); Integer extcreditid = e.getKey(); if ("1".equals(extcredit.get("showinthread"))) { authorinfoitems.put("extcredits" + extcreditid, (String) extcredit.get("title")); items.append(",extcredits" + extcreditid); } } List<Map<String, String>> profilefields = dataBaseService.executeQuery( "SELECT fieldid,title FROM jrun_profilefields WHERE available='1' AND invisible='0' AND showinthread='1' ORDER BY displayorder"); if (profilefields != null && profilefields.size() > 0) { for (Map<String, String> profilefield : profilefields) { authorinfoitems.put("field_" + profilefield.get("fieldid"), profilefield.get("title")); items.append(",field_" + profilefield.get("fieldid")); } } authorinfoitems.put("readperm", getMessage(request, "threads_readperm")); authorinfoitems.put("gender", getMessage(request, "gender")); authorinfoitems.put("location", getMessage(request, "location")); authorinfoitems.put("oltime", getMessage(request, "stats_onlinetime")); authorinfoitems.put("regtime", getMessage(request, "a_setting_regtime")); authorinfoitems.put("lastdate", getMessage(request, "a_setting_lastdate")); items.append(",readperm,gender,location,oltime,regtime,lastdate"); Map<String, Map<String, String>> customauthorinfo = (Map<String, Map<String, String>>) dataParse .characterParse(settings.get("customauthorinfo"), true).get(0); request.setAttribute("authorinfoitems", authorinfoitems); request.setAttribute("customauthorinfo", customauthorinfo); request.setAttribute("items", items); Map msgforward = (Map<String, Object>) servlet.getServletContext().getAttribute("msgforward"); StringBuffer message = new StringBuffer(); Map<Integer, String> messages = (Map<Integer, String>) msgforward.get("messages"); if (messages != null && messages.size() > 0) { Set<Entry<Integer, String>> keys = messages.entrySet(); for (Entry<Integer, String> temp : keys) { message.append("\n" + temp.getValue()); } } request.setAttribute("msgforward_message", message.length() > 0 ? message.substring(1) : ""); return mapping.findForward("setting_styles"); }
From source file:com.hanuor.sapphire.utils.intentation.IntentationPrime.java
public Intent jsonToINTENT(String JSONString) throws JSONException { JSONObject jsonObject = new JSONObject(JSONString.toString()); String toArray = jsonObject.get("intentExtras").toString(); String contextName = jsonObject.get("context").toString(); String className = jsonObject.get("className").toString(); Log.d("Insass", className.toString()); Intent setIntent = new Intent(); setIntent.setClassName(contextName, className); HashMap<String, String> extrasHash = new HashMap<String, String>(); JSONObject issueObj = new JSONObject(toArray); for (int i = 0; i < issueObj.length(); i++) { extrasHash.put(issueObj.names().getString(i), issueObj.get(issueObj.names().getString(i)).toString()); }//w w w . j av a 2 s. c om Iterator it = extrasHash.entrySet().iterator(); while (it.hasNext()) { //add conditions and checks here Map.Entry pair = (Map.Entry) it.next(); String currentKey = (String) pair.getKey(); Log.d("HAHA", "" + currentKey); String[] getValuethroughSplit = pair.getValue().toString().split(LibraryDatabase.JSONSEPERATOR); String dataType = getValuethroughSplit[0]; String value = (String) getValuethroughSplit[2]; Log.d("Insamareen", getValuethroughSplit.length + " " + dataType + " " + value.toString()); switch (dataType) { case "String": setIntent.putExtra(currentKey, (String) value); break; case "String[]": String comp1 = value.substring(1, value.length() - 1); String[] comp2 = comp1.split(","); setIntent.putExtra(currentKey, comp2); break; case "Integer": setIntent.putExtra(currentKey, Integer.parseInt(value)); break; case "Double": setIntent.putExtra(currentKey, Double.parseDouble(value)); break; case "double[]": String compDouble1 = value.substring(1, value.length() - 1); String[] compDoub2 = compDouble1.split(","); double[] db = new double[compDoub2.length]; for (int i = 0; i < compDoub2.length; i++) { db[i] = Double.parseDouble(compDoub2[i]); } setIntent.putExtra(currentKey, db); break; case "int[]": String compInt1 = value.substring(1, value.length() - 1); String[] compInt2 = compInt1.split(","); int[] intVal = new int[compInt2.length]; for (int i = 0; i < compInt2.length; i++) { intVal[i] = Integer.parseInt(compInt2[i]); } Log.d("Hankey", intVal.toString()); setIntent.putExtra(currentKey, intVal); break; case "Boolean": setIntent.putExtra(currentKey, Boolean.valueOf(value)); break; case "boolean[]": String compB1 = value.substring(1, value.length() - 1); String[] compB2 = compB1.split(","); boolean[] BVal = new boolean[compB2.length]; for (int i = 0; i < compB2.length; i++) { BVal[i] = Boolean.parseBoolean(compB2[i]); } setIntent.putExtra(currentKey, value); break; case "Char": setIntent.putExtra(currentKey, value); break; case "char[]": String ch1 = value.substring(1, value.length() - 1); String[] ch2 = ch1.split(","); String newS = null; for (int i = 0; i < ch2.length; i++) { newS = newS + ch2[i]; } setIntent.putExtra(currentKey, newS.toCharArray()); break; case "CharSequence": setIntent.putExtra(currentKey, (CharSequence) value); break; case "Charsequence[]": setIntent.putExtra(currentKey, value.toString()); break; case "Byte": setIntent.putExtra(currentKey, Byte.valueOf(value)); break; case "byte[]": String by = value.substring(1, value.length() - 1); String[] by2 = by.split(","); byte[] by3 = new byte[by2.length]; for (int i = 0; i < by2.length; i++) { by3[i] = Byte.parseByte(by2[i]); } setIntent.putExtra(currentKey, by3); break; case "Float": setIntent.putExtra(currentKey, Float.valueOf(value)); break; case "float[]": String fl = value.substring(1, value.length() - 1); String[] fl2 = fl.split(","); float[] fl3 = new float[fl2.length]; for (int i = 0; i < fl2.length; i++) { fl3[i] = Float.parseFloat(fl2[i]); } setIntent.putExtra(currentKey, fl3); break; case "Short": setIntent.putExtra(currentKey, Short.valueOf(value)); break; case "short[]": String sh = value.substring(1, value.length() - 1); String[] sh2 = sh.split(","); short[] sh3 = new short[sh2.length]; for (int i = 0; i < sh2.length; i++) { sh3[i] = Short.parseShort(sh2[i]); } setIntent.putExtra(currentKey, sh3); break; case "Long": setIntent.putExtra(currentKey, Long.valueOf(value)); break; case "long[]": String ll = value.substring(1, value.length() - 1); String[] ll2 = ll.split(","); long[] ll3 = new long[ll2.length]; for (int i = 0; i < ll2.length; i++) { ll3[i] = Long.parseLong(ll2[i]); } setIntent.putExtra(currentKey, ll3); break; case "ArrayListString": Log.d("Hankey", currentKey + " "); String arrL = value.substring(1, value.length() - 1); String[] arrl2 = arrL.split(","); ArrayList<String> arrStr = new ArrayList<String>(); for (int i = 0; i < arrl2.length; i++) { arrStr.add(arrl2[i]); } setIntent.putStringArrayListExtra(currentKey, arrStr); break; case "ArrayListInteger": String arL = value.substring(1, value.length() - 1); String[] arl2 = arL.split(","); ArrayList<Integer> arrInt = new ArrayList<Integer>(); for (int i = 0; i < arl2.length; i++) { arrInt.add(Integer.parseInt(arl2[i])); } setIntent.putIntegerArrayListExtra(currentKey, arrInt); break; default: // whatever } } return setIntent; }
From source file:org.sparkcommerce.openadmin.server.service.persistence.module.provider.BasicFieldPersistenceProvider.java
@Override public FieldProviderResponse populateValue(PopulateValueRequest populateValueRequest, Serializable instance) { if (!canHandlePersistence(populateValueRequest, instance)) { return FieldProviderResponse.NOT_HANDLED; }//from w w w . j a va 2 s. c o m boolean dirty = false; try { Property prop = populateValueRequest.getProperty(); Object origValue = populateValueRequest.getFieldManager().getFieldValue(instance, prop.getName()); switch (populateValueRequest.getMetadata().getFieldType()) { case BOOLEAN: boolean v = Boolean.valueOf(populateValueRequest.getRequestedValue()); prop.setOriginalValue(String.valueOf(origValue)); prop.setOriginalDisplayValue(prop.getOriginalValue()); try { dirty = checkDirtyState(populateValueRequest, instance, v); populateValueRequest.getFieldManager().setFieldValue(instance, populateValueRequest.getProperty().getName(), v); } catch (IllegalArgumentException e) { char c = v ? 'Y' : 'N'; dirty = checkDirtyState(populateValueRequest, instance, c); populateValueRequest.getFieldManager().setFieldValue(instance, populateValueRequest.getProperty().getName(), c); } break; case DATE: Date date = (Date) populateValueRequest.getFieldManager().getFieldValue(instance, populateValueRequest.getProperty().getName()); String oldValue = null; if (date != null) { oldValue = populateValueRequest.getDataFormatProvider().getSimpleDateFormatter().format(date); } prop.setOriginalValue(oldValue); prop.setOriginalDisplayValue(prop.getOriginalValue()); dirty = !StringUtils.equals(oldValue, populateValueRequest.getRequestedValue()); populateValueRequest.getFieldManager().setFieldValue(instance, populateValueRequest.getProperty().getName(), populateValueRequest.getDataFormatProvider() .getSimpleDateFormatter().parse(populateValueRequest.getRequestedValue())); break; case DECIMAL: if (origValue != null) { prop.setOriginalValue(String.valueOf(origValue)); prop.setOriginalDisplayValue(prop.getOriginalValue()); } if (BigDecimal.class.isAssignableFrom(populateValueRequest.getReturnType())) { DecimalFormat format = populateValueRequest.getDataFormatProvider().getDecimalFormatter(); format.setParseBigDecimal(true); BigDecimal val = (BigDecimal) format.parse(populateValueRequest.getRequestedValue()); dirty = checkDirtyState(populateValueRequest, instance, val); populateValueRequest.getFieldManager().setFieldValue(instance, populateValueRequest.getProperty().getName(), val); format.setParseBigDecimal(false); } else { Double val = populateValueRequest.getDataFormatProvider().getDecimalFormatter() .parse(populateValueRequest.getRequestedValue()).doubleValue(); dirty = checkDirtyState(populateValueRequest, instance, val); populateValueRequest.getFieldManager().setFieldValue(instance, populateValueRequest.getProperty().getName(), val); } break; case MONEY: if (origValue != null) { prop.setOriginalValue(String.valueOf(origValue)); prop.setOriginalDisplayValue(prop.getOriginalValue()); } if (BigDecimal.class.isAssignableFrom(populateValueRequest.getReturnType())) { DecimalFormat format = populateValueRequest.getDataFormatProvider().getDecimalFormatter(); format.setParseBigDecimal(true); BigDecimal val = (BigDecimal) format.parse(populateValueRequest.getRequestedValue()); dirty = checkDirtyState(populateValueRequest, instance, val); populateValueRequest.getFieldManager().setFieldValue(instance, populateValueRequest.getProperty().getName(), val); format.setParseBigDecimal(true); } else if (Double.class.isAssignableFrom(populateValueRequest.getReturnType())) { Double val = populateValueRequest.getDataFormatProvider().getDecimalFormatter() .parse(populateValueRequest.getRequestedValue()).doubleValue(); dirty = checkDirtyState(populateValueRequest, instance, val); LOG.warn("The requested Money field is of type double and could result in a loss of precision." + " Spark recommends that the type of all Money fields are 'BigDecimal' in order to avoid" + " this loss of precision that could occur."); populateValueRequest.getFieldManager().setFieldValue(instance, populateValueRequest.getProperty().getName(), val); } else { DecimalFormat format = populateValueRequest.getDataFormatProvider().getDecimalFormatter(); format.setParseBigDecimal(true); BigDecimal val = (BigDecimal) format.parse(populateValueRequest.getRequestedValue()); dirty = checkDirtyState(populateValueRequest, instance, val); populateValueRequest.getFieldManager().setFieldValue(instance, populateValueRequest.getProperty().getName(), new Money(val)); format.setParseBigDecimal(false); } break; case INTEGER: if (origValue != null) { prop.setOriginalValue(String.valueOf(origValue)); prop.setOriginalDisplayValue(prop.getOriginalValue()); } if (int.class.isAssignableFrom(populateValueRequest.getReturnType()) || Integer.class.isAssignableFrom(populateValueRequest.getReturnType())) { dirty = checkDirtyState(populateValueRequest, instance, Integer.valueOf(populateValueRequest.getRequestedValue())); populateValueRequest.getFieldManager().setFieldValue(instance, populateValueRequest.getProperty().getName(), Integer.valueOf(populateValueRequest.getRequestedValue())); } else if (byte.class.isAssignableFrom(populateValueRequest.getReturnType()) || Byte.class.isAssignableFrom(populateValueRequest.getReturnType())) { dirty = checkDirtyState(populateValueRequest, instance, Byte.valueOf(populateValueRequest.getRequestedValue())); populateValueRequest.getFieldManager().setFieldValue(instance, populateValueRequest.getProperty().getName(), Byte.valueOf(populateValueRequest.getRequestedValue())); } else if (short.class.isAssignableFrom(populateValueRequest.getReturnType()) || Short.class.isAssignableFrom(populateValueRequest.getReturnType())) { dirty = checkDirtyState(populateValueRequest, instance, Short.valueOf(populateValueRequest.getRequestedValue())); populateValueRequest.getFieldManager().setFieldValue(instance, populateValueRequest.getProperty().getName(), Short.valueOf(populateValueRequest.getRequestedValue())); } else if (long.class.isAssignableFrom(populateValueRequest.getReturnType()) || Long.class.isAssignableFrom(populateValueRequest.getReturnType())) { dirty = checkDirtyState(populateValueRequest, instance, Long.valueOf(populateValueRequest.getRequestedValue())); populateValueRequest.getFieldManager().setFieldValue(instance, populateValueRequest.getProperty().getName(), Long.valueOf(populateValueRequest.getRequestedValue())); } break; case CODE: // **NOTE** We want to fall through in this case, do not break. setNonDisplayableValues(populateValueRequest); case STRING: case HTML_BASIC: case HTML: case EMAIL: if (origValue != null) { prop.setOriginalValue(String.valueOf(origValue)); prop.setOriginalDisplayValue(prop.getOriginalValue()); } dirty = checkDirtyState(populateValueRequest, instance, populateValueRequest.getRequestedValue()); populateValueRequest.getFieldManager().setFieldValue(instance, populateValueRequest.getProperty().getName(), populateValueRequest.getRequestedValue()); break; case FOREIGN_KEY: { if (origValue != null) { prop.setOriginalValue(String.valueOf(origValue)); } Serializable foreignInstance; if (StringUtils.isEmpty(populateValueRequest.getRequestedValue())) { foreignInstance = null; } else { if (SupportedFieldType.INTEGER.toString() .equals(populateValueRequest.getMetadata().getSecondaryType().toString())) { foreignInstance = populateValueRequest.getPersistenceManager().getDynamicEntityDao() .retrieve(Class.forName(populateValueRequest.getMetadata().getForeignKeyClass()), Long.valueOf(populateValueRequest.getRequestedValue())); } else { foreignInstance = populateValueRequest.getPersistenceManager().getDynamicEntityDao() .retrieve(Class.forName(populateValueRequest.getMetadata().getForeignKeyClass()), populateValueRequest.getRequestedValue()); } } if (Collection.class.isAssignableFrom(populateValueRequest.getReturnType())) { Collection collection; try { collection = (Collection) populateValueRequest.getFieldManager().getFieldValue(instance, populateValueRequest.getProperty().getName()); } catch (FieldNotAvailableException e) { throw new IllegalArgumentException(e); } if (!collection.contains(foreignInstance)) { collection.add(foreignInstance); dirty = true; } } else if (Map.class.isAssignableFrom(populateValueRequest.getReturnType())) { throw new IllegalArgumentException("Map structures are not supported for foreign key fields."); } else { dirty = checkDirtyState(populateValueRequest, instance, foreignInstance); populateValueRequest.getFieldManager().setFieldValue(instance, populateValueRequest.getProperty().getName(), foreignInstance); } break; } case ADDITIONAL_FOREIGN_KEY: { Serializable foreignInstance; if (StringUtils.isEmpty(populateValueRequest.getRequestedValue())) { foreignInstance = null; } else { if (SupportedFieldType.INTEGER.toString() .equals(populateValueRequest.getMetadata().getSecondaryType().toString())) { foreignInstance = populateValueRequest.getPersistenceManager().getDynamicEntityDao() .retrieve(Class.forName(populateValueRequest.getMetadata().getForeignKeyClass()), Long.valueOf(populateValueRequest.getRequestedValue())); } else { foreignInstance = populateValueRequest.getPersistenceManager().getDynamicEntityDao() .retrieve(Class.forName(populateValueRequest.getMetadata().getForeignKeyClass()), populateValueRequest.getRequestedValue()); } } // Best guess at grabbing the original display value String fkProp = populateValueRequest.getMetadata().getForeignKeyDisplayValueProperty(); Object origDispVal = null; if (origValue != null) { if (AdminMainEntity.MAIN_ENTITY_NAME_PROPERTY.equals(fkProp)) { if (origValue instanceof AdminMainEntity) { origDispVal = ((AdminMainEntity) origValue).getMainEntityName(); } } else { origDispVal = populateValueRequest.getFieldManager().getFieldValue(origValue, fkProp); } } if (origDispVal != null) { prop.setOriginalDisplayValue(String.valueOf(origDispVal)); Session session = populateValueRequest.getPersistenceManager().getDynamicEntityDao() .getStandardEntityManager().unwrap(Session.class); prop.setOriginalValue(String.valueOf(session.getIdentifier(foreignInstance))); } if (Collection.class.isAssignableFrom(populateValueRequest.getReturnType())) { Collection collection; try { collection = (Collection) populateValueRequest.getFieldManager().getFieldValue(instance, populateValueRequest.getProperty().getName()); } catch (FieldNotAvailableException e) { throw new IllegalArgumentException(e); } if (!collection.contains(foreignInstance)) { collection.add(foreignInstance); dirty = true; } } else if (Map.class.isAssignableFrom(populateValueRequest.getReturnType())) { throw new IllegalArgumentException("Map structures are not supported for foreign key fields."); } else { dirty = checkDirtyState(populateValueRequest, instance, foreignInstance); populateValueRequest.getFieldManager().setFieldValue(instance, populateValueRequest.getProperty().getName(), foreignInstance); } break; } case ID: if (populateValueRequest.getSetId()) { switch (populateValueRequest.getMetadata().getSecondaryType()) { case INTEGER: dirty = checkDirtyState(populateValueRequest, instance, Long.valueOf(populateValueRequest.getRequestedValue())); populateValueRequest.getFieldManager().setFieldValue(instance, populateValueRequest.getProperty().getName(), Long.valueOf(populateValueRequest.getRequestedValue())); break; case STRING: dirty = checkDirtyState(populateValueRequest, instance, populateValueRequest.getRequestedValue()); populateValueRequest.getFieldManager().setFieldValue(instance, populateValueRequest.getProperty().getName(), populateValueRequest.getRequestedValue()); break; } } break; } } catch (Exception e) { throw new PersistenceException(e); } populateValueRequest.getProperty().setIsDirty(dirty); return FieldProviderResponse.HANDLED; }