List of usage examples for java.util ArrayList get
public E get(int index)
From source file:edu.oregonstate.eecs.mcplan.util.Csv.java
public static RealMatrix readMatrix(final File f) { try {/*from w w w. j av a2 s .c om*/ final BufferedReader r = new BufferedReader(new FileReader(f)); String line; final ArrayList<String[]> rows = new ArrayList<String[]>(); while (true) { line = r.readLine(); if (line == null) { break; } rows.add(line.split(",")); } final Array2DRowRealMatrix M = new Array2DRowRealMatrix(rows.size(), rows.get(0).length); for (int i = 0; i < rows.size(); ++i) { final String[] row = rows.get(i); for (int j = 0; j < row.length; ++j) { M.setEntry(i, j, Double.parseDouble(row[j])); } } return M; } catch (final Exception ex) { throw new RuntimeException(ex); } }
From source file:gov.nih.nci.cabig.caaers.web.utils.WebUtils.java
public static int[] getIntParameters(HttpServletRequest request, String param) { ArrayList<Integer> values = new ArrayList<Integer>(); int ival = Integer.parseInt(getStringParameter(request, param)); values.add(ival);//from w w w . j av a 2s . com int[] ivals = new int[values.size()]; for (int i = 0; i < ivals.length; i++) { ivals[i] = values.get(i); } return ivals; }
From source file:edu.lafayette.metadb.model.dataman.DataExporter.java
/** * Export a project's attributes.//from w ww. ja va 2s .c o m * @param projectName The project name. * @param delimiter The delimiter to use. * @param encoder The character encoding to use. * @param technical A flag indicating whether to include technical attributes. * @return A String[] representing headers for the export file. */ public static String[] exportAttributes(String projectName, char delimiter, String encoder, boolean technical) { ArrayList attrList = null; attrList = AdminDescAttributesDAO.getAdminDescAttributes(projectName, Global.MD_TYPE_DESC); attrList.addAll(AdminDescAttributesDAO.getAdminDescAttributes(projectName, Global.MD_TYPE_ADMIN)); if (technical) attrList.addAll(TechAttributesDAO.getTechAttributes(projectName)); String[] out = new String[attrList.size()]; for (int i = 0; i < out.length; i++) try { String label = ((Attribute) attrList.get(i)).getLabel(); out[i] = StringUtils.trimToEmpty(new String( (((Attribute) attrList.get(i)).getElement() + (label.equals("") ? "" : "." + label)) .getBytes("UTF-8"), encoder).replace('\t', ' ')); } catch (UnsupportedEncodingException e) { MetaDbHelper.logEvent(e); out[i] = ((Attribute) attrList.get(i)).getElement() + "." + ((Attribute) attrList.get(i)).getLabel(); } return out; }
From source file:com.android.W3T.app.network.NetworkUtil.java
public static boolean syncUnsentReceipts() { ArrayList<Receipt> receipts = ReceiptsManager.getUnSentReceipts(); int num = receipts.size(); for (int i = 0; i < num; i++) { int ret = NetworkUtil.attemptSendReceipt(METHOD_SEND_RECEIPT, receipts.get(i)); if (ret > 0) { String detailstr = null; detailstr = NetworkUtil.attemptGetReceipt(METHOD_RECEIVE_RECEIPT_DETAIL, String.valueOf(ret)); // String itemsstr = null; // itemsstr = NetworkUtil.attemptGetReceipt(METHOD_RECEIVE_RECEIPT_ITEMS, String.valueOf(ret)); String time = null;// ww w .j av a 2 s . co m try { time = (new JSONArray(detailstr)).getJSONObject(0).getString("receipt_time"); } catch (JSONException e) { e.printStackTrace(); } receipts.get(i).getBasicInfo().setTime(time); receipts.get(i).getBasicInfo().setId(String.valueOf(ret)); receipts.get(i).setWhere(FROM_DB); } else { return false; } } return true; }
From source file:mitm.application.djigzo.DjigzoConfigurator.java
@SuppressWarnings("unchecked") private static void initializeRegistry() { /*/*from w w w. j av a2 s.c o m*/ * Load additional spring config files and sort them. */ Collection<File> unsortedConfigFiles = FileUtils.listFiles(new File(additionalSpringConfigDir), new String[] { "xml" }, true /* recursive */); ArrayList<File> sortedConfigFiles = new ArrayList<File>(unsortedConfigFiles); Collections.sort(sortedConfigFiles, DefaultFileComparator.DEFAULT_COMPARATOR); String[] configFiles = new String[sortedConfigFiles.size() + 1]; /* * The main config should be loaded first */ configFiles[0] = springConfig; for (int i = 1; i < configFiles.length; i++) { configFiles[i] = sortedConfigFiles.get(i - 1).getPath(); } logger.info("spring config files: {}", StringUtils.join(configFiles, ", ")); DjigzoServiceRegistry.initialize(configFiles); }
From source file:com.ibm.bi.dml.runtime.controlprogram.parfor.opt.OptimizationWrapper.java
/** * //from ww w . ja v a 2s .co m * @param prog * @param rtprog * @throws LanguageException */ private static void findParForProgramBlocks(DMLProgram prog, Program rtprog, HashMap<Long, ParForStatementBlock> sbs, HashMap<Long, ParForProgramBlock> pbs) throws LanguageException { //handle function program blocks HashMap<String, FunctionProgramBlock> fpbs = rtprog.getFunctionProgramBlocks(); for (Entry<String, FunctionProgramBlock> entry : fpbs.entrySet()) { String[] keypart = entry.getKey().split(Program.KEY_DELIM); String namespace = keypart[0]; String name = keypart[1]; ProgramBlock pb = entry.getValue(); StatementBlock sb = prog.getFunctionStatementBlock(namespace, name); //recursive find rfindParForProgramBlocks(sb, pb, sbs, pbs); } //handle actual program blocks ArrayList<ProgramBlock> tpbs = rtprog.getProgramBlocks(); for (int i = 0; i < tpbs.size(); i++) { ProgramBlock pb = tpbs.get(i); StatementBlock sb = prog.getStatementBlock(i); //recursive find rfindParForProgramBlocks(sb, pb, sbs, pbs); } }
From source file:ca.uhn.hl7v2.testpanel.util.compare.Hl7V2MessageCompare.java
private static boolean nameIsEqual(ArrayList<String> theNames1, ArrayList<String> theNames2, int i1, int i2) { String name1 = theNames1.get(i1); if (!name1.contains("_") && name1.length() > 3) { name1 = name1.substring(0, 3);/* w w w . j ava 2 s . co m*/ } String name2 = theNames2.get(i2); if (!name2.contains("_") && name2.length() > 3) { name2 = name2.substring(0, 3); } return StringUtils.equals(name1, name2); }
From source file:com.clutch.ClutchSync.java
public static void background(final ClutchStats clutchStats) { ArrayList<StatRow> logs = clutchStats.getLogs(); if (logs.size() == 0) { return;/* w w w . j av a2s .c o m*/ } final StatRow lastRow = logs.get(logs.size() - 1); JSONArray jsonLogs = new JSONArray(); for (StatRow row : logs) { JSONObject rowObj = new JSONObject(); try { rowObj.put("uuid", row.uuid); rowObj.put("ts", row.ts); rowObj.put("action", row.action); rowObj.put("data", row.data); } catch (JSONException e1) { Log.e(TAG, "Could not properly encode the logs into JSON for upload to Clutch. Discarding the row."); // TODO: Don't discard the row. continue; } jsonLogs.put(rowObj); } HashMap<String, JSONArray> params = new HashMap<String, JSONArray>(); params.put("logs", jsonLogs); ClutchAPIClient.callMethod("stats", params, new ClutchAPIResponseHandler() { @Override public void onSuccess(JSONObject response) { if ("ok".equals(response.optString("status"))) { clutchStats.deleteLogs(lastRow.ts); } else { Log.e(TAG, "Failed to send the Clutch stats logs to the server."); } } @Override public void onFailure(Throwable e, JSONObject errorResponse) { Log.e(TAG, "Failed to send logs to Clutch: " + errorResponse); } }); }
From source file:com.clustercontrol.jobmanagement.util.JobKickFilterPropertyUtil.java
/** * DTO?????/* ww w .j ava2 s. c o m*/ * * @param property * @return */ public static JobKickFilterInfo property2dto(Property property) { JobKickFilterInfo info = new JobKickFilterInfo(); ArrayList<?> values = null; // ID values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.JOBKICK_ID); if (!"".equals(values.get(0))) { info.setJobkickId((String) values.get(0)); } // ?? values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.JOBKICK_NAME); if (!"".equals(values.get(0))) { info.setJobkickName((String) values.get(0)); } // values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.JOBKICK_TYPE); if (!"".equals(values.get(0))) { info.setJobkickType((Integer) JobKickTypeMessage.stringToType((String) values.get(0))); } // ID values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.JOBUNIT_ID); if (!"".equals(values.get(0))) { info.setJobunitId((String) values.get(0)); } // ID values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.JOB_ID); if (!"".equals(values.get(0))) { info.setJobId((String) values.get(0)); } // ID values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.CALENDAR_ID); if (!"".equals(values.get(0))) { info.setCalendarId((String) values.get(0)); } // Boolean validFlg = null; values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.VALID_FLG); if (!"".equals(values.get(0))) { if (ValidMessage.STRING_VALID.equals(values.get(0))) { validFlg = true; } else { validFlg = false; } } info.setValidFlg(validFlg); //?? values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.REG_USER); if (!"".equals(values.get(0))) { info.setRegUser((String) values.get(0)); } //?(From) Timestamp regFromDate = null; values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.REG_FROM_DATE); if (values.get(0) instanceof Date) { regFromDate = new Timestamp(((Date) values.get(0)).getTime()); regFromDate.setNanos(999999999); info.setRegFromDate(regFromDate.getTime()); } //?(To) Timestamp regToDate = null; values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.REG_TO_DATE); if (values.get(0) instanceof Date) { regToDate = new Timestamp(((Date) values.get(0)).getTime()); regToDate.setNanos(999999999); info.setRegToDate(regToDate.getTime()); } // values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.UPDATE_USER); if (!"".equals(values.get(0))) { info.setUpdateUser((String) values.get(0)); } //(From) Timestamp updateFromDate = null; values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.UPDATE_FROM_DATE); if (values.get(0) instanceof Date) { updateFromDate = new Timestamp(((Date) values.get(0)).getTime()); updateFromDate.setNanos(999999999); info.setUpdateFromDate(updateFromDate.getTime()); } //(To) Timestamp updateToDate = null; values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.UPDATE_TO_DATE); if (values.get(0) instanceof Date) { updateToDate = new Timestamp(((Date) values.get(0)).getTime()); updateToDate.setNanos(999999999); info.setUpdateToDate(updateToDate.getTime()); } //ID values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.OWNER_ROLE_ID); if (!"".equals(values.get(0))) { info.setOwnerRoleId((String) values.get(0)); } return info; }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Usuario.Read.java
protected static void quitarDocenteTaller(HttpServletRequest request, HttpServletResponse response) throws IOException { ArrayList r = CtrlUsuario.abandonarTallerDocente(Integer.parseInt(request.getParameter("1")), Integer.parseInt(request.getParameter("2"))); //1. idUsuario, 2. idEvento response.setContentType("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); if (r.get(0) == "error") { JSONObject obj = new JSONObject(); obj.put("isError", true); obj.put("errorDescrip", r.get(1)); out.print(obj);/*from w w w.j ava 2 s. c o m*/ } else if (r.get(0) == "isExitoso") { JSONObject obj = new JSONObject(); obj.put("Exitoso", true); out.print(obj); } else { Util.errordeRespuesta(r, out); } }