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:com.nridge.core.io.gson.IOJSON.java
/** * Writes a JSON field name/values if the value is not empty. * * @param aWriter JSON writer output stream. * @param aName Field name./* ww w. j av a 2 s . com*/ * @param aValues Field values. * * @throws IOException I/O related exception. */ public static void writeNameValue(JsonWriter aWriter, String aName, ArrayList<String> aValues) throws IOException { if ((aValues != null) && (aValues.size() > 0)) { aWriter.name(aName).beginArray(); for (String value : aValues) aWriter.value(value); aWriter.endArray(); } }
From source file:com.topsoft.botspider.io.UnionData.java
public static void setParseClass(Configuration conf, Class... classez) { if (conf == null || classez == null) return;//w w w .ja va 2s.c o m ArrayList<String> arrParse = new ArrayList<String>(classez.length); for (Class clzss : classez) { arrParse.add(clzss.getName()); } conf.setStrings(UNION_CLASS, arrParse.toArray(new String[arrParse.size()])); }
From source file:ArrayConverter.java
public static Object[] getAsList(final Object maybeArray, final Class arrayType) { if (maybeArray == null) { return null; }// w ww . ja va 2 s. co m if (maybeArray.getClass().isArray() == false) { return new Object[] { maybeArray }; } final ArrayList list = new ArrayList(); ArrayConverter.addToList(list, maybeArray); final Object o = Array.newInstance(arrayType, list.size()); return list.toArray((Object[]) o); }
From source file:Main.java
public static void split(String[] items, ArrayList<String> res, int number) { // split items to res1 and res2, where res2 has number items res.clear();//from w ww . j a va 2 s . co m String res1 = ""; String res2 = ""; ArrayList<String> newList = new ArrayList<String>(); for (int i = 0; i < items.length; i++) { newList.add(items[i]); } Collections.shuffle(newList); for (int i = 0; i < newList.size(); i++) { if (i < number) { res1 += newList.get(i) + "\t"; } else { res2 += newList.get(i) + "\t"; } } res.add(res1); res.add(res2); }
From source file:org.apache.streams.gnip.powertrack.GnipActivityFixer.java
public static void editJson(JSONObject json, ArrayList<String> keyPath, Object nullFragment) throws JSONException { Integer numKeys = keyPath.size(); JSONObject newJson = new JSONObject(); if (numKeys > 1) { for (int i = numKeys - 1; i > 0; i -= 1) { String key = keyPath.get(i); if (i == numKeys - 1) { newJson = newJson.put(key, nullFragment); } else { newJson = newJson.put(key, newJson); }//from w w w . j av a2 s. c o m } json.put(keyPath.get(0), newJson); } else { json.put(keyPath.get(0), nullFragment); } }
From source file:com.shmsoft.dmass.print.Html2Pdf.java
/** * Bad rendering, perhaps used only for Windows *///from w w w. ja v a 2 s . co m @SuppressWarnings({ "rawtypes", "unchecked" }) private static void convertHtml2Pdf(Reader htmlReader, String outputFile) throws Exception { Document pdfDocument = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(pdfDocument, baos); pdfDocument.open(); StyleSheet styles = new StyleSheet(); styles.loadTagStyle("body", "font", "Times New Roman"); ImageProvider imageProvider = new ImageProvider() { @Override public Image getImage(String src, HashMap arg1, ChainedProperties arg2, DocListener arg3) { try { Image image = Image.getInstance(IOUtils.toByteArray( getClass().getClassLoader().getResourceAsStream(ParameterProcessing.NO_IMAGE_FILE))); return image; } catch (Exception e) { System.out.println("Problem with html->pdf imaging, image provider fault"); } return null; } }; HashMap interfaceProps = new HashMap(); interfaceProps.put("img_provider", imageProvider); ArrayList arrayElementList = HTMLWorker.parseToList(htmlReader, styles, interfaceProps); for (int i = 0; i < arrayElementList.size(); ++i) { Element e = (Element) arrayElementList.get(i); pdfDocument.add(e); } pdfDocument.close(); byte[] bs = baos.toByteArray(); File pdfFile = new File(outputFile); FileOutputStream out = new FileOutputStream(pdfFile); out.write(bs); out.close(); }
From source file:fr.bmartel.android.tictactoe.request.ResponseParser.java
public static String parseUsernameEvent(Intent intent) { ArrayList<String> actionsStr = intent.getStringArrayListExtra(""); if (actionsStr.size() > 0) { try {/*from w ww . j a va 2 s . c o m*/ JSONObject mainObject = new JSONObject(actionsStr.get(0)); if (mainObject.has(RequestConstants.DEVICE_NAME)) { return mainObject.get(RequestConstants.DEVICE_NAME).toString(); } } catch (JSONException e) { e.printStackTrace(); } } return ""; }
From source file:Main.java
public static boolean getBoundaryLevel(Point bound) { if (mLevelSet == null) mLevelSet = mContext.getSharedPreferences(PREFER, Context.MODE_WORLD_READABLE).getStringSet(LEVELSET, null);//w w w.j av a2 s.c o m if (mLevelSet != null) { ArrayList<String> array = Collections.list(Collections.enumeration(mLevelSet)); Collections.sort(array, mComparator); bound.x = Integer.valueOf(array.get(0)); bound.y = Integer.valueOf(array.get(array.size() - 1)); return true; } return false; }
From source file:Main.java
public static String getTabsStringFromList(final ArrayList<String> tabs) { final StringBuilder resultTabs; if (tabs == null || tabs.isEmpty()) { resultTabs = new StringBuilder(""); } else {/*from www . j a v a2s.c om*/ resultTabs = new StringBuilder(tabs.size() * 10); resultTabs.append(tabs.get(0)); for (int i = 1; i < tabs.size(); i++) { resultTabs.append(LIBRARY_TABS_DELIMITER); resultTabs.append(tabs.get(i)); } } return resultTabs.toString(); }
From source file:Main.java
public static void appendLog(String text) { File logFile = new File(Environment.getExternalStorageDirectory() + "/clr_log.file"); if (!logFile.exists()) { try {/*from w ww. j av a 2 s.co m*/ logFile.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } try { BufferedReader buf = new BufferedReader(new FileReader(logFile)); String line = ""; ArrayList<String> lines = new ArrayList<String>(); while ((line = buf.readLine()) != null) { lines.add(line); } int size = lines.size(); //Every time the number of lines go over 1000, only add the last 500. This will keep its size to a minimum int i = lines.size() - 500; if (i < 0) { i = 0; } buf.close(); BufferedWriter bufW = new BufferedWriter(new FileWriter(logFile, true)); if (size > 1000) { bufW.write(""); for (; i < lines.size(); i++) { bufW.append(line); } } bufW.append(text + "\n"); bufW.close(); } catch (IOException e) { e.printStackTrace(); } }