本文整理匯總了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";
}
示例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 "";
}
示例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);
}
示例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()]);
}
示例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;
}
}
示例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;
}
示例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";
}
示例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;
}
示例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();
}
示例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());
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}