Search in sources :

Example 36 with LinkedHashSet

use of java.util.LinkedHashSet in project grails-core by grails.

the class PathMatchingResourcePatternResolver method doFindPathMatchingJarResources.

/**
     * Find all resources in jar files that match the given location pattern
     * via the Ant-style PathMatcher.
     * @param rootDirResource the root directory as Resource
     * @param subPattern the sub pattern to match (below the root directory)
     * @return the Set of matching Resource instances
     * @throws IOException in case of I/O errors
     * @see java.net.JarURLConnection
     */
protected Set<Resource> doFindPathMatchingJarResources(Resource rootDirResource, String subPattern) throws IOException {
    URLConnection con = rootDirResource.getURL().openConnection();
    JarFile jarFile;
    String jarFileUrl;
    String rootEntryPath;
    boolean newJarFile = false;
    if (con instanceof JarURLConnection) {
        // Should usually be the case for traditional JAR files.
        JarURLConnection jarCon = (JarURLConnection) con;
        GrailsResourceUtils.useCachesIfNecessary(jarCon);
        jarFile = jarCon.getJarFile();
        jarFileUrl = jarCon.getJarFileURL().toExternalForm();
        JarEntry jarEntry = jarCon.getJarEntry();
        rootEntryPath = (jarEntry != null ? jarEntry.getName() : "");
    } else {
        // No JarURLConnection -> need to resort to URL file parsing.
        // We'll assume URLs of the format "jar:path!/entry", with the protocol
        // being arbitrary as long as following the entry format.
        // We'll also handle paths with and without leading "file:" prefix.
        String urlFile = rootDirResource.getURL().getFile();
        int separatorIndex = urlFile.indexOf(GrailsResourceUtils.JAR_URL_SEPARATOR);
        if (separatorIndex != -1) {
            jarFileUrl = urlFile.substring(0, separatorIndex);
            rootEntryPath = urlFile.substring(separatorIndex + GrailsResourceUtils.JAR_URL_SEPARATOR.length());
            jarFile = getJarFile(jarFileUrl);
        } else {
            jarFile = new JarFile(urlFile);
            jarFileUrl = urlFile;
            rootEntryPath = "";
        }
        newJarFile = true;
    }
    try {
        if (!"".equals(rootEntryPath) && !rootEntryPath.endsWith("/")) {
            // Root entry path must end with slash to allow for proper matching.
            // The Sun JRE does not return a slash here, but BEA JRockit does.
            rootEntryPath = rootEntryPath + "/";
        }
        Set<Resource> result = new LinkedHashSet<Resource>(8);
        for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements(); ) {
            JarEntry entry = entries.nextElement();
            String entryPath = entry.getName();
            if (entryPath.startsWith(rootEntryPath)) {
                String relativePath = entryPath.substring(rootEntryPath.length());
                if (getPathMatcher().match(subPattern, relativePath)) {
                    result.add(rootDirResource.createRelative(relativePath));
                }
            }
        }
        return result;
    } finally {
        // not from JarURLConnection, which might cache the file reference.
        if (newJarFile) {
            jarFile.close();
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) JarURLConnection(java.net.JarURLConnection) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) URLConnection(java.net.URLConnection) JarURLConnection(java.net.JarURLConnection)

Example 37 with LinkedHashSet

use of java.util.LinkedHashSet in project groovy-core by groovy.

the class SourceExtensionHandler method getRegisteredExtensions.

public static Set<String> getRegisteredExtensions(ClassLoader loader) {
    Set<String> extensions = new LinkedHashSet<String>();
    extensions.add("groovy");
    try {
        Enumeration<URL> globalServices = loader.getResources("META-INF/services/org.codehaus.groovy.source.Extensions");
        while (globalServices.hasMoreElements()) {
            BufferedReader svcIn = null;
            URL service = globalServices.nextElement();
            try {
                svcIn = new BufferedReader(new InputStreamReader(service.openStream()));
                String extension = svcIn.readLine();
                while (extension != null) {
                    extension = extension.trim();
                    if (!extension.startsWith("#") && extension.length() > 0) {
                        extensions.add(extension);
                    }
                    extension = svcIn.readLine();
                }
            } catch (IOException ex) {
                throw new GroovyRuntimeException("IO Exception attempting to load registered source extension " + service.toExternalForm() + ". Exception: " + ex.toString());
            } finally {
                if (svcIn != null)
                    svcIn.close();
            }
        }
    } catch (IOException ex) {
        throw new GroovyRuntimeException("IO Exception getting registered source extensions. Exception: " + ex.toString());
    }
    return extensions;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) GroovyRuntimeException(groovy.lang.GroovyRuntimeException) IOException(java.io.IOException) URL(java.net.URL)

Example 38 with LinkedHashSet

use of java.util.LinkedHashSet in project groovy-core by groovy.

the class TraitComposer method createSuperForwarder.

/**
     * Creates, if necessary, a super forwarder method, for stackable traits.
     * @param forwarder a forwarder method
     * @param genericsSpec
     */
private static void createSuperForwarder(ClassNode targetNode, MethodNode forwarder, final Map<String, ClassNode> genericsSpec) {
    List<ClassNode> interfaces = new ArrayList<ClassNode>(Traits.collectAllInterfacesReverseOrder(targetNode, new LinkedHashSet<ClassNode>()));
    String name = forwarder.getName();
    Parameter[] forwarderParameters = forwarder.getParameters();
    LinkedHashSet<ClassNode> traits = new LinkedHashSet<ClassNode>();
    List<MethodNode> superForwarders = new LinkedList<MethodNode>();
    for (ClassNode node : interfaces) {
        if (Traits.isTrait(node)) {
            MethodNode method = node.getDeclaredMethod(name, forwarderParameters);
            if (method != null) {
                // a similar method exists, we need a super bridge
                // trait$super$foo(Class currentTrait, ...)
                traits.add(node);
                superForwarders.add(method);
            }
        }
    }
    for (MethodNode superForwarder : superForwarders) {
        doCreateSuperForwarder(targetNode, superForwarder, traits.toArray(new ClassNode[traits.size()]), genericsSpec);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ClassNode(org.codehaus.groovy.ast.ClassNode) MethodNode(org.codehaus.groovy.ast.MethodNode) ArrayList(java.util.ArrayList) Parameter(org.codehaus.groovy.ast.Parameter) LinkedList(java.util.LinkedList)

Example 39 with LinkedHashSet

use of java.util.LinkedHashSet in project hazelcast by hazelcast.

the class ClusterServiceImpl method sendMembershipEvents.

private void sendMembershipEvents(Collection<MemberImpl> currentMembers, Collection<MemberImpl> newMembers) {
    Set<Member> eventMembers = new LinkedHashSet<Member>(currentMembers);
    if (!newMembers.isEmpty()) {
        if (newMembers.size() == 1) {
            MemberImpl newMember = newMembers.iterator().next();
            // sync call
            node.getPartitionService().memberAdded(newMember);
            // async events
            eventMembers.add(newMember);
            sendMembershipEventNotifications(newMember, unmodifiableSet(eventMembers), true);
        } else {
            for (MemberImpl newMember : newMembers) {
                // sync call
                node.getPartitionService().memberAdded(newMember);
                // async events
                eventMembers.add(newMember);
                sendMembershipEventNotifications(newMember, unmodifiableSet(new LinkedHashSet<Member>(eventMembers)), true);
            }
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MemberImpl(com.hazelcast.instance.MemberImpl) Member(com.hazelcast.core.Member)

Example 40 with LinkedHashSet

use of java.util.LinkedHashSet in project hazelcast by hazelcast.

the class ClusterServiceImpl method shrinkMembersRemovedWhileClusterIsNotActiveState.

public void shrinkMembersRemovedWhileClusterIsNotActiveState(Collection<String> memberUuidsToRemove) {
    lock.lock();
    try {
        Set<MemberImpl> membersRemovedInNotActiveState = new LinkedHashSet<MemberImpl>(membersRemovedInNotActiveStateRef.get().getMembers());
        Iterator<MemberImpl> it = membersRemovedInNotActiveState.iterator();
        while (it.hasNext()) {
            MemberImpl member = it.next();
            if (memberUuidsToRemove.contains(member.getUuid())) {
                logger.fine("Removing " + member + " from members removed while in cluster not active state");
                it.remove();
            }
        }
        membersRemovedInNotActiveStateRef.set(MemberMap.createNew(membersRemovedInNotActiveState.toArray(new MemberImpl[0])));
    } finally {
        lock.unlock();
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MemberImpl(com.hazelcast.instance.MemberImpl)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)1511 ArrayList (java.util.ArrayList)292 Set (java.util.Set)194 HashSet (java.util.HashSet)163 HashMap (java.util.HashMap)142 File (java.io.File)128 Map (java.util.Map)125 LinkedHashMap (java.util.LinkedHashMap)110 IOException (java.io.IOException)108 List (java.util.List)104 Test (org.junit.Test)103 ProcessResult (org.asqatasun.entity.audit.ProcessResult)77 SourceCodeRemark (org.asqatasun.entity.audit.SourceCodeRemark)73 LinkedList (java.util.LinkedList)63 URL (java.net.URL)43 Collection (java.util.Collection)41 DataCell (org.knime.core.data.DataCell)39 DataColumnSpec (org.knime.core.data.DataColumnSpec)39 Iterator (java.util.Iterator)38 TreeSet (java.util.TreeSet)35