List of usage examples for java.util HashSet clear
public void clear()
From source file:gov.nih.nci.cabig.caaers.web.study.SolicitedAdverseEventTab.java
@Override protected void validate(final StudyCommand command, final BeanWrapper commandBean, final Map<String, InputFieldGroup> fieldGroups, final Errors errors) { List<Epoch> listOfEpochs = command.getStudy().getActiveEpochs(); List<String> listOfEpochNames = new ArrayList<String>(); for (Epoch epoch : listOfEpochs) { if (epoch.getName() == null) epoch.setName("Enter name here"); if (StringUtils.isBlank(epoch.getName()) || epoch.getName().equalsIgnoreCase("Enter name here")) errors.reject("STU_015", "Each evaluation period type must have a valid title. Type the title or delete the evaluation period type."); listOfEpochNames.add(epoch.getName().toUpperCase()); }// w ww.j a v a2 s .c om java.util.Set<String> setOfEpochNames = new java.util.HashSet<String>(); for (Epoch epoch : listOfEpochs) { setOfEpochNames.add(epoch.getName().toUpperCase()); } if (setOfEpochNames.size() != listOfEpochNames.size()) errors.reject("STU_016", "There is a duplicate evaluation period type. Modify or delete the evaluation period types so they are all unique."); HashSet<SolicitedAdverseEvent> solicitedAEsWithinEpochSet = new HashSet<SolicitedAdverseEvent>(); HashMap<String, Boolean> otherMeddraErrorMap = new HashMap<String, Boolean>(); // This is used to avoid repeating the error messages. for (Epoch epoch : listOfEpochs) { solicitedAEsWithinEpochSet.clear(); for (SolicitedAdverseEvent sae : epoch.getArms().get(0).getSolicitedAdverseEvents()) { //check within an arm if terms are duplicated if (!solicitedAEsWithinEpochSet.add(sae)) { //this is a dup. String termName = (sae.getCtcterm() != null) ? sae.getCtcterm().getTerm() : sae.getLowLevelTerm().getMeddraTerm(); errors.reject("STU_001", new Object[] { termName, epoch.getName() }, "Duplicate term added in evaluation period"); } // Validate otherMeddra for ctc terminology. if (sae.getCtcterm() != null && sae.getCtcterm().isOtherRequired()) { if (sae.getVerbatim() == null && sae.getOtherTerm() == null && !otherMeddraErrorMap.containsKey(sae.getCtcterm().getTerm())) { errors.reject("STU_017", new Object[] { sae.getCtcterm().getTerm() }, "Other medDRA term or Verbatim is required for the term " + sae.getCtcterm().getTerm()); otherMeddraErrorMap.put(sae.getCtcterm().getTerm(), Boolean.TRUE); } } } } }
From source file:com.android.i18n.addressinput.CacheData.java
License:asdf
private void notifyListenersAfterJobDone(String key) { LookupKey lookupKey = new LookupKey.Builder(key).build(); HashSet<CacheListener> listeners = mTemporaryListenerStore.get(lookupKey); if (listeners != null) { for (CacheListener listener : listeners) { listener.onAdd(key.toString()); }/*w w w. j a v a 2 s . c om*/ listeners.clear(); } }
From source file:com.google.i18n.addressinput.common.CacheData.java
License:asdf
private void notifyListenersAfterJobDone(String key) { LookupKey lookupKey = new LookupKey.Builder(key).build(); HashSet<CacheListener> listeners = temporaryListenerStore.get(lookupKey); if (listeners != null) { for (CacheListener listener : listeners) { listener.onAdd(key.toString()); }//from w ww. ja v a 2 s. co m listeners.clear(); } }
From source file:org.tellervo.desktop.bulkdataentry.command.ImportSelectedObjectsCommand.java
/** * @see com.dmurph.mvc.control.ICommand#execute(com.dmurph.mvc.MVCEvent) *//*from www . j a va 2 s . com*/ @Override public void execute(MVCEvent argEvent) { BulkImportModel model = BulkImportModel.getInstance(); ObjectTableModel tmodel = model.getObjectModel().getTableModel(); ArrayList<IBulkImportSingleRowModel> selected = new ArrayList<IBulkImportSingleRowModel>(); tmodel.getSelected(selected); // here is where we verify they contain required info HashSet<String> requiredMessages = new HashSet<String>(); ArrayList<IBulkImportSingleRowModel> incompleteModels = new ArrayList<IBulkImportSingleRowModel>(); HashSet<String> definedProps = new HashSet<String>(); HashSet<String> objectCodeSet = new HashSet<String>(); for (IBulkImportSingleRowModel som : selected) { definedProps.clear(); for (String s : SingleObjectModel.TABLE_PROPERTIES) { if (som.getProperty(s) != null) { definedProps.add(s); } } boolean incomplete = false; // object code if (!definedProps.contains(SingleObjectModel.OBJECT_CODE)) { requiredMessages.add("Cannot import without an object code."); incomplete = true; } else { String code = som.getProperty(SingleObjectModel.OBJECT_CODE).toString(); if (code.length() < 3) { requiredMessages.add("Object code must be at least 3 characters"); incomplete = true; } if (code.contains(" ")) { requiredMessages.add("Object code cannot contain whitespace."); incomplete = true; } if (objectCodeSet.contains(code)) { requiredMessages.add("There cannot be duplicate object codes."); incomplete = true; } else { objectCodeSet.add(code); } } if (definedProps.contains(SingleObjectModel.PARENT_OBJECT)) { if (this.fixTempObjectCode(som)) { // fixed } else { requiredMessages.add("Cannot import as parent object has not been created yet"); incomplete = true; } } // type if (!definedProps.contains(SingleObjectModel.TYPE)) { requiredMessages.add("Object must contain type."); incomplete = true; } // title if (!definedProps.contains(SingleObjectModel.TITLE)) { requiredMessages.add("Object must have a title"); incomplete = true; } // lat/long if (definedProps.contains(SingleObjectModel.LATITUDE) || definedProps.contains(SingleObjectModel.LONGITUDE)) { if (!definedProps.contains(SingleObjectModel.LATITUDE) || !definedProps.contains(SingleObjectModel.LONGITUDE)) { requiredMessages .add("If coordinates are specified then both latitude and longitude are required"); incomplete = true; } else { String attempt = som.getProperty(SingleObjectModel.LATITUDE).toString().trim(); try { Double lat = Double.parseDouble(attempt); if (lat > -90 || lat < 90) { requiredMessages .add("Latitude must be betweOne or more errors were encountereden -90 and 90"); incomplete = true; } } catch (NumberFormatException e) { requiredMessages.add("Cannot parse '" + attempt + "' into a number."); incomplete = true; } attempt = som.getProperty(SingleObjectModel.LONGITUDE).toString().trim(); try { Double lng = Double.parseDouble(attempt); if (lng > -180 || lng < 180) { requiredMessages.add("Longitude must be between -180 and 180"); incomplete = true; } } catch (NumberFormatException e) { requiredMessages.add("Cannot parse '" + attempt + "' into a number."); incomplete = true; } } } if (incomplete) { incompleteModels.add(som); } } if (!incompleteModels.isEmpty()) { StringBuilder message = new StringBuilder(); message.append("Please correct the following errors:\n"); message.append(StringUtils.join(requiredMessages.toArray(), "\n")); Alert.message(model.getMainView(), "Importing Errors", message.toString()); return; } // now we actually create the models int i = 0; for (IBulkImportSingleRowModel srm : selected) { SingleObjectModel som = (SingleObjectModel) srm; TridasObjectEx origObject = new TridasObjectEx(); if (!som.isDirty()) { System.out.println("Object isn't dirty, not saving/updating: " + som.getProperty(SingleObjectModel.OBJECT_CODE).toString()); } som.populateTridasObject(origObject); TridasObject parentObject = null; try { parentObject = ((TridasObjectOrPlaceholder) som.getProperty(SingleObjectModel.PARENT_OBJECT)) .getTridasObject(); } catch (Exception e) { } EntityResource<TridasObjectEx> resource; if (origObject.getIdentifier() != null) { resource = new EntityResource<TridasObjectEx>(origObject, TellervoRequestType.UPDATE, TridasObjectEx.class); } else { if (parentObject != null) { resource = new EntityResource<TridasObjectEx>(origObject, parentObject, TridasObjectEx.class); } else { resource = new EntityResource<TridasObjectEx>(origObject, TellervoRequestType.CREATE, TridasObjectEx.class); } } // set up a dialog... Window parentWindow = SwingUtilities.getWindowAncestor(model.getMainView()); TellervoResourceAccessDialog dialog = new TellervoResourceAccessDialog(parentWindow, resource, i, selected.size()); resource.query(); dialog.setVisible(true); if (!dialog.isSuccessful()) { JOptionPane.showMessageDialog(BulkImportModel.getInstance().getMainView(), I18n.getText("error.savingChanges") + "\r\n" + I18n.getText("error") + ": " + dialog.getFailException().getLocalizedMessage(), I18n.getText("error"), JOptionPane.ERROR_MESSAGE); continue; } som.populateFromTridasObject(resource.getAssociatedResult()); som.setDirty(false); tmodel.setSelected(som, false); // add to imported list or update existing if (origObject.getIdentifier() != null) { TridasObjectEx found = null; for (TridasObjectEx tox : model.getObjectModel().getImportedList()) { if (tox.getIdentifier().getValue().equals(origObject.getIdentifier().getValue())) { found = tox; break; } } if (found == null) { Alert.error("Error updating model", "Couldn't find the object in the model to update, please report bug."); } else { resource.getAssociatedResult().copyTo(found); App.tridasObjects.updateTridasObject(found); } } else { model.getObjectModel().getImportedList().add(resource.getAssociatedResult()); App.tridasObjects.addTridasObject(resource.getAssociatedResult()); } i++; } // finally, update the combo boxes in the table to the new options //DynamicJComboBoxEvent event = new DynamicJComboBoxEvent(model.getObjectModel().getImportedDynamicComboBoxKey(), model.getObjectModel().getImportedListStrings()); //event.dispatch(); // FIXME this should be removed once other lists listen for changes in the object list //App.updateTridasObjectList(); }
From source file:org.tellervo.desktop.bulkdataentry.command.ImportSelectedElementsCommand.java
/** * @see com.dmurph.mvc.control.ICommand#execute(com.dmurph.mvc.MVCEvent) *///w ww .ja va2s . c om @Override public void execute(MVCEvent argEvent) { BulkImportModel model = BulkImportModel.getInstance(); ElementModel emodel = model.getElementModel(); ElementTableModel tmodel = emodel.getTableModel(); ArrayList<IBulkImportSingleRowModel> selected = new ArrayList<IBulkImportSingleRowModel>(); tmodel.getSelected(selected); // here is where we verify they contain required info HashSet<String> requiredMessages = new HashSet<String>(); ArrayList<IBulkImportSingleRowModel> incompleteModels = new ArrayList<IBulkImportSingleRowModel>(); HashSet<String> definedProps = new HashSet<String>(); for (IBulkImportSingleRowModel som : selected) { definedProps.clear(); for (String s : SingleElementModel.TABLE_PROPERTIES) { if (som.getProperty(s) != null) { definedProps.add(s); } } boolean incomplete = false; // object if (!definedProps.contains(SingleElementModel.OBJECT)) { requiredMessages.add("Cannot import without a parent object."); incomplete = true; } else if (fixTempObjectCode(som)) { // There was a temp code but it is fixed now } else { requiredMessages.add("Cannot import as parent object has not been created yet"); incomplete = true; } // type if (!definedProps.contains(SingleElementModel.TYPE)) { requiredMessages.add("Element must contain a type."); incomplete = true; } // taxon if (!definedProps.contains(SingleElementModel.TAXON)) { requiredMessages.add("Element must contain a taxon."); incomplete = true; } // title if (!definedProps.contains(SingleElementModel.TITLE)) { requiredMessages.add("Element must have a title"); incomplete = true; } // lat/long if (definedProps.contains(SingleElementModel.LATITUDE) || definedProps.contains(SingleElementModel.LONGITUDE)) { if (!definedProps.contains(SingleElementModel.LATITUDE) || !definedProps.contains(SingleElementModel.LONGITUDE)) { requiredMessages .add("If coordinates are specified then both latitude and longitude are required"); incomplete = true; } else { String attempt = som.getProperty(SingleElementModel.LATITUDE).toString().trim(); try { Double lat = Double.parseDouble(attempt); if (lat > -90 || lat < 90) { requiredMessages.add("Latitude must be between -90 and 90"); incomplete = true; } } catch (NumberFormatException e) { requiredMessages.add("Cannot parse '" + attempt + "' into a number."); incomplete = true; } attempt = som.getProperty(SingleElementModel.LONGITUDE).toString().trim(); try { Double lng = Double.parseDouble(attempt); if (lng > -180 || lng < 180) { requiredMessages.add("Longitude must be between -180 and 180"); incomplete = true; } } catch (NumberFormatException e) { requiredMessages.add("Cannot parse '" + attempt + "' into a number."); incomplete = true; } } } if (definedProps.contains(SingleElementModel.HEIGHT) || definedProps.contains(SingleElementModel.WIDTH) || definedProps.contains(SingleElementModel.DEPTH) || definedProps.contains(SingleElementModel.DIAMETER)) { if (!definedProps.contains(SingleElementModel.UNIT)) { requiredMessages.add("Units must be specified when dimensions are included"); incomplete = true; } if ((definedProps.contains(SingleElementModel.HEIGHT) && definedProps.contains(SingleElementModel.DIAMETER) && !definedProps.contains(SingleElementModel.WIDTH) && !definedProps.contains(SingleElementModel.DEPTH))) { // h+diam but not width or depth } else if ((definedProps.contains(SingleElementModel.HEIGHT) && definedProps.contains(SingleElementModel.WIDTH) && definedProps.contains(SingleElementModel.DEPTH) && !definedProps.contains(SingleElementModel.DIAMETER))) { // h+w+d but not diam } else { requiredMessages.add( "When dimensions are included they must be: height/width/depth or height/diameter."); incomplete = true; } } if (incomplete) { incompleteModels.add(som); } } if (!incompleteModels.isEmpty()) { StringBuilder message = new StringBuilder(); message.append("Please correct the following errors:\n"); message.append(StringUtils.join(requiredMessages.toArray(), "\n")); Alert.message(model.getMainView(), "Importing Errors", message.toString()); return; } // now we actually create the models int i = -1; boolean hideErrorMessage = false; for (IBulkImportSingleRowModel srm : selected) { i++; SingleElementModel som = (SingleElementModel) srm; TridasElement origElement = new TridasElement(); if (!som.isDirty()) { System.out.println("Element isn't dirty, not saving/updating: " + som.getProperty(SingleElementModel.TITLE).toString()); } som.populateToTridasElement(origElement); Object o = som.getProperty(SingleElementModel.OBJECT); TridasObject parentObject = null; if (o instanceof TridasObjectOrPlaceholder) { parentObject = ((TridasObjectOrPlaceholder) o).getTridasObject(); } else if (o instanceof TridasObject) { parentObject = (TridasObject) o; } EntityResource<TridasElement> resource; if (origElement.getIdentifier() != null) { resource = new EntityResource<TridasElement>(origElement, TellervoRequestType.UPDATE, TridasElement.class); } else { resource = new EntityResource<TridasElement>(origElement, parentObject, TridasElement.class); } // set up a dialog... Window parentWindow = SwingUtilities.getWindowAncestor(model.getMainView()); TellervoResourceAccessDialog dialog = new TellervoResourceAccessDialog(parentWindow, resource, i, selected.size()); resource.query(); dialog.setVisible(true); if (!dialog.isSuccessful()) { if (hideErrorMessage) { continue; } else if (i < selected.size() - 1) { // More records remain Object[] options = { "Yes", "Yes, but hide further messages", "No" }; int result = JOptionPane.showOptionDialog(BulkImportModel.getInstance().getMainView(), //parent I18n.getText("error.savingChanges") + ":" + System.lineSeparator() + // message dialog.getFailException().getLocalizedMessage() + System.lineSeparator() + System.lineSeparator() + "Would you like to continue importing the remaining records?", I18n.getText("error"), // title JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]); if (result == JOptionPane.NO_OPTION) { hideErrorMessage = true; continue; } else if (result == JOptionPane.YES_OPTION) { continue; } else { break; } } else { JOptionPane.showMessageDialog(BulkImportModel.getInstance().getMainView(), //parent I18n.getText("error.savingChanges") + ":" + System.lineSeparator() + // message dialog.getFailException().getLocalizedMessage(), I18n.getText("error"), // title JOptionPane.ERROR_MESSAGE); //option break; } } som.populateFromTridasElement(resource.getAssociatedResult()); som.setDirty(false); tmodel.setSelected(som, false); // add to imported list or update existing if (origElement.getIdentifier() != null) { TridasElement found = null; for (TridasElement tox : model.getElementModel().getImportedList()) { if (tox.getIdentifier().getValue().equals(origElement.getIdentifier().getValue())) { found = tox; break; } } if (found == null) { log.warn( "Error updating model. Couldn't find the object in the model to update so adding to imported list."); model.getElementModel().getImportedList().add(resource.getAssociatedResult()); } else { resource.getAssociatedResult().copyTo(found); } } else { model.getElementModel().getImportedList().add(resource.getAssociatedResult()); } } // // // finally, update the combo boxes in the table to the new options // DynamicJComboBoxEvent event = new DynamicJComboBoxEvent(emodel.getImportedDynamicComboBoxKey(), emodel.getImportedListStrings()); // event.dispatch(); tmodel.fireTableDataChanged(); }
From source file:com.ibm.bi.dml.runtime.matrix.mapred.MapperBase.java
public void configure(JobConf job) { super.configure(job); //get the indexes that this matrix file represents, //since one matrix file can occur multiple times in a statement try {//from w ww . j a va 2 s .c o m representativeMatrixes = MRJobConfiguration.getInputMatrixIndexesInMapper(job); } catch (IOException e) { throw new RuntimeException(e); } //get input converter information inputConverter = MRJobConfiguration.getInputConverter(job, representativeMatrixes.get(0)); DataGenMRInstruction[] allDataGenIns; MRInstruction[] allMapperIns; ReblockInstruction[] allReblockIns; CSVReblockInstruction[] allCSVReblockIns; try { allDataGenIns = MRJobConfiguration.getDataGenInstructions(job); //parse the instructions on the matrices that this file represent allMapperIns = MRJobConfiguration.getInstructionsInMapper(job); //parse the reblock instructions on the matrices that this file represent allReblockIns = MRJobConfiguration.getReblockInstructions(job); allCSVReblockIns = MRJobConfiguration.getCSVReblockInstructions(job); } catch (DMLUnsupportedOperationException e) { throw new RuntimeException(e); } catch (DMLRuntimeException e) { throw new RuntimeException(e); } //get all the output indexes byte[] outputs = MRJobConfiguration.getOutputIndexesInMapper(job); //get the dimension of all the representative matrices rlens = new long[representativeMatrixes.size()]; clens = new long[representativeMatrixes.size()]; for (int i = 0; i < representativeMatrixes.size(); i++) { rlens[i] = MRJobConfiguration.getNumRows(job, representativeMatrixes.get(i)); clens[i] = MRJobConfiguration.getNumColumns(job, representativeMatrixes.get(i)); // System.out.println("get dimension for "+representativeMatrixes.get(i)+": "+rlens[i]+", "+clens[i]); } //get the block sizes of the representative matrices brlens = new int[representativeMatrixes.size()]; bclens = new int[representativeMatrixes.size()]; for (int i = 0; i < representativeMatrixes.size(); i++) { brlens[i] = MRJobConfiguration.getNumRowsPerBlock(job, representativeMatrixes.get(i)); bclens[i] = MRJobConfiguration.getNumColumnsPerBlock(job, representativeMatrixes.get(i)); // System.out.println("get blocksize for "+representativeMatrixes.get(i)+": "+brlens[i]+", "+bclens[i]); } rbounds = new long[representativeMatrixes.size()]; cbounds = new long[representativeMatrixes.size()]; lastblockrlens = new int[representativeMatrixes.size()]; lastblockclens = new int[representativeMatrixes.size()]; //calculate upper boundaries for key value pairs if (valueClass.equals(MatrixBlock.class)) { for (int i = 0; i < representativeMatrixes.size(); i++) { rbounds[i] = (long) Math.ceil((double) rlens[i] / (double) brlens[i]); cbounds[i] = (long) Math.ceil((double) clens[i] / (double) bclens[i]); lastblockrlens[i] = (int) (rlens[i] % brlens[i]); lastblockclens[i] = (int) (clens[i] % bclens[i]); if (lastblockrlens[i] == 0) lastblockrlens[i] = brlens[i]; if (lastblockclens[i] == 0) lastblockclens[i] = bclens[i]; /* * what is this for???? // DRB: the row indexes need to be fixed rbounds[i] = rlens[i];*/ } } else { for (int i = 0; i < representativeMatrixes.size(); i++) { rbounds[i] = rlens[i]; cbounds[i] = clens[i]; lastblockrlens[i] = 1; lastblockclens[i] = 1; // System.out.println("get bound for "+representativeMatrixes.get(i)+": "+rbounds[i]+", "+cbounds[i]); } } //load data from distributed cache (if required, reuse if jvm_reuse) try { setupDistCacheFiles(job); } catch (IOException ex) { throw new RuntimeException(ex); } //collect unary instructions for each representative matrix HashSet<Byte> set = new HashSet<Byte>(); for (int i = 0; i < representativeMatrixes.size(); i++) { set.clear(); set.add(representativeMatrixes.get(i)); //collect the relavent datagen instructions for this representative matrix ArrayList<DataGenMRInstruction> dataGensForThisMatrix = new ArrayList<DataGenMRInstruction>(); if (allDataGenIns != null) { for (DataGenMRInstruction ins : allDataGenIns) { if (set.contains(ins.getInput())) { dataGensForThisMatrix.add(ins); set.add(ins.output); } } } if (dataGensForThisMatrix.size() > 1) throw new RuntimeException("only expects at most one rand instruction per input"); if (dataGensForThisMatrix.isEmpty()) dataGen_instructions.add(null); else dataGen_instructions.add(dataGensForThisMatrix.get(0)); //collect the relavent instructions for this representative matrix ArrayList<MRInstruction> opsForThisMatrix = new ArrayList<MRInstruction>(); if (allMapperIns != null) { for (MRInstruction ins : allMapperIns) { try { /* boolean toAdd=true; for(byte input: ins.getInputIndexes()) if(!set.contains(input)) { toAdd=false; break; } */ boolean toAdd = false; for (byte input : ins.getInputIndexes()) if (set.contains(input)) { toAdd = true; break; } if (toAdd) { opsForThisMatrix.add(ins); set.add(ins.output); } } catch (DMLRuntimeException e) { throw new RuntimeException(e); } } } mapper_instructions.add(opsForThisMatrix); //collect the relavent reblock instructions for this representative matrix ArrayList<ReblockInstruction> reblocksForThisMatrix = new ArrayList<ReblockInstruction>(); if (allReblockIns != null) { for (ReblockInstruction ins : allReblockIns) { if (set.contains(ins.input)) { reblocksForThisMatrix.add(ins); set.add(ins.output); } } } reblock_instructions.add(reblocksForThisMatrix); //collect the relavent reblock instructions for this representative matrix ArrayList<CSVReblockInstruction> csvReblocksForThisMatrix = new ArrayList<CSVReblockInstruction>(); if (allCSVReblockIns != null) { for (CSVReblockInstruction ins : allCSVReblockIns) { if (set.contains(ins.input)) { csvReblocksForThisMatrix.add(ins); set.add(ins.output); } } } csv_reblock_instructions.add(csvReblocksForThisMatrix); //collect the output indexes for this representative matrix ArrayList<Byte> outsForThisMatrix = new ArrayList<Byte>(); for (byte output : outputs) { if (set.contains(output)) outsForThisMatrix.add(output); } outputIndexes.add(outsForThisMatrix); } }
From source file:com.adobe.cq.wcm.core.components.internal.servlets.ClientLibraryCategoriesDataSourceServlet.java
private List<Resource> getCategoryResourceList(@Nonnull SlingHttpServletRequest request, LibraryType libraryType) {/*w ww .j a v a2s.co m*/ List<Resource> categoryResourceList = new ArrayList<>(); HashSet<String> clientLibraryCategories = new HashSet<String>(); for (ClientLibrary library : htmlLibraryManager.getLibraries().values()) { for (String category : library.getCategories()) { clientLibraryCategories.add(category); } } if (libraryType != null) { Collection<ClientLibrary> clientLibraries = htmlLibraryManager.getLibraries( clientLibraryCategories.toArray(new String[clientLibraryCategories.size()]), libraryType, true, true); clientLibraryCategories.clear(); for (ClientLibrary library : clientLibraries) { for (String category : library.getCategories()) { clientLibraryCategories.add(category); } } } for (String category : clientLibraryCategories) { categoryResourceList.add(new CategoryResource(category, request.getResourceResolver())); } return categoryResourceList; }
From source file:org.apache.zookeeper.graph.servlets.Throughput.java
public String handleRequest(JsonRequest request) throws Exception { long starttime = 0; long endtime = 0; long period = 0; long scale = 0; starttime = request.getNumber("start", 0); endtime = request.getNumber("end", 0); period = request.getNumber("period", 0); if (starttime == 0) { starttime = source.getStartTime(); }// w w w.j av a2 s.co m if (endtime == 0) { if (period > 0) { endtime = starttime + period; } else { endtime = source.getEndTime(); } } String scalestr = request.getString("scale", "minutes"); if (scalestr.equals("seconds")) { scale = MS_PER_SEC; } else if (scalestr.equals("hours")) { scale = MS_PER_HOUR; } else { scale = MS_PER_MIN; } LogIterator iter = source.iterator(starttime, endtime); long current = 0; long currentms = 0; HashSet<Long> zxids_ms = new HashSet<Long>(); long zxidcount = 0; JSONArray events = new JSONArray(); while (iter.hasNext()) { LogEntry e = iter.next(); if (e.getType() != LogEntry.Type.TXN) { continue; } TransactionEntry cxn = (TransactionEntry) e; long ms = cxn.getTimestamp(); long inscale = ms / scale; if (currentms != ms && currentms != 0) { zxidcount += zxids_ms.size(); zxids_ms.clear(); } if (inscale != current && current != 0) { JSONObject o = new JSONObject(); o.put("time", current * scale); o.put("count", zxidcount); events.add(o); zxidcount = 0; } current = inscale; currentms = ms; zxids_ms.add(cxn.getZxid()); } JSONObject o = new JSONObject(); o.put("time", current * scale); o.put("count", zxidcount); events.add(o); iter.close(); return JSONValue.toJSONString(events); }
From source file:afest.datastructures.tree.decision.erts.grower.AERTGrower.java
/** * Return k random attributes (non-constant) picked without replacement unless less then k attributes are non-constant. * @param constantAttributes attributes that are constant. * @param attributeList list of all attributes present in each point in the set. * @return k random attributes (non-constant) picked without replacement unless less then k attributes are non-constant. *//*from w w w . j a va 2 s . c om*/ private ArrayList<R> getKRandomAttributes(ArrayList<R> constantAttributes, ArrayList<R> attributeList) { ArrayList<R> kRandomAttributes = new ArrayList<R>(); HashSet<R> pickedAttributes = new HashSet<R>(constantAttributes); for (int k = 0; k < fK; k++) { // If all non-constant attributes have been picked and k is not reached yet, start resampling the non-constant attributes. if (pickedAttributes.size() == attributeList.size()) { pickedAttributes.clear(); pickedAttributes.addAll(constantAttributes); } // Count the number of attributes that are available for a pick int numNotPicked = attributeList.size() - pickedAttributes.size(); // get a random attribute int randomAttribute = fRandom.nextInt(numNotPicked); int count = 0; for (R aR : attributeList) { // If the attribute is not picked if (!pickedAttributes.contains(aR)) { // verify if it is the one corresponding to the random pick if (count == randomAttribute) { kRandomAttributes.add(aR); pickedAttributes.add(aR); break; } else // increase the count { count++; } } } } return kRandomAttributes; }
From source file:org.apache.solr.handler.TestConfigReload.java
private void checkConfReload(SolrZkClient client, String resPath, String name, String uri) throws Exception { Stat stat = new Stat(); byte[] data = null; try {//from w w w. ja v a 2 s . com data = client.getData(resPath, null, stat, true); } catch (KeeperException.NoNodeException e) { data = "{}".getBytes(StandardCharsets.UTF_8); log.info("creating_node {}", resPath); client.create(resPath, data, CreateMode.PERSISTENT, true); } long startTime = System.nanoTime(); Stat newStat = client.setData(resPath, data, true); client.setData("/configs/conf1", new byte[] { 1 }, true); assertTrue(newStat.getVersion() > stat.getVersion()); log.info("new_version " + newStat.getVersion()); Integer newVersion = newStat.getVersion(); long maxTimeoutSeconds = 20; DocCollection coll = cloudClient.getZkStateReader().getClusterState().getCollection("collection1"); List<String> urls = new ArrayList<>(); for (Slice slice : coll.getSlices()) { for (Replica replica : slice.getReplicas()) urls.add("" + replica.get(ZkStateReader.BASE_URL_PROP) + "/" + replica.get(ZkStateReader.CORE_NAME_PROP)); } HashSet<String> succeeded = new HashSet<>(); while (TimeUnit.SECONDS.convert(System.nanoTime() - startTime, TimeUnit.NANOSECONDS) < maxTimeoutSeconds) { Thread.sleep(50); for (String url : urls) { Map respMap = getAsMap(url + uri + "?wt=json"); if (String.valueOf(newVersion) .equals(String.valueOf(getObjectByPath(respMap, true, asList(name, "znodeVersion"))))) { succeeded.add(url); } } if (succeeded.size() == urls.size()) break; succeeded.clear(); } assertEquals(StrUtils.formatString("tried these servers {0} succeeded only in {1} ", urls, succeeded), urls.size(), succeeded.size()); }