List of usage examples for java.util List clear
void clear();
From source file:com.google.cloud.bigtable.hbase.TestBatch.java
/** * Requirement 8.1/*ww w . j a v a2s . c o m*/ */ @Test public void testBatchIncrement() throws IOException, InterruptedException { // Initialize data Table table = getConnection().getTable(TABLE_NAME); byte[] rowKey1 = dataHelper.randomData("testrow-"); byte[] qual1 = dataHelper.randomData("qual-"); Random random = new Random(); long value1 = random.nextLong(); byte[] rowKey2 = dataHelper.randomData("testrow-"); byte[] qual2 = dataHelper.randomData("qual-"); long value2 = random.nextLong(); // Put Put put1 = new Put(rowKey1).addColumn(COLUMN_FAMILY, qual1, Bytes.toBytes(value1)); Put put2 = new Put(rowKey2).addColumn(COLUMN_FAMILY, qual2, Bytes.toBytes(value2)); List<Row> batch = new ArrayList<Row>(2); batch.add(put1); batch.add(put2); table.batch(batch, null); // Increment Increment increment1 = new Increment(rowKey1).addColumn(COLUMN_FAMILY, qual1, 1L); Increment increment2 = new Increment(rowKey2).addColumn(COLUMN_FAMILY, qual2, 1L); batch.clear(); batch.add(increment1); batch.add(increment2); Object[] results = new Object[2]; table.batch(batch, results); Assert.assertEquals("Should be value1 + 1", value1 + 1, Bytes.toLong(CellUtil.cloneValue(((Result) results[0]).getColumnLatestCell(COLUMN_FAMILY, qual1)))); Assert.assertEquals("Should be value2 + 1", value2 + 1, Bytes.toLong(CellUtil.cloneValue(((Result) results[1]).getColumnLatestCell(COLUMN_FAMILY, qual2)))); table.close(); }
From source file:edu.uci.ics.asterix.optimizer.rules.am.BTreeAccessMethod.java
private void getNewConditionExprs(Mutable<ILogicalExpression> conditionRef, Set<ILogicalExpression> replacedFuncExprs, List<Mutable<ILogicalExpression>> remainingFuncExprs) { remainingFuncExprs.clear(); if (replacedFuncExprs.isEmpty()) { return;//from w w w. ja va 2s .com } AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) conditionRef.getValue(); if (replacedFuncExprs.size() == 1) { Iterator<ILogicalExpression> it = replacedFuncExprs.iterator(); if (!it.hasNext()) { return; } if (funcExpr == it.next()) { // There are no remaining function exprs. return; } } // The original select cond must be an AND. Check it just to be sure. if (funcExpr.getFunctionIdentifier() != AlgebricksBuiltinFunctions.AND) { throw new IllegalStateException(); } // Clean the conjuncts. for (Mutable<ILogicalExpression> arg : funcExpr.getArguments()) { ILogicalExpression argExpr = arg.getValue(); if (argExpr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) { continue; } // If the function expression was not replaced by the new index // plan, then add it to the list of remaining function expressions. if (!replacedFuncExprs.contains(argExpr)) { remainingFuncExprs.add(arg); } } }
From source file:hsa.awp.scire.procedureLogic.DrawLoadTest.java
private void generateAndRegisterComplexPriorityLists() { for (int i = 0; i < 2000; i++) { singleUser = userFacade.saveSingleUser(createUser(String.valueOf(i))); Set<PriorityList> lists = new HashSet<PriorityList>(); List<Event> prioEvents = new LinkedList<Event>(); if (i % 200 == 0) { System.out.println(i + "Lists have been created"); }//from www . j a v a2 s .co m prioEvents.add(events.get((i + 3) % 60)); prioEvents.add(events.get((i + 7) % 60)); prioEvents.add(events.get((i + 13) % 60)); lists.add(generatePriorityList(singleUser, singleUser, prioEvents)); prioEvents.clear(); prioEvents.add(events.get((i + 17) % 60)); prioEvents.add(events.get((i + 19) % 60)); prioEvents.add(events.get((i + 31) % 60)); lists.add(generatePriorityList(singleUser, singleUser, prioEvents)); prioEvents.clear(); prioEvents.add(events.get((i + 11) % 60)); prioEvents.add(events.get((i + 23) % 60)); prioEvents.add(events.get((i + 29) % 60)); lists.add(generatePriorityList(singleUser, singleUser, prioEvents)); drawProcedureLogic.register(lists); } }
From source file:org.tallison.cc.CCGetter.java
private void writeStatus(CCIndexRecord r, String actualDigest, Header[] headers, long actualLength, boolean isTruncated, FETCH_STATUS fetchStatus, BufferedWriter writer) throws IOException { List<String> row = new LinkedList<>(); if (!writtenHeader) { row.addAll(Arrays.asList(new String[] { "URL", "CC_MIME", "CC_DIGEST", "COMPUTED_DIGEST", "HEADER_ENCODING", "HEADER_TYPE", "HEADER_LANGUAGE", "HEADER_LENGTH", "ACTUAL_LENGTH", "WARC_IS_TRUNCATED", "FETCH_STATUS" })); writer.write(StringUtils.join(row, "\t")); writer.write("\n"); row.clear(); writtenHeader = true;// w ww. j av a 2s . com } row.add(clean(r.getUrl())); row.add(clean(r.getMime())); row.add(clean(r.getDigest())); if (actualDigest != null) { row.add(actualDigest); } else { row.add(""); } row.add(getHeader("content-encoding", headers)); row.add(getHeader("content-type", headers)); row.add(getHeader("content-language", headers)); row.add(getHeader("content-length", headers)); row.add(Long.toString(actualLength)); if (isTruncated) { row.add("TRUE"); } else { row.add(""); } row.add(clean(fetchStatus.toString())); writer.write(StringUtils.join(row, "\t")); writer.write("\n"); }
From source file:org.syncope.console.wicket.markup.html.form.AjaxCheckBoxPanel.java
@Override public FieldPanel setNewModel(final List<Serializable> list) { setNewModel(new Model() { private static final long serialVersionUID = 527651414610325237L; @Override//from w ww .j a v a 2s .c o m public Serializable getObject() { Boolean value = null; if (list != null && !list.isEmpty() && StringUtils.hasText(list.get(0).toString())) { value = "true".equalsIgnoreCase(list.get(0).toString()); } return value; } @Override public void setObject(final Serializable object) { if (object != null) { list.clear(); list.add(((Boolean) object).toString()); } } }); return this; }
From source file:com.pureinfo.tgirls.servlet.OtherCompanyInitServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { JsonBase result = new JsonBase(); response.setContentType("text/json; charset=utf-8"); String userId = request.getParameter("uid"); if (StringUtils.isEmpty(userId)) { response.sendError(HttpServletResponse.SC_BAD_REQUEST); return;/*from ww w .j av a 2 s . com*/ } try { IUserMgr umgr = (IUserMgr) ArkContentHelper.getContentMgrOf(User.class); User currentUser = umgr.getUserByTaobaoId(userId); if (currentUser == null) { response.sendRedirect(request.getContextPath() + "/tgirls/need-login.html"); return; } logger.info("other company init with user[" + currentUser.getTaobaoID() + "]"); IPhotoMgr mgr = (IPhotoMgr) ArkContentHelper.getContentMgrOf(Photo.class); List<Photo> uploadlist = mgr.getUserUploadPublicPics(currentUser.getTaobaoID()); if (uploadlist != null) { List<JSONObject> pjsonlist = new ArrayList<JSONObject>(); Photo object = null; for (Iterator iterator = uploadlist.iterator(); iterator.hasNext();) { object = (Photo) iterator.next(); pjsonlist.add(new JSONObject(object)); } logger.debug("uploads:" + pjsonlist.size()); result.put("uploads", pjsonlist); uploadlist.clear(); } List<Photo> buylist = mgr.getUserBuyPublicPics(currentUser.getTaobaoID()); if (buylist != null) { List<JSONObject> pjsonlist = new ArrayList<JSONObject>(); Photo object = null; for (Iterator iterator = buylist.iterator(); iterator.hasNext();) { object = (Photo) iterator.next(); pjsonlist.add(new JSONObject(object)); } logger.debug("buys:" + pjsonlist.size()); result.put("buys", pjsonlist); buylist.clear(); } // List<JSONObject> infolist = GetInformationsServlet.getInformations(currentUser.getTaobaoID()); // if (infolist != null) { // result.put("informations", infolist); // } result.put("uinfo", new JSONObject(currentUser)); } catch (JSONException e) { logger.error("json error", e); } catch (PureException e) { logger.error("ark error", e); } // logger.debug("result:" + result.toString()); response.getWriter().write(result.toString()); return; }
From source file:com.github.magicsky.sya.checkers.TestSourceReader.java
/** * Returns an array of StringBuilder objects for each comment section found preceding the named * test in the source code.//from ww w .j a va 2s .c om * * @param srcRoot the directory inside the bundle containing the packages * @param clazz the name of the class containing the test * @param testName the name of the test * @param numSections the number of comment sections preceding the named test to return. * Pass zero to get all available sections. * @return an array of StringBuilder objects for each comment section found preceding the named * test in the source code. * @throws IOException */ public static StringBuilder[] getContentsForTest(String srcRoot, Class clazz, final String testName, int numSections) throws IOException { // Walk up the class inheritance chain until we find the test method. try { while (clazz.getMethod(testName).getDeclaringClass() != clazz) { clazz = clazz.getSuperclass(); } } catch (SecurityException e) { Assert.fail(e.getMessage()); } catch (NoSuchMethodException e) { Assert.fail(e.getMessage()); } while (true) { // Find and open the .java file for the class clazz. String fqn = clazz.getName().replace('.', '/'); fqn = fqn.indexOf("$") == -1 ? fqn : fqn.substring(0, fqn.indexOf("$")); String classFile = fqn + ".java"; InputStream in; Class superclass = clazz.getSuperclass(); try { in = FileUtils.openInputStream(new File(srcRoot + '/' + classFile)); } catch (IOException e) { if (superclass == null || !superclass.getPackage().equals(clazz.getPackage())) { throw e; } clazz = superclass; continue; } BufferedReader br = new BufferedReader(new InputStreamReader(in)); try { // Read the java file collecting comments until we encounter the test method. List<StringBuilder> contents = new ArrayList<StringBuilder>(); StringBuilder content = new StringBuilder(); for (String line = br.readLine(); line != null; line = br.readLine()) { line = line.replaceFirst("^\\s*", ""); // Replace leading whitespace, preserve trailing if (line.startsWith("//")) { content.append(line.substring(2) + "\n"); } else { if (!line.startsWith("@") && content.length() > 0) { contents.add(content); if (numSections > 0 && contents.size() == numSections + 1) contents.remove(0); content = new StringBuilder(); } if (line.length() > 0 && !contents.isEmpty()) { int idx = line.indexOf(testName); if (idx != -1 && !Character.isJavaIdentifierPart(line.charAt(idx + testName.length()))) { return contents.toArray(new StringBuilder[contents.size()]); } if (!line.startsWith("@")) { contents.clear(); } } } } } finally { br.close(); } if (superclass == null || !superclass.getPackage().equals(clazz.getPackage())) { throw new IOException("Test data not found for " + clazz.getName() + "." + testName); } clazz = superclass; } }
From source file:gov.sfmta.sfpark.MainScreenActivity.java
void reset() { List<Overlay> mapOverlays = mapView.getOverlays(); mapOverlays.clear(); SFparkActivity.responseString = null; availabilityAnnotationsOverlay = null; pricingAnnotationsOverlay = null;/*from ww w .ja v a 2s .c om*/ if (annotations != null) { annotations.clear(); } annotations = null; refreshData(); }
From source file:Scheduler.java
/******************************************************************** * Method: testClasses/*from www. j a v a2 s . c o m*/ * Purpose: tests if classes work together /*******************************************************************/ public boolean testClasses(List<Course> coursesOrig, Course courseCmpOrig, List<Course> clone, List<Meeting> courseSubs) { try { // Add course clone.add(courseCmpOrig); // Generate a complete list of sub courses courseSubs.clear(); for (Course courselist : coursesOrig) { // Add course to cloned list clone.add(courselist); // Add all sub courses for (Meeting course : courselist.getMeetings()) courseSubs.add(course); } // Add sub courses from compare course (except for first one) for (Meeting courseCmp : courseCmpOrig.getMeetings()) { // Get time TimeBlock cmpBlock = courseCmp.getTime(); if (cmpBlock == null) return false; // Get time info to minutes int startC = cmpBlock.getStartHours() * 60 + cmpBlock.getStartMin(); int endC = cmpBlock.getEndHours() * 60 + cmpBlock.getEndMin(); int uniqueCrn = courseCmp.getCourseReference().getCRN() * 1000 + courseCmp.getMeetingNumber(); String crnS = ""; // Check all sub courses against the compare course for (Meeting course : courseSubs) { int currentUniqueCRN = course.getCourseReference().getCRN() * 1000 + course.getMeetingNumber(); // Sort crn string as smallest crn first (for hashing value) if (uniqueCrn < currentUniqueCRN) { // Correct order crnS = uniqueCrn + (currentUniqueCRN + ""); } else crnS = (currentUniqueCRN + "") + uniqueCrn; // Check if the comparison has already been done if (MainApplication.courseChecks.containsKey(crnS)) { // If conflict, then simply return false if (!MainApplication.courseChecks.get(crnS)) return false; } // Courses have never been compared else { // Get time information for comparison block TimeBlock block = course.getTime(); if (block == null) return false; // Start for block B int startB = block.getStartHours() * 60 + block.getStartMin(); int endB = block.getEndHours() * 60 + block.getEndMin(); // Times overlap? if (startB < endC && endB > startC) { // Days also over lap? if ((course.M && courseCmp.M) || (course.T && courseCmp.T) || (course.W && courseCmp.W) || (course.R && courseCmp.R) || (course.F && courseCmp.F)) { // Store comparison and return false MainApplication.courseChecks.put(crnS, false); return false; } else { // Store comparison as successful MainApplication.courseChecks.put(crnS, true); } } else { // Store comparison as successful MainApplication.courseChecks.put(crnS, true); } } } } // At least one course must exist for schedule to be successful return coursesOrig.size() > 0; } catch (java.lang.OutOfMemoryError e) { exception = true; return false; } }
From source file:de.seitenbau.govdata.edit.gui.controller.EditController.java
/** * Converts the EditForm to a dataset and saves it to ckan * @param editForm form to save/*w w w .j a va 2 s .c o m*/ * @throws OpenDataRegistryException */ private void saveDataset(EditForm form, de.fhg.fokus.odp.registry.model.User ckanUser) throws OpenDataRegistryException { log.info("saving: " + form.getName()); // get existing Dataset if available Metadata metadata = null; if (form.isNewDataset()) { metadata = registryClient.getInstance().createMetadata(MetadataEnumType.fromField(form.getTyp())); } else { metadata = registryClient.getInstance().getMetadata(ckanUser, form.getName()); if (metadata == null) { throw new OpenDataRegistryException( "dataset is not new, but could not be found in ckan: " + form.getName()); } } metadata.setOwnerOrg(form.getOrganizationId()); metadata.setPrivate(form.isPrivate()); metadata.setTitle(form.getTitle()); metadata.setNotes(form.getNotes()); // tags List<Tag> tags = metadata.getTags(); // get the list and add tags String[] formTags = form.getTags().trim().split(","); tags.clear(); // we don't want to keep existing tags if (formTags.length > 0) { for (String formTag : formTags) { formTag = formTag.trim(); if (formTag.length() > 0) { TagBean tagBean = new TagBean(); tagBean.setName(formTag); tagBean.setDisplay_name(formTag); tags.add(new TagImpl(tagBean)); } } } metadata.setUrl(form.getUrl()); metadata.setType(MetadataEnumType.fromField(form.getTyp())); metadata.setLicence(licenceCache.getLicenceMap().get(form.getLicenseId())); metadata.setSpatialDataValue(form.getSpatial()); Date fromDate = parseDate(form.getTemporalCoverageFrom()); Date untilDate = parseDate(form.getTemporalCoverageUntil()); metadata.setTemporalCoverageFrom(fromDate); metadata.setTemporalCoverageTo(untilDate); metadata.setCreated(parseDate(form.getDatesCreated())); metadata.setPublished(parseDate(form.getDatesPublished())); metadata.setModified(parseDate(form.getDatesModified())); // categories List<Category> categories = metadata.getCategories(); categories.clear(); // we don't want to keep existing categories if (form.getCategories() != null) { for (String formCat : form.getCategories()) { categories.add(categoryCache.getCategoryMap().get(formCat)); } } // resources List<de.fhg.fokus.odp.registry.model.Resource> resources = metadata.getResources(); resources.clear(); if (form.getResources() != null) { for (Resource res : form.getResources()) { ResourceBean resourceBean = new ResourceBean(); resourceBean.setName(res.getName()); resourceBean.setDescription(res.getDescription()); resourceBean.setFormat(res.getFormat()); resourceBean.setUrl(res.getUrl()); resourceBean.setLanguage(res.getLanguage()); resources.add(new ResourceImpl(resourceBean)); } } // contacts List<de.fhg.fokus.odp.registry.model.Contact> contacts = metadata.getContacts(); contacts.clear(); if (form.getContacts() != null) { for (Entry<String, Contact> con : form.getContacts().entrySet()) { // don't save contact if name is empty if (StringUtils.isEmpty(con.getValue().getName())) { continue; } ContactBean contactBean = new ContactBean(); contactBean.setRole(con.getKey()); contactBean.setName(con.getValue().getName()); contactBean.setEmail(con.getValue().getEmail()); contactBean.setUrl(con.getValue().getUrl()); contactBean.setAddress(con.getValue().getAddress()); contacts.add(new ContactImpl(contactBean)); } } try { registryClient.getInstance().persistMetadata(ckanUser, metadata); } catch (ClientErrorException e) { if (e.getResponse().getStatus() == 409) { throw new OpenDataRegistryException("od.editform.save.error.alreadyexists"); } else { throw new OpenDataRegistryException(); } } }