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:ded.model.Entity.java
/** Return the value to which 'index' is mapped in 'integerToEntity'. */ public static Entity fromJSONRef(ArrayList<Entity> integerToEntity, long index) throws JSONException { if (0 <= index && index < integerToEntity.size()) { return integerToEntity.get((int) index); } else {// www . j a va 2 s . com throw new JSONException("invalid entity ref " + index); } }
From source file:com.pros.jsontransform.sort.ArraySortAbstract.java
static void doSort(final ArrayNode arrayNode, final JsonNode sortNode, final ObjectTransformer transformer) { // move array nodes to sorted array int size = arrayNode.size(); ArrayList<JsonNode> sortedArray = new ArrayList<JsonNode>(arrayNode.size()); for (int i = 0; i < size; i++) { sortedArray.add(arrayNode.remove(0)); }//from w w w.ja v a2 s . c o m // sort array sortedArray.sort(new NodeComparator(sortNode, transformer)); // move nodes back to targetArray for (int i = 0; i < sortedArray.size(); i++) { arrayNode.add(sortedArray.get(i)); } }
From source file:CB_Core.GCVote.GCVote.java
public static ArrayList<RatingData> GetRating(String User, String password, ArrayList<String> Waypoints) { ArrayList<RatingData> result = new ArrayList<RatingData>(); String data = "userName=" + User + "&password=" + password + "&waypoints="; for (int i = 0; i < Waypoints.size(); i++) { data += Waypoints.get(i);//from w w w . j a v a 2 s . c om if (i < (Waypoints.size() - 1)) data += ","; } try { HttpPost httppost = new HttpPost("http://gcvote.de/getVotes.php"); httppost.setEntity(new ByteArrayEntity(data.getBytes("UTF8"))); // Log.info(log, "GCVOTE-Post" + data); // Execute HTTP Post Request String responseString = Execute(httppost); // Log.info(log, "GCVOTE-Response" + responseString); DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(responseString)); Document doc = db.parse(is); NodeList nodelist = doc.getElementsByTagName("vote"); for (Integer i = 0; i < nodelist.getLength(); i++) { Node node = nodelist.item(i); RatingData ratingData = new RatingData(); ratingData.Rating = Float.valueOf(node.getAttributes().getNamedItem("voteAvg").getNodeValue()); String userVote = node.getAttributes().getNamedItem("voteUser").getNodeValue(); ratingData.Vote = (userVote == "") ? 0 : Float.valueOf(userVote); ratingData.Waypoint = node.getAttributes().getNamedItem("waypoint").getNodeValue(); result.add(ratingData); } } catch (Exception e) { String Ex = ""; if (e != null) { if (e != null && e.getMessage() != null) Ex = "Ex = [" + e.getMessage() + "]"; else if (e != null && e.getLocalizedMessage() != null) Ex = "Ex = [" + e.getLocalizedMessage() + "]"; else Ex = "Ex = [" + e.toString() + "]"; } Log.err(log, "GcVote-Error" + Ex); return null; } return result; }
From source file:com.ibm.rtc.automation.examples.client.RTCUserUtil.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public static void listUsers(ITeamRepository repo) throws TeamRepositoryException { IContributorManager icm = repo.contributorManager(); List allContribs = icm.fetchAllContributors(null); //System.out.println(allContribs.size()); ArrayList clone = new ArrayList(); clone.addAll(allContribs);/*from w w w. ja va2 s. c o m*/ Collections.sort(clone, new UserComparator()); int allContribSize = clone.size(); for (int i = 0; i < allContribSize; i++) { IContributor user = (IContributor) clone.get(i); System.out.println(user.getName()); } System.out.println("There are " + allContribSize + " total users in the repository"); }
From source file:de.tudarmstadt.ukp.lmf.transform.sensealignments.FrameNetWiktionaryAlignment.java
/** * // w ww. j a v a2 s .c om * @param classifierOut - output tsv of weka classification * @param classifierIn - data section of arff input file for classification * (contains ids in same order as classifications in classifierOut) * @param tsvFile * @throws IOException */ public static void classifierOutputToTsv(String classifierOut, String classifierIn, String tsvFile) throws IOException { List<String> res = new ArrayList<String>(); // read classification InputStream is = new BufferedInputStream(new FileInputStream(new File(classifierOut))); Reader reader = new InputStreamReader(is); BufferedReader br = new BufferedReader(reader); String line = br.readLine(); line = br.readLine(); ArrayList<String> scoreLines = new ArrayList<String>(); while (line != null) { scoreLines.add(line); line = br.readLine(); System.out.println(scoreLines.size()); } // read ids InputStream is2 = new BufferedInputStream(new FileInputStream(new File(classifierIn))); Reader reader2 = new InputStreamReader(is2); BufferedReader br2 = new BufferedReader(reader2); String line2 = br2.readLine(); line2 = br2.readLine(); ArrayList<String> idLines = new ArrayList<String>(); while (line2 != null) { idLines.add(line2); line2 = br2.readLine(); } System.out.println(scoreLines.size()); System.out.println(idLines.size()); if (scoreLines.size() != idLines.size()) {// logger.warn("files do not agree"); } int positive = 0; int negative = 0; for (int i = 0; i < scoreLines.size(); i++) { String[] scoreitems = scoreLines.get(i).split(":"); String[] iditems = idLines.get(i).split(","); String first = iditems[0]; String second = iditems[1]; String sysScore = scoreitems[2].split(",")[0]; if (sysScore.equals("1")) {// pair classified as alignment res.add(first + "\t" + second); positive++; } else { negative++; } } logger.info("positive class-->added as alignment: " + positive); logger.info("negative class-->no alignment: " + negative); System.out.println("write positive class to file"); FileWriter fw = new FileWriter(new File(tsvFile)); for (String r : res) { fw.write(r + "\n"); } fw.close(); br2.close(); br.close(); }
From source file:edu.cmu.cs.lti.util.general.BasicConvenience.java
public static int[] ArrayOfIntegers2intArray(ArrayList<Integer> in) { int[] result = new int[in.size()]; for (int i = 0; i < in.size(); i++) { result[i] = in.get(i);/*from w ww . jav a2 s. co m*/ } return result; }
From source file:com.ibm.rtc.automation.examples.client.RTCUserUtil.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public static void listUsersEmail(ITeamRepository repo) throws TeamRepositoryException { IContributorManager icm = repo.contributorManager(); List allContribs = icm.fetchAllContributors(null); //System.out.println(allContribs.size()); ArrayList clone = new ArrayList(); clone.addAll(allContribs);/*from ww w . j ava 2 s . c o m*/ Collections.sort(clone, new UserComparator()); int allContribSize = clone.size(); for (int i = 0; i < allContribSize; i++) { IContributor user = (IContributor) clone.get(i); if (!user.isArchived()) { System.out.println(user.getUserId() + " ," + user.getEmailAddress()); } } System.out.println("There are " + allContribSize + " total users in the repository"); }
From source file:be.ac.ucl.lfsab1509.llncampus.ADE.java
/** * Fetch information about courses which codes are given as parameter. * //from w w w . j av a2s .c om * @param code * Code of courses to fetch, separated by comma (e.g. "lelec1530,lfsab1509"). * @param weeks * Week numbers, separated by comma (e.g. "0,1,2,3,42"). * @return An ArrayList of Events or null if failure. */ public static ArrayList<Event> getInfo(final String code, final String weeks) { String html = ""; // A long string containing all the HTML ArrayList<Event> events = new ArrayList<Event>(); if (!connectADE(code, weeks)) { return null; } try { HttpClient client = ExternalAppUtility.getHttpClient(); HttpGet request = new HttpGet(SERVER_URL + INFO_PATH); HttpResponse response = client.execute(request); html = EntityUtils.toString(response.getEntity()); String table = HTMLAnalyser.getTagsContent(html, "table").get(0); ArrayList<String> lines = HTMLAnalyser.getTagsContent(table, "tr"); // Skip the 2 header lines. for (int i = 2; i < lines.size(); i++) { ArrayList<String> cells = HTMLAnalyser.getTagsContent(lines.get(i), "td"); String date = HTMLAnalyser.removeHTMLTag(cells.get(0)); String beginHour = HTMLAnalyser.removeHTMLTag(cells.get(2)); String duration = HTMLAnalyser.removeHTMLTag(cells.get(3)); Event event = new Event(date, beginHour, duration); event.addDetail("trainees", HTMLAnalyser.removeHTMLTag(cells.get(6))); event.addDetail("trainers", HTMLAnalyser.removeHTMLTag(cells.get(7))); event.addDetail("room", HTMLAnalyser.removeHTMLTag(cells.get(8))); event.addDetail("course", HTMLAnalyser.removeHTMLTag(cells.get(9))); event.addDetail("activity_name", HTMLAnalyser.removeHTMLTag(cells.get(1))); events.add(event); } } catch (Exception e) { Log.e("ADE.java", "Error with connection or analysis of HTML : " + e.getMessage()); e.printStackTrace(); return null; } return events; }
From source file:com.sec.ose.osi.thread.ui_related.ActionIdentifyOrReset.java
public static boolean requestIdentify(UIResponseObserver mObserver, UEIdentifyResetComment ueIdentification) { log.debug("Request Identify"); int matchedType = ueIdentification.getMatchType(); String projectName = ueIdentification.getProjectName(); ArrayList<String> selectedPaths = ueIdentification.getSelectedPath(); int curCount = 0; int selectedPathsSize = selectedPaths.size(); for (String path : selectedPaths) { IdentifyData identifyData = null; int compositeType = matchedType; if (ueIdentification.isFile() == false) { // folder compositeType = matchedType | IdentificationConstantValue.FOLDER_TYPE; if (path.equals("") == false) { path += "/"; }/* www .j av a 2 s .co m*/ } ArrayList<String> pendingFileListForIdentify = null; switch (matchedType) { case IdentificationConstantValue.STRING_MATCH_TYPE: UEStringMatch ueStringMatch = (UEStringMatch) ueIdentification.getUeMatched(); if (ueStringMatch == null) { return false; } pendingFileListForIdentify = IdentificationDBManager.getStringMatchFileList(projectName, path, ueStringMatch.getStringSearch(), AbstractMatchInfo.STATUS_PENDING); break; case IdentificationConstantValue.CODE_MATCH_TYPE: UECodeMatch ueCodeMatch = (UECodeMatch) ueIdentification.getUeMatched(); pendingFileListForIdentify = IdentificationDBManager.getCodeMatchFileList(projectName, path, ueCodeMatch.getOriginComponentName(), ueCodeMatch.getOriginVersionName(), ueCodeMatch.getOriginLicenseName(), AbstractMatchInfo.STATUS_PENDING); if (pendingFileListForIdentify.size() == 0 && ueCodeMatch.getCurrentVersionName().equals("Unspecified")) { pendingFileListForIdentify = IdentificationDBManager.getCodeMatchFileList(projectName, path, ueCodeMatch.getOriginComponentName(), "", ueCodeMatch.getOriginLicenseName(), AbstractMatchInfo.STATUS_PENDING); } break; case IdentificationConstantValue.PATTERN_MATCH_TYPE: pendingFileListForIdentify = IdentificationDBManager.getPatternMatchFileList(projectName, path, AbstractMatchInfo.STATUS_PENDING); break; } int pendingFileListForIdentifySize = pendingFileListForIdentify.size(); for (String curPath : pendingFileListForIdentify) { ++curCount; identifyData = IdentifyMediator.getInstance().createIdentifyData(projectName, matchedType, compositeType, curPath, ueIdentification.getUeMatched(), ueIdentification.getComment()); if (identifyData == null) return false; if (matchedType == IdentificationConstantValue.STRING_MATCH_TYPE && (identifyData.getNewLicenseName() == null || identifyData.getNewLicenseName().equals(""))) { return false; } IdentifyQueue.getInstance().enqueue(identifyData); if (selectedPathsSize > 1) { // JList selection mObserver.setMessageHeader( "Identify processing...(" + curCount + "/" + selectedPathsSize + ")\n"); } else { // JTree selection mObserver.setMessageHeader( "Identify processing...(" + curCount + "/" + pendingFileListForIdentifySize + ")\n"); } AbstractDiscoveryController discoveryController = ProjectDiscoveryControllerMap .getDiscoveryController(projectName, matchedType); discoveryController.identifyFile(identifyData, mObserver); } } IdentifyMediator.getInstance().updateUIFrameWithAdditionalIdentifiedFiles(projectName, ueIdentification.getSelectedPath()); MatchedInfoMgr.getInstance().loadIdentifiedFilesInfoToMemory(projectName); IdentifyMediator.getInstance().refreshIdentificationInfoForTreeListChildFrames(projectName, null, matchedType); if (IdentifyMediator.getInstance().getIndexOfTreeOrList() == JPanIdentifyMain.INDEX_LIST) { IdentifyMediator.getInstance().getJListMatchedFile() .changeSelectedIndex(IdentificationConstantValue.IDENTIFY_TYPE); } return true; }