List of usage examples for java.util Collection toArray
Object[] toArray();
From source file:Main.java
/** * the intersection of two collections.//from w w w. j a v a 2 s. c o m * * @param c1 * collection1. * @param c2 * collection2. * @return the intersection, i.e. all elements that are in both collections. * @since 0.1 */ public static Collection intersection(final Collection c1, final Collection c2) { final List list = new ArrayList(); final Object[] members_c1 = c1.toArray(); for (int i = 0; i < members_c1.length; i++) { if (c2.contains(members_c1[i])) { list.add(members_c1[i]); } } return list; }
From source file:Main.java
public static String toSqlInString(Collection col) { if (col == null) { return null; }/* ww w. ja v a 2 s .com*/ return toSqlInString(col.toArray()); }
From source file:Main.java
/** * /*from w w w . j av a 2 s . c om*/ * @param collection * @return String */ public static String toString(final Collection<?> collection) { return toString(collection.toArray()); }
From source file:com.qwazr.utils.ArrayUtils.java
public static String prettyPrint(Collection<?> collection) { if (collection == null) return null; return Arrays.toString(collection.toArray()); }
From source file:Main.java
public static <T> T[] toTypedArray(Collection<?> collection, Class<T> type) { @SuppressWarnings("unchecked") T[] array = (T[]) Array.newInstance(type, collection.size()); Object[] data = collection.toArray(); for (int i = 0; i < array.length; i++) { array[i] = type.cast(data[i]);//from w ww. java 2 s .c om } return array; }
From source file:com.movies.jsf.JsfUtil.java
public static Object[] collectionToArray(Collection<?> c) { if (c == null) { return new Object[0]; }/*from ww w . ja va 2 s . com*/ return c.toArray(); }
From source file:Main.java
/** * //from w ww . j a va 2s . com * @param value * @return Object[] */ public static Object[] toArray(final String value) { if (value == null) { return new Object[] {}; } final int BRACKET_LENGTH = 1; final String strippedValue = value.substring(BRACKET_LENGTH, value.length() - BRACKET_LENGTH); final StringTokenizer tokenizer = new StringTokenizer(strippedValue, ELEMENT_SEPARATOR); final Collection<Object> collection = new ArrayList<>(); while (tokenizer.hasMoreTokens()) { collection.add(tokenizer.nextToken().trim()); } return collection.toArray(); }
From source file:net.sf.morph.util.TestUtils.java
public static boolean contains(Collection collection, Object value) { return collection != null && contains(collection.toArray(), value); }
From source file:com.glluch.ecf2xmlmaven.Writer.java
public static void competencesParts2Solr(Collection<Competence> competences, String path) throws IOException { debug(competences.size() + " comptences"); Object[] ca = competences.toArray(); int i = 0;//from w ww . ja v a 2 s.c o m while (i < ca.length) { Competence c = (Competence) ca[i++]; show("Processing " + c.getTitle() + " " + c.getCode() + " " + i); competenceParts2Solr(c, path); } }
From source file:it.cnr.icar.eric.common.security.X509Parser.java
/** * Parses a X509Certificate from a DER formatted input stream. Uses the * BouncyCastle provider if available.// ww w . ja v a 2s . c om * * @param inStream The DER InputStream with the certificate. * @return X509Certificate parsed from stream. * @throws JAXRException in case of IOException or CertificateException * while parsing the stream. */ public static X509Certificate parseX509Certificate(InputStream inStream) throws JAXRException { try { //possible options // - der x509 generated by keytool -export // - der x509 generated by openssh x509 (might require BC provider) // Get the CertificateFactory to parse the stream // if BouncyCastle provider available, use it CertificateFactory cf; try { Class<?> clazz = Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider"); Constructor<?> constructor = clazz.getConstructor(new Class[] {}); Provider bcProvider = (Provider) constructor.newInstance(new Object[] {}); Security.addProvider(bcProvider); cf = CertificateFactory.getInstance("X.509", "BC"); } catch (Exception e) { // log error if bc present but failed to instanciate/add provider if (!(e instanceof ClassNotFoundException)) { log.error(CommonResourceBundle.getInstance() .getString("message.FailedToInstantiateBouncyCastleProvider")); } // fall back to default provider cf = CertificateFactory.getInstance("X.509"); } // Read the stream to a local variable DataInputStream dis = new DataInputStream(inStream); byte[] bytes = new byte[dis.available()]; dis.readFully(bytes); ByteArrayInputStream certStream = new ByteArrayInputStream(bytes); // Parse the cert stream int i = 0; Collection<? extends Certificate> c = cf.generateCertificates(certStream); X509Certificate[] certs = new X509Certificate[c.toArray().length]; for (Iterator<? extends Certificate> it = c.iterator(); it.hasNext();) { certs[i++] = (X509Certificate) it.next(); } // Some logging.. if (log.isDebugEnabled()) { if (c.size() == 1) { log.debug("One certificate, no chain."); } else { log.debug("Certificate chain length: " + c.size()); } log.debug("Subject DN: " + certs[0].getSubjectDN().getName()); log.debug("Issuer DN: " + certs[0].getIssuerDN().getName()); } // Do we need to return the chain? // do we need to verify if cert is self signed / valid? return certs[0]; } catch (CertificateException e) { String msg = CommonResourceBundle.getInstance().getString("message.parseX509CertificateStreamFailed", new Object[] { e.getClass().getName(), e.getMessage() }); throw new JAXRException(msg, e); } catch (IOException e) { String msg = CommonResourceBundle.getInstance().getString("message.parseX509CertificateStreamFailed", new Object[] { e.getClass().getName(), e.getMessage() }); throw new JAXRException(msg, e); } finally { try { inStream.close(); } catch (IOException e) { inStream = null; } } }