List of usage examples for java.util LinkedList toArray
@SuppressWarnings("unchecked") public <T> T[] toArray(T[] a)
From source file:Main.java
public static void main(String[] args) { LinkedList<String> theList = new LinkedList<String>(); theList.add("A"); theList.add("B"); theList.add("C"); theList.add("D"); String[] my = theList.toArray(new String[0]); for (int i = 0; i < my.length; i++) { System.out.println(my[i]); }/*from w w w. j a va 2 s. c o m*/ }
From source file:Main.java
public static void main(String[] args) { LinkedList<String> list = new LinkedList<String>(); // add some elements list.add("Hello"); list.add("from java2s.com"); list.add("java tutorial"); System.out.println(list);/*from w w w. jav a 2 s .c o m*/ // create an array and copy the list to it Object[] array = list.toArray(new Object[4]); System.out.println(Arrays.toString(array)); }
From source file:ubic.gemma.core.apps.GemmaCLI.java
public static void main(String[] args) { /*//from w w w .j a v a2s. c o m * Build a map from command names to classes. */ Map<CommandGroup, Map<String, String>> commands = new HashMap<>(); Map<String, Class<? extends AbstractCLI>> commandClasses = new HashMap<>(); try { final ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider( false); provider.addIncludeFilter(new RegexPatternTypeFilter(Pattern.compile(".*"))); // searching entire hierarchy is 1) slow and 2) generates annoying logging from static initialization code. final Set<BeanDefinition> classes = provider.findCandidateComponents("ubic.gemma.core.apps"); classes.addAll(provider.findCandidateComponents("ubic.gemma.core.loader.association.phenotype")); for (BeanDefinition bean : classes) { try { @SuppressWarnings("unchecked") Class<? extends AbstractCLI> aClazz = (Class<? extends AbstractCLI>) Class .forName(bean.getBeanClassName()); Object cliInstance = aClazz.newInstance(); Method method = aClazz.getMethod("getCommandName"); String commandName = (String) method.invoke(cliInstance, new Object[] {}); if (commandName == null || StringUtils.isBlank(commandName)) { // keep null to avoid printing some commands... continue; } Method method2 = aClazz.getMethod("getShortDesc"); String desc = (String) method2.invoke(cliInstance, new Object[] {}); Method method3 = aClazz.getMethod("getCommandGroup"); CommandGroup g = (CommandGroup) method3.invoke(cliInstance, new Object[] {}); if (!commands.containsKey(g)) { commands.put(g, new TreeMap<String, String>()); } commands.get(g).put(commandName, desc + " (" + bean.getBeanClassName() + ")"); commandClasses.put(commandName, aClazz); } catch (Exception e) { // OK, this can happen if we hit a non useful class. } } } catch (Exception e1) { System.err.println("ERROR! Report to developers: " + e1.getMessage()); System.exit(1); } if (args.length == 0 || args[0].equalsIgnoreCase("--help") || args[0].equalsIgnoreCase("-help") || args[0].equalsIgnoreCase("help")) { GemmaCLI.printHelp(commands); } else { LinkedList<String> f = new LinkedList<>(Arrays.asList(args)); String commandRequested = f.remove(0); Object[] argsToPass = f.toArray(new String[] {}); if (!commandClasses.containsKey(commandRequested)) { System.err.println("Unrecognized command: " + commandRequested); GemmaCLI.printHelp(commands); System.err.println("Unrecognized command: " + commandRequested); System.exit(1); } else { try { Class<?> c = commandClasses.get(commandRequested); Method method = c.getMethod("main", String[].class); System.err.println("========= Gemma CLI invocation of " + commandRequested + " ============"); System.err.println("Options: " + GemmaCLI.getOptStringForLogging(argsToPass)); //noinspection JavaReflectionInvocation // It works method.invoke(null, (Object) argsToPass); } catch (Exception e) { System.err.println("Gemma CLI error: " + e.getClass().getName() + " - " + e.getMessage()); System.err.println(ExceptionUtils.getStackTrace(e)); throw new RuntimeException(e); } finally { System.err.println("========= Gemma CLI run of " + commandRequested + " complete ============"); System.exit(0); } } } }
From source file:de.tudarmstadt.ukp.dariah.pipeline.RunPipeline.java
public static void main(String[] args) { Date startDate = new Date(); PrintStream ps;// w w w. j a v a2s.c o m try { ps = new PrintStream("error.log"); System.setErr(ps); } catch (FileNotFoundException e) { System.out.println("Errors cannot be redirected"); } try { if (!parseArgs(args)) { System.out.println("Usage: java -jar pipeline.jar -help"); System.out.println("Usage: java -jar pipeline.jar -input <Input File> -output <Output Folder>"); System.out.println( "Usage: java -jar pipeline.jar -config <Config File> -input <Input File> -output <Output Folder>"); return; } } catch (ParseException e) { e.printStackTrace(); System.out.println( "Error when parsing command line arguments. Use\njava -jar pipeline.jar -help\n to get further information"); System.out.println("See error.log for further details"); return; } LinkedList<String> configFiles = new LinkedList<>(); String configFolder = "configs/"; configFiles.add(configFolder + "default.properties"); //Language dependent properties file String path = configFolder + "default_" + optLanguage + ".properties"; File f = new File(path); if (f.exists()) { configFiles.add(path); } else { System.out.println("Language config file: " + path + " not found"); } String[] configFileArg = new String[0]; for (int i = 0; i < args.length - 1; i++) { if (args[i].equals("-config")) { configFileArg = args[i + 1].split("[,;]"); break; } } for (String configFile : configFileArg) { f = new File(configFile); if (f.exists()) { configFiles.add(configFile); } else { //Check in configs folder path = configFolder + configFile; f = new File(path); if (f.exists()) { configFiles.add(path); } else { System.out.println("Config file: " + configFile + " not found"); return; } } } for (String configFile : configFiles) { try { parseConfig(configFile); } catch (Exception e) { e.printStackTrace(); System.out.println("Exception when parsing config file: " + configFile); System.out.println("See error.log for further details"); } } printConfiguration(configFiles.toArray(new String[0])); try { // Read in the input files String defaultFileExtension = (optReader == ReaderType.XML) ? ".xml" : ".txt"; GlobalFileStorage.getInstance().readFilePaths(optInput, defaultFileExtension, optOutput, optResume); System.out.println("Process " + GlobalFileStorage.getInstance().size() + " files"); CollectionReaderDescription reader; if (optReader == ReaderType.XML) { reader = createReaderDescription(XmlReader.class, XmlReader.PARAM_LANGUAGE, optLanguage); } else { reader = createReaderDescription(TextReaderWithInfo.class, TextReaderWithInfo.PARAM_LANGUAGE, optLanguage); } AnalysisEngineDescription paragraph = createEngineDescription(ParagraphSplitter.class, ParagraphSplitter.PARAM_SPLIT_PATTERN, (optParagraphSingleLineBreak) ? ParagraphSplitter.SINGLE_LINE_BREAKS_PATTERN : ParagraphSplitter.DOUBLE_LINE_BREAKS_PATTERN); AnalysisEngineDescription seg = createEngineDescription(optSegmenterCls, optSegmenterArguments); AnalysisEngineDescription paragraphSentenceCorrector = createEngineDescription( ParagraphSentenceCorrector.class); AnalysisEngineDescription frenchQuotesSeg = createEngineDescription(PatternBasedTokenSegmenter.class, PatternBasedTokenSegmenter.PARAM_PATTERNS, "+|[]"); AnalysisEngineDescription quotesSeg = createEngineDescription(PatternBasedTokenSegmenter.class, PatternBasedTokenSegmenter.PARAM_PATTERNS, "+|[\"\"]"); AnalysisEngineDescription posTagger = createEngineDescription(optPOSTaggerCls, optPOSTaggerArguments); AnalysisEngineDescription lemma = createEngineDescription(optLemmatizerCls, optLemmatizerArguments); AnalysisEngineDescription chunker = createEngineDescription(optChunkerCls, optChunkerArguments); AnalysisEngineDescription morph = createEngineDescription(optMorphTaggerCls, optMorphTaggerArguments); AnalysisEngineDescription hyphenation = createEngineDescription(optHyphenationCls, optHyphenationArguments); AnalysisEngineDescription depParser = createEngineDescription(optDependencyParserCls, optDependencyParserArguments); AnalysisEngineDescription constituencyParser = createEngineDescription(optConstituencyParserCls, optConstituencyParserArguments); AnalysisEngineDescription ner = createEngineDescription(optNERCls, optNERArguments); AnalysisEngineDescription directSpeech = createEngineDescription(DirectSpeechAnnotator.class, DirectSpeechAnnotator.PARAM_START_QUOTE, optStartQuote); AnalysisEngineDescription srl = createEngineDescription(optSRLCls, optSRLArguments); //Requires DKPro 1.8.0 AnalysisEngineDescription coref = createEngineDescription(optCorefCls, optCorefArguments); //StanfordCoreferenceResolver.PARAM_POSTPROCESSING, true AnalysisEngineDescription writer = createEngineDescription(DARIAHWriter.class, DARIAHWriter.PARAM_TARGET_LOCATION, optOutput, DARIAHWriter.PARAM_OVERWRITE, true); AnalysisEngineDescription annWriter = createEngineDescription(AnnotationWriter.class); AnalysisEngineDescription noOp = createEngineDescription(NoOpAnnotator.class); System.out.println("\nStart running the pipeline (this may take a while)..."); while (!GlobalFileStorage.getInstance().isEmpty()) { try { SimplePipeline.runPipeline(reader, paragraph, (optSegmenter) ? seg : noOp, paragraphSentenceCorrector, frenchQuotesSeg, quotesSeg, (optPOSTagger) ? posTagger : noOp, (optLemmatizer) ? lemma : noOp, (optChunker) ? chunker : noOp, (optMorphTagger) ? morph : noOp, (optHyphenation) ? hyphenation : noOp, directSpeech, (optDependencyParser) ? depParser : noOp, (optConstituencyParser) ? constituencyParser : noOp, (optNER) ? ner : noOp, (optSRL) ? srl : noOp, //Requires DKPro 1.8.0 (optCoref) ? coref : noOp, writer // ,annWriter ); } catch (OutOfMemoryError e) { System.out.println("Out of Memory at file: " + GlobalFileStorage.getInstance().getLastPolledFile().getAbsolutePath()); } } Date enddate = new Date(); double duration = (enddate.getTime() - startDate.getTime()) / (1000 * 60.0); System.out.println("---- DONE -----"); System.out.printf("All files processed in %.2f minutes", duration); } catch (ResourceInitializationException e) { System.out.println("Error when initializing the pipeline."); if (e.getCause() instanceof FileNotFoundException) { System.out.println("File not found. Maybe the input / output path is incorrect?"); System.out.println(e.getCause().getMessage()); } e.printStackTrace(); System.out.println("See error.log for further details"); } catch (UIMAException e) { e.printStackTrace(); System.out.println("Error in the pipeline."); System.out.println("See error.log for further details"); } catch (IOException e) { e.printStackTrace(); System.out .println("Error while reading or writing to the file system. Maybe some paths are incorrect?"); System.out.println("See error.log for further details"); } }
From source file:Main.java
public static String[] parseStringList(String list) { // final Pattern patWs = Pattern.compile("\\s+"); final Matcher matchWs = Pattern.compile("[^\\s]+").matcher(""); matchWs.reset(list);/*from w ww . ja v a 2 s.co m*/ LinkedList<String> matchList = new LinkedList<String>(); while (matchWs.find()) { matchList.add(matchWs.group()); } String[] retArr = new String[matchList.size()]; return (String[]) matchList.toArray(retArr); }
From source file:Main.java
public static Element[] getChildrenByName(Element e, String name) { NodeList nl = e.getChildNodes(); int max = nl.getLength(); LinkedList<Node> list = new LinkedList<Node>(); for (int i = 0; i < max; i++) { Node n = nl.item(i);/*from w w w.j ava 2s. c om*/ if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals(name)) { list.add(n); } } return list.toArray(new Element[list.size()]); }
From source file:Main.java
public static Element[] getChildrenByName(Element parentElement, String childrenName) { NodeList nl = parentElement.getChildNodes(); int max = nl.getLength(); LinkedList<Node> list = new LinkedList<Node>(); for (int i = 0; i < max; i++) { Node n = nl.item(i);/*from w w w. j ava 2 s . c o m*/ if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals(childrenName)) { list.add(n); } } return list.toArray(new Element[list.size()]); }
From source file:net.portalblock.untamedchat.bungee.UCConfig.java
private static String[] makeCommandArray(JSONArray array, String... defs) { if (array == null) return defs; LinkedList<String> val = new LinkedList<String>(); for (int i = 0; i < array.length(); i++) { val.add(array.getString(i)); }/* w w w . j av a 2 s. co m*/ return val.toArray(new String[val.size()]); }
From source file:Main.java
public static String[] getChildrenText(Element parentElement, String childrenName) { NodeList nl = parentElement.getChildNodes(); int max = nl.getLength(); LinkedList<String> list = new LinkedList<String>(); for (int i = 0; i < max; i++) { Node n = nl.item(i);/*from w w w. ja va 2 s . c o m*/ if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals(childrenName)) { list.add(getText((Element) n)); } } return list.toArray(new String[list.size()]); }
From source file:Main.java
public static Element[] getChildrenByName(Element element, String paramString) { NodeList localNodeList = element.getChildNodes(); int i = localNodeList.getLength(); LinkedList<Node> nodes = new LinkedList<Node>(); for (int j = 0; j < i; ++j) { Node localNode = localNodeList.item(j); if ((localNode.getNodeType() != 1) || (!localNode.getNodeName().equals(paramString))) continue; nodes.add(localNode);//from w w w . j ava 2s . c om } return (Element[]) nodes.toArray(new Element[nodes.size()]); }