private static String join(Enumeration<String> aliases) { return JOINER.join(Iterators.forEnumeration(aliases)); }
@Override public Iterator<?> apply(final Attribute groupNameAttribute) { try { final NamingEnumeration<?> enumeration = groupNameAttribute.getAll(); return Iterators.forEnumeration(enumeration); } catch (final NamingException namingException) { log.warn("Unable to read group name(s)", namingException); return null; } } });
@Override public Enumeration<URL> getResources(final String name) throws IOException { final List<URL> urls = new ArrayList<>(); Iterators.addAll(urls, Iterators.forEnumeration(super.getResources(name))); Iterators.addAll(urls, Iterators.forEnumeration(druidLoader.getResources(name))); return Iterators.asEnumeration(urls.iterator()); } }
@Override public Enumeration<URL> getResources(String name) throws IOException { return Iterators.asEnumeration(Iterators.concat(// Iterators.forEnumeration(findResources(name)), // Iterators.forEnumeration(m_parentLoader.getResources(name)))); }
private List<String> toList(Enumeration<String> enumeration) { return Lists.newArrayList(Iterators.forEnumeration(enumeration)); } }
@Override public Enumeration<URL> getResources(String name) throws IOException { List<Iterator<URL>> resources = new ArrayList<>(); boolean parentFirst = isParentFirstPath(name); if (!parentFirst) { Iterator<URL> childResources = Iterators.forEnumeration(findResources(name)); resources.add(childResources); } Iterator<URL> parentResources = Iterators.forEnumeration(getParent().getResources(name)); resources.add(parentResources); if (parentFirst) { Iterator<URL> childResources = Iterators.forEnumeration(findResources(name)); resources.add(childResources); } return Iterators.asEnumeration(Iterators.concat(resources.iterator())); }
private Collection<String> extractGroupNamesFromSearchResult(final SearchResult searchResult) { // Get all attributes for that group final Iterator<? extends Attribute> attributesIterator = Iterators.forEnumeration(searchResult.getAttributes().getAll()); // Find the attribute representing the group name final Iterator<? extends Attribute> groupNameAttributesIterator = Iterators.filter(attributesIterator, new Predicate<Attribute>() { @Override public boolean apply(final Attribute attribute) { return groupNameId.equalsIgnoreCase(attribute.getID()); } }); // Extract the group name from the attribute // Note: at this point, groupNameAttributesIterator should really contain a single element final Iterator<Iterator<?>> groupNamesIterator = Iterators.transform(groupNameAttributesIterator, new Function<Attribute, Iterator<?>>() { @Override public Iterator<?> apply(final Attribute groupNameAttribute) { try { final NamingEnumeration<?> enumeration = groupNameAttribute.getAll(); return Iterators.forEnumeration(enumeration); } catch (final NamingException namingException) { log.warn("Unable to read group name(s)", namingException); return null; } } }); final Iterator<?> finalGroupNamesIterator = Iterators.filter(Iterators.concat(groupNamesIterator), Predicates.notNull()); return ImmutableList.<String>copyOf(Iterators.transform(finalGroupNamesIterator, Functions.toStringFunction())); }
public void testForEnumerationEmpty() { Enumeration<Integer> enumer = enumerate(); Iterator<Integer> iter = Iterators.forEnumeration(enumer); assertFalse(iter.hasNext()); try { iter.next(); fail(); } catch (NoSuchElementException expected) { } }
public void testForEnumerationTypical() { Enumeration<Integer> enumer = enumerate(1, 2, 3); Iterator<Integer> iter = Iterators.forEnumeration(enumer); assertTrue(iter.hasNext()); assertEquals(1, (int) iter.next()); assertTrue(iter.hasNext()); assertEquals(2, (int) iter.next()); assertTrue(iter.hasNext()); assertEquals(3, (int) iter.next()); assertFalse(iter.hasNext()); }
public void testForEnumerationSingleton() { Enumeration<Integer> enumer = enumerate(1); Iterator<Integer> iter = Iterators.forEnumeration(enumer); assertTrue(iter.hasNext()); assertTrue(iter.hasNext()); assertEquals(1, (int) iter.next()); try { iter.remove(); fail(); } catch (UnsupportedOperationException expected) { } assertFalse(iter.hasNext()); try { iter.next(); fail(); } catch (NoSuchElementException expected) { } }
@Test public void zip_directory() throws IOException { File foo = FileUtils.toFile(getClass().getResource("/org/sonar/api/utils/ZipUtilsTest/shouldZipDirectory/foo.txt")); File dir = foo.getParentFile(); File zip = temp.newFile(); ZipUtils.zipDir(dir, zip); assertThat(zip).exists().isFile(); assertThat(zip.length()).isGreaterThan(1L); Iterator<? extends ZipEntry> zipEntries = Iterators.forEnumeration(new ZipFile(zip).entries()); assertThat(zipEntries).hasSize(4); File unzipDir = temp.newFolder(); ZipUtils.unzip(zip, unzipDir); assertThat(new File(unzipDir, "bar.txt")).exists().isFile(); assertThat(new File(unzipDir, "foo.txt")).exists().isFile(); assertThat(new File(unzipDir, "dir1/hello.properties")).exists().isFile(); }
private static ImmutableList<URL> getResources(String resourceName) throws IOException { ClassLoader loader = PluginCache.class.getClassLoader(); if (loader == null) { return ImmutableList .copyOf(Iterators.forEnumeration(ClassLoader.getSystemResources(resourceName))); } else { return ImmutableList .copyOf(Iterators.forEnumeration(loader.getResources(resourceName))); } }
@Override public Enumeration<URL> getResources(String name) throws IOException { List<Iterator<URL>> resources = new ArrayList<>(); // If this is not a parent first resource, add resources from local urls first if (!isParentFirstResource(name)) { Iterator<URL> myResources = Iterators.forEnumeration(findResources(name)); resources.add(myResources); } // Add parent resources // if (!isHiddenResource(name)) { // Iterator<URL> parentResources = Iterators.forEnumeration(getParent().getResources(name)); // resources.add(parentResources); // } // If this is a parent first resource, now add resources from local urls if (isParentFirstResource(name)) { Iterator<URL> myResources = Iterators.forEnumeration(findResources(name)); resources.add(myResources); } return Iterators.asEnumeration(Iterators.concat(resources.iterator())); }
@Override public Iterator<T> iterator() { return Iterators.forEnumeration(e); } };
@Override public Iterator<InetAddress> apply(NetworkInterface netIface) { return Iterators.forEnumeration(netIface.getInetAddresses()); } })));
@Override public boolean apply(NetworkInterface input) { return Iterators.tryFind( Iterators.forEnumeration(input.getInetAddresses()), filter).isPresent(); }}).isPresent(); }
@Override @SuppressWarnings("unchecked") public ImmutableList<Locale> getLocales() { return ImmutableList.copyOf(Iterators.<Locale>forEnumeration(request.getLocales())); } }
/** * Create a new {@link PropertyTree} from the given {@link Dictionary}. * The keys of the properties are handled as full-qualified dot-separated paths. * * @param properties the path / value mapping used to create the property tree * @return a new {@link PropertyTree} instance */ public static PropertyTree from(final Dictionary<String, ?> properties) { return from(Maps.toMap(Iterators.forEnumeration(properties.keys()), key -> (String) properties.get(key))); }
static void loadParameters(final ConfigurationAdmin admin, final AgentConfiguration agentConfig) throws IOException { final Configuration conf = getConfig(admin); if (conf.getProperties() != null) { Iterator<String> keys = Iterators.filter(Iterators.forEnumeration(conf.getProperties().keys()), DefaultAgentParser::isValidParameter); final Map<String, String> params = Maps.toMap(keys, key -> getValue(conf.getProperties(), key, Objects::toString).orElse("")); agentConfig.load(params); } } }
@Override public boolean containsSpringContext() { final JarFile jar = open(); try { final Manifest manifest = getManifest(jar); return hasSpringContext(manifest) || any(forEnumeration(jar.entries()), this::isSpringContext); } finally { closeJarQuietly(jar); } }