List of usage examples for java.util ArrayList indexOf
public int indexOf(Object o)
From source file:im.vector.activity.HomeActivity.java
private void removeAccount() { final ArrayList<MXSession> sessions = new ArrayList<MXSession>(Matrix.getMXSessions(this)); // only one session -> loggout if (sessions.size() == 1) { CommonActivityUtils.logout(HomeActivity.this); }//from w w w . j a v a2 s . c om FragmentManager fm = getSupportFragmentManager(); AccountsSelectionDialogFragment fragment = (AccountsSelectionDialogFragment) fm .findFragmentByTag(TAG_FRAGMENT_ACCOUNT_SELECTION_DIALOG); if (fragment != null) { fragment.dismissAllowingStateLoss(); } fragment = AccountsSelectionDialogFragment.newInstance(Matrix.getMXSessions(getApplicationContext())); fragment.setListener(new AccountsSelectionDialogFragment.AccountsListener() { @Override public void onSelected(final MXSession session) { HomeActivity.this.runOnUiThread(new Runnable() { @Override public void run() { final int sectionPos = sessions.indexOf(session); CommonActivityUtils.logout(HomeActivity.this, session, true); HomeActivity.this.runOnUiThread(new Runnable() { @Override public void run() { // expand/collapse to force the group refresh collapseAllGroups(); mAdapter.removeSection(sectionPos); mAdapter.notifyDataSetChanged(); // all the groups must be displayed during a search mAdapter.setDisplayAllGroups(mSearchRoomEditText.getVisibility() == View.VISIBLE); expandAllGroups(); } }); } }); } }); fragment.show(fm, TAG_FRAGMENT_ACCOUNT_SELECTION_DIALOG); }
From source file:org.o3project.odenos.component.federator.Federator.java
/** */* w w w .j av a2 s.co m*/ * @return map of the ports. * dict<org_nwid::org_node_id::org_port_id, list[federated_node_id, federated_port_id]> */ protected Map<String, ArrayList<String>> getNwPortsFed() { logger.debug(""); ArrayList<String> nwcIds = conversionTable().getConnectionList(ORIGINAL_NETWORK); HashMap<String, ArrayList<String>> portTable = conversionTable().getPort(); Map<String, ArrayList<String>> nwcPorts = new HashMap<>(); for (String orgPort : portTable.keySet()) { String[] nwcId = orgPort.split("::"); // nwcId::nodeId::portId if (nwcIds.indexOf(nwcId[0]) < 0) { continue; } ArrayList<String> fedPorts = portTable.get(orgPort); String[] fedPortStr = fedPorts.get(0).split("::"); // nwcId::nodeId::portId ArrayList<String> fedPort = new ArrayList<>(Arrays.asList(fedPortStr)); fedPort.remove(0); nwcPorts.put(orgPort, fedPort); } return nwcPorts; }
From source file:org.matrix.console.activity.HomeActivity.java
private void refreshPublicRoomsList(final ArrayList<MXSession> sessions, final ArrayList<String> checkedHomeServers, final int index, final ArrayList<List<PublicRoom>> publicRoomsListList) { // sanity checks if ((null == sessions) || (index >= sessions.size())) { Log.d(LOG_TAG, "notifyDataSetChanged after the public rooms update."); mAdapter.setPublicRoomsList(publicRoomsListList, checkedHomeServers); mAdapter.notifyDataSetChanged(); mPublicRoomsListList = publicRoomsListList; mHomeServerNames = checkedHomeServers; return;// ww w. j av a2 s. c om } final MXSession session = sessions.get(index); // check if the session is still active if (session.isActive()) { final String homeServerUrl = session.getHomeserverConfig().getHomeserverUri().toString(); // the home server has already been checked ? if (checkedHomeServers.indexOf(homeServerUrl) >= 0) { // jump to the next session refreshPublicRoomsList(sessions, checkedHomeServers, index + 1, publicRoomsListList); } else { // use any session to get the public rooms list session.getEventsApiClient().loadPublicRooms(new SimpleApiCallback<List<PublicRoom>>(this) { @Override public void onSuccess(List<PublicRoom> publicRooms) { checkedHomeServers.add(homeServerUrl); publicRoomsListList.add(publicRooms); // jump to the next session refreshPublicRoomsList(sessions, checkedHomeServers, index + 1, publicRoomsListList); } }); } } else { refreshPublicRoomsList(sessions, checkedHomeServers, index + 1, publicRoomsListList); } }
From source file:fr.inria.oak.paxquery.pact.operations.xml.navigation.SingleDocumentExtractor.java
/** * This method attempts to locate children of em in the stack s, either * directly from em's children, or by transitivity from em's own children * (matches in the same stack, corresponding to ancestors of em). The method * returns em's resulting (potentially enhanced) children in the stack s. * //from ww w. j a v a 2s . com * @param em * The match. * @param s * The stack for which we attempt to find children. * @return the set of the match's children in the stack, if any were found. */ private final ArrayList<ExtractorMatch> findChildInStack(ExtractorMatch em, ExtractorMatchStack s, boolean isParent) { if (em.childrenByStack == null) { return null; } ArrayList<ExtractorMatch> v = em.childrenByStack.get(s); if (em.ownChildren != null) { Iterator<ExtractorMatch> it = em.ownChildren.iterator(); while (it.hasNext()) { ExtractorMatch emChild = it.next(); // cannot be null ArrayList<ExtractorMatch> vAux = findChildInStack(emChild, s, isParent); if (vAux != null) { Iterator<ExtractorMatch> iAux = vAux.iterator(); if (v == null) { v = new ArrayList<ExtractorMatch>(); em.childrenByStack.put(s, v); } while (iAux.hasNext()) { ExtractorMatch o = iAux.next(); if (v.indexOf(o) == -1) { ExtractorMatch emo = o; if ((!isParent) || (em.depth + 1 == emo.depth)) { v.add(o); } } } } } } return v; }
From source file:output.ExcelM3Upgrad.java
private void writeGraph() { busyDial.setText("Gnration des graphiques statistiques"); Sheet s = workbook.getSheetAt(1);/*w w w . ja v a2 s.c o m*/ workbook.setSheetName(1, "Statistiques"); ArrayList<Integer> listHeader = new ArrayList<>(); for (int i = 0; i < M3UpdObjModel.header.length; i++) { listHeader.add(M3UpdObjModel.header[i]); } int irow = 4; Row row = s.createRow(irow); Cell cell = row.createCell(2); s.addMergedRegion(new CellRangeAddress(irow, irow, 2, 7)); cell.setCellValue("Rpartition des spcifiques"); cell.setCellStyle(styles.get("cell_centered_locked")); irow = 8; row = s.createRow(irow); for (int i = 0; i < com.app.main.Ressource.listTypeM3Entity.length; i++) { cell = row.createCell(3); cell.setCellValue(com.app.main.Ressource.listTypeM3Entity[i]); cell = row.createCell(4); cell.setCellType(HSSFCell.CELL_TYPE_FORMULA); String columnLetter = CellReference.convertNumToColString(beginCOL); cell.setCellFormula("COUNTIF(" + workbook.getSheetName(0) + "!" + columnLetter + (beginROW + 2) + ":" + columnLetter + (beginROW + data.length + 1) + ",\"" + com.app.main.Ressource.listTypeM3Entity[i] + "\")"); irow++; row = s.createRow(irow); dialStatus(); } irow = 4; row = s.getRow(irow); cell = row.createCell(10); s.addMergedRegion(new CellRangeAddress(irow, irow, 10, 15)); cell.setCellValue("Existance des sources"); cell.setCellStyle(styles.get("cell_centered_locked")); int posVal = listHeader.indexOf(199); posVal += beginCOL; irow = 8; row = s.getRow(irow); cell = row.createCell(12); cell.setCellValue("OK"); cell = row.createCell(13); cell.setCellType(HSSFCell.CELL_TYPE_FORMULA); String columnLetter = CellReference.convertNumToColString(posVal); cell.setCellFormula("COUNTIF(" + workbook.getSheetName(0) + "!" + columnLetter + (beginROW + 2) + ":" + columnLetter + (beginROW + data.length + 1) + ",\"" + "Oui" + "\")"); irow++; row = s.getRow(irow); cell = row.createCell(12); cell.setCellValue("NOK"); cell = row.createCell(13); cell.setCellType(HSSFCell.CELL_TYPE_FORMULA); // columnLetter = CellReference.convertNumToColString(posVal); cell.setCellFormula("COUNTIF(" + workbook.getSheetName(0) + "!" + columnLetter + (beginROW + 2) + ":" + columnLetter + (beginROW + data.length + 1) + ",\"" + "Non" + "\")"); irow = 24; row = s.createRow(irow); cell = row.createCell(2); s.addMergedRegion(new CellRangeAddress(irow, irow, 2, 7)); cell.setCellValue("Synthse de migration"); cell.setCellStyle(styles.get("cell_centered_locked")); int posMig = listHeader.indexOf(201); posMig += beginCOL; int posUser = listHeader.indexOf(202); posUser += beginCOL; irow = 28; row = s.createRow(irow); cell = row.createCell(3); cell.setCellValue("OK+USER"); cell = row.createCell(4); cell.setCellType(HSSFCell.CELL_TYPE_FORMULA); String columnMig = CellReference.convertNumToColString(posMig); String columnUser = CellReference.convertNumToColString(posUser); cell.setCellFormula("SUMPRODUCT((" + workbook.getSheetName(0) + "!" + columnMig + (beginROW + 2) + ":" + columnMig + (beginROW + data.length + 1) + "=\"" + "OK" + "\")*(" + workbook.getSheetName(0) + "!" + columnUser + (beginROW + 2) + ":" + columnUser + (beginROW + data.length + 1) + "<>\"" + "" + "\"))"); irow++; row = s.createRow(irow); cell = row.createCell(3); cell.setCellValue("OK"); cell = row.createCell(4); cell.setCellType(HSSFCell.CELL_TYPE_FORMULA); cell.setCellFormula("SUMPRODUCT((" + workbook.getSheetName(0) + "!" + columnMig + (beginROW + 2) + ":" + columnMig + (beginROW + data.length + 1) + "=\"" + "OK" + "\")*(" + workbook.getSheetName(0) + "!" + columnUser + (beginROW + 2) + ":" + columnUser + (beginROW + data.length + 1) + "=\"" + "" + "\"))"); irow++; row = s.createRow(irow); cell = row.createCell(3); cell.setCellValue("NOK"); cell = row.createCell(4); cell.setCellType(HSSFCell.CELL_TYPE_FORMULA); cell.setCellFormula("COUNTIF(" + workbook.getSheetName(0) + "!" + columnMig + (beginROW + 2) + ":" + columnMig + (beginROW + data.length + 1) + ",\"KO\")"); irow++; row = s.createRow(irow); cell = row.createCell(3); cell.setCellValue("Somme"); cell = row.createCell(4); cell.setCellType(HSSFCell.CELL_TYPE_FORMULA); String posSum = CellReference.convertNumToColString(4); cell.setCellFormula("SUM(" + posSum + (irow - 2) + ":" + posSum + (irow) + ")"); posVal = listHeader.indexOf(217); posVal += beginCOL; irow = 24; row = s.getRow(irow); cell = row.createCell(10); s.addMergedRegion(new CellRangeAddress(irow, irow, 10, 15)); cell.setCellValue("Analyse des objets instanciables"); cell.setCellStyle(styles.get("cell_centered_locked")); irow = 28; row = s.getRow(irow); cell = row.createCell(12); cell.setCellValue("Class OK"); cell = row.createCell(13); cell.setCellType(HSSFCell.CELL_TYPE_FORMULA); columnLetter = CellReference.convertNumToColString(posVal); cell.setCellFormula("COUNTIF(" + workbook.getSheetName(0) + "!" + columnLetter + (beginROW + 2) + ":" + columnLetter + (beginROW + data.length + 1) + ",\"" + "" + "\")"); irow++; row = s.getRow(irow); cell = row.createCell(12); cell.setCellValue("Class NOK"); cell = row.createCell(13); cell.setCellType(HSSFCell.CELL_TYPE_FORMULA); columnLetter = CellReference.convertNumToColString(posVal); //cell.setCellFormula("COUNTIF(" + workbook.getSheetName(0) + "!" + columnLetter + (beginROW + 2) + ":" + columnLetter + (beginROW + data.length + 1) + ",\"" + "<>" + "\"&\"" + "*" + "\")"); cell.setCellFormula("E32-N29"); s.protectSheet("3kles2014"); }
From source file:de.tudarmstadt.tk.statistics.importer.ExternalResultsReader.java
public static List<SampleData> splitData(SampleData data, StatsConfig config) { List<SampleData> splitted = new ArrayList<SampleData>(); //Use lists instead of sets to maintain order of model metadata ArrayList<String> featureSets = new ArrayList<String>(); ArrayList<String> classifiers = new ArrayList<String>(); for (Pair<String, String> metadata : data.getModelMetadata()) { if (!classifiers.contains(metadata.getLeft())) { classifiers.add(metadata.getLeft()); }//ww w .j ava 2s . com if (!featureSets.contains(metadata.getRight())) { featureSets.add(metadata.getRight()); } } //Only separate data if there's more than one independent variable if (!(featureSets.size() > 1 && classifiers.size() > 1)) { splitted.add(data); return splitted; } List<String> it = (config .getFixIndependentVariable() == StatsConfigConstants.INDEPENDENT_VARIABLES_VALUES.Classifier) ? classifiers : featureSets; for (String fixed : it) { ArrayList<Pair<String, String>> modelMetadata = new ArrayList<Pair<String, String>>(); HashMap<String, ArrayList<ArrayList<Double>>> samples = new HashMap<String, ArrayList<ArrayList<Double>>>(); HashMap<String, ArrayList<Double>> sampleAverages = new HashMap<String, ArrayList<Double>>(); for (int i = 0; i < data.getModelMetadata().size(); i++) { Pair<String, String> model = data.getModelMetadata().get(i); boolean eq = (config .getFixIndependentVariable() == StatsConfigConstants.INDEPENDENT_VARIABLES_VALUES.Classifier) ? model.getLeft().equals(fixed) : model.getRight().equals(fixed); if (eq) { modelMetadata.add(model); for (String measure : data.getSamples().keySet()) { if (!samples.containsKey(measure)) { samples.put(measure, new ArrayList<ArrayList<Double>>()); sampleAverages.put(measure, new ArrayList<Double>()); } samples.get(measure).add(data.getSamples().get(measure).get(i)); sampleAverages.get(measure).add(data.getSamplesAverage().get(measure).get(i)); } } } ArrayList<Pair<String, String>> baselineModelData = new ArrayList<Pair<String, String>>(); if (data.isBaselineEvaluation()) { Pair<String, String> baselineModel = null; for (int i = 0; i < data.getBaselineModelMetadata().size(); i++) { boolean eq = (config .getFixIndependentVariable() == StatsConfigConstants.INDEPENDENT_VARIABLES_VALUES.Classifier) ? data.getBaselineModelMetadata().get(i).getLeft().equals(fixed) : data.getBaselineModelMetadata().get(i).getRight().equals(fixed); if (eq) { baselineModel = data.getBaselineModelMetadata().get(i); break; } } if (baselineModel != null) { baselineModelData.add(baselineModel); int modelIndex = modelMetadata.indexOf(baselineModel); modelMetadata.remove(modelIndex); modelMetadata.add(0, baselineModel); for (String measure : data.getSamples().keySet()) { ArrayList<Double> s = samples.get(measure).get(modelIndex); samples.get(measure).remove(modelIndex); samples.get(measure).add(0, s); double a = sampleAverages.get(measure).get(modelIndex); sampleAverages.get(measure).remove(modelIndex); sampleAverages.get(measure).add(0, a); } } else { logger.log(Level.ERROR, "Missing baseline model! Please check if baseline indicators are set correctly in the input file, and if they correspond correctly to the fixIndependentVariable property in the configuration. In case of both varying feature sets and classifiers, baseline indicators have to be set multiple times."); System.err.println( "Missing baseline model! Please check if baseline indicators are set correctly in the input file, and if they correspond correctly to the fixIndependentVariable property in the configuration. In case of both varying feature sets and classifiers, baseline indicators have to be set multiple times."); System.exit(1); } } SampleData newData = new SampleData(null, samples, sampleAverages, data.getDatasetNames(), modelMetadata, baselineModelData, data.getPipelineType(), data.getnFolds(), data.getnRepetitions()); splitted.add(newData); } return splitted; }
From source file:hw.java
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed // ResultSet rs1; // /*from w w w . ja va2 s . c o m*/ // try { MongoCollection<Document> coll = db.getCollection("business"); //MongoCollection<Document> catcollection = db.getCollection("catout"); MongoCollection<Document> rcoll = db.getCollection("review"); //final DBCollection collection = db.getCollection("review"); MongoCollection<Document> ccoll = db.getCollection("checkin"); String from_dropdown = jComboBox3.getSelectedItem().toString(); String to_dropdown = jComboBox6.getSelectedItem().toString(); String from_value = jTextField9.getText(); String to_value = jTextField10.getText(); String check_count_value = jTextField11.getText(); String check_count_dropdown = jComboBox8.getSelectedItem().toString(); String fromdate_value = jTextField1.getText(); String todate_value = jTextField3.getText(); String stars_value = jTextField12.getText(); String votes_value = jTextField13.getText(); String stars_dropdown = jComboBox4.getSelectedItem().toString(); String votes_dropdown = jComboBox12.getSelectedItem().toString(); String select = jComboBox1.getSelectedItem().toString(); List<String> category_value = jList2.getSelectedValuesList(); String poi = jComboBox5.getSelectedItem().toString(); String proximity = jComboBox2.getSelectedItem().toString(); BasicDBObject qryBusiness = new BasicDBObject(); BasicDBObject qryReview = new BasicDBObject(); BasicDBList BusinessList = new BasicDBList(); BasicDBList ReviewList = new BasicDBList(); FindIterable<Document> cursor; FindIterable<Document> cursor1; List<String> catout = new ArrayList<String>(); List<String> proout = new ArrayList<String>(); List<String> checkinout = new ArrayList<String>(); List<String> reviewout = new ArrayList<String>(); List<String> finalout = new ArrayList<String>(); if (category_value.isEmpty())//&& poi == null && proximity == null && from_value == null && fromdate_value == null) { BasicDBObject nu = new BasicDBObject(); FindIterable<Document> fi; fi = coll.find(nu); jTextField8.setText("db.business.find()"); String Columnames[] = { "business_id", "state", "city", "stars" }; DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel(); dtm.setColumnCount(0); dtm.setRowCount(0); int numberOfColumns = Columnames.length; for (int i = 0; i < numberOfColumns; i++) { String name = Columnames[i]; dtm.addColumn(name); } fi.forEach(new Block<Document>() { @Override public void apply(final Document document) { Object rowData[] = new Object[numberOfColumns]; rowData[0] = document.get("business_id"); rowData[1] = document.get("state"); rowData[2] = document.get("city"); rowData[3] = document.get("stars"); dtm.addRow(rowData); rowData = null; } }); jTable1.setRowSelectionAllowed(true); jTable1.setModel(dtm); jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); dtm.fireTableDataChanged(); } else { Object[] l = jList2.getSelectedValues(); //BasicDBList subcat = new BasicDBList(); BasicDBList clist = new BasicDBList(); BasicDBObject qrycategory; if (l.length > 0) { for (int i = 0; i < l.length; i++) { BasicDBObject buinessop = new BasicDBObject("categories", l[i]); clist.add(buinessop); } } qrycategory = new BasicDBObject("$or", clist); // subcatquery = new BasicDBObject("$out","subcat"); // subcat.add(qrycategory); // subcat.add(subcatquery); // System.out.println(subcat); cursor = coll.find(qrycategory); System.out.println(qrycategory); //BasicDBObject category = new BasicDBObject(); cursor.forEach(new Block<Document>() { @Override public void apply(final Document document) { System.out.println(document.get("business_id")); //category.put((String)document.get("business_id"), db); catout.add((String) document.get("business_id")); // System.out.println(document.get("state")); // System.out.println(document.get("city")); // System.out.println(document.get("stars")); // } }); MongoCollection<Document> collecttest = db.getCollection("test"); String[] addresses5 = { "", "4840 E Indian School Rd\\nSte 101\\nPhoenix, AZ 85018", "631 S Main St\\nDe Forest, WI 53532", "5813 Main St\\nMc Farland, WI 53558", "2039 Allen Blvd\\nMiddleton, WI 53562", "6230 University Ave\\nMiddleton, WI 53562" }; String[][] latLong = { { "33.499313000000001", "-111.98375799999999" }, { "43.2408748", "-89.343721700000003" }, { "43.014164000000001", "-89.288567" }, { "43.090642000000003", "-89.485168999999999" }, { "43.0910607", "-89.487486700000005" } }; BasicDBObject queryBusiness = new BasicDBObject(); BasicDBList businessinputlist = new BasicDBList(); String selectedAddress = jComboBox5.getSelectedItem().toString(); String selectedProximity = jComboBox2.getSelectedItem().toString(); Double pro = Double.parseDouble(selectedProximity) / 3963.2; int index = Arrays.asList(addresses5).indexOf(selectedAddress); Double Latitude = Double.parseDouble(latLong[index][0]); Double Longitude = Double.parseDouble(latLong[index][1]); System.out.println("lat" + Latitude); System.out.println("longi" + Longitude); //BasicDBObject lat = new BasicDBObject(Latitude.toString(),Longitude); BasicDBList c1 = new BasicDBList(); BasicDBList cs = new BasicDBList(); cs.add(Latitude); cs.add(Longitude); c1.add(cs); c1.add(pro); BasicDBObject c = new BasicDBObject("$centerSphere", c1); BasicDBObject bq = new BasicDBObject("loc", new BasicDBObject("$geoWithin", c)); FindIterable<Document> fi; fi = collecttest.find(bq); System.out.println(bq); jTextField8.setText("db.test.find(" + bq + ")"); fi.forEach(new Block<Document>() { @Override public void apply(final Document document) { System.out.println(document.get("business_id")); proout.add((String) document.get("business_id")); //System.out.println(document.get("loc")); } }); int checkinempty = 0; if (from_value == null || to_value == null || check_count_value.equals("0")) { checkinempty = 1; List<String> pr = new ArrayList<String>(catout); System.out.println(pr.size()); pr.retainAll(proout); System.out.println(pr.size()); String Columnames[] = { "Business_id", "state", "city", "stars" }; DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel(); dtm.setColumnCount(0); dtm.setRowCount(0); int numberOfColumns = Columnames.length; Object rowData[] = new Object[numberOfColumns]; for (int i = 0; i < numberOfColumns; i++) { String name = Columnames[i]; dtm.addColumn(name); } for (int i = 0; i < pr.size(); i++) { rowData[0] = pr.get(i); BasicDBObject c11 = new BasicDBObject("business_id", pr.get(i)); FindIterable<Document> f1; f1 = coll.find(c11); f1.forEach(new Block<Document>() { @Override public void apply(final Document document) { Object rowData[] = new Object[numberOfColumns]; rowData[0] = document.get("business_id"); rowData[1] = document.get("state"); rowData[2] = document.get("city"); rowData[3] = document.get("stars"); dtm.addRow(rowData); rowData = null; } }); // // // } jTable1.setRowSelectionAllowed(true); jTable1.setModel(dtm); jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); dtm.fireTableDataChanged(); } if (checkinempty != 1) { BasicDBList checkinputlist = new BasicDBList(); // ArrayList<String> list1; list1 = new ArrayList<String>(); list1.add("0"); list1.add("1"); list1.add("2"); list1.add("3"); list1.add("4"); list1.add("5"); list1.add("6"); int from = list1.indexOf(from_dropdown); int to = list1.indexOf(to_dropdown); int count = to - from; int hoursfrom1 = Integer.parseInt(from_value); int hoursto1 = Integer.parseInt(to_value); int count1 = hoursto1 - hoursfrom1; FindIterable<Document> iterable = ccoll.find(); iterable.forEach(new Block<Document>() { @Override public void apply(final Document document) { //System.out.println(document.get("checkin_info")); String s = document.toJson(); s.replace("Document", ""); // System.out.println(s); JSONParser parser = new JSONParser(); try { Object obj = parser.parse(s); JSONObject doc = (JSONObject) obj; //System.out.println(doc.get("checkin_info")); JSONObject cinfo = (JSONObject) doc.get("checkin_info"); if (count >= 0) { long num_checkin = 0; for (int i = from; i <= to; i++) { if (count1 >= 0) { for (int j = hoursfrom1; j <= hoursto1; j++) { //System.out.println(cinfo.get(j+"-"+i)); if (cinfo.containsKey(j + "-" + i)) { num_checkin = num_checkin + (long) cinfo.get(j + "-" + i); // System.out.println(document.get("checkin_info."+j+"-"+i)); } } } } if (num_checkin != 0) { if (jComboBox8.getSelectedItem().equals(">") && num_checkin > Long.parseLong(check_count_value)) { System.out .println(num_checkin + " checkins into " + doc.get("business_id")); checkinout.add((String) document.get("business_id")); } if (jComboBox8.getSelectedItem().equals("<") && num_checkin < Long.parseLong(check_count_value)) { System.out .println(num_checkin + " checkins into " + doc.get("business_id")); checkinout.add((String) document.get("business_id")); } if (jComboBox8.getSelectedItem().equals("=") && num_checkin == Long.parseLong(check_count_value)) { System.out .println(num_checkin + " checkins into " + doc.get("business_id")); checkinout.add((String) document.get("business_id")); } } num_checkin = 0; } } catch (Exception e) { System.out.println(e); } } }); if (fromdate_value != null && todate_value != null) { BasicDBObject fdv = new BasicDBObject("date", new BasicDBObject("$gte", fromdate_value)); ReviewList.add(fdv); BasicDBObject tdv = new BasicDBObject("date", new BasicDBObject("$lte", todate_value)); ReviewList.add(tdv); } if (stars_value != null) { if (stars_dropdown == ">") { BasicDBObject sv = new BasicDBObject("stars", new BasicDBObject("$gt", Integer.parseInt(stars_value))); ReviewList.add(sv); } if (stars_dropdown == "<") { BasicDBObject sv = new BasicDBObject("stars", new BasicDBObject("$lt", Integer.parseInt(stars_value))); ReviewList.add(sv); } if (stars_dropdown == "=") { BasicDBObject sv = new BasicDBObject("stars", Integer.parseInt(stars_value)); ReviewList.add(sv); } } if (votes_value != null) { if (votes_dropdown == ">") { BasicDBObject vv = new BasicDBObject("votes", new BasicDBObject("$gt", Integer.parseInt(votes_value))); //ReviewList.add(vv); } if (votes_dropdown == "<") { BasicDBObject vv = new BasicDBObject("votes", new BasicDBObject("$lt", Integer.parseInt(votes_value))); //ReviewList.add(vv); } if (votes_dropdown == "=") { BasicDBObject vv = new BasicDBObject("votes", Integer.parseInt(votes_value)); //ReviewList.add(vv); } } qryReview = new BasicDBObject("$and", ReviewList); if (qryReview == null) { //jTextField8.setText("db.review.find()"); cursor1 = rcoll.find(); } else { //jTextField8.setText("db.review.find("+qryReview.toString()+")"); cursor1 = rcoll.find(qryReview); } cursor1.forEach(new Block<Document>() { @Override public void apply(final Document document) { System.out.println(document.get("business_id")); reviewout.add((String) document.get("business_id")); } }); if ("AND".equals(jComboBox1.getSelectedItem().toString())) { //jTextField8.setText("db.checkin.find("+"{}"+","+"{business_id"+":1}"+")"); List<String> fin = new ArrayList<String>(catout); System.out.println(fin.size()); fin.retainAll(proout); System.out.println(fin.size()); fin.retainAll(checkinout); System.out.println(fin.size()); fin.retainAll(reviewout); // System.out.println(fin.size()); String Columnames[] = { "Business_id", "state", "city", "stars" }; DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel(); dtm.setColumnCount(0); dtm.setRowCount(0); int numberOfColumns = Columnames.length; Object rowData[] = new Object[numberOfColumns]; for (int i = 0; i < numberOfColumns; i++) { String name = Columnames[i]; dtm.addColumn(name); } for (int i = 0; i < fin.size(); i++) { rowData[0] = fin.get(i); BasicDBObject c11 = new BasicDBObject("business_id", fin.get(i)); FindIterable<Document> f1; f1 = coll.find(c11); f1.forEach(new Block<Document>() { @Override public void apply(final Document document) { Object rowData[] = new Object[numberOfColumns]; rowData[0] = document.get("business_id"); rowData[1] = document.get("state"); rowData[2] = document.get("city"); rowData[3] = document.get("stars"); dtm.addRow(rowData); rowData = null; } }); // // // } jTable1.setRowSelectionAllowed(true); jTable1.setModel(dtm); jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); dtm.fireTableDataChanged(); } if ("OR".equals(jComboBox1.getSelectedItem().toString())) { //MongoCollection<Document> = db.getCollection("business"); //jTextField8.setText("db.checkin.find("+"{}"+","+"{business_id"+":1}"+")"); List<String> fin = new ArrayList<String>(catout); //create a Set with all the elements in a fin.addAll(proout); System.out.println(fin.size()); fin.addAll(checkinout); System.out.println(fin.size()); fin.addAll(reviewout); System.out.println(fin.size()); String Columnames[] = { "Business_id", "state", "city", "stars" }; DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel(); dtm.setColumnCount(0); dtm.setRowCount(0); int numberOfColumns = Columnames.length; //Object rowData[] = new Object[numberOfColumns]; //Object rd1,rd2,rd3; for (int i = 0; i < numberOfColumns; i++) { String name = Columnames[i]; dtm.addColumn(name); } for (int i = 0; i < fin.size(); i++) { Object rowData[] = new Object[numberOfColumns]; rowData[0] = fin.get(i); BasicDBObject c11 = new BasicDBObject("business_id", fin.get(i)); FindIterable<Document> f1; f1 = coll.find(c11); f1.forEach(new Block<Document>() { @Override public void apply(final Document document) { Object rowData[] = new Object[numberOfColumns]; rowData[0] = document.get("business_id"); rowData[1] = document.get("state"); rowData[2] = document.get("city"); rowData[3] = document.get("stars"); dtm.addRow(rowData); rowData = null; } }); } // }); //Object rowData[] = new Object[numberOfColumns]; // // // jTable1.setRowSelectionAllowed(true); jTable1.setModel(dtm); jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); dtm.fireTableDataChanged(); } if (qryBusiness == null) { //jTextField8.setText("db.business.find()"); cursor = coll.find(); } else { //jTextField8.setText("db.business.find("+qryBusiness.toString()+")"); cursor = coll.find(qryBusiness); } // } catch (SQLException ex) { // Logger.getLogger(hw.class.getName()).log(Level.SEVERE, null, ex); // } // // // // } } }
From source file:org.sead.repositories.reference.RefRepository.java
private JsonNode getItem(String item, File indexFile, CountingInputStream cis, boolean withChildren, Long oreFileSize, long curOffset, ArrayList<String> entries, ArrayList<Long> offsets) throws JsonParseException, JsonMappingException, IOException { log.trace("Getting: " + item + " with starting offset: " + curOffset); long curPos = curOffset; if ((entries == null) || (offsets == null)) { entries = new ArrayList<String>(); offsets = new ArrayList<Long>(); FileInputStream fis = new FileInputStream(indexFile); JsonFactory f = new MappingJsonFactory(); JsonParser jp = f.createParser(fis); JsonToken current;/*from w w w . j a v a2s . co m*/ log.trace("Reading Index file"); current = jp.nextToken(); // Start object while ((current = jp.nextToken()) != null) { if (current.equals(JsonToken.FIELD_NAME)) { String fName = jp.getText(); current = jp.nextToken(); // Get to start of // value long offset = jp.getLongValue(); log.trace("Adding: " + fName + " : " + offset); entries.add(fName); offsets.add(offset); } } try { fis.close(); } catch (Exception e) { log.debug(e.getMessage()); } } byte[] b = null; int bytesRead = 0; int index = entries.indexOf(item); if (index == -1) { log.warn(item + " not in index"); } // getSizeEstimateFor(index) int estSize; if (index < offsets.size() - 1) { estSize = (int) (offsets.get(index + 1) - offsets.get(index)); } else { estSize = (int) (oreFileSize - offsets.get(index)); } curPos += skipTo(cis, curPos, offsets.get(index)); log.trace("Current Pos updated to : " + curPos); b = new byte[estSize]; bytesRead = cis.read(b); log.trace("Read " + bytesRead + " bytes"); if (bytesRead == estSize) { log.trace("Read: " + new String(b)); InputStream is = new ByteArrayInputStream(b); // mapper seems to be OK ignoring a last char such as a comma after // the object/tree ObjectNode resultNode = (ObjectNode) mapper.readTree(is); try { is.close(); } catch (Exception e) { log.debug(e.getMessage()); } curPos += bytesRead; log.trace("curPos: " + curPos + " : count: " + cis.getByteCount()); log.trace(resultNode.toString()); if ((resultNode.has("Has Part")) && withChildren) { resultNode = getChildren(resultNode, indexFile, cis, oreFileSize, curPos, entries, offsets); } else { resultNode.remove("aggregates"); } /* * if (args[2] != null) { long offset2 = Long.parseLong(args[2]); * sbc.position(offset2); b.clear(); sbc.read(b); * * InputStream is2 = new ByteArrayInputStream(b.array()); * * JsonNode node2 = mapper.readTree(is2); * System.out.println(node2.toString()); is2.close(); } */ return resultNode; } else { return null; } }
From source file:com.geotrackin.gpslogger.GpsMainActivity.java
/** * Allows user to send a GPX/KML file along with location, or location only * using a provider. 'Provider' means any application that can accept such * an intent (Facebook, SMS, Twitter, Email, K-9, Bluetooth) *//*from w w w . j a v a 2s.c o m*/ private void Share() { tracer.debug("GpsMainActivity.Share"); try { final String locationOnly = getString(R.string.sharing_location_only); final File gpxFolder = new File(AppSettings.getGpsLoggerFolder()); if (gpxFolder.exists()) { File[] enumeratedFiles = Utilities.GetFilesInFolder(gpxFolder); Arrays.sort(enumeratedFiles, new Comparator<File>() { public int compare(File f1, File f2) { return -1 * Long.valueOf(f1.lastModified()).compareTo(f2.lastModified()); } }); List<String> fileList = new ArrayList<String>(enumeratedFiles.length); for (File f : enumeratedFiles) { fileList.add(f.getName()); } fileList.add(0, locationOnly); final String[] files = fileList.toArray(new String[fileList.size()]); final ArrayList selectedItems = new ArrayList(); // Where we track the selected items AlertDialog.Builder builder = new AlertDialog.Builder(this); // Set the dialog title builder.setTitle(R.string.osm_pick_file) .setMultiChoiceItems(files, null, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { if (isChecked) { if (which == 0) { //Unselect all others ((AlertDialog) dialog).getListView().clearChoices(); ((AlertDialog) dialog).getListView().setItemChecked(which, isChecked); selectedItems.clear(); } else { //Unselect the settings item ((AlertDialog) dialog).getListView().setItemChecked(0, false); if (selectedItems.contains(0)) { selectedItems.remove(selectedItems.indexOf(0)); } } selectedItems.add(which); } else if (selectedItems.contains(which)) { // Else, if the item is already in the array, remove it selectedItems.remove(Integer.valueOf(which)); } } }).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { if (selectedItems.size() <= 0) { return; } final Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("*/*"); if (selectedItems.get(0).equals(0)) { tracer.debug("User selected location only"); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.sharing_mylocation)); if (Session.hasValidLocation()) { String bodyText = getString(R.string.sharing_googlemaps_link, String.valueOf(Session.getCurrentLatitude()), String.valueOf(Session.getCurrentLongitude())); intent.putExtra(Intent.EXTRA_TEXT, bodyText); intent.putExtra("sms_body", bodyText); startActivity( Intent.createChooser(intent, getString(R.string.sharing_via))); } } else { intent.setAction(Intent.ACTION_SEND_MULTIPLE); intent.putExtra(Intent.EXTRA_SUBJECT, "Geotrackin (Android app): Here are some files."); intent.setType("*/*"); ArrayList<Uri> chosenFiles = new ArrayList<Uri>(); for (Object path : selectedItems) { File file = new File(gpxFolder, files[Integer.valueOf(path.toString())]); Uri uri = Uri.fromFile(file); chosenFiles.add(uri); } intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, chosenFiles); startActivity(Intent.createChooser(intent, getString(R.string.sharing_via))); } } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { selectedItems.clear(); } }); builder.create(); builder.show(); } else { Utilities.MsgBox(getString(R.string.sorry), getString(R.string.no_files_found), this); } } catch (Exception ex) { tracer.error("Share", ex); } }
From source file:com.atomjack.vcfp.VideoControllerView.java
private void initControllerView(View v) { mPauseButton = (ImageButton) v.findViewById(R.id.pause); if (mPauseButton != null) { mPauseButton.requestFocus();// w ww. j a v a 2 s . co m mPauseButton.setOnClickListener(mPauseListener); } mFullscreenButton = (ImageButton) v.findViewById(R.id.fullscreen); if (mFullscreenButton != null) { mFullscreenButton.requestFocus(); mFullscreenButton.setOnClickListener(mFullscreenListener); } mMediaOptionsButton = (ImageButton) v.findViewById(R.id.mediaOptions); if (mMediaOptionsButton != null) { mMediaOptionsButton.setOnClickListener(mMediaOptionsListener); } mMicButton = (ImageButton) v.findViewById(R.id.mic); if (mMicButton != null) { mMicButton.setOnClickListener(mMicListener); } mMediaControllerPosterContainer = (ViewGroup) v.findViewById(R.id.mediaControllerPosterContainer); mMediaControllerPosterContainer.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { mPlayer.onPosterContainerTouch(v, event); return true; } }); mFfwdButton = (ImageButton) v.findViewById(R.id.ffwd); if (mFfwdButton != null) { mFfwdButton.setOnClickListener(mFfwdListener); if (!mFromXml) { mFfwdButton.setVisibility(mUseFastForward ? View.VISIBLE : View.GONE); } } mRewButton = (ImageButton) v.findViewById(R.id.rew); if (mRewButton != null) { mRewButton.setOnClickListener(mRewListener); if (!mFromXml) { mRewButton.setVisibility(mUseFastForward ? View.VISIBLE : View.GONE); } } mStopButton = (ImageButton) v.findViewById(R.id.stop); if (mStopButton != null) { mStopButton.setOnClickListener(mStopListener); } // By default these are hidden. They will be enabled when setPrevNextListeners() is called mNextButton = (ImageButton) v.findViewById(R.id.next); if (mNextButton != null && !mFromXml && !mListenersSet) { mNextButton.setVisibility(View.GONE); } mPrevButton = (ImageButton) v.findViewById(R.id.prev); if (mPrevButton != null && !mFromXml && !mListenersSet) { mPrevButton.setVisibility(View.GONE); } mPoster = (ImageView) v.findViewById(R.id.poster); if (mPosterBitmap != null) mPoster.setImageBitmap(mPosterBitmap); mBitrateSpinner = (CustomSpinner) v.findViewById(R.id.bitrateSpinner); if (mBitrateSpinner != null) { mBitrateSpinner.getBackground().setColorFilter(ContextCompat.getColor(mContext, R.color.white), PorterDuff.Mode.SRC_ATOP); final ArrayList<String> list = new ArrayList<>( VoiceControlForPlexApplication.localVideoQualityOptions.keySet()); ArrayAdapter<String> adapter = new ArrayAdapter<String>(mContext, R.layout.bitrate_dropdown_item, list) { @Override public View getView(int position, View convertView, ViewGroup parent) { TextView textView = (TextView) super.getView(position, convertView, parent); textView.setTextColor(ContextCompat.getColor(mContext, R.color.white)); return textView; } @Override public View getDropDownView(int position, View convertView, ViewGroup parent) { TextView textView = (TextView) super.getDropDownView(position, convertView, parent); textView.setTextColor(ContextCompat.getColor(mContext, textView.getText().equals(mCurrentVideoQuality) ? R.color.black : R.color.white)); textView.setBackgroundColor(ContextCompat.getColor(mContext, textView.getText().equals(mCurrentVideoQuality) ? R.color.white : R.color.mediaControllerBackground)); return textView; } }; mBitrateSpinner.setAdapter(adapter); mBitrateSpinner.setSelection(list.indexOf(mCurrentVideoQuality), false); mBitrateSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { String item = list.get(position); // Only notify the activity if the bitrate clicked on is not the current one if (mBitrateChangeListener != null && !item.equals(mCurrentVideoQuality)) { hide(); mBitrateChangeListener.onBitrateChange(item); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); mBitrateSpinner.setSpinnerEventsListener(new CustomSpinner.OnSpinnerEventsListener() { @Override public void onSpinnerOpened() { mBitrateSpinnerIsOpen = true; } @Override public void onSpinnerClosed() { mBitrateSpinnerIsOpen = false; // hide the controller after 3 seconds Message msg = mHandler.obtainMessage(FADE_OUT); mHandler.removeMessages(FADE_OUT); mHandler.sendMessageDelayed(msg, sDefaultTimeout); } }); } mProgress = (SeekBar) v.findViewById(R.id.mediacontroller_progress); if (mProgress != null) { if (mProgress instanceof SeekBar) { SeekBar seeker = (SeekBar) mProgress; seeker.setOnSeekBarChangeListener(mSeekListener); } mProgress.setMax(1000); } mEndTime = (TextView) v.findViewById(R.id.time); mCurrentTime = (TextView) v.findViewById(R.id.time_current); mFormatBuilder = new StringBuilder(); mFormatter = new Formatter(mFormatBuilder, Locale.getDefault()); installPrevNextListeners(); }