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.predic8.membrane.core.util.TextUtil.java
public static String toEnglishList(String conjuction, String... args) { ArrayList<String> l = new ArrayList<String>(); for (String arg : args) if (arg != null && arg.length() > 0) l.add(arg);// w w w. j a v a 2 s . c o m StringBuilder sb = new StringBuilder(); for (int i = 0; i < l.size(); i++) { sb.append(l.get(i)); if (i == l.size() - 2) { sb.append(" "); sb.append(conjuction); sb.append(" "); } if (i < l.size() - 2) sb.append(", "); } return sb.toString(); }
From source file:com.yalin.fidoclient.op.ASMMessageHandler.java
public static boolean checkFacetId(String facetId, ArrayList<FacetIdList> facetIdList) { if (facetIdList != null && facetIdList.size() > 0) { FacetIdList facetIdList1 = facetIdList.get(0); if (facetIdList1.ids != null) { for (String id : facetIdList1.ids) { if (id.equals(facetId)) { return true; }/*w w w . j ava 2s .com*/ } } } return false; }
From source file:Main.java
/** * Will return a list of random location from the given position & radius * @param amount//from w w w . ja v a 2 s .c om * @param lat * @param lng * @param radius * @return ArrayList<Location> */ public static ArrayList<Location> randomLocations(int amount, double lat, double lng, double radius) { ArrayList<Location> locations = new ArrayList<Location>(0); Location centerLocation = new Location("local"); centerLocation.setLatitude(lat); centerLocation.setLongitude(lng); final double lngScale = Math.cos((Math.PI / 180.0) * lat); final double radiusDeg = radius / 111.2; // radius converted to degrees (square) while (locations.size() < amount) { Location l = new Location("local"); double dLat = (Math.random() * radiusDeg * 2) - radiusDeg; double dLng = (Math.random() * radiusDeg * 2 / lngScale) - (radiusDeg / lngScale); l.setLatitude(centerLocation.getLatitude() + dLat); l.setLongitude(centerLocation.getLongitude() + dLng); double dist = l.distanceTo(centerLocation) / 1000.0; if (dist < (radius)) { locations.add(l); } } return locations; }
From source file:io.lqd.sdk.model.LQNetworkRequest.java
@SuppressWarnings("unchecked") public static ArrayList<LQNetworkRequest> loadQueue(Context context, String fileName) { Object result = LQModel.loadObject(context, fileName + ".queue"); ArrayList<LQNetworkRequest> queue = (ArrayList<LQNetworkRequest>) result; if (queue == null) { queue = new ArrayList<LQNetworkRequest>(); }/*from w ww. j a va2s .c o m*/ LQLog.infoVerbose("Loading queue with " + queue.size() + " items from disk"); return queue; }
From source file:com.qasp.diego.arsp.Atualiza.java
private static void LeituraeAtualizacao(InputStream in, ArrayList<Estacao> estacoes) throws Exception { InputStreamReader isr = new InputStreamReader(in, Charset.forName("UTF-8")); BufferedReader br = new BufferedReader(isr); int size = estacoes.size(); for (int e = 0; e < size; e++) { String line = br.readLine(); // Detectar estacoes defeituosas while (!line.equals(estacoes.get(e).getId())) { estacoes.get(e).setIndisponivel(true); e++;//from w ww. j a va 2 s .c o m } // Leitura e adicao dos poluentes line = br.readLine(); String[] poluentes = line.split("[ ]"); int NOxcol = -1; int NOcol = -1; int ERT = -1; int colcnt = 0; Log.d("Estacao", estacoes.get(e).getNome()); for (String p : poluentes) { Log.d("Poluentes (String p):", p); if (p.equals("NO")) NOcol = colcnt + 2; else if (p.equals("NOx")) NOxcol = colcnt + 2; else if (p.equals("ERT")) ERT = colcnt + 2; colcnt++; } // Leitura das medicoes das ultimas tres horas int maxlin = 3; boolean horamaisrecente = true; for (int i = 0; i < maxlin; i++) { line = br.readLine(); String[] cols = line.split("[ ]"); colcnt = 0; String datatemp = " "; String horastemp = " "; // DATA HORA MED1 MED2 ... for (String c : cols) { if (colcnt != NOxcol && colcnt != NOcol && colcnt != ERT) { if (colcnt == DATA) datatemp = c; else if (colcnt == HORAS) horastemp = c; else { if (c.equals("--")) { horamaisrecente = false; break; } else { estacoes.get(e).AtualizaPoluente(Integer.parseInt(c), PoluentesIndices.PoluenteproIndice(poluentes[colcnt - 2])); } } } if (horamaisrecente && colcnt > 1) estacoes.get(e).AtualizaTempo(datatemp, horastemp); colcnt++; } } } }
From source file:no.digipost.android.api.ContentOperations.java
public static Documents getAccountContentMetaDocument(Context context, int content, String oldestVisibleDocumentDate) throws DigipostApiException, DigipostClientException, DigipostAuthenticationException { getCurrentMailbox(context);//from ww w . ja v a 2s .c o m if (mailbox == null) { return null; } refreshApiAccess(); if (oldestVisibleDocumentDate == null) { oldestVisibleDocumentDate = Long.toString(new Date().getTime()); } MultivaluedMap params = new MultivaluedMapImpl(); params.add(ApiConstants.GET_DOCUMENT_LASTSEEN, oldestVisibleDocumentDate); params.add(ApiConstants.GET_DOCUMENT_LIMIT, Integer.toString(ApiConstants.GET_DOCUMENT_LIMIT_N)); if (content == ApplicationConstants.MAILBOX) { return (Documents) JSONUtilities.processJackson(Documents.class, apiAccess.getApiJsonString(context, mailbox.getInboxUri(), params)); } else { content -= ApplicationConstants.numberOfStaticFolders; ArrayList<Folder> folders = mailbox.getFolders().getFolder(); if (folders != null && content < folders.size()) { Folder folder = (Folder) JSONUtilities.processJackson(Folder.class, apiAccess.getApiJsonString(context, folders.get(content).getSelfUri(), params)); if (folder != null) { return folder.getDocuments(); } } } return null; }
From source file:Main.java
public static byte[] encodeData(byte[] data) { // use arraylists because byte[] is annoying. ArrayList<Byte> inData = fromBytes(data); ArrayList<Byte> outData = new ArrayList<>(); final byte[] codes = new byte[] { 21, 49, 50, 35, 52, 37, 38, 22, 26, 25, 42, 11, 44, 13, 14, 28 }; int acc = 0;/* ww w. j av a 2 s. c o m*/ int bitcount = 0; int i; for (i = 0; i < inData.size(); i++) { acc <<= 6; acc |= codes[(inData.get(i) >> 4) & 0x0f]; bitcount += 6; acc <<= 6; acc |= codes[inData.get(i) & 0x0f]; bitcount += 6; while (bitcount >= 8) { byte outByte = (byte) (acc >> (bitcount - 8) & 0xff); outData.add(outByte); bitcount -= 8; acc &= (0xffff >> (16 - bitcount)); } } if (bitcount > 0) { acc <<= (8 - bitcount); byte outByte = (byte) (acc & 0xff); outData.add(outByte); } // convert back to byte[] byte[] rval = toBytes(outData); Log.e(TAG, "encodeData: (length " + data.length + ") input is " + toHexString(data)); Log.e(TAG, "encodeData: (length " + rval.length + ") output is " + toHexString(rval)); return rval; }
From source file:Main.java
/** * Given a coordinate relative to the descendant, find the coordinate in a parent view's * coordinates./*w ww .j a v a2s . com*/ * * @param descendant The descendant to which the passed coordinate is relative. * @param root The root view to make the coordinates relative to. * @param coord The coordinate that we want mapped. * @param includeRootScroll Whether or not to account for the scroll of the descendant: * sometimes this is relevant as in a child's coordinates within the descendant. * @return The factor by which this descendant is scaled relative to this DragLayer. Caution * this scale factor is assumed to be equal in X and Y, and so if at any point this * assumption fails, we will need to return a pair of scale factors. */ public static float getDescendantCoordRelativeToParent(View descendant, View root, int[] coord, boolean includeRootScroll) { ArrayList<View> ancestorChain = new ArrayList<View>(); float[] pt = { coord[0], coord[1] }; View v = descendant; while (v != root && v != null) { ancestorChain.add(v); v = (View) v.getParent(); } ancestorChain.add(root); float scale = 1.0f; int count = ancestorChain.size(); for (int i = 0; i < count; i++) { View v0 = ancestorChain.get(i); // For TextViews, scroll has a meaning which relates to the text position // which is very strange... ignore the scroll. if (v0 != descendant || includeRootScroll) { pt[0] -= v0.getScrollX(); pt[1] -= v0.getScrollY(); } v0.getMatrix().mapPoints(pt); pt[0] += v0.getLeft(); pt[1] += v0.getTop(); scale *= v0.getScaleX(); } coord[0] = (int) Math.round(pt[0]); coord[1] = (int) Math.round(pt[1]); return scale; }
From source file:info.dolezel.fatrat.plugins.helpers.NativeHelpers.java
public static Class[] findAnnotatedClasses(String packageName, Class annotation) throws IOException, ClassNotFoundException { String path = packageName.replace('.', '/'); Enumeration<URL> resources = loader.getResources(path); Set<File> dirs = new HashSet<File>(); while (resources.hasMoreElements()) { URL resource = resources.nextElement(); dirs.add(new File(resource.getFile())); }//w ww .j a v a2 s . co m for (URL url : loader.getURLs()) { dirs.add(new File(url.getFile())); } ArrayList<Class> classes = new ArrayList<Class>(); for (File directory : dirs) { classes.addAll(findClasses(directory, packageName, annotation)); } return classes.toArray(new Class[classes.size()]); }
From source file:Main.java
public static File[] getSavegames(File folder) { File[] files = folder.listFiles(); ArrayList<File> saveFiles = new ArrayList<File>(); if (files != null) { for (final File fileEntry : files) { if (fileEntry.isFile()) { if (fileEntry.getName().toLowerCase().endsWith(".lsd")) { saveFiles.add(fileEntry); }//from w ww . jav a2 s . c om } } } return saveFiles.toArray(new File[saveFiles.size()]); }