當前位置: 首頁>>代碼示例>>Java>>正文


Java LinkedHashSet.removeAll方法代碼示例

本文整理匯總了Java中java.util.LinkedHashSet.removeAll方法的典型用法代碼示例。如果您正苦於以下問題:Java LinkedHashSet.removeAll方法的具體用法?Java LinkedHashSet.removeAll怎麽用?Java LinkedHashSet.removeAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.LinkedHashSet的用法示例。


在下文中一共展示了LinkedHashSet.removeAll方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getIPs

import java.util.LinkedHashSet; //導入方法依賴的package包/類
/**
 * Returns all the IPs associated with the provided interface, if any, in
 * textual form.
 * 
 * @param strInterface
 *            The name of the network interface or sub-interface to query
 *            (eg eth0 or eth0:0) or the string "default"
 * @param returnSubinterfaces
 *            Whether to return IPs associated with subinterfaces of
 *            the given interface
 * @return A string vector of all the IPs associated with the provided
 *         interface. The local host IP is returned if the interface
 *         name "default" is specified or there is an I/O error looking
 *         for the given interface.
 * @throws UnknownHostException
 *             If the given interface is invalid
 * 
 */
public static String[] getIPs(String strInterface,
    boolean returnSubinterfaces) throws UnknownHostException {
  if ("default".equals(strInterface)) {
    return new String[] { cachedHostAddress };
  }
  NetworkInterface netIf;
  try {
    netIf = NetworkInterface.getByName(strInterface);
    if (netIf == null) {
      netIf = getSubinterface(strInterface);
    }
  } catch (SocketException e) {
    LOG.warn("I/O error finding interface " + strInterface +
        ": " + e.getMessage());
    return new String[] { cachedHostAddress };
  }
  if (netIf == null) {
    throw new UnknownHostException("No such interface " + strInterface);
  }

  // NB: Using a LinkedHashSet to preserve the order for callers
  // that depend on a particular element being 1st in the array.
  // For example, getDefaultIP always returns the first element.
  LinkedHashSet<InetAddress> allAddrs = new LinkedHashSet<InetAddress>();
  allAddrs.addAll(Collections.list(netIf.getInetAddresses()));
  if (!returnSubinterfaces) {
    allAddrs.removeAll(getSubinterfaceInetAddrs(netIf));
  }

  String ips[] = new String[allAddrs.size()];
  int i = 0;
  for (InetAddress addr : allAddrs) {
    ips[i++] = addr.getHostAddress();
  }
  return ips;
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:55,代碼來源:DNS.java

示例2: getIPsAsInetAddressList

import java.util.LinkedHashSet; //導入方法依賴的package包/類
/**
 * Returns all the IPs associated with the provided interface, if any, as
 * a list of InetAddress objects.
 *
 * @param strInterface
 *            The name of the network interface or sub-interface to query
 *            (eg eth0 or eth0:0) or the string "default"
 * @param returnSubinterfaces
 *            Whether to return IPs associated with subinterfaces of
 *            the given interface
 * @return A list of all the IPs associated with the provided
 *         interface. The local host IP is returned if the interface
 *         name "default" is specified or there is an I/O error looking
 *         for the given interface.
 * @throws UnknownHostException
 *             If the given interface is invalid
 *
 */
public static List<InetAddress> getIPsAsInetAddressList(String strInterface,
    boolean returnSubinterfaces) throws UnknownHostException {
  if ("default".equals(strInterface)) {
    return Arrays.asList(InetAddress.getByName(cachedHostAddress));
  }
  NetworkInterface netIf;
  try {
    netIf = NetworkInterface.getByName(strInterface);
    if (netIf == null) {
      netIf = getSubinterface(strInterface);
    }
  } catch (SocketException e) {
    LOG.warn("I/O error finding interface " + strInterface +
        ": " + e.getMessage());
    return Arrays.asList(InetAddress.getByName(cachedHostAddress));
  }
  if (netIf == null) {
    throw new UnknownHostException("No such interface " + strInterface);
  }

  // NB: Using a LinkedHashSet to preserve the order for callers
  // that depend on a particular element being 1st in the array.
  // For example, getDefaultIP always returns the first element.
  LinkedHashSet<InetAddress> allAddrs = new LinkedHashSet<InetAddress>();
  allAddrs.addAll(Collections.list(netIf.getInetAddresses()));
  if (!returnSubinterfaces) {
    allAddrs.removeAll(getSubinterfaceInetAddrs(netIf));
  }
  return new Vector<InetAddress>(allAddrs);
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:49,代碼來源:DNS.java

示例3: unregister

import java.util.LinkedHashSet; //導入方法依賴的package包/類
boolean unregister(DiscreteResourceId key, List<ContinuousResource> values) {
    // short-circuit: receiving empty resource is regarded as success
    if (values.isEmpty()) {
        return true;
    }

    // even if one of the resources is allocated to a consumer,
    // all unregistrations are regarded as failure
    boolean allocated = values.stream().anyMatch(x -> isAllocated(x.id()));
    if (allocated) {
        log.warn("Failed to unregister {}: allocation exists", key);
        return false;
    }

    Set<ContinuousResource> oldValues = childMap.putIfAbsent(key, new LinkedHashSet<>());
    if (oldValues == null) {
        log.trace("No-Op removing values. key {} did not exist", key);
        return true;
    }

    if (values.stream().allMatch(x -> !oldValues.contains(x))) {
        // don't write map because none of the values are stored
        log.trace("No-Op removing values. key {} did not contain {}", key, values);
        return true;
    }

    LinkedHashSet<ContinuousResource> newValues = new LinkedHashSet<>(oldValues);
    newValues.removeAll(values);
    return childMap.replace(key, oldValues, newValues);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:31,代碼來源:TransactionalContinuousResourceSubStore.java


注:本文中的java.util.LinkedHashSet.removeAll方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。