java.util.TreeSet#clear ( )源码实例Demo

下面列出了java.util.TreeSet#clear ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dnsjava   文件: TypeBitmap.java
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);
}
 
源代码2 项目: j2objc   文件: LocaleMatcherTest.java
/**
 * 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);
}
 
源代码3 项目: UVA   文件: 10660 Citizen attention offices.java
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);
		}
		
	}
}
 
源代码4 项目: osp   文件: PerspectiveFilter.java
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]);
	}
	}
}
 
源代码5 项目: lucene-solr   文件: SimUtils.java
/**
 * 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;
}
 
源代码6 项目: osp   文件: PerspectiveFilter.java
/**
 * 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$
	}
}
 
源代码7 项目: kylin   文件: ResourceParallelCopier.java
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);
    }
}
 
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");
        }
    }
}
 
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");
        }
    }
}
 
源代码10 项目: twister2   文件: BarrierMonitor.java
/**
 * 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;
}
 
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");
        }
    }
}
 
源代码12 项目: openjdk-jdk9   文件: TreeSetTest.java
/**
 * 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());
}
 
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");
        }
    }
}
 
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");
        }
    }
}
 
源代码15 项目: hottub   文件: ModelStandardIndexedDirectorTest.java
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");
        }
    }
}
 
源代码16 项目: knopflerfish.org   文件: SessionCommandGroup.java
/**
 * 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;
}
 
源代码17 项目: baratine   文件: AndExpr.java
/**
 * 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);
  }
}
 
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");
        }
    }
}
 
源代码19 项目: iaf   文件: TestTool.java
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;
}
 
源代码20 项目: hadoop   文件: NamenodeFsck.java
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());
  }
}