Java Code Examples for java.util.TreeSet#clear()
The following examples show how to use
java.util.TreeSet#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: TypeBitmap.java From dnsjava with BSD 2-Clause "Simplified" License | 6 votes |
public void toWire(DNSOutput out) { if (types.size() == 0) { return; } int mapbase = -1; TreeSet<Integer> map = new TreeSet<>(); for (Integer type : types) { int t = type; int base = t >> 8; if (base != mapbase) { if (map.size() > 0) { mapToWire(out, map, mapbase); map.clear(); } mapbase = base; } map.add(t); } mapToWire(out, map, mapbase); }
Example 2
Source File: PerspectiveFilter.java From osp with GNU General Public License v3.0 | 6 votes |
/** * Sets the fixed position behavior (all frames identical). * * @param fix true to set the corner positions the same in all frames * @param in true for input corners, false for output */ public void setFixed(boolean fix, boolean in) { if (isFixed(in)!=fix) { String filterState = new XMLControlElement(this).toXML(); if (in) fixedIn = fix; else fixedOut = fix; if (isFixed(in)) { TreeSet<Integer> keyFrames = in? inKeyFrames: outKeyFrames; keyFrames.clear(); saveCorners(fixedKey, in); // save input corners } support.firePropertyChange("fixed", filterState, null); //$NON-NLS-1$ } }
Example 3
Source File: SimUtils.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * Prepare collection and node / host names for redaction. * @param clusterState cluster state */ public static RedactionUtils.RedactionContext getRedactionContext(ClusterState clusterState) { RedactionUtils.RedactionContext ctx = new RedactionUtils.RedactionContext(); TreeSet<String> names = new TreeSet<>(clusterState.getLiveNodes()); for (String nodeName : names) { String urlString = Utils.getBaseUrlForNodeName(nodeName, "http"); try { URL u = new URL(urlString); // protocol format String hostPort = u.getHost() + ":" + u.getPort(); ctx.addName(u.getHost() + ":" + u.getPort(), RedactionUtils.NODE_REDACTION_PREFIX); // node name format ctx.addEquivalentName(hostPort, u.getHost() + "_" + u.getPort() + "_", RedactionUtils.NODE_REDACTION_PREFIX); } catch (MalformedURLException e) { log.warn("Invalid URL for node name {}, replacing including protocol and path", nodeName, e); ctx.addName(urlString, RedactionUtils.NODE_REDACTION_PREFIX); ctx.addEquivalentName(urlString, Utils.getBaseUrlForNodeName(nodeName, "https"), RedactionUtils.NODE_REDACTION_PREFIX); } } names.clear(); names.addAll(clusterState.getCollectionStates().keySet()); names.forEach(n -> ctx.addName(n, RedactionUtils.COLL_REDACTION_PREFIX)); return ctx; }
Example 4
Source File: PerspectiveFilter.java From osp with GNU General Public License v3.0 | 6 votes |
private void loadCornerData(double[][][] cornerData, boolean in) { ensureCornerCapacity(cornerData.length); TreeSet<Integer> keyFrames = in? inKeyFrames: outKeyFrames; keyFrames.clear(); Point2D[][] cornerPoints = in? inCornerPoints: outCornerPoints; for (int j=0; j<cornerData.length; j++) { if (cornerData[j]==null) continue; keyFrames.add(j); if (cornerPoints[j]==null) { cornerPoints[j] = new Point2D[4]; for (int i=0; i<4; i++) { cornerPoints[j][i] = new Point2D.Double(); } } for (int i=0; i<4; i++) { cornerPoints[j][i].setLocation(cornerData[j][i][0], cornerData[j][i][1]); } } }
Example 5
Source File: 10660 Citizen attention offices.java From UVA with GNU General Public License v3.0 | 6 votes |
public static void dfs(int [][] map, HashSet<Integer> offices, int currMax, TreeSet<Integer> ans) { if (offices.size()<5) { for (int i=currMax;i<25;i++) { offices.add(i); dfs(map, offices, i+1, ans); offices.remove(i); } } else { int totalDist=0; for (int x=0;x<5;x++) for (int y=0;y<5;y++) if (map[x][y]>0) { int minDist=Integer.MAX_VALUE; for (int office : offices) minDist=Math.min(minDist, (Math.abs(office/5-x)+Math.abs(office%5-y)) * map[x][y]); totalDist+=minDist; } if (totalDist<MinTotalDist) { MinTotalDist=totalDist; ans.clear(); ans.addAll(offices); } } }
Example 6
Source File: LocaleMatcherTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * If all the base languages are the same, then each sublocale matches * itself most closely */ @Test public void testExactMatches() { String lastBase = ""; TreeSet<ULocale> sorted = new TreeSet<ULocale>(); for (ULocale loc : ULocale.getAvailableLocales()) { String language = loc.getLanguage(); if (!lastBase.equals(language)) { check(sorted); sorted.clear(); lastBase = language; } sorted.add(loc); } check(sorted); }
Example 7
Source File: BarrierMonitor.java From twister2 with Apache License 2.0 | 5 votes |
/** * when a barrier completes either with success or failure, * we clear its status data */ private void barrierCompleted(TreeSet<Integer> waitList, LongObject expectedWorkers, LongObject startTime, LongObject barrierTimeout) { waitList.clear(); expectedWorkers.number = 0; startTime.number = 0; barrierTimeout.number = 0; }
Example 8
Source File: ModelStandardIndexedDirectorTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private static void testDirector(ModelPerformer[] performers) throws Exception { final TreeSet<Integer> played = new TreeSet<Integer>(); ModelDirectedPlayer player = new ModelDirectedPlayer() { public void play(int performerIndex, ModelConnectionBlock[] connectionBlocks) { played.add(performerIndex); } }; ModelStandardIndexedDirector idirector = new ModelStandardIndexedDirector(performers, player); ModelStandardDirector director = new ModelStandardDirector(performers, player); for (int n = 0; n < 128; n++) { for (int v = 0; v < 128; v++) { director.noteOn(n, v); String p1 = treeToString(played); played.clear(); idirector.noteOn(n, v); String p2 = treeToString(played); played.clear(); if(!p1.equals(p2)) throw new Exception( "Note = " + n + ", Vel = " + v + " failed"); } } }
Example 9
Source File: TreeSetTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * clear removes all elements */ public void testClear() { TreeSet q = populatedSet(SIZE); q.clear(); assertTrue(q.isEmpty()); assertEquals(0, q.size()); q.add(new Integer(1)); assertFalse(q.isEmpty()); q.clear(); assertTrue(q.isEmpty()); }
Example 10
Source File: ModelStandardIndexedDirectorTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private static void testDirector(ModelPerformer[] performers) throws Exception { final TreeSet<Integer> played = new TreeSet<Integer>(); ModelDirectedPlayer player = new ModelDirectedPlayer() { public void play(int performerIndex, ModelConnectionBlock[] connectionBlocks) { played.add(performerIndex); } }; ModelStandardIndexedDirector idirector = new ModelStandardIndexedDirector(performers, player); ModelStandardDirector director = new ModelStandardDirector(performers, player); for (int n = 0; n < 128; n++) { for (int v = 0; v < 128; v++) { director.noteOn(n, v); String p1 = treeToString(played); played.clear(); idirector.noteOn(n, v); String p2 = treeToString(played); played.clear(); if(!p1.equals(p2)) throw new Exception( "Note = " + n + ", Vel = " + v + " failed"); } } }
Example 11
Source File: ModelStandardIndexedDirectorTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private static void testDirector(ModelPerformer[] performers) throws Exception { final TreeSet<Integer> played = new TreeSet<Integer>(); ModelDirectedPlayer player = new ModelDirectedPlayer() { public void play(int performerIndex, ModelConnectionBlock[] connectionBlocks) { played.add(performerIndex); } }; ModelStandardIndexedDirector idirector = new ModelStandardIndexedDirector(performers, player); ModelStandardDirector director = new ModelStandardDirector(performers, player); for (int n = 0; n < 128; n++) { for (int v = 0; v < 128; v++) { director.noteOn(n, v); String p1 = treeToString(played); played.clear(); idirector.noteOn(n, v); String p2 = treeToString(played); played.clear(); if(!p1.equals(p2)) throw new Exception( "Note = " + n + ", Vel = " + v + " failed"); } } }
Example 12
Source File: ModelStandardIndexedDirectorTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static void testDirector(ModelPerformer[] performers) throws Exception { final TreeSet<Integer> played = new TreeSet<Integer>(); ModelDirectedPlayer player = new ModelDirectedPlayer() { public void play(int performerIndex, ModelConnectionBlock[] connectionBlocks) { played.add(performerIndex); } }; ModelStandardIndexedDirector idirector = new ModelStandardIndexedDirector(performers, player); ModelStandardDirector director = new ModelStandardDirector(performers, player); for (int n = 0; n < 128; n++) { for (int v = 0; v < 128; v++) { director.noteOn(n, v); String p1 = treeToString(played); played.clear(); idirector.noteOn(n, v); String p2 = treeToString(played); played.clear(); if(!p1.equals(p2)) throw new Exception( "Note = " + n + ", Vel = " + v + " failed"); } } }
Example 13
Source File: ModelStandardIndexedDirectorTest.java From hottub with GNU General Public License v2.0 | 5 votes |
private static void testDirector(ModelPerformer[] performers) throws Exception { final TreeSet<Integer> played = new TreeSet<Integer>(); ModelDirectedPlayer player = new ModelDirectedPlayer() { public void play(int performerIndex, ModelConnectionBlock[] connectionBlocks) { played.add(performerIndex); } }; ModelStandardIndexedDirector idirector = new ModelStandardIndexedDirector(performers, player); ModelStandardDirector director = new ModelStandardDirector(performers, player); for (int n = 0; n < 128; n++) { for (int v = 0; v < 128; v++) { director.noteOn(n, v); String p1 = treeToString(played); played.clear(); idirector.noteOn(n, v); String p2 = treeToString(played); played.clear(); if(!p1.equals(p2)) throw new Exception( "Note = " + n + ", Vel = " + v + " failed"); } } }
Example 14
Source File: SessionCommandGroup.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Help about available command groups. * * @param out * output device to print result */ int help(PrintWriter out, SessionImpl si) { final TreeSet<String> cgInfos = new TreeSet<String>(); cgInfos.add(helpLine(this)); try { final Collection<ServiceReference<CommandGroup>> refs = bc .getServiceReferences(CommandGroup.class, null); for (ServiceReference<CommandGroup> srcg : refs) { final CommandGroup c = bc.getService(srcg); if (c != null) { cgInfos.add(helpLine(c)); bc.ungetService(srcg); } } out.println("Available command groups (type 'enter' to enter a group):"); for (String cgLine : cgInfos) { out.println(cgLine); } cgInfos.clear(); } catch (InvalidSyntaxException ignore) { } return 0; }
Example 15
Source File: AndExpr.java From baratine with GNU General Public License v2.0 | 5 votes |
/** * Returns all the keys assigned statically, e.g. by param or literal. */ @Override public void fillAssignedKeys(Set<String> keys) { TreeSet<String> subKeys = new TreeSet<>(); for (ExprKraken expr : _exprs) { subKeys.clear(); expr.fillAssignedKeys(subKeys); keys.addAll(subKeys); } }
Example 16
Source File: ModelStandardIndexedDirectorTest.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private static void testDirector(ModelPerformer[] performers) throws Exception { final TreeSet<Integer> played = new TreeSet<Integer>(); ModelDirectedPlayer player = new ModelDirectedPlayer() { public void play(int performerIndex, ModelConnectionBlock[] connectionBlocks) { played.add(performerIndex); } }; ModelStandardIndexedDirector idirector = new ModelStandardIndexedDirector(performers, player); ModelStandardDirector director = new ModelStandardDirector(performers, player); for (int n = 0; n < 128; n++) { for (int v = 0; v < 128; v++) { director.noteOn(n, v); String p1 = treeToString(played); played.clear(); idirector.noteOn(n, v); String p2 = treeToString(played); played.clear(); if(!p1.equals(p2)) throw new Exception( "Note = " + n + ", Vel = " + v + " failed"); } } }
Example 17
Source File: ModelStandardIndexedDirectorTest.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
private static void testDirector(ModelPerformer[] performers) throws Exception { final TreeSet<Integer> played = new TreeSet<Integer>(); ModelDirectedPlayer player = new ModelDirectedPlayer() { public void play(int performerIndex, ModelConnectionBlock[] connectionBlocks) { played.add(performerIndex); } }; ModelStandardIndexedDirector idirector = new ModelStandardIndexedDirector(performers, player); ModelStandardDirector director = new ModelStandardDirector(performers, player); for (int n = 0; n < 128; n++) { for (int v = 0; v < 128; v++) { director.noteOn(n, v); String p1 = treeToString(played); played.clear(); idirector.noteOn(n, v); String p2 = treeToString(played); played.clear(); if(!p1.equals(p2)) throw new Exception( "Note = " + n + ", Vel = " + v + " failed"); } } }
Example 18
Source File: ResourceParallelCopier.java From kylin with Apache License 2.0 | 5 votes |
void divideGroups(NavigableSet<String> resources, String prefixSoFar, TreeMap<String, Integer> groupCollector) { if (resources.isEmpty()) return; if (resources.size() <= groupSize) { String group = longestCommonPrefix(resources, prefixSoFar); groupCollector.put(group, resources.size()); return; } // the resources set is too big, divide it TreeSet<String> newSet = new TreeSet<>(); String newPrefix = null; int newPrefixLen = prefixSoFar.length() + 1; for (String path : resources) { String myPrefix = path.length() < newPrefixLen ? path : path.substring(0, newPrefixLen); if (newPrefix != null && !myPrefix.equals(newPrefix)) { // cut off last group divideGroups(newSet, newPrefix, groupCollector); newSet.clear(); newPrefix = null; } if (newPrefix == null) newPrefix = myPrefix; newSet.add(path); } // the last group if (!newSet.isEmpty()) { divideGroups(newSet, newPrefix, groupCollector); } }
Example 19
Source File: TestTool.java From iaf with Apache License 2.0 | 4 votes |
public static String initScenariosRootDirectories( AppConstants appConstants, String realPath, String paramScenariosRootDirectory, List<String> scenariosRootDirectories, List<String> scenariosRootDescriptions, Map<String, Object> writers) { String currentScenariosRootDirectory = null; if (realPath == null) { errorMessage("Could not read webapp real path", writers); } else { if (!realPath.endsWith(File.separator)) { realPath = realPath + File.separator; } Map<String, String> scenariosRoots = new HashMap<String, String>(); Map<String, String> scenariosRootsBroken = new HashMap<String, String>(); int j = 1; String directory = appConstants.getResolvedProperty("scenariosroot" + j + ".directory"); String description = appConstants.getResolvedProperty("scenariosroot" + j + ".description"); while (directory != null) { if (description == null) { errorMessage("Could not find description for root directory '" + directory + "'", writers); } else if (scenariosRoots.get(description) != null) { errorMessage("A root directory named '" + description + "' already exist", writers); } else { String parent = realPath; String m2eFileName = appConstants.getResolvedProperty("scenariosroot" + j + ".m2e.pom.properties"); if (m2eFileName != null) { File m2eFile = new File(realPath, m2eFileName); if (m2eFile.exists()) { debugMessage("Read m2e pom.properties: " + m2eFileName, writers); Properties m2eProperties = readProperties(null, m2eFile, false, writers); parent = m2eProperties.getProperty("m2e.projectLocation"); debugMessage("Use m2e parent: " + parent, writers); } } directory = getAbsolutePath(parent, directory, true); if (new File(directory).exists()) { scenariosRoots.put(description, directory); } else { scenariosRootsBroken.put(description, directory); } } j++; directory = appConstants.getResolvedProperty("scenariosroot" + j + ".directory"); description = appConstants.getResolvedProperty("scenariosroot" + j + ".description"); } TreeSet<String> treeSet = new TreeSet<String>(new CaseInsensitiveComparator()); treeSet.addAll(scenariosRoots.keySet()); Iterator<String> iterator = treeSet.iterator(); while (iterator.hasNext()) { description = (String)iterator.next(); scenariosRootDescriptions.add(description); scenariosRootDirectories.add(scenariosRoots.get(description)); } treeSet.clear(); treeSet.addAll(scenariosRootsBroken.keySet()); iterator = treeSet.iterator(); while (iterator.hasNext()) { description = (String)iterator.next(); scenariosRootDescriptions.add("X " + description); scenariosRootDirectories.add(scenariosRootsBroken.get(description)); } debugMessage("Read scenariosrootdirectory parameter", writers); debugMessage("Get current scenarios root directory", writers); if (paramScenariosRootDirectory == null || paramScenariosRootDirectory.equals("")) { String scenariosRootDefault = appConstants.getResolvedProperty("scenariosroot.default"); if (scenariosRootDefault != null) { currentScenariosRootDirectory = scenariosRoots.get(scenariosRootDefault); } if (currentScenariosRootDirectory == null && scenariosRootDirectories.size() > 0) { currentScenariosRootDirectory = (String)scenariosRootDirectories.get(0); } } else { currentScenariosRootDirectory = paramScenariosRootDirectory; } } return currentScenariosRootDirectory; }
Example 20
Source File: NamenodeFsck.java From hadoop with Apache License 2.0 | 4 votes |
private void copyBlock(final DFSClient dfs, LocatedBlock lblock, OutputStream fos) throws Exception { int failures = 0; InetSocketAddress targetAddr = null; TreeSet<DatanodeInfo> deadNodes = new TreeSet<DatanodeInfo>(); BlockReader blockReader = null; ExtendedBlock block = lblock.getBlock(); while (blockReader == null) { DatanodeInfo chosenNode; try { chosenNode = bestNode(dfs, lblock.getLocations(), deadNodes); targetAddr = NetUtils.createSocketAddr(chosenNode.getXferAddr()); } catch (IOException ie) { if (failures >= DFSConfigKeys.DFS_CLIENT_MAX_BLOCK_ACQUIRE_FAILURES_DEFAULT) { throw new IOException("Could not obtain block " + lblock, ie); } LOG.info("Could not obtain block from any node: " + ie); try { Thread.sleep(10000); } catch (InterruptedException iex) { } deadNodes.clear(); failures++; continue; } try { String file = BlockReaderFactory.getFileName(targetAddr, block.getBlockPoolId(), block.getBlockId()); blockReader = new BlockReaderFactory(dfs.getConf()). setFileName(file). setBlock(block). setBlockToken(lblock.getBlockToken()). setStartOffset(0). setLength(-1). setVerifyChecksum(true). setClientName("fsck"). setDatanodeInfo(chosenNode). setInetSocketAddress(targetAddr). setCachingStrategy(CachingStrategy.newDropBehind()). setClientCacheContext(dfs.getClientContext()). setConfiguration(namenode.conf). setRemotePeerFactory(new RemotePeerFactory() { @Override public Peer newConnectedPeer(InetSocketAddress addr, Token<BlockTokenIdentifier> blockToken, DatanodeID datanodeId) throws IOException { Peer peer = null; Socket s = NetUtils.getDefaultSocketFactory(conf).createSocket(); try { s.connect(addr, HdfsServerConstants.READ_TIMEOUT); s.setSoTimeout(HdfsServerConstants.READ_TIMEOUT); peer = TcpPeerServer.peerFromSocketAndKey( dfs.getSaslDataTransferClient(), s, NamenodeFsck.this, blockToken, datanodeId); } finally { if (peer == null) { IOUtils.closeQuietly(s); } } return peer; } }). build(); } catch (IOException ex) { // Put chosen node into dead list, continue LOG.info("Failed to connect to " + targetAddr + ":" + ex); deadNodes.add(chosenNode); } } byte[] buf = new byte[1024]; int cnt = 0; boolean success = true; long bytesRead = 0; try { while ((cnt = blockReader.read(buf, 0, buf.length)) > 0) { fos.write(buf, 0, cnt); bytesRead += cnt; } if ( bytesRead != block.getNumBytes() ) { throw new IOException("Recorded block size is " + block.getNumBytes() + ", but datanode returned " +bytesRead+" bytes"); } } catch (Exception e) { LOG.error("Error reading block", e); success = false; } finally { blockReader.close(); } if (!success) { throw new Exception("Could not copy block data for " + lblock.getBlock()); } }