List of usage examples for java.util Collection toArray
default <T> T[] toArray(IntFunction<T[]> generator)
From source file:com.smartmarmot.orabbix.Configurator.java
private static Query[] getQueries(String parameter, Properties _propsq) throws Exception { try {//from ww w . j a va 2 s .c om StringTokenizer stq = new StringTokenizer(_propsq.getProperty(parameter), Constants.DELIMITER); String[] QueryLists = new String[stq.countTokens()]; int count = 0; while (stq.hasMoreTokens()) { String token = stq.nextToken().toString().trim(); QueryLists[count] = token; count++; } Collection<Query> Queries = new ArrayList<Query>(); for (int i = 0; i < QueryLists.length; i++) { try { Query q = getQueryProperties(_propsq, QueryLists[i]); Queries.add(q); } catch (Exception e1) { SmartLogger.logThis(Level.ERROR, "Error on Configurator on reading query " + QueryLists[i] + e1); SmartLogger.logThis(Level.INFO, "Query " + QueryLists[i] + " skipped due to error " + e1); } } Query[] queries = (Query[]) Queries.toArray(new Query[0]); return queries; } catch (Exception ex) { SmartLogger.logThis(Level.ERROR, "Error on Configurator on reading properties file " + _propsq.toString() + " getQueries(" + parameter + "," + _propsq.toString() + ") " + ex.getMessage()); return null; } }
From source file:net.sf.jabref.gui.FileListEntryEditor.java
private void setValues(FileListEntry entry) { description.setText(entry.description); link.setText(entry.link);// w ww . j a va 2 s. c om //if (link.getText().length() > 0) // checkExtension(); Collection<ExternalFileType> list = ExternalFileTypes.getInstance().getExternalFileTypeSelection(); types.setModel(new DefaultComboBoxModel<>(list.toArray(new ExternalFileType[list.size()]))); types.setSelectedIndex(-1); // See what is a reasonable selection for the type combobox: if ((entry.type.isPresent()) && !(entry.type.get() instanceof UnknownExternalFileType)) { types.setSelectedItem(entry.type.get()); } else if ((entry.link != null) && (!entry.link.isEmpty())) { checkExtension(); } }
From source file:com.espertech.esper.client.scopetest.EPAssertionUtil.java
/** * Compare the collection of object arrays, and using property names for messages, against expected values. * @param actual colleciton of array of objects * @param propertyNames property names/* w ww.j a v a 2 s.c o m*/ * @param expected expected values */ public static void assertEqualsExactOrder(Collection<Object[]> actual, String[] propertyNames, Object[][] expected) { Object[][] arr = actual.toArray(new Object[actual.size()][]); assertEqualsExactOrder(arr, propertyNames, expected); }
From source file:com.cyclopsgroup.tornado.hibernate.impl.DefaultHibernateService.java
/** * Override method getEntityClasses in class DefaultHibernateHome * * @see com.cyclopsgroup.tornado.hibernate.HibernateService#getEntityClasses(java.lang.String) */// ww w . j a va2s. co m public Class[] getEntityClasses(String dataSourceName) { Collection classes = (Collection) entityClasses.get(dataSourceName); return classes == null ? ArrayUtils.EMPTY_CLASS_ARRAY : (Class[]) classes.toArray(ArrayUtils.EMPTY_CLASS_ARRAY); }
From source file:com.opemind.cartspage.client.android.result.supplement.BookResultInfoRetriever.java
@Override void retrieveSupplementalInfo() throws IOException { CharSequence contents = HttpHelper.downloadViaHttp( "https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn, HttpHelper.ContentType.JSON); if (contents.length() == 0) { return;// w w w . ja v a 2 s . c o m } String title; String pages; Collection<String> authors = null; try { JSONObject topLevel = (JSONObject) new JSONTokener(contents.toString()).nextValue(); JSONArray items = topLevel.optJSONArray("items"); if (items == null || items.isNull(0)) { return; } JSONObject volumeInfo = ((JSONObject) items.get(0)).getJSONObject("volumeInfo"); if (volumeInfo == null) { return; } title = volumeInfo.optString("title"); pages = volumeInfo.optString("pageCount"); JSONArray authorsArray = volumeInfo.optJSONArray("authors"); if (authorsArray != null && !authorsArray.isNull(0)) { authors = new ArrayList<>(authorsArray.length()); for (int i = 0; i < authorsArray.length(); i++) { authors.add(authorsArray.getString(i)); } } } catch (JSONException e) { throw new IOException(e); } Collection<String> newTexts = new ArrayList<>(); maybeAddText(title, newTexts); maybeAddTextSeries(authors, newTexts); maybeAddText(pages == null || pages.isEmpty() ? null : pages + "pp.", newTexts); String baseBookUri = "http://www.google." + LocaleManager.getBookSearchCountryTLD(context) + "/search?tbm=bks&source=zxing&q="; append(isbn, source, newTexts.toArray(new String[newTexts.size()]), baseBookUri + isbn); }
From source file:com.koda.integ.hbase.test.BlockCacheSimpleRegionTests.java
/** * _test random direct scanners.//from w ww . j a v a 2s . co m * * @throws IOException Signals that an I/O exception has occurred. */ public void _testRandomDirectScanners() throws IOException { LOG.info("Random StoreFile scanners . Running " + (N / 10) + " of size " + M + " scanners"); Random r = new Random(); long totalScanned = 0; long start = System.currentTimeMillis(); Map<byte[], Store> storeMap = region.getStores(); Collection<Store> stores = storeMap.values(); Store store = stores.iterator().next(); Collection<StoreFile> files = store.getStorefiles(); StoreFile[] array = new StoreFile[files.size()]; files.toArray(array); for (int i = 0; i < N / 10; i++) { StoreFile file = array[r.nextInt(files.size())]; byte[] row = (ROW_PREFIX + r.nextInt(N)).getBytes(); StoreFile.Reader reader = file.createReader(); StoreFileScanner scanner = reader.getStoreFileScanner(false, false); KeyValue kv = new KeyValue(row, CF, CQQ[0]); scanner.seek(kv); int total = 0; while (total++ < M && scanner.next() != null) { totalScanned++; } if (i % 100000 == 0 && i > 0) { LOG.info("Scanner " + i + " scanned=" + totalScanned + " avg per scanner=" + (totalScanned / i)); } scanner.close(); reader.close(false); } LOG.info("Random StoreFile scanners done. " + (N / 10) + " in " + (System.currentTimeMillis() - start) + "ms. Total scanned=" + totalScanned + " Avg. =" + ((totalScanned * 10) / N)); }
From source file:com.apecat.shoppingadvisor.scan.result.supplement.BookResultInfoRetriever.java
@Override void retrieveSupplementalInfo() throws IOException { CharSequence contents = HttpHelper.downloadViaHttp( "https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn, HttpHelper.ContentType.JSON); if (contents.length() == 0) { return;// ww w . j a va 2s . co m } String title; String pages; Collection<String> authors = null; try { JSONObject topLevel = (JSONObject) new JSONTokener(contents.toString()).nextValue(); JSONArray items = topLevel.optJSONArray("items"); if (items == null || items.isNull(0)) { return; } JSONObject volumeInfo = ((JSONObject) items.get(0)).getJSONObject("volumeInfo"); if (volumeInfo == null) { return; } title = volumeInfo.optString("title"); pages = volumeInfo.optString("pageCount"); JSONArray authorsArray = volumeInfo.optJSONArray("authors"); if (authorsArray != null && !authorsArray.isNull(0)) { authors = new ArrayList<String>(authorsArray.length()); for (int i = 0; i < authorsArray.length(); i++) { authors.add(authorsArray.getString(i)); } } } catch (JSONException e) { throw new IOException(e); } Collection<String> newTexts = new ArrayList<String>(); maybeAddText(title, newTexts); maybeAddTextSeries(authors, newTexts); maybeAddText(pages == null || pages.isEmpty() ? null : pages + "pp.", newTexts); String baseBookUri = "http://www.google." + LocaleManager.getBookSearchCountryTLD(context) + "/search?tbm=bks&source=zxing&q="; append(isbn, source, newTexts.toArray(new String[newTexts.size()]), baseBookUri + isbn); }
From source file:com.flavik.barcode.recognizer.client.android.result.supplement.BookResultInfoRetriever.java
@Override void retrieveSupplementalInfo() throws IOException { CharSequence contents = HttpHelper.downloadViaHttp( "https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn, HttpHelper.ContentType.JSON); if (contents.length() == 0) { return;// w w w . j ava 2s . c o m } String title; String pages; Collection<String> authors = null; try { JSONObject topLevel = (JSONObject) new JSONTokener(contents.toString()).nextValue(); JSONArray items = topLevel.optJSONArray("items"); if (items == null || items.isNull(0)) { return; } JSONObject volumeInfo = ((JSONObject) items.get(0)).getJSONObject("volumeInfo"); if (volumeInfo == null) { return; } title = volumeInfo.optString("title"); pages = volumeInfo.optString("pageCount"); JSONArray authorsArray = volumeInfo.optJSONArray("authors"); if (authorsArray != null && !authorsArray.isNull(0)) { authors = new ArrayList<String>(authorsArray.length()); for (int i = 0; i < authorsArray.length(); i++) { authors.add(authorsArray.getString(i)); } } } catch (JSONException e) { throw new IOException(e.toString()); } Collection<String> newTexts = new ArrayList<String>(); maybeAddText(title, newTexts); maybeAddTextSeries(authors, newTexts); maybeAddText(pages == null || pages.isEmpty() ? null : pages + "pp.", newTexts); String baseBookUri = "http://www.google." + LocaleManager.getBookSearchCountryTLD(context) + "/search?tbm=bks&source=zxing&q="; append(isbn, source, newTexts.toArray(new String[newTexts.size()]), baseBookUri + isbn); }
From source file:com.ecrimebureau.File.Hash.java
private void gethash() { File f = FileChooser.fileChoosers(JFileChooser.FILES_AND_DIRECTORIES);//new File(this.path); this.path = f.getAbsolutePath(); if (f.isFile()) { try {//from www .j av a 2 s . c o m jInternalFrame.setTitle("Hashing a Single File (1)"); String hash = getChecksum(path, algorithim); //or "SHA-256", "SHA-384", "SHA-512,SHA1" jTA.append(hash + " -> " + path + "\n"); System.out.println(hash); } catch (Exception e) { System.out.println("An error occured. hashing -> " + path + "\n"); jTA.append("An error occured. hashing -> " + path + "\n"); } } else if (f.isDirectory()) { isDirectory = true; Collection files = FileUtils.listFiles(f, new RegexFileFilter("^(.*?)"), DirectoryFileFilter.DIRECTORY); int totalNumberofFiles = files.size(); int startprogress = 1; jProgressBar.setMaximum(100); jInternalFrame.setTitle("Hashing " + totalNumberofFiles + " Files"); for (Object i : files.toArray(new File[] {})) { try { String hash = getChecksum(i.toString(), algorithim); //or "SHA-256", "SHA-384", "SHA-512,SHA1" System.out.println(hash + " -> " + i.toString() + "\n"); jTA.append(hash + " -> " + i.toString() + "\n"); //for the progress bar int percentageCompleted = (int) Math.round(startprogress * 100.0 / totalNumberofFiles); jProgressBar.setValue(percentageCompleted); //set the progress bar value jProgressBar.setString(String.valueOf(percentageCompleted) + "%");//the display string startprogress++; //increase the value //end progress bar } catch (Exception e) { System.out.println("An error occured. hashing -> " + i.toString() + "\n"); jTA.append("An error occured. hashing -> " + i.toString() + "\n"); } } } }
From source file:io.github.tjg1.library.norilib.SearchResult.java
/** * Create a smaller version of this SearchResult containing {@link Image}s from the given Search * paging offset only. This is to make it suitable for passing between Activities without * triggering a {@link android.os.TransactionTooLargeException}. * * @param page Paging offset used to filter {@link Image}s. * @return A {@link SearchResult} containing only {@link Image}s for the given search paging offset. *//*from w w w .j a v a2 s . c o m*/ public SearchResult getSearchResultForPage(final int page) { Collection<Image> selectedImages = CollectionUtils.select(images, new Predicate<Image>() { @Override public boolean evaluate(Image image) { return (image.searchPage != null && image.searchPage == page); } }); return new SearchResult(selectedImages.toArray(new Image[selectedImages.size()]), this.query, page); }