List of usage examples for java.util List clear
void clear();
From source file:acromusashi.kafka.log.producer.LinuxLogTailExecutor.java
/** * ?Tail???KafkaBroker?????//from w w w .ja v a2 s .c o m */ protected void sendTailedLog() { String[] tailCommandArgs = this.tailCommandStr.split("\\s+"); BufferedReader tailReader = null; Process tailProcess = null; try { tailProcess = new ProcessBuilder(tailCommandArgs).start(); tailReader = new BufferedReader(new InputStreamReader(tailProcess.getInputStream(), this.encoding)); String tailedLine = null; List<String> tailedLineList = Lists.newArrayList(); int count = 0; while ((tailedLine = tailReader.readLine()) != null) { tailedLineList.add(tailedLine); count++; if (count >= this.maxSendSize) { List<KeyedMessage<String, String>> messageList = getKeyedMessage(tailedLineList); tailedLineList.clear(); this.producer.send(messageList); count = 0; } } List<KeyedMessage<String, String>> messageList = getKeyedMessage(tailedLineList); tailedLineList.clear(); this.producer.send(messageList); } catch (Exception e) { logger.error("Failed while running command: " + this.tailCommandStr, e); if (e instanceof InterruptedException) { Thread.currentThread().interrupt(); } } finally { if (tailReader != null) { IOUtils.closeQuietly(tailReader); } if (tailProcess != null) { tailProcess.destroy(); try { tailProcess.waitFor(); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } } } }
From source file:uta.ak.usttmp.common.processInterface.impl.AssociationFilterEvolutionTrackingService.java
@Override @Transactional/*www .j a v a 2s . co m*/ public List<EvolutionRelationship> getTopicEvolutionRelationships(MiningTask mt, List<Topic> preTopics, List<Topic> nextTopics) { //Generate EvolutionRelationship List List<EvolutionRelationship> erList = new ArrayList<EvolutionRelationship>(); for (Topic preTp : preTopics) { List<EvolutionRelationship> tempErList = new ArrayList<EvolutionRelationship>(); for (Topic nextTp : nextTopics) { EvolutionRelationship er = new EvolutionRelationship(); er.setPreTopic(preTp); er.setNextTopic(nextTp); er.setSimilarity(this.getSimilarity(preTp, nextTp)); erList.add(er); } } for (Topic preTp : preTopics) { List<EvolutionRelationship> nextErList = this.getEvolutionRelaByPreTopicOrderBySimilarity(preTp, erList); int i = 1; for (EvolutionRelationship tempEr : nextErList) { tempEr.setRankAgainstPreTopicInNextGroup(i); i++; } } for (Topic nextTp : nextTopics) { List<EvolutionRelationship> preErList = this.getEvolutionRelaByNextTopicOrderBySimilarity(nextTp, erList); int i = 1; for (EvolutionRelationship tempEr : preErList) { tempEr.setRankAgainstNextTopicInPreGroup(i); i++; } } //Filter EvolutionRelationship //1. Filter by minimum similarity for (Iterator<EvolutionRelationship> i = erList.iterator(); i.hasNext();) { EvolutionRelationship ter = i.next(); if (AssociationFilterEvolutionTrackingService.similarityThreshold > ter.getSimilarity()) { i.remove(); } } List<String> removeList = new ArrayList<String>(); //2.1 Filter by inappropriate ER removeList.clear(); for (Topic preTp : preTopics) { Topic tPostTp = this.getPostTopic(preTp, erList); if (null == tPostTp) { continue; } // String preTIDnextTID=preTp.getId() + "," + tPostTp.getId(); List<EvolutionRelationship> tERList = this.getEvolutionRelaByNextTopicOrderBySimilarity(tPostTp, erList); boolean removeSign = false; for (EvolutionRelationship tER : tERList) { if (tER.getPreTopic().getId() == preTp.getId()) { break; } else { Topic kPostTp = this.getPostTopic(tER.getPreTopic(), erList); if (kPostTp == null || kPostTp.getId() != tPostTp.getId()) { removeSign = true; break; } } } if (removeSign) { removeER(preTp.getId(), tPostTp.getId(), erList); // removeList.add(preTIDnextTID); } } // for(Iterator<EvolutionRelationship> i =erList.iterator();i.hasNext();){ // EvolutionRelationship tEr=i.next(); // String preTIDnextTID=tEr.getPreTopic().getId() + "," + tEr.getNextTopic().getId(); // if(removeList.contains(preTIDnextTID)){ // i.remove(); // } // } //2.2 Filter by minimun ratioThresholdToMaxSimilarity removeList.clear(); for (Iterator<Topic> i = preTopics.iterator(); i.hasNext();) { Topic preT = i.next(); List<EvolutionRelationship> tErList = this.getEvolutionRelaByPreTopicOrderBySimilarity(preT, erList); if (tErList != null && (!tErList.isEmpty())) { double maxSimThreshold = (tErList.get(0)).getSimilarity() * AssociationFilterEvolutionTrackingService.ratioThresholdToMaxSimilarity; for (Iterator<EvolutionRelationship> j = tErList.iterator(); j.hasNext();) { EvolutionRelationship tEr = j.next(); if (maxSimThreshold > tEr.getSimilarity()) { removeList.add(tEr.getPreTopic().getId() + "," + tEr.getNextTopic().getId()); } } } } for (Iterator<Topic> i = nextTopics.iterator(); i.hasNext();) { Topic nextT = i.next(); List<EvolutionRelationship> tErList = this.getEvolutionRelaByNextTopicOrderBySimilarity(nextT, erList); if (tErList != null && (!tErList.isEmpty())) { double maxSimThreshold = (tErList.get(0)).getSimilarity() * AssociationFilterEvolutionTrackingService.ratioThresholdToMaxSimilarity; for (Iterator<EvolutionRelationship> j = tErList.iterator(); j.hasNext();) { EvolutionRelationship tEr = j.next(); if (maxSimThreshold > tEr.getSimilarity()) { removeList.add(tEr.getPreTopic().getId() + "," + tEr.getNextTopic().getId()); } } } } for (Iterator<EvolutionRelationship> i = erList.iterator(); i.hasNext();) { EvolutionRelationship tEr = i.next(); String preTIDnextTID = tEr.getPreTopic().getId() + "," + tEr.getNextTopic().getId(); if (removeList.contains(preTIDnextTID)) { i.remove(); } } /* //3. Filter by inappropriate ER removeList.clear(); boolean removePositionStart=false; for(Iterator<Topic> i=preTopics.iterator();i.hasNext();){ Topic preT=i.next(); List<EvolutionRelationship> tErList=this.getEvolutionRelaByPreTopicOrderBySimilarity(preT, erList); removePositionStart=false; if(tErList!=null && (!tErList.isEmpty())){ int k=1; for(Iterator<EvolutionRelationship> j=tErList.iterator();j.hasNext();){ EvolutionRelationship tEr=j.next(); if(removePositionStart){ removeList.add(tEr.getPreTopic().getId() + "," + tEr.getNextTopic().getId()); }else{ int rankIndex=tEr.getRankAgainstPreTopicInNextGroup(); if(k==rankIndex){ k++; }else{ removeList.add(tEr.getPreTopic().getId() + "," + tEr.getNextTopic().getId()); removePositionStart=true; } } } } } for(Iterator<Topic> i=nextTopics.iterator();i.hasNext();){ Topic nextT=i.next(); List<EvolutionRelationship> tErList=this.getEvolutionRelaByNextTopicOrderBySimilarity(nextT, erList); removePositionStart=false; if(tErList!=null && (!tErList.isEmpty())){ int k=1; for(Iterator<EvolutionRelationship> j=tErList.iterator();j.hasNext();){ EvolutionRelationship tEr=j.next(); if(removePositionStart){ removeList.add(tEr.getPreTopic().getId() + "," + tEr.getNextTopic().getId()); }else{ int rankIndex=tEr.getRankAgainstNextTopicInPreGroup(); if(k==rankIndex){ k++; }else{ removeList.add(tEr.getPreTopic().getId() + "," + tEr.getNextTopic().getId()); removePositionStart=true; } } } } } for(Iterator<EvolutionRelationship> i =erList.iterator();i.hasNext();){ EvolutionRelationship tEr=i.next(); String preTIDnextTID=tEr.getPreTopic().getId() + "," + tEr.getNextTopic().getId(); if(removeList.contains(preTIDnextTID)){ i.remove(); } }*/ return (erList.size() > 0) ? erList : null; }
From source file:com.yahoo.egads.models.tsmm.OlympicModel2.java
@Override public void train(final DataSequence data) throws Exception { initializeIndices(data, modelStartEpoch); final long size = data.size(); ZonedDateTime model_ts = Instant.ofEpochSecond(modelStartEpoch).atZone(zone); ZonedDateTime end_ts = model_ts.plus(windowSize, windowUnits); int prediction_index = 0; final List<WeightedValue> accumulator = Lists.newArrayList(); // start the loop and break once we've filled the model. while (true) { accumulator.clear(); for (int i = 0; i < windowTimes.length; i++) { if (indices[i] < 0 || indices[i] >= size) { continue; }/*from www . j a v a 2 s .c o m*/ // advance windowTimes[i] = windowTimes[i].plus(interval, intervalUnits); long interval_end = windowTimes[i].toEpochSecond(); final List<Double> doubles = Lists.newArrayList(); long first_ts = -1; while (indices[i] < size && data.get(indices[i]).time < interval_end) { if (Double.isFinite(data.get(indices[i]).value)) { doubles.add((double) data.get(indices[i]).value); } if (first_ts < 0) { first_ts = data.get(indices[i]).time; } indices[i]++; } if (!doubles.isEmpty()) { // TODO - for DST if we jumped back then we may have a // period // with more than we expect. In that case, depending on the // aggregator, we may need to use only part of the data. // TODO - potentially other aggregations. double sum = 0; for (final Double v : doubles) { sum += v; } accumulator.add(new WeightedValue((sum / doubles.size()), i + 1)); } } if (drop_lowest > 0 || drop_highest > 0) { if (drop_highest > drop_lowest) { WeightedValue.drop(accumulator, drop_highest, true); WeightedValue.drop(accumulator, drop_lowest, false); } else { WeightedValue.drop(accumulator, drop_lowest, false); WeightedValue.drop(accumulator, drop_highest, true); } } model.add(new Pair<Long, Double>(model_ts.toEpochSecond(), WeightedValue.aggregate(accumulator, windowAggregator))); model_ts = model_ts.plus(interval, intervalUnits); if (model_ts.toEpochSecond() > end_ts.toEpochSecond()) { prediction_index++; if (prediction_index >= futureWindows) { break; } model_ts = Instant.ofEpochSecond(modelStartEpoch).atZone(zone); model_ts = model_ts.plus((windowDistanceInterval * prediction_index), windowDistanceIntervalUnits); end_ts = model_ts.plus(windowSize, windowUnits); for (int i = 0; i < windowTimes.length; i++) { windowTimes[i] = null; indices[i] = 0; } initializeIndices(data, model_ts.toEpochSecond()); } } }
From source file:org.jenkins_ci.plugins.run_condition.core.CauseConditionTest.java
@Test public void testUCAnyUser() throws Exception { List<Cause> BuildCauses = new ArrayList<Cause>(); // tests with no users defined RunCondition condition = new CauseCondition("USER_CAUSE", false); // started by SYSTEM user BuildCauses.add(new UserCause()); runtest(BuildCauses, condition, true); // started by user BuildCauses.clear(); BuildCauses.add(createUserCause("fred")); runtest(BuildCauses, condition, true); // started by different causes BuildCauses.clear();/* w w w . ja va2s . c om*/ BuildCauses.add(new LegacyCodeCause()); runtest(BuildCauses, condition, false); // started by mltiple users including requested BuildCauses.clear(); BuildCauses.add(createUserCause("tom")); BuildCauses.add(createUserCause("fred")); BuildCauses.add(createUserCause("harry")); runtest(BuildCauses, condition, true); // started by different causes BuildCauses.clear(); BuildCauses.add(new LegacyCodeCause()); runtest(BuildCauses, condition, false); // multiple different causes // add a second cause BuildCauses.add(new RemoteCause("dummy_host", "dummynote")); runtest(BuildCauses, condition, false); // test with Exclusive set condition = new CauseCondition("USER_CAUSE", true); // started by correct user BuildCauses.clear(); BuildCauses.add(createUserCause("fred")); runtest(BuildCauses, condition, true); // started by several users BuildCauses.clear(); BuildCauses.add(createUserCause("eviloverlord")); BuildCauses.add(createUserCause("fred")); runtest(BuildCauses, condition, false); // started by several causes BuildCauses.clear(); BuildCauses.add(createUserCause("eviloverlord")); BuildCauses.add(createUserCause("fred")); BuildCauses.add(new LegacyCodeCause()); BuildCauses.add(new RemoteCause("dummy_host", "dummynote")); BuildCauses.add(new TimerTriggerCause()); runtest(BuildCauses, condition, false); }
From source file:eagle.storage.jdbc.TestJdbcStorage.java
/** * TODO: Investigate why writing performance becomes slower as records count increases * * 1) Wrote 100000 records in about 18820 ms for empty table * 2) Wrote 100000 records in about 35056 ms when 1M records in table * * @throws IOException//from www. ja va2 s . c o m */ //@Test public void testWriterPerformance() throws IOException { StopWatch stopWatch = new StopWatch(); stopWatch.start(); List<TestTimeSeriesAPIEntity> entityList = new ArrayList<TestTimeSeriesAPIEntity>(); int i = 0; while (i++ < 100000) { entityList.add(newInstance()); if (entityList.size() >= 1000) { ModifyResult<String> result = storage.create(entityList, entityDefinition); Assert.assertNotNull(result); entityList.clear(); } } stopWatch.stop(); LOG.info("Wrote 100000 records in " + stopWatch.getTime() + " ms"); }
From source file:com.google.uzaygezen.core.BoundedRollupTest.java
@Test public void subtreeIsOptimalWithinConstraints() { final List<int[]> list = Lists.newArrayList(); IntArrayCallback callback = new ListCollector(list); for (int n = 0; n < 3; ++n) { list.clear(); // Exact sum means that no array will be a prefix of another one. TestUtils.generateSpecWithExactSum(n, 2 * n, callback); Collections.sort(list, IntArrayComparator.INSTANCE); BoundedRollup<Integer, LongContent> rollup = BoundedRollup.create(TestUtils.ZERO_LONG_CONTENT, Integer.MAX_VALUE); MapNode<Integer, LongContent> fullTreeRoot = createTree(list, rollup); checkTreeIsComplete(list, n, fullTreeRoot); int fullTreeSize = fullTreeRoot.subtreeSizeAndLeafCount()[0]; for (int i = 1; i <= fullTreeSize + 5; ++i) { List<List<MapNode<Integer, LongContent>>> allPossibleExpansions = allPossibleExpansions( fullTreeRoot, i);/*from w ww. j a va 2 s . c om*/ BoundedRollup<Integer, LongContent> constrainedRollup = BoundedRollup .create(TestUtils.ZERO_LONG_CONTENT, i); MapNode<Integer, LongContent> constrainedTreeRoot = createTree(list, constrainedRollup); List<MapNode<Integer, LongContent>> actual = constrainedTreeRoot.preorder(); List<List<MapNode<Integer, LongContent>>> all = toSortedValueListList(allPossibleExpansions); List<MapNode<Integer, LongContent>> constrained = toSortedValueList(actual); List<List<MapNode<Integer, LongContent>>> allSameSize = Lists.newArrayList(); for (List<MapNode<Integer, LongContent>> row : all) { Assert.assertTrue(row.size() <= constrained.size()); if (row.size() == constrained.size()) { allSameSize.add(row); } } Assert.assertEquals(Collections.max(allSameSize, new ListComparator<MapNode<Integer, LongContent>>( new MapNodeValueComparator<Integer, LongContent>())), constrained); } } }
From source file:nz.co.senanque.sandbox.ObjectTest.java
@Test public void test1() throws Exception { @SuppressWarnings("unused") Object en = IndustryType.fromValue("Ag"); ValidationSession validationSession = m_validationEngine.createSession(); // create a customer Customer customer = m_customerDAO.createCustomer(); validationSession.bind(customer);// w w w . jav a 2 s .co m Invoice invoice = new Invoice(); invoice.setDescription("test invoice"); invoice.setTestBoolean(true); customer.getInvoices().add(invoice); boolean exceptionFound = false; try { customer.setName("ttt"); } catch (ValidationException e) { exceptionFound = true; } assertTrue(exceptionFound); final ObjectMetadata customerMetadata = validationSession.getMetadata(customer); @SuppressWarnings("unused") final FieldMetadata customerTypeMetadata = customerMetadata.getFieldMetadata(Customer.CUSTOMERTYPE); // assertFalse(customerTypeMetadata.isActive()); // assertFalse(customerTypeMetadata.isReadOnly()); // assertFalse(customerTypeMetadata.isRequired()); customer.setName("aaaab"); exceptionFound = false; try { customer.setCustomerType("B"); } catch (Exception e) { exceptionFound = true; } // assertTrue(exceptionFound); exceptionFound = false; try { customer.setCustomerType("XXX"); } catch (Exception e) { exceptionFound = true; } assertTrue(exceptionFound); customer.setBusiness(IndustryType.AG); customer.setAmount(new Double(500.99)); final long id = m_customerDAO.save(customer); log.info("{}", id); // fetch customer back customer = m_customerDAO.getCustomer(id); @SuppressWarnings("unused") final int invoiceCount = customer.getInvoices().size(); validationSession.bind(customer); invoice = new Invoice(); ValidationUtils.setDefaults(invoice); invoice.setDescription("test invoice2"); invoice.setTestBoolean(true); customer.getInvoices().add(invoice); assertEquals("xyz", invoice.getTestDefault()); assertEquals("Ag", invoice.getTestEnumDefault().value()); m_customerDAO.save(customer); // fetch customer again customer = m_customerDAO.getCustomer(id); customer.toString(); final Invoice inv0 = customer.getInvoices().get(0); assertTrue(inv0.isTestBoolean()); validationSession.bind(customer); final Invoice inv = customer.getInvoices().get(0); assertTrue(inv.isTestBoolean()); customer.getInvoices().remove(inv); //ObjectMetadata metadata = validationSession.getMetadata(customer); ObjectMetadata metadata = customer.getMetadata(); assertEquals("this is a description", metadata.getFieldMetadata(Customer.NAME).getDescription()); assertEquals("ABC", metadata.getFieldMetadata(Customer.NAME).getPermission()); @SuppressWarnings("unused") List<ChoiceBase> choices = metadata.getFieldMetadata(Customer.BUSINESS).getChoiceList(); // assertEquals(1,choices.size()); List<ChoiceBase> choices2 = metadata.getFieldMetadata(Customer.CUSTOMERTYPE).getChoiceList(); // assertEquals(1,choices2.size()); choices2 = metadata.getFieldMetadata(Customer.CUSTOMERTYPE).getChoiceList(); // assertEquals(1,choices2.size()); for (ChoiceBase choice : choices2) { System.out.println(choice.getDescription()); } customer.setName("aab"); choices2 = metadata.getFieldMetadata(Customer.CUSTOMERTYPE).getChoiceList(); // assertEquals(6,choices2.size()); // Convert customer to XML QName qname = new QName("http://www.example.org/sandbox", "Session"); JAXBElement<Session> sessionJAXB = new JAXBElement<Session>(qname, Session.class, new Session()); sessionJAXB.getValue().getCustomers().add(customer); //??This fails to actually add StringWriter marshallWriter = new StringWriter(); Result marshallResult = new StreamResult(marshallWriter); m_marshaller.marshal(sessionJAXB, marshallResult); marshallWriter.flush(); String result = marshallWriter.getBuffer().toString().trim(); String xml = result.replaceAll("\\Qhttp://www.example.org/sandbox\\E", "http://www.example.org/sandbox"); log.info("{}", xml); // Convert customer back to objects SAXBuilder builder = new SAXBuilder(); org.jdom.Document resultDOM = builder.build(new StringReader(xml)); @SuppressWarnings("unchecked") JAXBElement<Session> request = (JAXBElement<Session>) m_unmarshaller.unmarshal(new JDOMSource(resultDOM)); validationSession = m_validationEngine.createSession(); validationSession.bind(request.getValue()); assertEquals(3, validationSession.getProxyCount()); List<Customer> customers = request.getValue().getCustomers(); assertEquals(1, customers.size()); assertTrue(customers.get(0).getInvoices().get(0).isTestBoolean()); customers.clear(); assertEquals(1, validationSession.getProxyCount()); request.toString(); validationSession.close(); }
From source file:com.freesundance.contacts.google.ContactsExample.java
/** * Updates a contact or a group. Presence of any property of a given kind * (im, phone, mail, etc.) causes the existing properties of that kind to be * replaced.//from ww w.j a va2s .c o m * * @param parameters parameters storing updated contact values. */ public void updateEntry(ContactsExampleParameters parameters) throws IOException, ServiceException { if (parameters.isGroupFeed()) { ContactGroupEntry group = buildGroup(parameters); // get the group then update it ContactGroupEntry canonicalGroup = getGroupInternal(parameters.getId()); canonicalGroup.setTitle(group.getTitle()); canonicalGroup.setContent(group.getContent()); // update fields List<ExtendedProperty> extendedProperties = canonicalGroup.getExtendedProperties(); extendedProperties.clear(); if (group.hasExtendedProperties()) { extendedProperties.addAll(group.getExtendedProperties()); } printGroup(canonicalGroup.update()); } else { ContactEntry contact = buildContact(parameters); // get the contact then update it ContactEntry canonicalContact = getContactInternal(parameters.getId()); ElementHelper.updateContact(canonicalContact, contact); printContact(canonicalContact.update()); } }
From source file:com.boundary.sdk.snmp.metric.PollersTest.java
@Test public void testGetHostIds() throws URISyntaxException { Pollers pollers = Pollers.load(POLLERS_TEST_FILENAME); PollerEntry entry = pollers.getPollers().get(0); List<Long> expectedIds = new ArrayList<Long>(); expectedIds.add(new Long(1)); List<Long> ids = entry.getHostListIds(); assertEquals("check getHostListIds 1", expectedIds, ids); entry = pollers.getPollers().get(1); ids = entry.getHostListIds();/*from w w w.ja v a 2 s .c o m*/ expectedIds.add(new Long(3)); assertEquals("check getHostListIds 2", expectedIds, ids); entry = pollers.getPollers().get(2); ids = entry.getHostListIds(); expectedIds.clear(); expectedIds.add(new Long(3)); assertEquals("check getHostListIds 3", expectedIds, ids); }
From source file:jef.database.wrapper.clause.SelectPart.java
public void appendNoGroupFunc(StringBuilder sb) { sb.append("select "); if (distinct) sb.append("distinct "); Set<String> alreadyField = new HashSet<String>(); List<String> columns = new ArrayList<String>(); for (CommentEntry entry : entries) { String column;//w w w.j av a2 s .co m if (entry.getKey().indexOf('(') > 0) { column = StringUtils.substringBetween(entry.getKey(), "(", ")"); } else { column = entry.getKey(); } int point = column.indexOf('.'); String key = point == -1 ? column : column.substring(point + 1); if ("*".equals(key)) { columns.clear(); columns.add(column); break; } if (!alreadyField.contains(key)) { alreadyField.add(key); columns.add(column); } } Iterator<String> iter = columns.iterator(); sb.append(iter.next()); for (; iter.hasNext();) { sb.append(',').append(iter.next()); } if (ORMConfig.getInstance().isFormatSQL() && columns.size() > 1) { sb.append("\n"); } }