List of usage examples for java.util Set toArray
<T> T[] toArray(T[] a);
From source file:de.saly.elasticsearch.importer.imap.support.IndexableMailMessage.java
public static IndexableMailMessage fromJavaMailMessage(final Message jmm, final boolean withTextContent, final boolean withHtmlContent, final boolean preferHtmlContent, 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())); }/* w ww . j a v a 2 s . c o 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, preferHtmlContent); 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 (withHtmlContent) { // try { String htmlContent = getText(jmm, 0, true); im.setHtmlContent(htmlContent); // } 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; }
From source file:com.esofthead.mycollab.community.cache.service.DefaultCacheService.java
@Override public void removeCacheItems(String group, String prefixKey) { CacheObject<String, Object> cache = getCache(group); Set<String> keys = cache.keySet(); if (CollectionUtils.isNotEmpty(keys)) { String[] keyArr = keys.toArray(new String[0]); for (int i = 0; i < keyArr.length; i++) { if (keyArr[i].startsWith(prefixKey)) { cache.remove(keyArr[i]); }/*from w w w .jav a 2 s. c o m*/ } } }
From source file:cmpt305.lab3.gui.controllers.CompareGraphController.java
public CompareGraphController(User main, Set<User> users) { this(main, (User[]) users.toArray(new User[users.size()])); }
From source file:HSqlPrimerDesign.java
@SuppressWarnings("Duplicates") public static void locations(Connection connection) throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException, IOException { long time = System.nanoTime(); String base = new File("").getAbsolutePath(); DpalLoad.main(new String[0]); Dpal_Inst = DpalLoad.INSTANCE_WIN64; System.out.println(Dpal_Inst); Connection db = connection;/*from w w w . j av a2s . c om*/ db.setAutoCommit(false); Statement stat = db.createStatement(); PrintWriter log = new PrintWriter(new File("javalog.log")); stat.execute("SET FILES LOG FALSE;"); PreparedStatement st = db.prepareStatement("INSERT INTO Primerdb.MatchedPrimers(" + "Primer, PrimerMatch, Comp,FragAVG,FragVAR,H2SD,L2SD, Cluster, Strain)" + "Values(?,?,?,?,?,?,?,?,?)"); ResultSet call = stat.executeQuery("Select * From Primerdb.Phages;"); List<String[]> phages = new ArrayList<>(); while (call.next()) { String[] r = new String[3]; r[0] = call.getString("Strain"); r[1] = call.getString("Cluster"); r[2] = call.getString("Name"); phages.add(r); // if(strain.equals("-myco")) { // if (r[2].equals("xkcd")) { // strain = r[0]; // } // }else if(strain.equals("-arthro")){ // if (r[2].equals("ArV1")) { // strain = r[0]; // } // } } call.close(); Set<String> strains = phages.stream().map(y -> y[0]).collect(Collectors.toSet()); for (String x : strains) { Set<String> clust = phages.stream().filter(y -> y[0].equals(x)).map(y -> y[1]) .collect(Collectors.toSet()); String[] clusters = clust.toArray(new String[clust.size()]); // String z ="A1"; for (String z : clusters) { System.out.println("Starting:" + z); List<Primer> primers = new ArrayList<>(); Set<Matches> matched = new HashSet<>(); Set<String> clustphage = phages.stream().filter(a -> a[0].equals(x) && a[1].equals(z)) .map(a -> a[2]).collect(Collectors.toSet()); String[] clustphages = clustphage.toArray(new String[clustphage.size()]); if (clustphages.length > 1) { try { ResultSet resultSet = stat .executeQuery("Select * from primerdb.primers" + " where Strain ='" + x + "' and Cluster ='" + z + "' and UniqueP = true" + " and Hairpin = false"); while (resultSet.next()) { Primer primer = new Primer(resultSet.getString("Sequence")); primer.setTm(resultSet.getDouble("Tm")); primers.add(primer); } resultSet.close(); } catch (SQLException e) { e.printStackTrace(); System.out.println("Error occurred at " + x + " " + z); } System.out.println(primers.size()); Set<Primer> primerlist2 = primers.stream().collect(Collectors.toSet()); Primer[] primers2 = primerlist2.toArray(new Primer[primerlist2.size()]); Map<String, Map<CharSequence, List<Integer>>> locations = Collections .synchronizedMap(new HashMap<>()); clustphage.stream().forEach(phage -> { String[] seqs = Fasta.parse(base + "/Fastas/" + phage + ".fasta"); String sequence = seqs[0] + seqs[1]; Map<String, List<Integer>> seqInd = new HashMap<>(); for (int i = 0; i <= sequence.length() - 10; i++) { String sub = sequence.substring(i, i + 10); if (seqInd.containsKey(sub)) { seqInd.get(sub).add(i); } else { List<Integer> list = new ArrayList<>(); list.add(i); seqInd.put(sub, list); } } Map<CharSequence, List<Integer>> alllocs = new HashMap<>(); for (Primer primer : primers2) { List<Integer> locs = new ArrayList<>(); String sequence1 = primer.getSequence(); String frag = sequence1.substring(0, 10); List<Integer> integers = seqInd.get(frag); if (integers != null) { for (Integer i : integers) { if ((sequence1.length() + i) < sequence.length() && sequence.substring(i, sequence1.length() + i).equals(sequence1)) { locs.add(i); } } } alllocs.put(sequence1, locs); } locations.put(phage, alllocs); }); System.out.println("locations found"); System.out.println((System.nanoTime() - time) / Math.pow(10, 9) / 60.0); final int[] k = new int[] { 0 }; primerlist2.parallelStream().forEach(a -> { int matches = 0; int i = 0; while (primers2[i] != a) { i++; } for (int j = i + 1; j < primers2.length; j++) { double[] frags = new double[clustphages.length]; int phageCounter = 0; Primer b = primers2[j]; boolean match = true; if (matches > 0) { break; } if (Math.abs(a.getTm() - b.getTm()) > 5.0 || a.getSequence().equals(b.getSequence())) { continue; } for (String phage : clustphages) { List<Integer> loc1 = locations.get(phage).get(a.getSequence()); List<Integer> loc2 = locations.get(phage).get(b.getSequence()); // if(loc1.size()==0){ // System.out.println(phage+" "+a.getSequence()); // } if (loc1.size() == 0 || loc2.size() == 0) { // if (loc1.size()!=1||loc2.size()!=1){ match = false; break; } boolean found = false; int fragCount = 0; int l1 = loc1.get(0); int l2 = loc2.get(0); int count1 = 0; int count2 = 0; int frag = Math.abs(l1 - l2); while (!found) { if (frag >= 500 && frag <= 2000) { fragCount++; if (++count1 < loc1.size()) l1 = loc1.get(count1); else if (++count2 < loc2.size()) l2 = loc2.get(count2); } else if (l1 < l2 && frag < 500) { count2++; } else if (l1 > l2 && frag < 500) { count1++; } else if (l1 > l2 && frag > 2000) { count2++; } else if (l1 < l2 && frag > 2000) { count1++; } else { break; } if (count1 < loc1.size() && count2 < loc2.size()) { l1 = loc1.get(count1); l2 = loc2.get(count2); frag = Math.abs(l1 - l2); } else { if (fragCount == 1) { found = true; frags[phageCounter++] = frag + 0.0; } else { break; } } } if (!found) { match = false; break; } } if (match) { matches++; matched.add(new Matches(a, b, frags)); } } // k[0]++; // System.out.println(k[0]); }); System.out.println((System.nanoTime() - time) / Math.pow(10, 9) / 60.0); System.out.println("Primers matched"); int c = 0; int i = 0; try { for (Matches primerkey : matched) { c++; String primer1 = primerkey.one.getSequence(); String primer2 = primerkey.two.getSequence(); st.setString(1, primer1); st.setString(2, primer2); st.setDouble(3, complementarity(primer1, primer2, Dpal_Inst)); st.setDouble(4, primerkey.stats.getMean()); st.setDouble(5, primerkey.stats.getVariance()); st.setDouble(6, primerkey.stats.getMean() + 2 * primerkey.stats.getStandardDeviation()); st.setDouble(7, primerkey.stats.getMean() - 2 * primerkey.stats.getStandardDeviation()); st.setString(8, z); st.setString(9, x); st.addBatch(); i++; if (i == 1000) { i = 0; st.executeBatch(); db.commit(); } } if (i > 0) { st.executeBatch(); db.commit(); } } catch (SQLException e) { e.printStackTrace(); System.out.println("Error occurred at " + x + " " + z); } System.out.println(c); } log.println(z); log.flush(); System.gc(); } } stat.execute("SET FILES LOG TRUE;"); st.close(); stat.close(); System.out.println("Matches Submitted"); }
From source file:backup.namenode.NameNodeRestoreProcessor.java
private DatanodeInfo getDataNodeAddress(Set<DatanodeDescriptor> storages) { DatanodeInfo[] datanodeInfos = storages.toArray(new DatanodeInfo[storages.size()]); int index = BackupUtil.nextInt(datanodeInfos.length); return datanodeInfos[index]; }
From source file:BreadthFirstPathTreeIterator.java
protected String[] getPathArray(String path) { Set pathSet = servletContext.getResourcePaths(path); return (String[]) pathSet.toArray(new String[pathSet.size()]); }
From source file:org.duracloud.account.app.controller.AbstractController.java
protected void setUserRights(DuracloudUserService userService, Long accountId, Long userId, Role role) { Set<Role> roles = role.getRoleHierarchy(); userService.setUserRights(accountId, userId, roles.toArray(new Role[roles.size()])); }
From source file:com.mycollab.cache.service.impl.InfinispanCacheService.java
@Override public void removeCacheItem(String id, String prefixKey) { BasicCache<String, Object> cache = instance.getCache(id); LOG.debug("Remove cache has prefix {} in group {}", prefixKey, id); Set<String> keys = cache.keySet(); if (CollectionUtils.isNotEmpty(keys)) { String[] keyArr = keys.toArray(new String[0]); for (int i = 0; i < keyArr.length; i++) { if (keyArr[i].startsWith(prefixKey)) { LOG.debug("Remove cache key {}", keyArr[i]); cache.remove(keyArr[i]); }/* ww w.j a v a2 s . c o m*/ } } }
From source file:com.intellectualcrafters.plot.commands.TP.java
private Plot isAlias(final World world, String a) { int index = 0; if (a.contains(";")) { final String[] split = a.split(";"); if ((split[1].length() > 0) && StringUtils.isNumeric(split[1])) { index = Integer.parseInt(split[1]); }//from w w w. j a v a 2s . co m a = split[0]; } @SuppressWarnings("deprecation") final Player player = Bukkit.getPlayer(a); if (player != null) { final java.util.Set<Plot> plotMainPlots = PlotMain.getPlots(world, player); final Plot[] plots = plotMainPlots.toArray(new Plot[plotMainPlots.size()]); if (plots.length > index) { return plots[index]; } return null; } for (final Plot p : PlotMain.getPlots(world).values()) { if ((p.settings.getAlias().length() > 0) && p.settings.getAlias().equalsIgnoreCase(a)) { return p; } } return null; }
From source file:com.mac.holdempoker.app.impl.SimpleRound.java
public Player[] showDown(Board board) throws Exception { WinnerContainer wc = new WinnerContainer(); SimpleHandAggregator sha = new SimpleHandAggregator(); for (Player p : players) { Hand sh = new SimpleHand(p, board); wc.addPlayerScore(p, sha.scoreHand(sh)); }/* w w w. j a v a2s. c o m*/ Set<Player> winners = pot.getPlayersToBePaid(wc); pot.multiplePlayersWon(wc); return winners.toArray(new Player[winners.size()]); }