List of usage examples for java.util ArrayList contains
public boolean contains(Object o)
From source file:com.ffmpeger.card.iabutils.IabHelper.java
int querySkuDetails(String itemType, Inventory inv, List<String> moreSkus) throws RemoteException, JSONException { logDebug("Querying SKU details."); ArrayList<String> skuList = new ArrayList<String>(); skuList.addAll(inv.getAllOwnedSkus(itemType)); if (moreSkus != null) { for (String sku : moreSkus) { if (!skuList.contains(sku)) { skuList.add(sku);/*ww w . j a va 2 s. c o m*/ } } } if (skuList.size() == 0) { logDebug("queryPrices: nothing to do because there are no SKUs."); return BILLING_RESPONSE_RESULT_OK; } // Split the sku list in blocks of no more than 20 elements. ArrayList<ArrayList<String>> packs = new ArrayList<ArrayList<String>>(); ArrayList<String> tempList; int n = skuList.size() / 20; int mod = skuList.size() % 20; for (int i = 0; i < n; i++) { tempList = new ArrayList<String>(); for (String s : skuList.subList(i * 20, i * 20 + 20)) { tempList.add(s); } packs.add(tempList); } if (mod != 0) { tempList = new ArrayList<String>(); for (String s : skuList.subList(n * 20, n * 20 + mod)) { tempList.add(s); } packs.add(tempList); for (ArrayList<String> skuPartList : packs) { Bundle querySkus = new Bundle(); querySkus.putStringArrayList(GET_SKU_DETAILS_ITEM_LIST, skuPartList); Bundle skuDetails = mService.getSkuDetails(3, mContext.getPackageName(), itemType, querySkus); if (!skuDetails.containsKey(RESPONSE_GET_SKU_DETAILS_LIST)) { int response = getResponseCodeFromBundle(skuDetails); if (response != BILLING_RESPONSE_RESULT_OK) { logDebug("getSkuDetails() failed: " + getResponseDesc(response)); return response; } else { logError("getSkuDetails() returned a bundle with neither an error nor a detail list."); return IABHELPER_BAD_RESPONSE; } } ArrayList<String> responseList = skuDetails.getStringArrayList(RESPONSE_GET_SKU_DETAILS_LIST); for (String thisResponse : responseList) { SkuDetails d = new SkuDetails(itemType, thisResponse); logDebug("Got sku details: " + d); inv.addSkuDetails(d); } } } return BILLING_RESPONSE_RESULT_OK; }
From source file:com.globalsight.everest.tda.TdaHelper.java
private void sortMatchList(ArrayList matchList) { for (int i = 0; i < matchList.size() - 1; i++) { LeverageTDAResult tdaResult1 = (LeverageTDAResult) matchList.get(i); for (int j = i + 1; j < matchList.size(); j++) { LeverageTDAResult tdaResult2 = (LeverageTDAResult) matchList.get(j); if (PecentToInt(tdaResult1.getMatchPercent()) < PecentToInt(tdaResult2.getMatchPercent())) { LeverageTDAResult temp = tdaResult1; tdaResult1 = tdaResult2; tdaResult2 = temp;/*from ww w .j av a2 s . c o m*/ } tdaResult1.setOrderNum(TmCoreManager.LM_ORDER_NUM_START_TDA + i); tdaResult2.setOrderNum(TmCoreManager.LM_ORDER_NUM_START_TDA + j); matchList.set(i, tdaResult1); matchList.set(j, tdaResult2); } } // remember the segment whose match percent and match content is all // same ArrayList<LeverageTDAResult> sameArray = new ArrayList<LeverageTDAResult>(); for (int i = 0; i < matchList.size() - 1; i++) { LeverageTDAResult tdaResult1 = (LeverageTDAResult) matchList.get(i); for (int j = i + 1; j < matchList.size(); j++) { LeverageTDAResult tdaResult2 = (LeverageTDAResult) matchList.get(j); if (PecentToInt(tdaResult1.getMatchPercent()) == PecentToInt(tdaResult2.getMatchPercent()) && tdaResult1.getResultText().equals(tdaResult2.getResultText())) { if (!sameArray.contains(tdaResult2)) { sameArray.add(tdaResult2); } } } } matchList.removeAll(sameArray); }
From source file:com.concursive.connect.web.modules.messages.workflow.SendPrivateMessageNotification.java
/** * Description of the Method/* ww w . java 2s. co m*/ * * @param context Description of the Parameter * @return Description of the Return Value */ public boolean execute(ComponentContext context) { boolean result = false; try { ArrayList<Integer> users = new ArrayList<Integer>(); // Add project leads Project thisProject = (Project) context.getAttribute(PROJECT); PrivateMessage thisPrivateMessage = (PrivateMessage) context.getThisObject(); User senderUser = UserUtils.loadUser(thisPrivateMessage.getEnteredBy()); String url = context.getParameter(URL); Key key = (Key) context.getAttribute("TEAM.KEY"); Configuration freeMarkerConfiguration = (Configuration) context .getAttribute(ComponentContext.FREEMARKER_CONFIGURATION); // Go through userIds set as attributes String includeList = (String) context.getAttribute(USERS_TO_IDS); if (includeList != null) { StringTokenizer st = new StringTokenizer(includeList, ","); while (st.hasMoreTokens()) { Integer id = Integer.parseInt(st.nextToken().trim()); if (!users.contains(id)) { users.add(id); } } } // Send the message(s) if (users.size() > 0) { SMTPMessage message = SMTPMessageFactory.createSMTPMessageInstance(context.getApplicationPrefs()); message.setFrom(context.getParameter(ComponentContext.APPLICATION_EMAIL_ADDRESS)); message.setType("text/html"); // Send to each user Iterator userList = users.iterator(); while (userList.hasNext()) { Integer id = (Integer) userList.next(); User teamMemberUser = UserUtils.loadUser(id.intValue()); String email = teamMemberUser.getEmail(); // Initialize the message template Template inviteSubject = null; Template inviteBody = null; // Set the data model Map subjectMappings = new HashMap(); subjectMappings.put("user", senderUser); Map bodyMappings = new HashMap(); bodyMappings.put("site", new HashMap()); ((Map) bodyMappings.get("site")).put("title", context.getApplicationPrefs().get(ApplicationPrefs.WEB_PAGE_TITLE)); bodyMappings.put("project", thisProject); bodyMappings.put("user", senderUser); bodyMappings.put("teamMember", teamMemberUser); bodyMappings.put("private", new HashMap()); ((Map) bodyMappings.get("private")).put("message", StringUtils.toHtmlValue(thisPrivateMessage.getBody())); bodyMappings.put("link", new HashMap()); ((Map) bodyMappings.get("link")).put("info", url); ((Map) bodyMappings.get("link")).put("projectMessages", url + "/show/" + thisProject.getUniqueId() + "/message/inbox/" + thisPrivateMessage.getId()); inviteSubject = freeMarkerConfiguration.getTemplate("project_private_message_subject-text.ftl"); inviteBody = freeMarkerConfiguration.getTemplate("project_private_message_body-html.ftl"); // Set the subject from the template StringWriter inviteSubjectTextWriter = new StringWriter(); inviteSubject.process(subjectMappings, inviteSubjectTextWriter); message.setSubject(inviteSubjectTextWriter.toString()); // Set the body from the template StringWriter inviteBodyTextWriter = new StringWriter(); inviteBody.process(bodyMappings, inviteBodyTextWriter); message.setBody(inviteBodyTextWriter.toString()); message.setTo(email); message.setType("text/html"); int emailResult = message.send(); if (emailResult == 0) { LOG.debug("email sent successfully to " + teamMemberUser.getNameFirstLast()); } else { LOG.debug("email not sent to " + teamMemberUser.getNameFirstLast()); } } } result = true; } catch (Exception e) { e.printStackTrace(System.out); } return result; }
From source file:antiboring.game.controller.appBilling.util.IabHelper.java
int querySkuDetails(String itemType, Inventory inv, List<String> moreSkus) throws RemoteException, JSONException { logDebug("Querying SKU details."); ArrayList<String> skuList = new ArrayList<String>(); skuList.addAll(inv.getAllOwnedSkus(itemType)); if (moreSkus != null) { for (String sku : moreSkus) { if (!skuList.contains(sku)) { skuList.add(sku);//ww w .ja v a 2 s . c o m } } } if (skuList.size() == 0) { logDebug("queryPrices: nothing to do because there are no SKUs."); return BILLING_RESPONSE_RESULT_OK; } // Split the sku list in blocks of no more than 20 elements. ArrayList<ArrayList<String>> packs = new ArrayList<ArrayList<String>>(); ArrayList<String> tempList; int n = skuList.size() / 20; int mod = skuList.size() % 20; for (int i = 0; i < n; i++) { tempList = new ArrayList<String>(); for (String s : skuList.subList(i * 20, i * 20 + 20)) { tempList.add(s); } packs.add(tempList); } if (mod != 0) { tempList = new ArrayList<String>(); for (String s : skuList.subList(n * 20, n * 20 + mod)) { tempList.add(s); } packs.add(tempList); } for (ArrayList<String> skuPartList : packs) { Bundle querySkus = new Bundle(); querySkus.putStringArrayList(GET_SKU_DETAILS_ITEM_LIST, skuPartList); Bundle skuDetails = mService.getSkuDetails(3, mContext.getPackageName(), itemType, querySkus); if (!skuDetails.containsKey(RESPONSE_GET_SKU_DETAILS_LIST)) { int response = getResponseCodeFromBundle(skuDetails); if (response != BILLING_RESPONSE_RESULT_OK) { logDebug("getSkuDetails() failed: " + getResponseDesc(response)); return response; } else { logError("getSkuDetails() returned a bundle with neither an error nor a detail list."); return IABHELPER_BAD_RESPONSE; } } ArrayList<String> responseList = skuDetails.getStringArrayList(RESPONSE_GET_SKU_DETAILS_LIST); for (String thisResponse : responseList) { SkuDetails d = new SkuDetails(itemType, thisResponse); logDebug("Got sku details: " + d); inv.addSkuDetails(d); } } return BILLING_RESPONSE_RESULT_OK; }
From source file:module.siadap.presentationTier.actions.SiadapPersonnelManagement.java
@EntryPoint public final ActionForward start(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) throws Exception { SiadapYearWrapper siadapYearWrapper = (SiadapYearWrapper) getRenderedObject("siadapYearWrapper"); String yearString = getAttribute(request, "year"); if (siadapYearWrapper == null && yearString != null) { siadapYearWrapper = new SiadapYearWrapper(Integer.valueOf(yearString)); }/*from w ww. jav a2 s. c o m*/ if (siadapYearWrapper == null) { ArrayList<Integer> yearsWithConfigs = SiadapYearsFromExistingSiadapConfigurations .getYearsWithExistingConfigs(); if (yearsWithConfigs.contains(new Integer(new LocalDate().getYear()))) { int year = new LocalDate().getYear(); siadapYearWrapper = new SiadapYearWrapper(year); } else { siadapYearWrapper = new SiadapYearWrapper(yearsWithConfigs.get(yearsWithConfigs.size() - 1)); } } request.setAttribute("siadapYearWrapper", siadapYearWrapper); VariantBean bean = new VariantBean(); request.setAttribute("bean", bean); // let's get all of the people that aren't harmonized for this year Set<Siadap> siadapsWithoutValidHarmonizationUnit = siadapYearWrapper.getSiadapYearConfiguration() .getSiadapsWithoutValidHarmonizationUnit(); if (siadapsWithoutValidHarmonizationUnit.isEmpty() == false) { addLocalizedWarningMessage(request, BundleUtil.getString(Siadap.SIADAP_BUNDLE_STRING, "siadapPersonnelManagement.start.warning.withoutValidHarm")); } request.setAttribute("person", new PersonSiadapWrapper(Authenticate.getUser().getPerson(), new LocalDate().getYear())); return forward("/module/siadap/management/start.jsp"); }
From source file:cz.mzk.editor.server.config.EditorConfiguration.java
public List<Constants.USER_IDENTITY_TYPES> getIdentityTypes() { String[] identities = getConfiguration().getStringArray(ServerConstants.IDENTITIES); if (identities == null || identities.length == 0) { ArrayList<USER_IDENTITY_TYPES> idents = new ArrayList<Constants.USER_IDENTITY_TYPES>(); idents.add(USER_IDENTITY_TYPES.OPEN_ID); return idents; } else {/* w w w . j av a 2 s. co m*/ ArrayList<USER_IDENTITY_TYPES> idents = new ArrayList<Constants.USER_IDENTITY_TYPES>(identities.length); for (int i = 0; i < identities.length; i++) { if (identities[i].toLowerCase().equals("openid") && !idents.contains(USER_IDENTITY_TYPES.OPEN_ID)) { idents.add(USER_IDENTITY_TYPES.OPEN_ID); } if (identities[i].toLowerCase().equals("ldap") && !idents.contains(USER_IDENTITY_TYPES.LDAP)) { idents.add(USER_IDENTITY_TYPES.LDAP); } if (identities[i].toLowerCase().equals("shibboleth") && !idents.contains(USER_IDENTITY_TYPES.SHIBBOLETH)) { idents.add(USER_IDENTITY_TYPES.SHIBBOLETH); } } if (idents.isEmpty()) idents.add(USER_IDENTITY_TYPES.OPEN_ID); return idents; } }
From source file:blue.Arrangement.java
public String generateGlobalOrc() { StrBuilder retVal = new StrBuilder(); ArrayList<Instrument> instruments = new ArrayList<Instrument>(); for (Iterator<InstrumentAssignment> iter = arrangement.iterator(); iter.hasNext();) { InstrumentAssignment ia = iter.next(); if (!ia.enabled) { continue; }// w ww . j a v a 2 s . c o m Instrument instr = ia.instr; if (!instruments.contains(instr)) { String globalOrc = instr.generateGlobalOrc(); if (globalOrc != null) { String transformed = replaceInstrumentId(ia, globalOrc); retVal.append(transformed); retVal.append("\n"); } instruments.add(instr); } } return retVal.toString(); }
From source file:net.lightbody.bmp.proxy.jetty.util.JarFileResource.java
public synchronized String[] list() { if (isDirectory() && _list == null) { ArrayList list = new ArrayList(32); checkConnection();/*w ww. j a v a2 s . c om*/ JarFile jarFile = _jarFile; if (jarFile == null) { try { jarFile = ((JarURLConnection) ((new URL(_jarUrl)).openConnection())).getJarFile(); } catch (Exception e) { LogSupport.ignore(log, e); } } Enumeration e = jarFile.entries(); String dir = _urlString.substring(_urlString.indexOf("!/") + 2); while (e.hasMoreElements()) { JarEntry entry = (JarEntry) e.nextElement(); String name = entry.getName().replace('\\', '/'); if (!name.startsWith(dir) || name.length() == dir.length()) continue; String listName = name.substring(dir.length()); int dash = listName.indexOf('/'); if (dash >= 0) { listName = listName.substring(0, dash + 1); if (list.contains(listName)) continue; } list.add(listName); } _list = new String[list.size()]; list.toArray(_list); } return _list; }
From source file:controlador.Peticiones.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// w w w.j av a2 s . co m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //response.setContentType("text/html;charset=UTF-8"); String target, op, action, view; target = request.getParameter("target"); op = request.getParameter("op"); if (target.equals("login")) { bd = new ControlDB(); bd.cargarDriver(); bd.conectar(); String login = request.getParameter("login"); String pass = request.getParameter("password"); ResultSet r = bd.ejecutarSelect("SELECT * FROM roles WHERE nombreRol='" + login + "' AND passRol='" + Auxiliar.encriptarPass(pass) + "'"); JSONObject objetoJSON = new JSONObject(); response.setContentType("application/json; charset=utf-8"); response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); try { if (r != null && r.next()) { objetoJSON.put("r", "1"); out.print(objetoJSON); } else { objetoJSON.put("r", "0"); out.print(objetoJSON); } } catch (SQLException ex) { } catch (JSONException ex) { } } else { if (target.equals("pedido")) { bd = new ControlDB(); bd.cargarDriver(); bd.conectar(); String s = request.getParameter("datos"); JSONTokener token = new JSONTokener(s); JSONArray ar = null; ArrayList<Producto> productos = new ArrayList(); try { ar = new JSONArray(token); for (int i = 0; i < ar.length(); i++) { agregarProducto(ar.getJSONObject(i).getInt("idMesa"), ar.getJSONObject(i).getInt("idProducto")); ResultSet rs = bd.ejecutarSelect("SELECT nombreProducto from productos where idProducto = " + ar.getJSONObject(i).getInt("idProducto")); rs.next(); String nombre = rs.getString("nombreProducto"); Producto pr = new Producto(nombre); if (productos.contains(pr)) { int pos = productos.indexOf(pr); productos.get(pos).sumaCantidad(); } else { productos.add(new Producto(nombre)); } } ResultSet nombreMesa = bd.ejecutarSelect( "SELECT nombreMesa, nombreZona from mesas inner join zona on idZona=Zona_Idzona where idmesa=" + ar.getJSONObject(0).getInt("idMesa")); nombreMesa.next(); String nombre = nombreMesa.getString("nombreMesa") + " " + nombreMesa.getString("nombreZona"); Comanda comanda = new Comanda(productos, nombre); System.out.println("Ticket: \n" + comanda.contenidoComanda); Auxiliar.imprimir(comanda.contenidoComanda); } catch (JSONException ex) { System.out.println("Error JSON " + ex.toString()); } catch (SQLException ex) { System.out.println("Error SQL " + ex.toString()); } // Crear un el objeto para enviar a comanda para imprimir, implementar response.setHeader("Content-Type", "application/json"); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); JSONObject obj = new JSONObject(); try { obj.put("r", "recibido"); } catch (JSONException ex) { } out.print(obj); out.flush(); } else { if (target.equals("mesas")) { bd = new ControlDB(); bd.cargarDriver(); bd.conectar(); ResultSet r = bd.ejecutarSelect( "SELECT mesas.idMesa, nombreMesa, nombreZona FROM mesas inner join zona on idzona = Zona_idZona"); JSONArray array = new JSONArray(); ResultSetMetaData rsMetaData = null; int columns = 0; try { rsMetaData = r.getMetaData(); columns = rsMetaData.getColumnCount(); } catch (SQLException ex) { } try { while (r.next()) { JSONObject objetoJSON = new JSONObject(); for (int i = 1; i <= columns; i++) { objetoJSON.put(rsMetaData.getColumnLabel(i), r.getString(i)); } System.out.println(objetoJSON + "\n"); array.put(objetoJSON); } } catch (SQLException ex) { } catch (JSONException ex) { } response.setHeader("Content-Type", "application/json"); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); out.print(array); out.flush(); } else { if (target.equals("familias")) { bd = new ControlDB(); bd.cargarDriver(); bd.conectar(); ResultSet r = bd.ejecutarSelect( "SELECT idFamilia, nombreFamilia FROM `familias` order by idFamilia"); JSONArray array = new JSONArray(); ResultSetMetaData rsMetaData = null; int columns = 0; try { rsMetaData = r.getMetaData(); columns = rsMetaData.getColumnCount(); } catch (SQLException ex) { } try { while (r.next()) { JSONObject objetoJSON = new JSONObject(); for (int i = 1; i <= columns; i++) { objetoJSON.put(rsMetaData.getColumnLabel(i), r.getString(i)); } array.put(objetoJSON); } } catch (SQLException ex) { } catch (JSONException ex) { ; } response.setHeader("Content-Type", "application/json"); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); out.print(array); out.flush(); } else { if (target.equals("productos")) { bd = new ControlDB(); bd.cargarDriver(); bd.conectar(); ResultSet r = bd.ejecutarSelect( "SELECT idProducto, nombreProducto,fotoProducto , precioProducto, Familias_idFamilias FROM productos order by idProducto"); JSONArray array = new JSONArray(); ResultSetMetaData rsMetaData = null; int columns = 0; try { rsMetaData = r.getMetaData(); columns = rsMetaData.getColumnCount(); } catch (SQLException ex) { } try { while (r.next()) { JSONObject objetoJSON = new JSONObject(); for (int i = 1; i <= columns; i++) { objetoJSON.put(rsMetaData.getColumnLabel(i), r.getString(i)); } array.put(objetoJSON); } } catch (SQLException ex) { } catch (JSONException ex) { } response.setHeader("Content-Type", "application/json"); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); out.print(array); out.flush(); } } } } } }
From source file:com.clust4j.algo.MeanShift.java
@Override protected MeanShift fit() { synchronized (fitLock) { if (null != labels) // Already fit this model return this; // Put the results into a Map (hash because tree imposes comparable casting) final LogTimer timer = new LogTimer(); centroids = new ArrayList<double[]>(); /*/* w ww.j a v a2 s. com*/ * Get the neighborhoods and center intensity object. Will iterate until * either the centers are found, or the max try count is exceeded. For each * iteration, will increase bandwidth. */ RadiusNeighbors nbrs = new RadiusNeighbors(this, bandwidth).fit(); // Compute the seeds and center intensity // If parallelism is permitted, try it. CenterIntensity intensity = null; if (parallel) { try { intensity = new ParallelCenterIntensity(nbrs); } catch (RejectedExecutionException e) { // Shouldn't happen... warn("parallel search failed; falling back to serial"); } } // Gets here if serial or if parallel failed... if (null == intensity) intensity = new SerialCenterIntensity(nbrs); // Check for points all too far from seeds if (intensity.isEmpty()) { error(new IllegalClusterStateException("No point " + "was within bandwidth=" + bandwidth + " of any seed; try increasing bandwidth")); } else { converged = true; itersElapsed = intensity.getIters(); // max iters elapsed } // Extract the centroids int idx = 0, m_prime = intensity.size(); final Array2DRowRealMatrix sorted_centers = new Array2DRowRealMatrix(m_prime, n); for (MeanShiftSeed entry : intensity) sorted_centers.setRow(idx++, entry.getPair().getKey()); // Fit the new neighbors model nbrs = new RadiusNeighbors(sorted_centers, new RadiusNeighborsParameters(bandwidth) .setSeed(this.random_state).setMetric(this.dist_metric).setForceParallel(parallel), true).fit(); // Post-processing. Remove near duplicate seeds // If dist btwn two kernels is less than bandwidth, remove one w fewer pts // Create a boolean mask, init true final boolean[] unique = new boolean[m_prime]; for (int i = 0; i < unique.length; i++) unique[i] = true; // Pre-filtered summaries... ArrayList<SummaryLite> allSummary = intensity.getSummaries(); // Iterate over sorted centers and query radii int redundant_ct = 0; int[] indcs; double[] center; for (int i = 0; i < m_prime; i++) { if (unique[i]) { center = sorted_centers.getRow(i); indcs = nbrs.getNeighbors(new double[][] { center }, bandwidth, false).getIndices()[0]; for (int id : indcs) unique[id] = false; unique[i] = true; // Keep this as true } } // Now assign the centroids... SummaryLite summ; for (int i = 0; i < unique.length; i++) { summ = allSummary.get(i); if (unique[i]) { summ.retained = true; centroids.add(sorted_centers.getRow(i)); } fitSummary.add(summ.toArray()); } // calc redundant ct redundant_ct = unique.length - centroids.size(); // also put the centroids into a matrix. We have to // wait to perform this op, because we have to know // the size of centroids first... Array2DRowRealMatrix centers = new Array2DRowRealMatrix(centroids.size(), n); for (int i = 0; i < centroids.size(); i++) centers.setRow(i, centroids.get(i)); // Build yet another neighbors model... NearestNeighbors nn = new NearestNeighbors(centers, new NearestNeighborsParameters(1) .setSeed(this.random_state).setMetric(this.dist_metric).setForceParallel(false), true).fit(); info((numClusters = centroids.size()) + " optimal kernel" + (numClusters != 1 ? "s" : "") + " identified"); info(redundant_ct + " nearly-identical kernel" + (redundant_ct != 1 ? "s" : "") + " removed"); // Get the nearest... final LogTimer clustTimer = new LogTimer(); Neighborhood knrst = nn.getNeighbors(data.getDataRef()); labels = MatUtils.flatten(knrst.getIndices()); // order the labels.. /* * Reduce labels to a sorted, gapless, list * sklearn line: cluster_centers_indices = np.unique(labels) */ ArrayList<Integer> centroidIndices = new ArrayList<Integer>(numClusters); for (Integer i : labels) // force autobox if (!centroidIndices.contains(i)) // Not race condition because synchronized centroidIndices.add(i); /* * final label assignment... * sklearn line: labels = np.searchsorted(cluster_centers_indices, labels) */ for (int i = 0; i < labels.length; i++) labels[i] = centroidIndices.indexOf(labels[i]); // Wrap up... // Count missing numNoisey = 0; for (int lab : labels) if (lab == NOISE_CLASS) numNoisey++; info(numNoisey + " record" + (numNoisey != 1 ? "s" : "") + " classified noise"); info("completed cluster labeling in " + clustTimer.toString()); sayBye(timer); return this; } }