Search in sources :

Example 66 with LinkedHashSet

use of java.util.LinkedHashSet in project tdi-studio-se by Talend.

the class CpuProfiler method getProfiledPackages.

/*
     * @see ICpuProfiler#getProfiledPackages()
     */
@Override
public Set<String> getProfiledPackages() throws JvmCoreException {
    if (type == ProfilerType.BCI) {
        validateAgent();
        Set<String> packages = new LinkedHashSet<String>();
        ProfilerState state = getState();
        if (state != ProfilerState.READY && state != ProfilerState.RUNNING) {
            return packages;
        }
        ObjectName objectName = jvm.getMBeanServer().getObjectName(PROFILER_MXBEAN_NAME);
        if (jvm.isConnected()) {
            for (String item : (String[]) jvm.getMBeanServer().getAttribute(objectName, PROFILED_PACKAGES)) {
                if (!item.isEmpty()) {
                    packages.add(item);
                }
            }
        }
        return packages;
    }
    return profiledPackages;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ObjectName(javax.management.ObjectName)

Example 67 with LinkedHashSet

use of java.util.LinkedHashSet in project tdi-studio-se by Talend.

the class TalendEditorPaletteFactory method getRelatedComponentNamesFromHelp.

protected static Set<String> getRelatedComponentNamesFromHelp(final String keyword) {
    if (keyword == null || keyword.isEmpty()) {
        return null;
    }
    // This method will cost lots of time to complete when it is called the first time
    final List<SearchHit> querySearchResult = new ArrayList<SearchHit>();
    if (searchInHelpJob != null && searchInHelpJob.getState() != Job.NONE) {
        searchInHelpJob.cancel();
    }
    searchInHelpJob = new Job(SEARCHING_FROM_HELP) {

        @SuppressWarnings("restriction")
        @Override
        protected IStatus run(IProgressMonitor monitor) {
            String helpKeyword = keyword;
            try {
                TalendPaletteSearchIndex searchIndex = TalendPaletteSearchIndex.getInstance();
                LocalSearchManager localSearchManager = BaseHelpSystem.getLocalSearchManager();
                // if not work or null, maybe should throw a warn to inform user and help us trace
                // if (searchIndex != null && localSearchManager != null) {
                localSearchManager.ensureIndexUpdated(monitor, searchIndex);
                //$NON-NLS-1$
                final String WHITESPACE = " ";
                //$NON-NLS-1$//$NON-NLS-2$
                helpKeyword = helpKeyword + WHITESPACE + "OR" + WHITESPACE + helpKeyword + "*";
                ISearchQuery searchQuery = new SearchQuery(helpKeyword, false, new ArrayList<String>(), Platform.getNL());
                searchIndex.search(searchQuery, new ISearchHitCollector() {

                    @Override
                    public void addQTCException(QueryTooComplexException exception) throws QueryTooComplexException {
                    // nothing need to do
                    }

                    @Override
                    public void addHits(List<SearchHit> hits, String wordsSearched) {
                        querySearchResult.addAll(hits);
                    }
                });
            // }
            } catch (Throwable e) {
                CommonExceptionHandler.process(e, Priority.WARN);
            }
            return Status.OK_STATUS;
        }

        @Override
        public boolean belongsTo(Object family) {
            return family.equals(FederatedSearchJob.FAMILY);
        }
    };
    try {
        searchInHelpJob.setPriority(Job.INTERACTIVE);
        searchInHelpJob.schedule();
        searchInHelpJob.join();
    } catch (Throwable e) {
        CommonExceptionHandler.process(e, Priority.WARN);
    }
    Set<String> componentNames = new LinkedHashSet<String>();
    // the limitation has been moved to it's caller
    // int limit = PaletteSettingsPreferencePage.getPaletteSearchResultLimitFromHelp();
    // int i = 1;
    Iterator<SearchHit> iter = querySearchResult.iterator();
    while (iter.hasNext()) {
        // if (limit < i) {
        // break;
        // }
        SearchHit result = iter.next();
        String label = result.getLabel();
        if (label == null || label.trim().length() == 0) {
            continue;
        }
        componentNames.add(label);
    // i++;
    }
    return componentNames;
}
Also used : ISearchQuery(org.eclipse.help.internal.search.ISearchQuery) SearchQuery(org.eclipse.help.internal.search.SearchQuery) LinkedHashSet(java.util.LinkedHashSet) IStatus(org.eclipse.core.runtime.IStatus) SearchHit(org.eclipse.help.internal.search.SearchHit) ArrayList(java.util.ArrayList) LocalSearchManager(org.eclipse.help.internal.search.LocalSearchManager) ISearchHitCollector(org.eclipse.help.internal.search.ISearchHitCollector) QueryTooComplexException(org.eclipse.help.internal.search.QueryTooComplexException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) FederatedSearchJob(org.eclipse.help.internal.search.federated.FederatedSearchJob) Job(org.eclipse.core.runtime.jobs.Job) ISearchQuery(org.eclipse.help.internal.search.ISearchQuery)

Example 68 with LinkedHashSet

use of java.util.LinkedHashSet in project ACS by ACS-Community.

the class DOMJavaClassIntrospector method getAccessibleFields.

/*
	public static String[] getChildren(Object node) {
		if (node instanceof Map)
			return getSubnodes(node);
		else if (node instanceof Element)
		{
			// TODO
			return null;
		}
		else
			return getFields(node);
	}
	*/
public static String[] getAccessibleFields(Object node, boolean primitivesOnly) {
    Set<String> subnodes = new LinkedHashSet<String>();
    final Class nodeType = node.getClass();
    Class type = nodeType;
    while (type != null) {
        Field[] fields = type.getDeclaredFields();
        for (Field field : fields) {
            boolean isPrimitive = isPrimitive(field.getType());
            if ((isPrimitive ^ !primitivesOnly) && getAccessorMethod(nodeType, field.getName()) != null) {
                // do not add null non-primitives check
                if (isPrimitive || getChild(field.getName(), node) != null)
                    subnodes.add(field.getName());
            }
        }
        type = type.getSuperclass();
    }
    // and subnodesMap map
    if (!primitivesOnly) {
        Object subnodesMap = getChild(SUBNODES_MAP_NAME, node);
        if (subnodesMap instanceof Map) {
            Set keySet = ((Map) subnodesMap).keySet();
            for (Object key : keySet) subnodes.add(key.toString());
        }
        subnodesMap = getChild(SUBNODES_MAP_NAME_ALTERNATIVE, node);
        if (subnodesMap instanceof Map) {
            Set keySet = ((Map) subnodesMap).keySet();
            for (Object key : keySet) subnodes.add(key.toString());
        }
    }
    return subnodes.toArray(new String[subnodes.size()]);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Field(java.lang.reflect.Field) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Example 69 with LinkedHashSet

use of java.util.LinkedHashSet in project ACS by ACS-Community.

the class DOMJavaClassIntrospector method getSubnodes.

public static String[] getSubnodes(Object node) {
    if (node instanceof alma.TMCDB.maci.ComponentNode)
        return getAccessibleFields(node, false);
    if (node instanceof Map && !(node instanceof InternalElementsMap)) {
        Set<String> subnodes = new LinkedHashSet<String>();
        Set keySet = ((Map) node).keySet();
        for (Object key : keySet) subnodes.add(key.toString());
        return subnodes.toArray(new String[subnodes.size()]);
    } else
        return new String[0];
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Example 70 with LinkedHashSet

use of java.util.LinkedHashSet in project ACS by ACS-Community.

the class DOMJavaClassIntrospector method getNodes.

public static String[] getNodes(Object node, String nodeName, Logger log) {
    if (node instanceof DAOImpl) {
        return getNodes(((DAOImpl) node).getRootNode().getNodesMap());
    } else if (node instanceof XMLTreeNode) {
        return getNodes(((XMLTreeNode) node).getNodesMap());
    } else if (node instanceof Map) {
        Set<String> subnodes = new LinkedHashSet<String>();
        Set keySet = ((Map) node).keySet();
        for (Object key : keySet) subnodes.add(key.toString());
        return subnodes.toArray(new String[subnodes.size()]);
    } else if (node instanceof Element) {
        List<String> list = new ArrayList<String>();
        for (Node childNode = ((Element) node).getFirstChild(); childNode != null; childNode = childNode.getNextSibling()) {
            if (childNode.getNodeType() == Element.ELEMENT_NODE)
                list.add(childNode.getNodeName());
        }
        return list.toArray(new String[list.size()]);
    } else if (node instanceof ExtraDataFeature) {
        String[] extraFields = null;
        Element extraData = ((ExtraDataFeature) node).getExtraData();
        if (extraData != null)
            extraFields = getNodes(extraData);
        String[] fields = getAccessibleFields(node, false);
        if (extraFields == null)
            return fields;
        // concat and remove duplicates
        LinkedHashSet<String> set = new LinkedHashSet<String>(Arrays.asList(fields));
        for (String ef : extraFields) if (!set.add(ef))
            if (log != null)
                log.warning("Duplicate node '" + nodeName + "/" + ef + "'.");
        return set.toArray(new String[0]);
    } else
        return getAccessibleFields(node, false);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) Element(org.w3c.dom.Element) XMLTreeNode(com.cosylab.cdb.jdal.XMLTreeNode) Node(org.w3c.dom.Node) XMLTreeNode(com.cosylab.cdb.jdal.XMLTreeNode) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) DAOImpl(com.cosylab.cdb.jdal.DAOImpl) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)3111 ArrayList (java.util.ArrayList)632 Set (java.util.Set)410 HashSet (java.util.HashSet)334 HashMap (java.util.HashMap)312 Map (java.util.Map)284 List (java.util.List)269 File (java.io.File)266 LinkedHashMap (java.util.LinkedHashMap)257 IOException (java.io.IOException)240 Test (org.junit.Test)239 LinkedList (java.util.LinkedList)139 Collection (java.util.Collection)103 URL (java.net.URL)83 ProcessResult (org.asqatasun.entity.audit.ProcessResult)76 Iterator (java.util.Iterator)73 SourceCodeRemark (org.asqatasun.entity.audit.SourceCodeRemark)73 TreeMap (java.util.TreeMap)70 TreeSet (java.util.TreeSet)70 Collectors (java.util.stream.Collectors)69