List of usage examples for java.util Set toArray
<T> T[] toArray(T[] a);
From source file:msi.gaml.types.GamaType.java
public static IType<?> findCommonType(final IExpression[] elements, final int kind) { final IType<?> result = Types.NO_TYPE; if (elements.length == 0) { return result; }//from w ww. ja v a2s. c o m final Set<IType<?>> types = new TLinkedHashSet<>(); for (final IExpression e : elements) { // TODO Indicates a previous error in compiling expressions. Maybe // we should cut this // part if (e == null) { continue; } final IType<?> eType = e.getGamlType(); types.add(kind == TYPE ? eType : kind == CONTENT ? eType.getContentType() : eType.getKeyType()); } final IType<?>[] array = types.toArray(new IType[types.size()]); return findCommonType(array); }
From source file:com.microsoft.tfs.client.eclipse.ui.actions.ActionHelpers.java
/** * Gets the {@link TFSRepository}s contained in the selection, if any are * connected./*from ww w . ja v a 2 s. c o m*/ * * @param selection * The selected {@link IResource}s (not <code>null/code>) * @return An array of {@link TFSRepository}s containing the selection * (never <code>null</code>) */ public static TFSRepository[] getRepositoriesFromSelection(final ISelection selection) { Check.notNull(selection, "selection"); //$NON-NLS-1$ if (!(selection instanceof IStructuredSelection)) { return new TFSRepository[0]; } final Set<TFSRepository> repositorySet = new HashSet<TFSRepository>(); @SuppressWarnings("rawtypes") final Iterator i; for (i = ((IStructuredSelection) selection).iterator(); i.hasNext();) { final IResource resource = (IResource) i.next(); final IProject project = resource.getProject(); if (project != null) { final TFSRepository repository = TFSEclipseClientPlugin.getDefault().getProjectManager() .getRepository(project); if (repository != null) { repositorySet.add(repository); } } } return repositorySet.toArray(new TFSRepository[repositorySet.size()]); }
From source file:ClassFinder.java
private static String[] addJarsInPath(String[] paths) { Set<String> fullList = new HashSet<String>(); for (final String path : paths) { fullList.add(path); // Keep the unexpanded path // TODO - allow directories to end with .jar by removing this check? if (!path.endsWith(DOT_JAR)) { File dir = new File(path); if (dir.exists() && dir.isDirectory()) { String[] jars = dir.list(new FilenameFilter() { public boolean accept(File f, String name) { return name.endsWith(DOT_JAR); }/*from w w w.j a v a2 s. co m*/ }); fullList.addAll(Arrays.asList(jars)); } } } return fullList.toArray(new String[0]); }
From source file:edu.umass.cs.utils.Util.java
/** * // w w w.ja v a2 s . c o m * @param dir * @param match * @return Files (recursively) within {@code dir} matching any of the match * patterns in {@code match}. */ public static File[] getMatchingFiles(String dir, String... match) { File dirFile = new File(dir); Set<File> matchFiles = new HashSet<File>(); for (String m : match) if (dirFile.getPath().toString().startsWith(m.replaceAll("/$", ""))) matchFiles.add(dirFile); if (dirFile.isDirectory()) { // check constituent files in directory for (File f : dirFile.listFiles()) matchFiles.addAll(Arrays.asList(getMatchingFiles(f.getPath(), match))); } return matchFiles.toArray(new File[0]); }
From source file:com.laidians.utils.ClassUtils.java
/** * ?<br/>/* ww w.j a va 2 s . co m*/ * Return all interfaces that the given class implements as array, * including ones implemented by superclasses. * <p>If the class itself is an interface, it gets returned as sole interface. * @param clazz the class to analyze for interfaces * @param classLoader the ClassLoader that the interfaces need to be visible in * (may be <code>null</code> when accepting all declared interfaces) * @return all interfaces that the given object implements as array */ public static Class<?>[] getAllInterfacesForClass(Class<?> clazz, ClassLoader classLoader) { Set<Class> ifcs = getAllInterfacesForClassAsSet(clazz, classLoader); return ifcs.toArray(new Class[ifcs.size()]); }
From source file:gr.interamerican.bo2.utils.JavaBeanUtils.java
/** * Copies all common properties of an object to another excluding some properties. * /*from w w w. ja v a 2s . c o m*/ * @see #copyProperties(Object, Object, String[]) * * @param source * Object who's properties will be copied to the target object. * @param target * Object to which the properties will be copied. * @param excluded * List of properties to exclude. */ public static void copyPropertiesExcluding(Object source, Object target, String[] excluded) { if (excluded == null || excluded.length == 0) { copyProperties(source, target, null); return; } PropertyDescriptor[] sourceProperties = JavaBeanUtils.getBeansProperties(source.getClass()); Set<String> properties = new HashSet<String>(); for (PropertyDescriptor pd : sourceProperties) { String property = pd.getName(); if (StringUtils.arrayContainsString(excluded, property) == -1) { properties.add(property); } } if (properties.size() == 0) { return; } copyProperties(source, target, properties.toArray(new String[] {})); }
From source file:h2o.common.spring.util.ClassUtils.java
/** * Return all interfaces that the given class implements as array, * including ones implemented by superclasses. * <p>If the class itself is an interface, it gets returned as sole interface. * @param clazz the class to analyze for interfaces * @param classLoader the ClassLoader that the interfaces need to be visible in * (may be <code>null</code> when accepting all declared interfaces) * @return all interfaces that the given object implements as array *//*from w w w. j a v a2s . co m*/ @SuppressWarnings("rawtypes") public static Class<?>[] getAllInterfacesForClass(Class<?> clazz, ClassLoader classLoader) { Set<Class> ifcs = getAllInterfacesForClassAsSet(clazz, classLoader); return ifcs.toArray(new Class[ifcs.size()]); }
From source file:io.wcm.testing.mock.jcr.MockNamespaceRegistry.java
@Override public String[] getPrefixes() throws RepositoryException { Set<String> keys = this.namespacePrefixMapping.keySet(); return keys.toArray(new String[keys.size()]); }
From source file:io.wcm.testing.mock.jcr.MockNamespaceRegistry.java
@Override public String[] getURIs() throws RepositoryException { Set<String> values = this.namespacePrefixMapping.values(); return values.toArray(new String[values.size()]); }
From source file:de.saly.elasticsearch.support.IndexableMailMessage.java
public static IndexableMailMessage fromJavaMailMessage(final Message jmm, final boolean withTextContent, final boolean withAttachments, final boolean stripTags, List<String> headersToFields) throws MessagingException, IOException { final IndexableMailMessage im = new IndexableMailMessage(); @SuppressWarnings("unchecked") final Enumeration<Header> allHeaders = jmm.getAllHeaders(); final Set<IndexableHeader> headerList = new HashSet<IndexableHeader>(); while (allHeaders.hasMoreElements()) { final Header h = allHeaders.nextElement(); headerList.add(new IndexableHeader(h.getName(), h.getValue())); }/*from w w w . ja va2 s . co m*/ im.setHeaders(headerList.toArray(new IndexableHeader[headerList.size()])); im.setSelectedHeaders(extractHeaders(im.getHeaders(), headersToFields)); if (jmm.getFolder() instanceof POP3Folder) { im.setPopId(((POP3Folder) jmm.getFolder()).getUID(jmm)); im.setMailboxType("POP"); } else { im.setMailboxType("IMAP"); } if (jmm.getFolder() instanceof UIDFolder) { im.setUid(((UIDFolder) jmm.getFolder()).getUID(jmm)); } im.setFolderFullName(jmm.getFolder().getFullName()); im.setFolderUri(jmm.getFolder().getURLName().toString()); im.setContentType(jmm.getContentType()); im.setSubject(jmm.getSubject()); im.setSize(jmm.getSize()); im.setSentDate(jmm.getSentDate()); if (jmm.getReceivedDate() != null) { im.setReceivedDate(jmm.getReceivedDate()); } if (jmm.getFrom() != null && jmm.getFrom().length > 0) { im.setFrom(Address.fromJavaMailAddress(jmm.getFrom()[0])); } if (jmm.getRecipients(RecipientType.TO) != null) { im.setTo(Address.fromJavaMailAddress(jmm.getRecipients(RecipientType.TO))); } if (jmm.getRecipients(RecipientType.CC) != null) { im.setCc(Address.fromJavaMailAddress(jmm.getRecipients(RecipientType.CC))); } if (jmm.getRecipients(RecipientType.BCC) != null) { im.setBcc(Address.fromJavaMailAddress(jmm.getRecipients(RecipientType.BCC))); } if (withTextContent) { // try { String textContent = getText(jmm, 0); if (stripTags) { textContent = stripTags(textContent); } im.setTextContent(textContent); // } catch (final Exception e) { // logger.error("Unable to retrieve text content for message {} due to {}", // e, ((MimeMessage) jmm).getMessageID(), e); // } } if (withAttachments) { try { final Object content = jmm.getContent(); // look for attachments if (jmm.isMimeType("multipart/*") && content instanceof Multipart) { List<ESAttachment> attachments = new ArrayList<ESAttachment>(); final Multipart multipart = (Multipart) content; for (int i = 0; i < multipart.getCount(); i++) { final BodyPart bodyPart = multipart.getBodyPart(i); if (!Part.ATTACHMENT.equalsIgnoreCase(bodyPart.getDisposition()) && !StringUtils.isNotBlank(bodyPart.getFileName())) { continue; // dealing with attachments only } final InputStream is = bodyPart.getInputStream(); final byte[] bytes = IOUtils.toByteArray(is); IOUtils.closeQuietly(is); attachments.add(new ESAttachment(bodyPart.getContentType(), bytes, bodyPart.getFileName())); } if (!attachments.isEmpty()) { im.setAttachments(attachments.toArray(new ESAttachment[attachments.size()])); im.setAttachmentCount(im.getAttachments().length); attachments.clear(); attachments = null; } } } catch (final Exception e) { logger.error( "Error indexing attachments (message will be indexed but without attachments) due to {}", e, e.toString()); } } im.setFlags(IMAPUtils.toStringArray(jmm.getFlags())); im.setFlaghashcode(jmm.getFlags().hashCode()); return im; }