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


Java Collections.list方法代碼示例

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


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

示例1: getMacAddressByNetworkInterface

import java.util.Collections; //導入方法依賴的package包/類
/**
 * 獲取設備MAC地址
 *
 * @return MAC地址
 */
@RequiresPermission(Manifest.permission.INTERNET)
private static String getMacAddressByNetworkInterface() {
    try {
        List<NetworkInterface> nis = Collections.list(NetworkInterface.getNetworkInterfaces());
        for (NetworkInterface ni : nis) {
            if (!ni.getName().equalsIgnoreCase("wlan0")) continue;
            byte[] macBytes = ni.getHardwareAddress();
            if (macBytes != null && macBytes.length > 0) {
                StringBuilder res1 = new StringBuilder();
                for (byte b : macBytes) {
                    res1.append(String.format("%02x:", b));
                }
                return res1.deleteCharAt(res1.length() - 1).toString();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "02:00:00:00:00:00";
}
 
開發者ID:senierr,項目名稱:ModuleFrame,代碼行數:26,代碼來源:DeviceUtil.java

示例2: getMACAddress

import java.util.Collections; //導入方法依賴的package包/類
/**
 * Returns MAC address of the given interface name.
 *
 * @param interfaceName eth0, wlan0 or NULL=use first interface
 * @return mac address or empty string
 */
public static String getMACAddress(String interfaceName) {
    try {
        List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
        for (NetworkInterface intf : interfaces) {
            if (interfaceName != null) {
                if (!intf.getName().equalsIgnoreCase(interfaceName)) continue;
            }
            byte[] mac = intf.getHardwareAddress();
            if (mac == null) return "";
            StringBuilder buf = new StringBuilder();
            for (byte aMac : mac) buf.append(String.format("%02X:", aMac));
            if (buf.length() > 0) buf.deleteCharAt(buf.length() - 1);
            return buf.toString();
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return "";
}
 
開發者ID:QuixomTech,項目名稱:DeviceInfo,代碼行數:26,代碼來源:Methods.java

示例3: getValue

import java.util.Collections; //導入方法依賴的package包/類
@Override
public Object getValue(HttpServletRequest request) throws Exception {
  Object value = null;
  if (targetType.isContainerType()) {
    Enumeration<String> headerValues = request.getHeaders(paramPath);
    if (headerValues == null) {
      return null;
    }

    value = Collections.list(headerValues);
  } else {
    value = request.getHeader(paramPath);
  }

  return convertValue(value, targetType);
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:17,代碼來源:HeaderProcessorCreator.java

示例4: getSiteLocalAddresses

import java.util.Collections; //導入方法依賴的package包/類
/** Returns all site-local scope (private) addresses for interfaces that are up. */
static InetAddress[] getSiteLocalAddresses() throws SocketException {
    List<InetAddress> list = new ArrayList<>();
    for (NetworkInterface intf : getInterfaces()) {
        if (intf.isUp()) {
            for (InetAddress address : Collections.list(intf.getInetAddresses())) {
                if (address.isSiteLocalAddress()) {
                    list.add(address);
                }
            }
        }
    }
    if (list.isEmpty()) {
        throw new IllegalArgumentException("No up-and-running site-local (private) addresses found, got " + getInterfaces());
    }
    return list.toArray(new InetAddress[list.size()]);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:18,代碼來源:NetworkUtils.java

示例5: findResources

import java.util.Collections; //導入方法依賴的package包/類
@Override
public Enumeration<URL> findResources(String name) throws IOException {
    try {
        Enumeration<URL> us = super.findResources(name);
        if (LOG.isLoggable(Level.FINER)) {
            // Make a copy so it can be logged:
            List<URL> resources = Collections.list(us);
            us = Collections.enumeration(resources);
            LOG.finer("APURLCL.fRs: " + name + " -> " + resources + " [" + this + "]");
        }
        return us;
    } catch (IOException e) {
        LOG.log(Level.FINE, null, e);
        throw e;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:AntBridge.java

示例6: getAddresses

import java.util.Collections; //導入方法依賴的package包/類
/**
 * Returns a list of all the addresses on the system.
 * @param  inclLoopback
 *         if {@code true}, include the loopback addresses
 * @param  ipv4Only
 *         it {@code true}, only IPv4 addresses will be included
 */
static List<InetAddress> getAddresses(boolean inclLoopback,
                                      boolean ipv4Only)
    throws SocketException {
    ArrayList<InetAddress> list = new ArrayList<InetAddress>();
    Enumeration<NetworkInterface> nets =
             NetworkInterface.getNetworkInterfaces();
    for (NetworkInterface netInf : Collections.list(nets)) {
        Enumeration<InetAddress> addrs = netInf.getInetAddresses();
        for (InetAddress addr : Collections.list(addrs)) {
            if (!list.contains(addr) &&
                    (inclLoopback ? true : !addr.isLoopbackAddress()) &&
                    (ipv4Only ? (addr instanceof Inet4Address) : true)) {
                list.add(addr);
            }
        }
    }

    return list;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:Util.java

示例7: getMacAddressByNetworkInterface

import java.util.Collections; //導入方法依賴的package包/類
/**
 * 獲取設備MAC地址
 * <p>需添加權限 {@code <uses-permission android:name="android.permission.INTERNET"/>}</p>
 *
 * @return MAC地址
 */
private static String getMacAddressByNetworkInterface() {
    try {
        List<NetworkInterface> nis = Collections.list(NetworkInterface.getNetworkInterfaces());
        for (NetworkInterface ni : nis) {
            if (!ni.getName().equalsIgnoreCase("wlan0")) continue;
            byte[] macBytes = ni.getHardwareAddress();
            if (macBytes != null && macBytes.length > 0) {
                StringBuilder res1 = new StringBuilder();
                for (byte b : macBytes) {
                    res1.append(String.format("%02x:", b));
                }
                return res1.deleteCharAt(res1.length() - 1).toString();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "02:00:00:00:00:00";
}
 
開發者ID:jiangkang,項目名稱:KTools,代碼行數:26,代碼來源:NetworkUtils.java

示例8: scanJar

import java.util.Collections; //導入方法依賴的package包/類
List<InFile> scanJar(JarFile jf) throws IOException {
    // Collect jar entries, preserving order.
    List<InFile> inFiles = new ArrayList<>();
    try {
        for (JarEntry je : Collections.list(jf.entries())) {
            InFile inFile = new InFile(jf, je);
            assert(je.isDirectory() == inFile.name.endsWith("/"));
            inFiles.add(inFile);
        }
    } catch (IllegalStateException ise) {
        throw new IOException(ise.getLocalizedMessage(), ise);
    }
    return inFiles;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:PackerImpl.java

示例9: testJarRewriting

import java.util.Collections; //導入方法依賴的package包/類
public void testJarRewriting() throws Exception {
    MockableJarGenerator generator = new MockableJarGenerator(true);
    
    File inputJar = new File(TestUtils.getRoot("testing"), "non-mockable.jar");
    File outputJar = new File(Files.createTempDir(), "mockable.jar");

    generator.createMockableJar(inputJar, outputJar);

    assertTrue(outputJar.exists());
    
    Set<String> expectedEntries = ImmutableSet.of(
            "META-INF/",
            "META-INF/MANIFEST.MF",
            "NonFinalClass.class",
            "FinalClass.class");
    
    Set<String> actualEntries = Sets.newHashSet();
    JarFile jarFile = new JarFile(outputJar);
    for (JarEntry entry : Collections.list(jarFile.entries())) {
        actualEntries.add(entry.getName());
    }
    
    assertEquals(expectedEntries, actualEntries);
    // TODO: Verify bytecode?
    
    jarFile.close();
}
 
開發者ID:codezjx,項目名稱:MockableJarGenerator,代碼行數:28,代碼來源:MockableJarGeneratorTest.java

示例10: findNestedClassIds

import java.util.Collections; //導入方法依賴的package包/類
private void findNestedClassIds(Object o, Collection<String> ids) {
	o = getDataElementValue(o);
	if (o instanceof Enumeration<?>) {
		for (Object o1 : Collections.list((Enumeration<?>) o))
			findNestedClassIds(o1, ids);
	} else if (o instanceof UUID) {
		ids.add(o.toString());
	}
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:10,代碼來源:InvitationListener.java

示例11: getHeaderValue

import java.util.Collections; //導入方法依賴的package包/類
private static Object getHeaderValue(HttpServletRequest request, String name) {
    List<String> value = Collections.list(request.getHeaders(name));
    if (value.size() == 1) {
        return value.get(0);
    }
    if (value.isEmpty()) {
        return "";
    }
    return value;
}
 
開發者ID:xm-online,項目名稱:xm-commons,代碼行數:11,代碼來源:TimelineEventProducer.java

示例12: getZipFileEntryNames

import java.util.Collections; //導入方法依賴的package包/類
static ArrayList<String> getZipFileEntryNames(ZipFile z) {
    ArrayList<String> out = new ArrayList<String>();
    for (ZipEntry ze : Collections.list(z.entries())) {
        out.add(ze.getName());
    }
    return out;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:Utils.java

示例13: getTestSetBy

import java.util.Collections; //導入方法依賴的package包/類
public TestSetNode getTestSetBy(TestSet testSet) {
    for (TestSetNode testSetNode : Collections.list(children())) {
        if (testSetNode.getTestSet().equals(testSet)) {
            return testSetNode;
        }
    }
    return null;
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:9,代碼來源:ReleaseNode.java

示例14: getIpAddress

import java.util.Collections; //導入方法依賴的package包/類
@Nullable
private static String getIpAddress(boolean useIPv4) {
    try {
        List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
        for (NetworkInterface networkInterface : interfaces) {
            List<InetAddress> addresses = Collections.list(networkInterface.getInetAddresses());
            for (InetAddress address : addresses) {
                if (!address.isLoopbackAddress()) {
                    String resultAddress = address.getHostAddress().toUpperCase();
                    boolean isIPv4 = isIPv4Address(resultAddress);
                    if (useIPv4) {
                        if (isIPv4) {
                            return resultAddress;
                        }
                    } else {
                        if (!isIPv4) {
                            int delimiter = resultAddress.indexOf('%');
                            return delimiter < 0 ? resultAddress : resultAddress.substring(0, delimiter);
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:bartwell,項目名稱:ultra-debugger,代碼行數:29,代碼來源:IpUtils.java

示例15: getPropertiesAsMap

import java.util.Collections; //導入方法依賴的package包/類
public Map<String, String> getPropertiesAsMap ()
{
    final Map<String, String> r = new HashMap<String, String> ();
    for ( final Object key : Collections.list ( this.controller.getProperties ().propertyNames () ) )
    {
        r.put ( (String)key, this.controller.getProperties ().getProperty ( (String)key ) );
    }
    return r;
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:10,代碼來源:SymbolContext.java


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