List of usage examples for java.util ArrayList subList
public List<E> subList(int fromIndex, int toIndex)
From source file:org.blockartistry.DynSurround.client.handlers.EnvironStateHandler.java
@SubscribeEvent public void serverDataEvent(final ServerDataEvent event) { final ArrayList<String> data = new ArrayList<String>(); final int diff = event.total - event.free; data.add(TextFormatting.GOLD + "Server Information"); data.add(String.format("Mem: %d%% %03d/%3dMB", diff * 100 / event.max, diff, event.max)); data.add(String.format("Allocated: %d%% %3dMB", event.total * 100 / event.max, event.total)); final int tps = (int) Math.min(1000.0D / event.meanTickTime, 20.0D); data.add(String.format("Ticktime Overall:%s %5.3fms (%d TPS)", getTpsFormatPrefix(tps), event.meanTickTime, tps));// ww w. ja v a2 s . c o m event.dimTps.forEachEntry(new TIntDoubleProcedure() { @Override public boolean execute(int a, double b) { final String dimName = DimensionManager.getProviderType(a).getName(); final int tps = (int) Math.min(1000.0D / b, 20.0D); data.add(String.format("%s (%d):%s %7.3fms (%d TPS)", dimName, a, getTpsFormatPrefix(tps), b, tps)); return true; } }); Collections.sort(data.subList(4, data.size())); this.serverDataReport = data; }
From source file:org.dmfs.webcal.utils.billing.IabHelper.java
int querySkuDetails(String itemType, Inventory inv, List<String> moreSkus) throws RemoteException, JSONException { logDebug("Querying SKU details."); Context context = mContext;//from w w w. j a v a 2 s.co m IInAppBillingService service = mService; if (context == null || service == null) { return IABHELPER_BAD_RESPONSE; } ArrayList<String> skuList = new ArrayList<String>(); skuList.addAll(inv.getAllOwnedSkus(itemType)); if (moreSkus != null) { for (String sku : moreSkus) { if (!skuList.contains(sku)) { skuList.add(sku); } } } if (skuList.size() == 0) { logDebug("queryPrices: nothing to do because there are no SKUs."); return BILLING_RESPONSE_RESULT_OK; } while (skuList.size() > 0) { ArrayList<String> skuSubList = new ArrayList<String>(skuList.subList(0, Math.min(19, skuList.size()))); skuList.removeAll(skuSubList); Bundle querySkus = new Bundle(); querySkus.putStringArrayList(GET_SKU_DETAILS_ITEM_LIST, skuSubList); Bundle skuDetails = service.getSkuDetails(3, context.getPackageName(), itemType, querySkus); if (!skuDetails.containsKey(RESPONSE_GET_SKU_DETAILS_LIST)) { int response = getResponseCodeFromBundle(skuDetails); if (response != BILLING_RESPONSE_RESULT_OK) { logDebug("getSkuDetails() failed: " + getResponseDesc(response)); return response; } else { logError("getSkuDetails() returned a bundle with neither an error nor a detail list."); return IABHELPER_BAD_RESPONSE; } } ArrayList<String> responseList = skuDetails.getStringArrayList(RESPONSE_GET_SKU_DETAILS_LIST); for (String thisResponse : responseList) { SkuDetails d = new SkuDetails(itemType, thisResponse); logDebug("Got sku details: " + d); inv.addSkuDetails(d); } } return BILLING_RESPONSE_RESULT_OK; }
From source file:com.uzmap.pkg.uzmodules.UISearchBar.SearchBarActivity.java
public void trimHistroyList(int historyCount) { ArrayList<String> tmpList = new ArrayList<String>(); @SuppressWarnings("unchecked") Map<String, String> map = (Map<String, String>) mPref.getAll(); if (map != null) { if (map.size() != 0) { for (int i = 0; i <= map.size(); i++) { for (Entry<String, String> iterable_element : map.entrySet()) { String key = iterable_element.getKey(); if ((i + "").equals(key)) { String txt = iterable_element.getValue(); tmpList.add(txt); }/*from www .j av a 2 s . c om*/ } } } } int tmpSize = tmpList.size(); if (config.historyCount > tmpSize) { return; } List<String> subList = tmpList.subList(tmpSize - config.historyCount, tmpSize); editor.clear(); editor.commit(); for (int i = 0; i < subList.size(); i++) { editor.putString(i + 1 + "", subList.get(i)); editor.commit(); } }
From source file:org.sakaiproject.tool.assessment.ui.bean.evaluation.TotalScoresBean.java
protected void init() { defaultSearchString = ContextUtil.getLocalizedString( "org.sakaiproject.tool.assessment.bundle.EvaluationMessages", "search_default_student_search_string"); if (searchString == null) { searchString = defaultSearchString; }/*from ww w .j a v a 2s . com*/ // Get allAgents only at the first time if (allAgents == null) { allAgents = getAllAgents(); } // For anonymous grading, we want to take out the records that has not been submitted if ("true".equalsIgnoreCase(anonymous)) { Iterator iter = allAgents.iterator(); ArrayList anonymousAgents = new ArrayList(); while (iter.hasNext()) { AgentResults agentResult = (AgentResults) iter.next(); if (agentResult.getSubmittedDate() != null && agentResult.getAssessmentGradingId().intValue() != -1) { anonymousAgents.add(agentResult); } } allAgents = anonymousAgents; } ArrayList matchingAgents; if (isFilteredSearch()) { matchingAgents = findMatchingAgents(searchString); } else { matchingAgents = allAgents; } scoreDataRows = matchingAgents.size(); ArrayList newAgents; if (maxDisplayedScoreRows == 0) { newAgents = matchingAgents; } else { int nextPageRow = Math.min(firstScoreRow + maxDisplayedScoreRows, scoreDataRows); newAgents = new ArrayList(matchingAgents.subList(firstScoreRow, nextPageRow)); log.debug("init(): subList " + firstScoreRow + ", " + nextPageRow); } agents = newAgents; }
From source file:com.hygenics.parser.KVParser.java
private void sendToDb(ArrayList<String> json, boolean split) { if (json.size() > 0) log.info("Records to Add: " + json.size()); if (split) {/*from ww w . j av a 2 s.co m*/ ForkJoinPool f2 = new ForkJoinPool( (Runtime.getRuntime().availableProcessors() + ((int) Math.ceil(procs * qnums)))); ArrayList<String> l; int size = (int) Math.ceil(json.size() / qnums); for (int conn = 0; conn < qnums; conn++) { l = new ArrayList<String>(); if (((conn + 1) * size) < json.size()) { l.addAll(json.subList((conn * size), ((conn + 1) * size))); } else { l.addAll(json.subList((conn * size), json.size())); } f2.execute(new SplitPost(template, l)); } int w = 0; while (f2.isQuiescent() == false && f2.getActiveThreadCount() > 0) { w++; } f2.shutdown(); int incrementor = 0; while (f2.isShutdown() == false && f2.getActiveThreadCount() > 0 && f2.isQuiescent() == false) { incrementor++; try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } log.info("Shutting Down" + incrementor); } l = null; f2 = null; } else { for (String j : json) { boolean valid = false; try { Json.read(j); valid = true; } catch (Exception e) { log.info("ERROR: JSON NOT FORMATTED PROPERLY"); System.out.println(j); } try { this.template.postSingleJson(j); } catch (Exception e) { log.info("Failed to Post"); log.error(j); e.printStackTrace(); } } } }
From source file:org.apache.sysml.runtime.compress.CompressedMatrixBlock.java
private static void leftMultByTransposeSelf(ArrayList<ColGroup> groups, MatrixBlock result, int gl, int gu) throws DMLRuntimeException { final int numRows = groups.get(0).getNumRows(); final int numGroups = groups.size(); //preallocated dense matrix block MatrixBlock lhs = new MatrixBlock(numRows, 1, false); lhs.allocateDenseBlock();//from w ww . ja v a 2 s.co m //approach: for each colgroup, extract uncompressed columns one at-a-time //vector-matrix multiplies against remaining col groups for (int i = gl; i < gu; i++) { //get current group and relevant col groups ColGroup group = groups.get(i); int[] ixgroup = group.getColIndices(); List<ColGroup> tmpList = groups.subList(i, numGroups); //for all uncompressed lhs columns vectors for (int j = 0; j < ixgroup.length; j++) { //decompress single column lhs.reset(numRows, 1, false); group.decompressToBlock(lhs, j); if (!lhs.isEmptyBlock(false)) { //compute vector-matrix partial result MatrixBlock tmpret = new MatrixBlock(1, result.getNumColumns(), false); leftMultByVectorTranspose(tmpList, lhs, tmpret, true); //write partial results (disjoint non-zeros) LinearAlgebraUtils.copyNonZerosToRowCol(result, tmpret, ixgroup[j]); } } } }
From source file:istata.service.StataService.java
/** * produce a list with possible sidebar suggestions for the current context * /*from w w w . j av a 2 s. c om*/ * @param filter * @param pos * @param from * @param to * @return */ public List<ContentLine> suggest(String filter, int pos, int from, int to) { LinkedHashSet<ContentLine> res = new LinkedHashSet<ContentLine>(); ArrayList<ContentLine> rescmd = new ArrayList<ContentLine>(); { int i = 0; for (ContentLine cl : cmdRepository.findAll()) { if (cl.getContent().startsWith(filter)) { ContentLine srl = new ContentLine(); Map<String, Object> model = new HashMap<String, Object>(); model.put("cmd", cl); model.put("from", from); model.put("to", to); String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "items/cmd.vm", "UTF-8", model); srl.setContent(text); srl.setLine(i++); rescmd.add(srl); } } } Collections.reverse(rescmd); res.addAll(rescmd.subList(0, Math.min(10, rescmd.size()))); List<ContentLine> out = new ArrayList<ContentLine>(); try { IStata stata = stataFactory.getInstance(); /* * get files */ Collection<ContentLine> filesNames = filteredFiles(filter, pos, from, to); res.addAll(filesNames); /* * get VARS, should be a mothod call probably */ // current token StringBuilder token = new StringBuilder(""); StringBuilder rest = new StringBuilder(filter); int p = (pos == -1 || pos > filter.length()) ? filter.length() : pos; char ch = 'x'; while (p > 0 && (CharUtils.isAsciiAlphanumeric(ch = filter.charAt(p - 1)) || ch == '_')) { token.insert(0, ch); rest.deleteCharAt(p - 1); p--; } // remove rest of potential token while (rest.length() > 0 && p > 0 && p < rest.length() && (CharUtils.isAsciiAlphanumeric(rest.charAt(p)) || rest.charAt(p) == '_')) { rest.deleteCharAt(p); } String t = token.toString(); List<StataVar> list = new ArrayList<StataVar>(); List<StataVar> listfull = stata.getVars("", false); if (t.length() > 0) { for (StataVar sv : listfull) { if (sv.getName().startsWith(t)) { list.add(sv); } } } else { list = listfull; } for (int i = 0; i < list.size(); i++) { ContentLine srl = new ContentLine(); srl.setLine(i + 100); String vname = list.get(i).getName(); String cl = new StringBuilder(rest).insert(p, " ").insert(p, vname).toString(); try { String cc = URLEncoder.encode(cl, "UTF-8"); Map<String, Object> model = new HashMap<String, Object>(); model.put("var", vname); model.put("repl", cc); model.put("focuspos", p + 1 + vname.length()); model.put("from", from); model.put("to", to); String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "items/var.vm", "UTF-8", model); srl.setContent(text); res.add(srl); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } catch (StataNotRunningException e) { ContentLine srl = new ContentLine(); srl.setLine(1); srl.setContent( "<div class='list-group-item sidebaritem error' >" + "Stata not running, you can try to start " + "an instance by clicking " + "<a target='_blank' href='/start'>here</a>" + "</div>"); out.add(srl); } catch (StataBusyException e1) { ContentLine srl = new ContentLine(); srl.setLine(1); srl.setContent("<div class='list-group-item sidebaritem error' >" + "Stata appears to by busy or not running, you can try to " + "start a new instance by clicking " + "<a target='_blank' href='/start'>here</a> " + "or wait for the current job to complete</div>"); out.add(srl); } out.addAll(res); return out; }
From source file:com.cdvdev.subscriptiondemo.helpers.IabHelper.java
int querySkuDetails(String itemType, Inventory inv, List<String> moreSkus) throws RemoteException, JSONException { logDebug("Querying SKU details."); ArrayList<String> skuList = new ArrayList<String>(); skuList.addAll(inv.getAllOwnedSkus(itemType)); if (moreSkus != null) { for (String sku : moreSkus) { if (!skuList.contains(sku)) { skuList.add(sku);/*from ww w . j a va 2s. co m*/ } } } if (skuList.size() == 0) { logDebug("queryPrices: nothing to do because there are no SKUs."); return BILLING_RESPONSE_RESULT_OK; } // Split the sku list in blocks of no more than 20 elements. ArrayList<ArrayList<String>> packs = new ArrayList<ArrayList<String>>(); ArrayList<String> tempList; int n = skuList.size() / 20; int mod = skuList.size() % 20; for (int i = 0; i < n; i++) { tempList = new ArrayList<String>(); for (String s : skuList.subList(i * 20, i * 20 + 20)) { tempList.add(s); } packs.add(tempList); } if (mod != 0) { tempList = new ArrayList<String>(); for (String s : skuList.subList(n * 20, n * 20 + mod)) { tempList.add(s); } packs.add(tempList); } for (ArrayList<String> skuPartList : packs) { Bundle querySkus = new Bundle(); querySkus.putStringArrayList(GET_SKU_DETAILS_ITEM_LIST, skuPartList); Bundle skuDetails = mIInAppBillingService.getSkuDetails(3, mContext.getPackageName(), itemType, querySkus); if (!skuDetails.containsKey(RESPONSE_GET_SKU_DETAILS_LIST)) { int response = getResponseCodeFromBundle(skuDetails); if (response != BILLING_RESPONSE_RESULT_OK) { logDebug("getSkuDetails() failed: " + getResponseDesc(response)); return response; } else { logError("getSkuDetails() returned a bundle with neither an error nor a detail list."); return IABHELPER_BAD_RESPONSE; } } ArrayList<String> responseList = skuDetails.getStringArrayList(RESPONSE_GET_SKU_DETAILS_LIST); for (String thisResponse : responseList) { SkuDetails d = new SkuDetails(itemType, thisResponse); logDebug("Got sku details: " + d); inv.addSkuDetails(d); } } return BILLING_RESPONSE_RESULT_OK; }
From source file:com.hygenics.parser.BreakMultiple.java
/** * Post to db//from w w w . j av a 2s .c o m * * @param json * @param split */ public void postToDb(ArrayList<String> json, boolean split) { log.info("Posting " + json.size() + " Records"); if (split) { ForkJoinPool f2 = new ForkJoinPool( (Runtime.getRuntime().availableProcessors() + ((int) Math.ceil(procnum * sqlnum)))); ArrayList<String> l; int size = (int) Math.ceil(json.size() / qnum); for (int conn = 0; conn < qnum; conn++) { l = new ArrayList<String>(); if (((conn + 1) * size) < json.size()) { l.addAll(json.subList((conn * size), ((conn + 1) * size))); } else { l.addAll(json.subList((conn * size), (json.size() - 1))); f2.execute(new SplitPost(template, l)); break; } f2.execute(new SplitPost(template, l)); } try { f2.awaitTermination(termtime, TimeUnit.MILLISECONDS); } catch (InterruptedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } f2.shutdown(); int incrementor = 0; while (f2.isShutdown() == false) { incrementor++; try { Thread.sleep(100); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } log.info("Shutting Down" + incrementor); } l = null; f2 = null; } else { log.info("Singlethread"); this.template.postJsonDatawithTable(json); } }
From source file:idgs.parse.OperatorParser.java
/** * parse group operator/* w ww .j a v a 2 s .c om*/ * 1. Aggregate with not group, like "select sum(c) from t". * 2. Group by with column witch is not key. * 3. Group by with key. * @return 1. ReduceByKeyTransformerOperator[GroupTransformerOperator] * 2. ReduceByKeyTransformerOperator * 3. ReduceTransformerOperator * 4. ReduceTransformerOperator[GroupTransformerOperator] * 5. HashjoinTransformerOperator[ReduceTransformerOperator[GroupTransformerOperator], ..., ReduceTransformerOperator, ...] * @throws IdgsParseException */ private IdgsOperator genGroupByPlan(Operator<? extends OperatorDesc> operator, List<IdgsOperator> children) throws IdgsParseException { IdgsOperator op = children.get(0); GroupByOperator groupOp = (GroupByOperator) operator; Operator<? extends OperatorDesc> lastOperator = operator.getParentOperators().get(0); if (lastOperator instanceof ReduceSinkOperator) { ReduceSinkOperator reduceOp = (ReduceSinkOperator) operator.getParentOperators().get(0); ArrayList<ExprNodeDesc> grpKeyCols = groupOp.getConf().getKeys(); ArrayList<ExprNodeDesc> keyCols = reduceOp.getConf().getKeyCols(); IdgsOperator grpOperator = null; if (grpKeyCols.isEmpty() && keyCols.isEmpty()) { // sql has no group by and distinct grpOperator = genGroupByPlanWithNoKey(operator, op); } else if (grpKeyCols.isEmpty() && !keyCols.isEmpty()) { // sql has no group by but has distinct grpOperator = genGroupByPlanWithDistinct(operator, op); } else if (isReuseKey(op, keyCols.subList(0, grpKeyCols.size()))) { // sql has group by and group by field is key grpOperator = genGroupByPlanReuseKey(operator, op); } else { // sql has group by and group by field is not key grpOperator = genGroupByPlan(operator, op); } genFilterAndSelectExpr(operator, grpOperator); return grpOperator; } else { LOG.error("Cannot parse GroupByOperator without ReduceSinkOperator, not supported yet."); throw new IdgsParseException("Not supported yet."); } }