List of usage examples for java.util LinkedList toArray
@SuppressWarnings("unchecked") public <T> T[] toArray(T[] a)
From source file:model.utilities.stats.collectors.PeriodicMarketObserver.java
public void attachCSVWriter(CSVWriter writer) throws IOException { this.writer = writer; LinkedList<String> row = new LinkedList<>(); row.add("price"); row.add("traded"); row.add("produced"); row.add("consumed"); row.add("day"); row.add("demand gap"); row.add("supply gap"); writer.writeNext(row.toArray(new String[row.size()])); writer.flush();//w w w .j a va2 s . c o m }
From source file:de.quadrillenschule.azocamsyncd.ftpservice.FTPConnection.java
public LinkedList<AZoFTPFile> checkConnection(boolean includeDirs) { if (!"".equals(getLastWorkingConnection())) { LinkedList<String> t = new LinkedList<>(); t.add(getLastWorkingConnection()); for (String s : possibleConnections) { if (!s.equals(lastWorkingConnection)) { t.add(s);/* w w w .jav a2s . c om*/ } } possibleConnections = t.toArray(new String[0]); } for (String ip : possibleConnections) { notify(FTPConnectionStatus.TRYING, ip, -1); if (ftpclient != null) { close(); } ftpclient = new FTPClient(); try { ftpclient.setDefaultTimeout(TIMEOUT); ftpclient.connect(ip); if (ftpclient.isAvailable()) { LinkedList<AZoFTPFile> retval = discoverRemoteFiles("/", includeDirs); lastWorkingConnection = ip; close(); notify(FTPConnectionStatus.CONNECTED, ip, -1); return retval; } else { close(); } } catch (IOException ex) { close(); notify(FTPConnectionStatus.NOCONNECTION, "", -1); Logger.getLogger(FTPConnection.class.getName()).log(Level.INFO, null, ex); } } setLooksFullySynced(false); notify(FTPConnectionStatus.NOCONNECTION, "", -1); return null; }
From source file:net.sf.jabref.external.ExternalFilePanel.java
/** * Creates a Runnable that searches the external file directory for the given * field name, including subdirectories, and looks for files named after the * current entry's bibtex key./*from w ww .ja v a2 s.c om*/ * * @param fieldName * The field to set. * @param editor * An EntryEditor instance where to set the value found. * @return A reference to the Runnable that can perform the operation. */ public Runnable autoSetFile(final String fieldName, final FieldEditor editor) { Object o = getKey(); if ((o == null) || (Globals.prefs.get(fieldName + Globals.DIR_SUFFIX) == null)) { output(Localization.lang("You must set both BibTeX key and %0 directory", fieldName.toUpperCase()) + '.'); return null; } output(Localization.lang("Searching for %0 file", fieldName.toUpperCase()) + " '" + o + '.' + fieldName + "'..."); return new Runnable() { @Override public void run() { /* * Find the following directories to look in for: * * default directory for this field type. * * directory of bibtex-file. // NOT POSSIBLE at the moment. * * JabRef-directory. */ LinkedList<String> list = new LinkedList<>(); String[] dirs = metaData.getFileDirectory(fieldName); Collections.addAll(list, dirs); String found = FileFinder.findPdf(getEntry(), fieldName, list.toArray(new String[list.size()]));// , off); // To activate findFile: // String found = Util.findFile(getEntry(), null, dir, // ".*[bibtexkey].*"); if (found != null) { editor.setText(found); if (entryEditor != null) { entryEditor.updateField(editor); } output(Localization.lang("%0 field set", fieldName.toUpperCase()) + '.'); } else { output(Localization.lang("No %0 found", fieldName.toUpperCase()) + '.'); } } }; }
From source file:com.blocks.framework.utils.date.StringUtil.java
/** * split?//from ww w. j a v a 2s . c o m * @param line String * @param separator String * @return String[] */ public static final String[] split(String line, String separator) { LinkedList<String> list = new LinkedList<String>(); if (line != null) { int start = 0; int end = 0; int separatorLen = separator.length(); while ((end = line.indexOf(separator, start)) >= 0) { list.add(line.substring(start, end)); start = end + separatorLen; } if (start < line.length()) { list.add(line.substring(start, line.length())); } } return (String[]) list.toArray(new String[list.size()]); }
From source file:net.semanticmetadata.lire.builders.GlobalDocumentBuilder.java
/** * @param image the image to analyze./*w ww .j av a 2 s .c o m*/ * @return Lucene Fields. */ @Override public Field[] createDescriptorFields(BufferedImage image) { docsCreated = true; LinkedList<Field> resultList = new LinkedList<Field>(); Field[] fields; if (extractorItems.size() > 0) { for (Map.Entry<ExtractorItem, String[]> extractorItemEntry : extractorItems.entrySet()) { fields = getGlobalDescriptorFields(image, extractorItemEntry.getKey()); Collections.addAll(resultList, fields); } } return resultList.toArray(new Field[resultList.size()]); }
From source file:org.gcaldaemon.gui.Messages.java
public static final Locale[] getAvailableLocales() { LinkedList list = new LinkedList(); list.addLast(Locale.ENGLISH); try {/*w w w.j a v a2 s.co m*/ Locale[] availables = Locale.getAvailableLocales(); String programDir = System.getProperty("gcaldaemon.program.dir", "/Progra~1/GCALDaemon"); File langDir = new File(programDir, "lang"); if (langDir.isDirectory()) { String[] names = langDir.list(); String name; int s, e; for (int i = 0; i < names.length; i++) { name = names[i]; if (name.equals("messages-en.txt")) { continue; } s = name.indexOf('-'); e = name.indexOf('.', s); if (s != -1 && e != -1) { name = name.substring(s + 1, e); Locale locale = null; for (s = 0; s < availables.length; s++) { if (name.equals(availables[s].getCountry().toLowerCase())) { locale = availables[s]; break; } } if (locale == null) { locale = new Locale(name); } list.add(locale); } } } } catch (Exception ignored) { log.warn(ignored); } Locale[] array = new Locale[list.size()]; list.toArray(array); return array; }
From source file:com.googlecode.datasourcetester.server.DataSourceTesterServiceImpl.java
public String[][] queryDataSource(String dataSourceJndiName, String query) { Connection conn = null;//from w w w . j av a 2 s . c om try { InitialContext jndiContext = new InitialContext(); DataSource ds = (DataSource) jndiContext.lookup(dataSourceJndiName); conn = ds.getConnection(); PreparedStatement stmt = conn.prepareStatement(query); ResultSet rs = stmt.executeQuery(); ResultSetMetaData resMeta = rs.getMetaData(); LinkedList<String[]> rowList = new LinkedList<String[]>(); String[] colLabels = new String[resMeta.getColumnCount()]; for (int colNr = 1; colNr <= resMeta.getColumnCount(); colNr++) { colLabels[colNr - 1] = resMeta.getColumnName(colNr); } rowList.add(colLabels); while (rs.next()) { String[] rowData = new String[resMeta.getColumnCount()]; for (int colNr = 1; colNr <= resMeta.getColumnCount(); colNr++) { rowData[colNr - 1] = rs.getString(colNr); } rowList.add(rowData); } conn.close(); return rowList.toArray(new String[rowList.size()][]); } catch (Exception e) { logger.error(e.getMessage(), e); try { if (conn != null && !conn.isClosed()) { conn.close(); } } catch (SQLException sqlEx) { logger.error(sqlEx.getMessage(), sqlEx); } return null; } }
From source file:pt.ist.vaadinframework.data.AbstractBufferedItem.java
private void applyWriter() { if (writer != null) { try {/*w w w . j av a 2 s . c o m*/ if (fieldDiffer(writer.getOrderedArguments())) { LinkedList<Class<?>> argumentTypes = new LinkedList<Class<?>>(); argumentTypes.add(getType()); argumentTypes.addAll(Arrays.asList(getArgumentTypes(writer.getOrderedArguments()))); Method method = findMethod(writer.getClass(), argumentTypes.toArray(new Class<?>[0])); LinkedList<Object> argumentValues = new LinkedList<Object>(); argumentValues.add(cache); argumentValues.addAll(Arrays.asList(readArguments(writer.getOrderedArguments()))); // VaadinFrameworkLogger.getLogger().debug( // "persisting item with writer with properties: [" // + StringUtils.join(writer.getOrderedArguments(), ", ") + // "] with values: [" // + StringUtils.join(argumentValues.subList(1, // argumentValues.size()), ", ") + "]"); method.invoke(writer, argumentValues.toArray(new Object[0])); for (Id id : writer.getOrderedArguments()) { if (getItemProperty(id) instanceof Buffered) { ((Buffered) getItemProperty(id)).discard(); } } } } catch (Throwable e) { ServiceUtils.handleException(e); throw new SourceException(this, e); } } }
From source file:org.apache.http.HC4.conn.ssl.AbstractVerifier.java
public static String[] getCNs(X509Certificate cert) { LinkedList<String> cnList = new LinkedList<String>(); /*// w ww.ja va 2 s . c o m Sebastian Hauer's original StrictSSLProtocolSocketFactory used getName() and had the following comment: Parses a X.500 distinguished name for the value of the "Common Name" field. This is done a bit sloppy right now and should probably be done a bit more according to <code>RFC 2253</code>. I've noticed that toString() seems to do a better job than getName() on these X500Principal objects, so I'm hoping that addresses Sebastian's concern. For example, getName() gives me this: 1.2.840.113549.1.9.1=#16166a756c6975736461766965734063756362632e636f6d whereas toString() gives me this: EMAILADDRESS=juliusdavies@cucbc.com Looks like toString() even works with non-ascii domain names! I tested it with "花子.co.jp" and it worked fine. */ String subjectPrincipal = cert.getSubjectX500Principal().toString(); StringTokenizer st = new StringTokenizer(subjectPrincipal, ","); while (st.hasMoreTokens()) { String tok = st.nextToken(); int x = tok.indexOf("CN="); if (x >= 0) { cnList.add(tok.substring(x + 3)); } } if (!cnList.isEmpty()) { String[] cns = new String[cnList.size()]; cnList.toArray(cns); return cns; } else { return null; } }
From source file:com.clustercontrol.jobmanagement.composite.JobTreeComposite.java
public void doSearch(String keyword) { // Check and format keyword if (null == keyword) { return;/* w w w.j a v a 2 s . c o m*/ } keyword = keyword.trim(); if (keyword.isEmpty()) { return; } StructuredSelection selection = (StructuredSelection) m_viewer.getSelection(); Object targetItem = selection.getFirstElement(); JobTreeItem result = searchItem((JobTreeItem) (null != targetItem ? targetItem : m_viewer.getInput()), keyword); if (null != result) { JobTreeItem trace = result; LinkedList<JobTreeItem> pathList = new LinkedList<>(); do { pathList.addFirst(trace); trace = trace.getParent(); } while (null != trace); TreePath path = new TreePath(pathList.toArray(new JobTreeItem[] {})); m_viewer.setSelection(new TreeSelection(path), true); } else { MessageDialog.openInformation(this.getShell(), Messages.getString("message"), Messages.getString("search.not.found")); m_viewer.setSelection(new StructuredSelection(((JobTreeItem) m_viewer.getInput()).getChildren().get(0)), true); } }