List of usage examples for java.util ArrayList size
int size
To view the source code for java.util ArrayList size.
Click Source Link
From source file:mlflex.helper.MathUtilities.java
/** Calculates the median value from a list of numeric values. * * @param values List of numeric values/* www. ja va 2 s. c o m*/ * @return Median value */ public static double Median(ArrayList<Double> values) { Collections.sort(values); if (values.size() % 2 == 1) return values.get((values.size() + 1) / 2 - 1); else { double lower = values.get(values.size() / 2 - 1); double upper = values.get(values.size() / 2); return (lower + upper) / 2.0; } }
From source file:net.swas.explorer.httpprofile.Profile.java
/** * @param fileName fileName of HTTP dump file * @param context context is for capturing the knowledge base configuration. * @return boolean//w ww . ja v a 2 s . c o m * @throws IOException * @throws HttpException * @throws SQLException */ public static boolean parseRequestByFile(String fileName, ServletContext context) throws IOException, HttpException, SQLException { log.info("In Parse Request by file"); boolean check = false; HttpMessageParser requestParser; List<HttpRequest> request = new ArrayList<HttpRequest>(); @SuppressWarnings("resource") BufferedReader br = new BufferedReader(new FileReader(fileName)); List<String> requestList = new ArrayList<String>(); String requestString = ""; String line = ""; line = br.readLine(); int i = 0; while (line != null) { if (line.startsWith("GET") || line.startsWith("POST")) { if (i == 0) { i = 1; } else { requestList.add(requestString); } requestString = ""; requestString = " " + requestString + line + "\r\n"; } else { if (line.contains(":")) { requestString = requestString + line + "\r\n"; } else if (!line.equals("")) { requestString = requestString + "SSRG: " + line + "\r\n"; } } line = br.readLine(); } for (String string : requestList) { SessionInputBuffer inbuffer = new FileInputBuffer(string, 1024, new BasicHttpParams()); requestParser = HttpRequestParser.createRequestParser(inbuffer, new DefaultHttpRequestFactory(), new BasicHttpParams()); HttpRequest httpRequest = HttpRequestParser.receiveRequestHeaderByFile(requestParser); request.add(httpRequest); } ArrayList<String> urls = null; DOProfile profile = new DOProfile(context); profile.insertRequest(request); log.info("Rquest Inserted"); urls = (ArrayList<String>) profile.getUrl(); if (urls.size() > 0) { check = true; profile.insertPairs(urls); } else { check = false; } log.info("Pairs inserted"); return check; }
From source file:unalcol.termites.boxplots.HybridGlobalInfoReport.java
private static String getTitle(ArrayList<Double> pf) { String s = "pf="; for (int i = 0; i < pf.size(); i++) { s += pf.get(i);//from ww w.j av a 2s .c o m if (i != pf.size() - 1) { s += " and "; } } return s; }
From source file:Main.java
public static Element[] getChildren(Element parent, String name) { ArrayList<Element> al = new ArrayList<Element>(); NodeList nl = parent.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node n = nl.item(i);//from w w w .ja v a 2 s .co m if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals(name)) { al.add((Element) n); } } return al.toArray(new Element[al.size()]); }
From source file:net.gcompris.GComprisActivity.java
public static void checkPayment() { if (m_instance.m_service == null) { Log.e(QtApplication.QtTAG, "Check full version is bought failed: No billing service"); return;/*from w w w .jav a 2 s.co m*/ } try { Bundle ownedItems = m_instance.m_service.getPurchases(3, m_instance.getPackageName(), "inapp", null); int responseCode = ownedItems.getInt("RESPONSE_CODE"); if (responseCode == 0) { ArrayList ownedSkus = ownedItems.getStringArrayList("INAPP_PURCHASE_ITEM_LIST"); ArrayList purchaseDataList = ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST"); for (int i = 0; i < purchaseDataList.size(); ++i) { String purchaseData = (String) purchaseDataList.get(i); String sku = (String) ownedSkus.get(i); if (sku.equals(SKU_NAME)) { bought(true); return; } else { Log.e(QtApplication.QtTAG, "Unknown item bought " + sku); } } bought(false); return; } else { bought(false); Log.e(QtApplication.QtTAG, "Item not owed " + responseCode); } } catch (Exception e) { Log.e(QtApplication.QtTAG, "Exception caught when checking if full version is bought!", e); } }
From source file:cn.edu.xidian.repace.xml2hbase.filter.TestFilter.java
public static Filter createFilterFromArguments(ArrayList<byte[]> filterArguments) { Preconditions.checkArgument(filterArguments.size() == 4 || filterArguments.size() == 6, "Expected 4 or 6 but got: %s", filterArguments.size()); byte[] family = ParseFilter.removeQuotesFromByteArray(filterArguments.get(0)); byte[] qualifier = ParseFilter.removeQuotesFromByteArray(filterArguments.get(1)); CompareOp compareOp = ParseFilter.createCompareOp(filterArguments.get(2)); WritableByteArrayComparable comparator = ParseFilter .createComparator(ParseFilter.removeQuotesFromByteArray(filterArguments.get(3))); if (comparator instanceof RegexStringComparator || comparator instanceof SubstringComparator) { if (compareOp != CompareOp.EQUAL && compareOp != CompareOp.NOT_EQUAL) { throw new IllegalArgumentException("A regexstring comparator and substring comparator " + "can only be used with EQUAL and NOT_EQUAL"); }/* w ww. j ava 2 s.c om*/ } SingleColumnValueFilter filter = new SingleColumnValueFilter(family, qualifier, compareOp, comparator); if (filterArguments.size() == 6) { boolean filterIfMissing = ParseFilter.convertByteArrayToBoolean(filterArguments.get(4)); boolean latestVersionOnly = ParseFilter.convertByteArrayToBoolean(filterArguments.get(5)); filter.setFilterIfMissing(filterIfMissing); filter.setLatestVersionOnly(latestVersionOnly); } return filter; }
From source file:com.shenit.commons.utils.CollectionUtils.java
/** * Drop n elements by direction//from ww w.ja v a 2 s . co m * @param cols * @param n * @param direction Negative direction means drop from tail; Others means drop from head * @return Collection after drop */ public static <T> Collection<T> drop(Collection<T> cols, int n, int direction) { if (cols == null || n < 0) return null; ArrayList<T> result = new ArrayList<T>(); ArrayList<T> colsArr = new ArrayList<T>(cols); int size = colsArr.size(); for (int i = 0; i < size; i++) { if ((i >= n && direction >= 0) || (i < size - n && direction < 0)) result.add(colsArr.get(i)); } return result; }
From source file:com.spun.util.ups.UPSUtils.java
/***********************************************************************/ private static UPSQuote[] extractQuotes(InputStream response) throws SAXException, IOException, ParserConfigurationException, FactoryConfigurationError { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(response); ArrayList<UPSQuote> quotes = new ArrayList<UPSQuote>(); NodeList list = document.getDocumentElement().getElementsByTagName("RatedShipment"); for (int i = 0; i < list.getLength(); i++) { quotes.add(extractQuote(list.item(i))); }//www . j av a2 s. c om if (quotes.size() == 0) { MySystem.warning("Couldn't find quote in response " + getDocument(document)); } return UPSQuote.toArray(quotes); }
From source file:Main.java
public static String[] removeFromStringArray(String[] a_aArray, String a_sString) /* */ {/*from w w w . j ava 2s .c om*/ /* 456 */String[] aReturnArray = a_aArray; /* */int iCount; /* 457 */if (a_aArray != null) /* */ { /* 459 */ArrayList<String> alStrings = new ArrayList(); /* 460 */for (String sTemp : a_aArray) /* */ { /* 462 */if (sTemp.equals(a_sString)) /* */continue; /* 464 */alStrings.add(sTemp); /* */} /* */ /* 467 */aReturnArray = new String[alStrings.size()]; /* 468 */iCount = 0; /* 469 */for (String sTemp : alStrings) /* */ { /* 471 */aReturnArray[iCount] = sTemp; /* 472 */iCount++; /* */} /* */} /* 475 */return aReturnArray; /* */}
From source file:Main.java
public static long[] getLongArrayfromString(final String string, final char token) { if (string == null) return new long[0]; final String[] items_string_array = string.split(String.valueOf(token)); final ArrayList<Long> items_list = new ArrayList<Long>(); for (final String id_string : items_string_array) { try {//from ww w . j a v a 2 s .co m items_list.add(Long.parseLong(id_string)); } catch (final NumberFormatException e) { // Ignore. } } final int list_size = items_list.size(); final long[] array = new long[list_size]; for (int i = 0; i < list_size; i++) { array[i] = items_list.get(i); } return array; }