Java Code Examples for java.util.List#clear()
The following examples show how to use
java.util.List#clear() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SunCertPathBuilder.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
private PKIXCertPathBuilderResult build() throws CertPathBuilderException { List<List<Vertex>> adjList = new ArrayList<>(); PKIXCertPathBuilderResult result = buildCertPath(false, adjList); if (result == null) { if (debug != null) { debug.println("SunCertPathBuilder.engineBuild: 2nd pass; " + "try building again searching all certstores"); } // try again adjList.clear(); result = buildCertPath(true, adjList); if (result == null) { throw new SunCertPathBuilderException("unable to find valid " + "certification path to requested target", new AdjacencyList(adjList)); } } return result; }
Example 2
Source File: Converters.java From SmartPaperScan with Apache License 2.0 | 6 votes |
public static void Mat_to_vector_vector_KeyPoint(Mat m, List<MatOfKeyPoint> kps) { if (kps == null) throw new java.lang.IllegalArgumentException("Output List can't be null"); if (m == null) throw new java.lang.IllegalArgumentException("Input Mat can't be null"); List<Mat> mats = new ArrayList<Mat>(m.rows()); Mat_to_vector_Mat(m, mats); for (Mat mi : mats) { MatOfKeyPoint vkp = new MatOfKeyPoint(mi); kps.add(vkp); mi.release(); } mats.clear(); }
Example 3
Source File: PermissionsDialog.java From AcDisplay with GNU General Public License v2.0 | 6 votes |
@Override public void onResume() { super.onResume(); List<Permission> data = mAdapter.getPermissionList(); data.clear(); for (Permission item : mPermissions) { if (!item.isGranted()) { data.add(item); } } // Dismiss permission dialog if there's no work for it. if (data.isEmpty()) { dismiss(); } mAdapter.notifyDataSetChanged(); }
Example 4
Source File: Converters.java From OpenCV-Android-Object-Detection with MIT License | 6 votes |
public static void Mat_to_vector_vector_DMatch(Mat m, List<MatOfDMatch> lvdm) { if (lvdm == null) throw new java.lang.IllegalArgumentException("Output List can't be null"); if (m == null) throw new java.lang.IllegalArgumentException("Input Mat can't be null"); List<Mat> mats = new ArrayList<Mat>(m.rows()); Mat_to_vector_Mat(m, mats); lvdm.clear(); for (Mat mi : mats) { MatOfDMatch vdm = new MatOfDMatch(mi); lvdm.add(vdm); mi.release(); } mats.clear(); }
Example 5
Source File: MycatRelBuilder.java From Mycat2 with GNU General Public License v3.0 | 6 votes |
public RelBuilder values(RelDataType rowType, Object... columnValues) { int columnCount = rowType.getFieldCount(); final ImmutableList.Builder<ImmutableList<RexLiteral>> listBuilder = ImmutableList.builder(); final List<RexLiteral> valueList = new ArrayList<>(); List<RelDataTypeField> fieldList = rowType.getFieldList(); for (int i = 0; i < columnValues.length; i++) { RelDataTypeField relDataTypeField = fieldList.get(valueList.size()); valueList.add((RexLiteral) literal(relDataTypeField.getType(), columnValues[i], false)); if ((i + 1) % columnCount == 0) { listBuilder.add(ImmutableList.copyOf(valueList)); valueList.clear(); } } super.values(listBuilder.build(), rowType); return this; }
Example 6
Source File: SystemManager.java From audiveris with GNU Affero General Public License v3.0 | 6 votes |
/** * Report the systems that contain the provided point * * @param point the provided pixel point * @param found (output) list to be populated (allocated if null) * @return the containing systems info, perhaps empty but not null */ public List<SystemInfo> getSystemsOf (Point2D point, List<SystemInfo> found) { if (found != null) { found.clear(); } else { found = new ArrayList<>(); } for (SystemInfo system : systems) { Area area = system.getArea(); if ((area != null) && area.contains(point)) { found.add(system); } } return found; }
Example 7
Source File: KShortestPathsSearchTest.java From onos with Apache License 2.0 | 6 votes |
@Test public void testTwoPath() { //Tests that there are only two paths between A and C and that they are returned in the correct order result = kShortestPathsSearch.search(graph, A, C, weigher, 3); assertTrue("There are an unexpected number of paths.", result.paths().size() == 2); Iterator<Path<TestVertex, TestEdge>> edgeListIterator = result.paths().iterator(); List<TestEdge> correctEdgeList = Lists.newArrayList(); correctEdgeList.add(new TestEdge(A, B, W1)); correctEdgeList.add(new TestEdge(B, C, W1)); assertTrue("The first path from A to C was incorrect.", edgeListsAreEqual(edgeListIterator.next().edges(), correctEdgeList)); correctEdgeList.clear(); correctEdgeList.add(new TestEdge(A, C, W3)); assertTrue("The second path from A to C was incorrect.", edgeListsAreEqual(edgeListIterator.next().edges(), correctEdgeList)); }
Example 8
Source File: CommandLineTests.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
static void testJDK() throws IOException { runPack200(false); // test the specimen JDK List<String> cmdsList = new ArrayList<String>(); cmdsList.add(javaCmd.getAbsolutePath()); cmdsList.add("-verify"); cmdsList.add("-version"); Utils.runExec(cmdsList); // invoke javac to test the tools.jar cmdsList.clear(); cmdsList.add(javacCmd.getAbsolutePath()); cmdsList.add("-J-verify"); cmdsList.add("-help"); Utils.runExec(cmdsList); }
Example 9
Source File: TestPgMockCDCRecord.java From datacollector with Apache License 2.0 | 6 votes |
public void setOldKeys( List<String> keyNames, List<String> keyTypes, List<Field> keyValues) { oldKeys = cdcChange.get("oldkeys").getValueAsMap(); List<Field> oldKeyKeynames = oldKeys.get("keynames").getValueAsList(); oldKeyKeynames.clear(); keyNames.forEach(keyname -> oldKeyKeynames.add(Field.create(keyname))); List<Field> oldKeyKeytypes = oldKeys.get("keytypes").getValueAsList(); oldKeyKeytypes.clear(); keyTypes.forEach(keytype -> oldKeyKeytypes.add(Field.create(keytype))); List<Field> oldKeyKeyvalues = oldKeys.get("keyvalue").getValueAsList(); oldKeyKeyvalues.clear(); keyValues.forEach(keyvalue -> oldKeyKeytypes.add(keyvalue.clone())); }
Example 10
Source File: TestTezMerger.java From tez with Apache License 2.0 | 5 votes |
@Test(timeout = 80000) public void testMerge() throws Exception { /** * test with number of files, keys per file and mergefactor */ //empty file merge(1, 0, 1); merge(100, 0, 5); //small files merge(12, 4, 2); merge(2, 10, 2); merge(1, 10, 1); merge(5, 10, 3); merge(200, 10, 100); //bigger files merge(5, 100, 5); merge(5, 1000, 5); merge(5, 1000, 10); merge(5, 1000, 100); //Create random mix of files (empty files + files with keys) List<Path> pathList = new LinkedList<Path>(); pathList.clear(); pathList.addAll(createIFiles(Math.max(2, rnd.nextInt(20)), 0)); pathList.addAll(createIFiles(Math.max(2, rnd.nextInt(20)), Math.max(2, rnd.nextInt(10)))); merge(pathList, Math.max(2, rnd.nextInt(10))); }
Example 11
Source File: OT3Test.java From swellrt with Apache License 2.0 | 5 votes |
/** * Check client sent signatures from the given version. * @param versions Each version number is after the operation as applied. */ public TestConfig checkClientSentOpen(int ... versions) { List<HashedVersion> signatures = serverConnectionMock.getReconnectSignatures(); assertEquals(versions.length, signatures.size()); for (int i = 0; i < versions.length; i++) { assertEquals(genSignature(versions[i]), signatures.get(i)); } signatures.clear(); return this; }
Example 12
Source File: Converters.java From effective_android_sample with Apache License 2.0 | 5 votes |
public static void Mat_to_vector_uchar(Mat m, List<Byte> us) { if (us == null) throw new java.lang.IllegalArgumentException("Output List can't be null"); int count = m.rows(); if (CvType.CV_8UC1 != m.type() || m.cols() != 1) throw new java.lang.IllegalArgumentException( "CvType.CV_8UC1 != m.type() || m.cols()!=1\n" + m); us.clear(); byte[] buff = new byte[count]; m.get(0, 0, buff); for (int i = 0; i < count; i++) { us.add(buff[i]); } }
Example 13
Source File: FindSimilarEntitiesByAdaptiveEditDistance.java From Drop-seq with MIT License | 5 votes |
public Integer findEditDistanceThreshold (final int [] edList) { // build and populate an object counter. ObjectCounter<Integer> counts = new ObjectCounter<>(); Arrays.stream(edList).forEach(x -> counts.increment(x)); // System.out.println(Arrays.toString(edList)); // loop through to find the minimum count point, from the lowest edit distance to the maximum ED. // int maxED = Arrays.stream(edList).max().getAsInt(); List<Integer> result = new ArrayList<>(); int resultCount=Integer.MAX_VALUE; // find the minimum positions in the object counter. This may include keys that don't exist (ie: they are 0.) // if there are multiple minimums, then select the lowest. for (int i=minEditDistance; i<=maxEditDistance; i++) { int count = counts.getCountForKey(i); // a lower or equal count. if (count<=resultCount) { // if this is a lower count, then it's the only result. // if this is the same count, then add it to the result. if (count<resultCount) result.clear(); result.add(i); resultCount=count; } } // no results found. if (result.size()==0) return -1; // special case: no entries within all of scanned results. return -1. int numPosScanned=(maxEditDistance-minEditDistance)+1; if (result.size()==numPosScanned && resultCount==0) return -1; // there may be ties. select the first entry (smallest ED) Collections.sort(result); int threshold=result.get(0); threshold=threshold-1; // steve reports the last filled position, not the empty one. return threshold; }
Example 14
Source File: TileEntityInserter.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
private void setSidesFromMask(int mask, List<EnumFacing> list) { list.clear(); for (EnumFacing side : EnumFacing.values()) { if ((mask & (1 << side.getIndex())) != 0) { list.add(side); } } }
Example 15
Source File: CacheClient.java From blazingcache with Apache License 2.0 | 4 votes |
private void performEviction() throws InterruptedException { long deltaMemory = maxMemory - actualMemory.longValue(); final long now = System.currentTimeMillis(); final boolean performMaxEntryAgeEviction = checkPerformEvictionForMaxLocalEntryAge(now); if (deltaMemory > 0 && !performMaxEntryAgeEviction) { return; } this.lastPerformedEvictionTimestamp = now; long to_release = -deltaMemory; long maxAgeTs = now - maxLocalEntryAge; if (maxMemory > 0 && maxLocalEntryAge > 0) { LOGGER.log(Level.FINER, "trying to release {0} bytes, and evicting local entries before {1}", new Object[]{to_release, new java.util.Date(maxAgeTs)}); } else if (maxMemory > 0) { LOGGER.log(Level.FINER, "trying to release {0} bytes", new Object[]{to_release}); } else if (maxLocalEntryAge > 0) { LOGGER.log(Level.FINER, "evicting local entries before {0}", new Object[]{new java.util.Date(maxAgeTs)}); } long maxAgeTsNanos = System.nanoTime() - maxLocalEntryAge * 1000L * 1000; List<EntryHandle> evictable = new ArrayList<>(); java.util.function.Consumer<EntryHandle> accumulator = new java.util.function.Consumer<EntryHandle>() { long releasedMemory = 0; @Override public void accept(EntryHandle t) { if ((maxMemory > 0 && releasedMemory < to_release) || (maxLocalEntryAge > 0 && t.getLastGetTime() < maxAgeTsNanos)) { evictable.add(t); releasedMemory += t.getSerializedDataLength(); } } }; try { cache.values().stream().sorted((EntryHandle o1, EntryHandle o2) -> { long diff = o1.getLastGetTime() - o2.getLastGetTime(); if (diff == 0) { return 0; } return diff > 0 ? 1 : -1; }).forEachOrdered(accumulator); } catch (Exception dataChangedDuringSort) { LOGGER.severe("dataChangedDuringSort: " + dataChangedDuringSort); return; } if (!evictable.isEmpty()) { LOGGER.log(Level.INFO, "found {0} evictable entries", evictable.size()); //update the age of the oldest evicted key //the oldest one is the first entry in evictable this.oldestEvictedKeyAge.getAndSet(System.nanoTime() - evictable.get(0).getPutTime()); List<EntryHandle> batch = new ArrayList<>(); for (final EntryHandle entry : evictable) { if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.log(Level.FINEST, "evict {0} size {1} bytes lastAccessDate {2}", new Object[]{entry.getKey(), entry.getSerializedDataLength(), entry.getLastGetTime()}); } batch.add(entry); if (batch.size() >= this.evictionBatchSize) { batchEvictEntries(batch); batch.clear(); } } batchEvictEntries(batch); LOGGER.log(Level.SEVERE, "eviction finished"); } }
Example 16
Source File: TestDirectoryPartitioner.java From samza with Apache License 2.0 | 4 votes |
@Test public void testInvalidDirectoryUpdating() { // the update is invalid when at least one old file is removed List<FileMetadata> testList = new ArrayList<>(); int numInput = 6; String[] inputFiles = { "part-001.avro", "part-002.avro", "part-003.avro", "part-005.avro", "part-004.avro", "part-006.avro"}; long[] fileLength = {150582, 138132, 214005, 205738, 158273, 982345}; for (int i = 0; i < numInput; i++) { testList.add(new FileMetadata(inputFiles[i], fileLength[i])); } String whiteList = ".*"; String blackList = ""; String groupPattern = ""; int expectedNumPartition = 6; int[][] expectedPartitioning = {{0}, {1}, {2}, {3}, {4}, {5}}; DirectoryPartitioner directoryPartitioner = new DirectoryPartitioner(whiteList, blackList, groupPattern, new TestFileSystemAdapter(testList)); Map<Partition, SystemStreamPartitionMetadata> metadataMap = directoryPartitioner.getPartitionMetadataMap("hdfs", null); Assert.assertEquals(expectedNumPartition, metadataMap.size()); Map<Partition, List<String>> descriporMap = directoryPartitioner.getPartitionDescriptor("hdfs"); verifyPartitionDescriptor(inputFiles, expectedPartitioning, expectedNumPartition, descriporMap); String[] updatedInputFiles = { "part-001.avro", "part-002.avro", "part-003.avro", "part-005.avro", "part-007.avro", // remove part-004 and replace it with 007 "part-006.avro"}; long[] updatedFileLength = {150582, 138132, 214005, 205738, 158273, 982345}; testList.clear(); for (int i = 0; i < numInput; i++) { testList.add(new FileMetadata(updatedInputFiles[i], updatedFileLength[i])); } directoryPartitioner = new DirectoryPartitioner(whiteList, blackList, groupPattern, new TestFileSystemAdapter(testList)); try { directoryPartitioner.getPartitionMetadataMap("hdfs", descriporMap); Assert.fail("Expect exception thrown from getting metadata. Should not reach this point."); } catch (SamzaException e) { // expect exception to be thrown } }
Example 17
Source File: ClassPathTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
void checkCompileCommands() throws Exception { // Without the -cp . parameter the command will fail seems like when called // from the command line, the current dir is added to the classpath // automatically but this is not happening when called using ProcessBuilder // testJavac success ClassPathTest3.java List<String> mainArgs = new ArrayList<>(); mainArgs.add(ToolBox.javacBinary.toString()); if (ToolBox.testToolVMOpts != null) { mainArgs.addAll(ToolBox.testToolVMOpts); } List<String> commonArgs = new ArrayList<>(); commonArgs.addAll(mainArgs); commonArgs.addAll(Arrays.asList("-cp", ".")); ToolBox.AnyToolArgs successParams = new ToolBox.AnyToolArgs() .appendArgs(commonArgs) .appendArgs("ClassPathTest3.java"); ToolBox.executeCommand(successParams); // testJavac failure ClassPathTest1.java ToolBox.AnyToolArgs failParams = new ToolBox.AnyToolArgs(ToolBox.Expect.FAIL) .appendArgs(commonArgs) .appendArgs("ClassPathTest1.java"); ToolBox.executeCommand(failParams); // This is done inside the executeCommand method // CLASSPATH=bar; export CLASSPATH Map<String, String> extVars = new TreeMap<>(); extVars.put("CLASSPATH", "bar"); // testJavac success ClassPathTest2.java successParams = new ToolBox.AnyToolArgs() .appendArgs(mainArgs) .appendArgs("ClassPathTest2.java") .set(extVars); ToolBox.executeCommand(successParams); // testJavac failure ClassPathTest1.java failParams = new ToolBox.AnyToolArgs(ToolBox.Expect.FAIL) .appendArgs(mainArgs) .appendArgs("ClassPathTest1.java") .set(extVars); ToolBox.executeCommand(failParams); // testJavac failure ClassPathTest3.java failParams = new ToolBox.AnyToolArgs(ToolBox.Expect.FAIL) .appendArgs(mainArgs) .appendArgs("ClassPathTest3.java") .set(extVars); ToolBox.executeCommand(failParams); // testJavac success -classpath foo ClassPathTest1.java commonArgs.clear(); commonArgs.addAll(mainArgs); commonArgs.addAll(Arrays.asList("-cp", "foo")); successParams = new ToolBox.AnyToolArgs() .appendArgs(commonArgs) .appendArgs("ClassPathTest1.java") .set(extVars); ToolBox.executeCommand(successParams); // testJavac failure -classpath foo ClassPathTest2.java failParams = new ToolBox.AnyToolArgs(ToolBox.Expect.FAIL) .appendArgs(commonArgs) .appendArgs("ClassPathTest2.java") .set(extVars); ToolBox.executeCommand(failParams); // testJavac failure -classpath foo ClassPathTest3.java failParams = new ToolBox.AnyToolArgs(ToolBox.Expect.FAIL) .appendArgs(commonArgs) .appendArgs("ClassPathTest3.java") .set(extVars); ToolBox.executeCommand(failParams); }
Example 18
Source File: TestRegionSizeUse.java From hbase with Apache License 2.0 | 4 votes |
/** * Writes at least {@code sizeInBytes} bytes of data to HBase and returns the TableName used. * * @param sizeInBytes The amount of data to write in bytes. * @return The table the data was written to */ private TableName writeData(long sizeInBytes) throws IOException { final Connection conn = TEST_UTIL.getConnection(); final Admin admin = TEST_UTIL.getAdmin(); final TableName tn = TableName.valueOf(testName.getMethodName()); // Delete the old table if (admin.tableExists(tn)) { admin.disableTable(tn); admin.deleteTable(tn); } // Create the table TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(tn); ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(F1)).build(); tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor); admin.createTable(tableDescriptorBuilder.build(), Bytes.toBytes("1"), Bytes.toBytes("9"), NUM_SPLITS); final Table table = conn.getTable(tn); try { List<Put> updates = new ArrayList<>(); long bytesToWrite = sizeInBytes; long rowKeyId = 0L; final StringBuilder sb = new StringBuilder(); final Random r = new Random(); while (bytesToWrite > 0L) { sb.setLength(0); sb.append(Long.toString(rowKeyId)); // Use the reverse counter as the rowKey to get even spread across all regions Put p = new Put(Bytes.toBytes(sb.reverse().toString())); byte[] value = new byte[SIZE_PER_VALUE]; r.nextBytes(value); p.addColumn(Bytes.toBytes(F1), Bytes.toBytes("q1"), value); updates.add(p); // Batch 50K worth of updates if (updates.size() > 50) { table.put(updates); updates.clear(); } // Just count the value size, ignore the size of rowkey + column bytesToWrite -= SIZE_PER_VALUE; rowKeyId++; } // Write the final batch if (!updates.isEmpty()) { table.put(updates); } return tn; } finally { table.close(); } }
Example 19
Source File: ConcurrentMapDataStore.java From boon with Apache License 2.0 | 3 votes |
@Override public void batchRead(ReadBatchRequest request) { int maxReadBatch = dataStoreConfig.dbMaxReadBatch(); long messageId = request.messageId(); String clientId = request.clientId(); List<String> keysToFetch = new ArrayList<>(maxReadBatch); for (String key : request.keys()) { keysToFetch.add(key); if (keysToFetch.size() > maxReadBatch) { quickBatchRead(messageId, clientId, new ArrayList<>(keysToFetch)); keysToFetch.clear(); } } if (keysToFetch.size() > 0) { quickBatchRead(messageId, clientId, new ArrayList<>(keysToFetch)); } this.readOperationsQueue.offer(request); }
Example 20
Source File: EmoUriComponent.java From emodb with Apache License 2.0 | 2 votes |
private static boolean[][] initEncodingTables() { boolean[][] tables = new boolean[Type.values().length][]; List<String> l = new ArrayList<>(); l.addAll(Arrays.asList(SCHEME)); tables[Type.SCHEME.ordinal()] = initEncodingTable(l); l.clear(); l.addAll(Arrays.asList(UNRESERVED)); tables[Type.UNRESERVED.ordinal()] = initEncodingTable(l); l.addAll(Arrays.asList(SUB_DELIMS)); tables[Type.HOST.ordinal()] = initEncodingTable(l); tables[Type.PORT.ordinal()] = initEncodingTable(Arrays.asList("0-9")); l.add(":"); tables[Type.USER_INFO.ordinal()] = initEncodingTable(l); l.add("@"); tables[Type.AUTHORITY.ordinal()] = initEncodingTable(l); tables[Type.PATH_SEGMENT.ordinal()] = initEncodingTable(l); tables[Type.PATH_SEGMENT.ordinal()][';'] = false; tables[Type.MATRIX_PARAM.ordinal()] = tables[Type.PATH_SEGMENT.ordinal()].clone(); tables[Type.MATRIX_PARAM.ordinal()]['='] = false; l.add("/"); tables[Type.PATH.ordinal()] = initEncodingTable(l); l.add("?"); tables[Type.QUERY.ordinal()] = initEncodingTable(l); tables[Type.FRAGMENT.ordinal()] = tables[Type.QUERY.ordinal()]; tables[Type.QUERY_PARAM.ordinal()] = initEncodingTable(l); tables[Type.QUERY_PARAM.ordinal()]['='] = false; tables[Type.QUERY_PARAM.ordinal()]['+'] = false; tables[Type.QUERY_PARAM.ordinal()]['&'] = false; return tables; }