List of usage examples for java.util Set toArray
<T> T[] toArray(T[] a);
From source file:fi.hsl.parkandride.ActiveProfileAppender.java
@Override public String[] resolve(Class<?> testClass) { Set<String> profiles = currentActiveProfiles(); profiles.addAll(profilesToAppend);// ww w . j ava 2s .c o m return profiles.toArray(new String[profiles.size()]); }
From source file:org.ambraproject.registration.BaseRegistrationAction.java
public UserRole[] getUserRoles() { Map<String, Object> session = ServletActionContext.getContext().getSession(); UserProfile user = (UserProfile) session.get(AMBRA_USER_KEY); if (user != null) { Set<UserRole> roles = user.getRoles(); return roles.toArray(new UserRole[roles.size()]); } else {//w w w . j a v a2 s.c o m return new UserRole[] {}; } }
From source file:io.sloeber.core.managers.Manager.java
/** * This method removes the json files from disk and removes memory * references to these files or their content * * @param packageUrlsToRemove/*from w ww. j av a 2s .co m*/ */ public static void removeBoardsPackageURLs(Set<String> packageUrlsToRemove) { // remove the files from memory Set<String> activeBoardUrls = new HashSet<>( Arrays.asList(ConfigurationPreferences.getBoardsPackageURLList())); activeBoardUrls.removeAll(packageUrlsToRemove); ConfigurationPreferences.setBoardsPackageURLs(activeBoardUrls.toArray(null)); // remove the files from disk for (String curJson : packageUrlsToRemove) { File localFile = getLocalFileName(curJson); if (localFile.exists()) { localFile.delete(); } } // reload the indices (this will remove all potential remaining // references // existing files do not need to be refreshed as they have been // refreshed at startup loadIndices(false); }
From source file:evyframework.common.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 *///w w w . j a va 2 s. c o 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:org.wallride.autoconfigure.WebAdminComponentScanRegistrar.java
private String[] toArray(Set<String> set) { return set.toArray(new String[set.size()]); }
From source file:org.davidmendoza.fileUpload.utils.ContextFinalizer.java
@Override public void onApplicationEvent(ContextClosedEvent e) { log.info("Stopping connections"); Enumeration<Driver> drivers = DriverManager.getDrivers(); Driver d = null;/*from w w w .j a v a 2 s . com*/ while (drivers.hasMoreElements()) { try { d = drivers.nextElement(); DriverManager.deregisterDriver(d); log.warn(String.format("Driver %s deregistered", d)); } catch (SQLException ex) { log.warn(String.format("Error deregistering driver %s", d), ex); } } Set<Thread> threadSet = Thread.getAllStackTraces().keySet(); Thread[] threadArray = threadSet.toArray(new Thread[threadSet.size()]); for (Thread t : threadArray) { if (t.getName().contains("Abandoned connection cleanup thread")) { synchronized (t) { t.stop(); //don't complain, it works } } } log.info("Finished stopping connections"); }
From source file:HSqlManager.java
@SuppressWarnings("Duplicates") @Deprecated//from w w w. j a v a 2s . c om public static void mycoUniqueDB(Connection connection, int bps) throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException, IOException { long time = System.currentTimeMillis(); DpalLoad.main(new String[1]); HSqlPrimerDesign.Dpal_Inst = DpalLoad.INSTANCE_WIN64; String base = new File("").getAbsolutePath(); if (!written) { CSV.makeDirectory(new File(base + "/PhageData")); INSTANCE.parseAllPhages(bps); } Connection db = connection; db.setAutoCommit(false); Statement stat = db.createStatement(); PrintWriter log = new PrintWriter(new File("javalog.log")); stat.execute("SET FILES LOG FALSE;\n"); PreparedStatement st = db .prepareStatement("UPDATE Primerdb.Primers" + " SET UniqueP = true, Tm = ?, GC =?, Hairpin =?" + "WHERE Cluster = ? and Strain = ? and " + "Sequence = ? and Bp = ?"); ResultSet call = stat.executeQuery("Select * From Primerdb.Phages;"); List<String[]> phages = new ArrayList<>(); String strain = ""; 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 (r[2].equals("xkcd")) { strain = r[0]; } } call.close(); String x = strain; 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()]); for (String z : clusters) { try { Set<String> nonclustphages = phages.stream().filter(a -> a[0].equals(x) && !a[1].equals(z)) .map(a -> a[2]).collect(Collectors.toSet()); ResultSet resultSet = stat.executeQuery( "Select Sequence from primerdb.primers" + " where Strain ='" + x + "' and Cluster ='" + z + "' and CommonP = true" + " and Bp = " + Integer.valueOf(bps) + " "); Set<CharSequence> primers = Collections.synchronizedSet(new HashSet<>()); while (resultSet.next()) { primers.add(resultSet.getString("Sequence")); } resultSet.close(); for (String phage : nonclustphages) { // 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()-bps; i++) { // String sub=sequence.substring(i,i+bps); // if(seqInd.containsKey(sub)){ // seqInd.get(sub).add(i); // }else { // List<Integer> list = new ArrayList<>(); // list.add(i); // seqInd.put(sub,list); // } // } // primers = primers.stream().filter(primer->!seqInd.containsKey(primer)).collect(Collectors.toSet()); // primers =Sets.difference(primers,CSV.readCSV(base + "/PhageData/"+Integer.toString(bps) // + phage + ".csv")); CSV.readCSV(base + "/PhageData/" + Integer.toString(bps) + phage + ".csv").stream() .filter(primers::contains).forEach(primers::remove); // System.gc(); } int i = 0; for (CharSequence a : primers) { try { st.setDouble(1, HSqlPrimerDesign.primerTm(a, 0, 800, 1.5, 0.2)); st.setDouble(2, HSqlPrimerDesign.gcContent(a)); st.setBoolean(3, HSqlPrimerDesign.calcHairpin((String) a, 4)); st.setString(4, z); st.setString(5, x); st.setString(6, a.toString()); st.setInt(7, bps); st.addBatch(); } catch (SQLException e) { e.printStackTrace(); System.out.println("Error occurred at " + x + " " + z); } 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); } log.println(z); log.flush(); System.gc(); } stat.execute("SET FILES LOG TRUE\n"); st.close(); stat.close(); System.out.println("Unique Updated"); System.out.println((System.currentTimeMillis() - time) / Math.pow(10, 3) / 60); }
From source file:net.mojodna.searchable.util.SearchableUtils.java
/** * @param clazz// ww w .j av a 2s. co m * @return Fields. */ public static final Field[] getFields(final Class<? extends Searchable> clazz) { Set<Field> fields = new HashSet<Field>(); for (final PropertyDescriptor d : PropertyUtils.getPropertyDescriptors(clazz)) { if (containsIndexAnnotations(d)) { final Field.Store stored = isStored(d); final Field.Index indexStyle = getIndexStyle(d); final float boost = getBoost(d); for (final String name : getFieldnames(d)) { final Field f = new Field(name, clazz.getName() + "#" + d.getName(), stored, indexStyle); f.setBoost(boost); fields.add(f); } } if (containsSortableAnnotations(d)) { fields.add(new Field(IndexSupport.SORTABLE_PREFIX + d.getName(), clazz.getName(), Field.Store.YES, Field.Index.NO)); } } return fields.toArray(new Field[] {}); }
From source file:org.synchronoss.cloud.nio.multipart.example.utils.ContextFinalizer.java
@Override public void onApplicationEvent(ContextClosedEvent event) { if (log.isInfoEnabled()) log.info("onApplicationEvent: " + event); Enumeration<Driver> drivers = DriverManager.getDrivers(); Driver driver = null;//from w w w .j a v a 2 s . co m while (drivers.hasMoreElements()) { try { driver = drivers.nextElement(); DriverManager.deregisterDriver(driver); if (log.isWarnEnabled()) log.warn(String.format("Driver %s unregistered", driver)); } catch (SQLException e) { if (log.isWarnEnabled()) log.warn(String.format("Error unregistering driver %s", driver), e); } } Set<Thread> threadSet = Thread.getAllStackTraces().keySet(); Thread[] threadArray = threadSet.toArray(new Thread[threadSet.size()]); for (Thread thread : threadArray) { if (thread.getName().contains("Abandoned connection cleanup thread")) { synchronized (thread) { thread.stop(); //don't complain, it works } } } if (log.isInfoEnabled()) log.info("Finished processing onApplicationEvent"); }
From source file:com.espertech.esper.core.service.StatementIsolationServiceImpl.java
public String[] getIsolationUnitNames() { Set<String> keyset = isolatedProviders.keySet(); return keyset.toArray(new String[keyset.size()]); }