List of usage examples for java.util LinkedList addAll
public boolean addAll(Collection<? extends E> c)
From source file:org.pdfsam.plugin.vcomposer.listeners.RunButtonActionListener.java
public void actionPerformed(ActionEvent e) { if (!panel.getComposerPanel().hasValidElements()) { JOptionPane.showMessageDialog(panel, GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "Please select a pdf document or undelete some pages"), GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "Warning"), JOptionPane.WARNING_MESSAGE); return;/* w ww. j a v a 2 s . com*/ } if (StringUtils.isEmpty(panel.getDestinationFileText().getText())) { DialogUtility.showWarningNoDestinationSelected(panel, DialogUtility.FILE_DESTINATION); return; } // overwrite confirmation if (panel.getOverwriteCheckbox().isSelected() && Configuration.getInstance().isAskOverwriteConfirmation()) { int dialogRet = DialogUtility.askForOverwriteConfirmation(panel); if (JOptionPane.NO_OPTION == dialogRet) { panel.getOverwriteCheckbox().setSelected(false); } else if (JOptionPane.CANCEL_OPTION == dialogRet) { return; } } LinkedList<String> args = new LinkedList<String>(); try { args.addAll(panel.getComposerPanel().getValidConsoleParameters()); // rotation String rotation = panel.getComposerPanel().getRotatedElementsString(); if (rotation != null && rotation.length() > 0) { args.add("-" + ConcatParsedCommand.R_ARG); args.add(rotation); } String destination = ""; // if no extension given ensurePdfExtensionOnTextField(panel.getDestinationFileText()); File destinationDir = new File(panel.getDestinationFileText().getText()); File parent = destinationDir.getParentFile(); if (!(parent != null && parent.exists())) { String suggestedDir = null; if (Configuration.getInstance().getDefaultWorkingDirectory() != null && Configuration.getInstance().getDefaultWorkingDirectory().length() > 0) { suggestedDir = new File(Configuration.getInstance().getDefaultWorkingDirectory(), destinationDir.getName()).getAbsolutePath(); } if (suggestedDir != null) { int chosenOpt = DialogUtility.showConfirmOuputLocationDialog(panel, suggestedDir); if (JOptionPane.YES_OPTION == chosenOpt) { panel.getDestinationFileText().setText(suggestedDir); } else if (JOptionPane.CANCEL_OPTION == chosenOpt) { return; } } } destination = panel.getDestinationFileText().getText(); // check if the file already exists and the user didn't select to overwrite File destFile = (destination != null) ? new File(destination) : null; if (destFile != null && destFile.exists() && !panel.getOverwriteCheckbox().isSelected()) { int chosenOpt = DialogUtility.askForOverwriteOutputFileDialog(panel, destFile.getName()); if (JOptionPane.YES_OPTION == chosenOpt) { panel.getOverwriteCheckbox().setSelected(true); } else if (JOptionPane.CANCEL_OPTION == chosenOpt) { return; } } args.add("-" + ConcatParsedCommand.O_ARG); args.add(destination); if (panel.getOverwriteCheckbox().isSelected()) args.add("-" + ConcatParsedCommand.OVERWRITE_ARG); if (panel.getOutputCompressedCheck().isSelected()) args.add("-" + ConcatParsedCommand.COMPRESSED_ARG); args.add("-" + ConcatParsedCommand.PDFVERSION_ARG); args.add(((StringItem) panel.getVersionCombo().getSelectedItem()).getId()); args.add(AbstractParsedCommand.COMMAND_CONCAT); String[] myStringArray = args.toArray(new String[args.size()]); WorkExecutor.getInstance().execute(new WorkThread(myStringArray)); } catch (Exception ex) { log.error(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "Error: "), ex); SoundPlayer.getInstance().playErrorSound(); } }
From source file:edu.cornell.mannlib.vitro.webapp.dao.jena.SparqlGraphMultilingual.java
@Override public ExtendedIterator<Triple> find(Node subject, Node predicate, Node object) { long startTime = System.currentTimeMillis(); ExtendedIterator<Triple> rawResults = super.find(subject, predicate, object); long rawTime = System.currentTimeMillis() - startTime; List<Triple> tripList = new ArrayList<Triple>(); while (rawResults.hasNext()) { tripList.add(rawResults.next()); }/*from w w w . j a v a 2 s .co m*/ if (tripList.size() == 0) { return WrappedIterator.create(tripList.iterator()); } if (subject.isConcrete() && predicate.isConcrete() && !object.isConcrete()) { Collections.sort(tripList, new TripleSortByLang()); LinkedList<Triple> tripl = new LinkedList<Triple>(); if (!tripList.get(0).getObject().isLiteral()) { tripl.addAll(tripList); } else if (StringUtils.isEmpty(tripList.get(0).getObject().getLiteralLanguage())) { tripl.addAll(tripList); // is this right? } else { String lang = tripList.get(0).getObject().getLiteralLanguage(); for (Triple t : tripList) { if (lang.equals(t.getObject().getLiteralLanguage())) { tripl.add(t); } else { break; } } } long filterTime = System.currentTimeMillis() - rawTime - startTime; if (filterTime > 1) { log.info("raw time " + rawTime + " ; filter time " + filterTime); } return WrappedIterator.create(tripl.iterator()); } else { if (rawTime > 9) { log.info("raw time " + rawTime); log.info("^ " + subject + " : " + predicate + " : " + object); } return WrappedIterator.create(tripList.iterator()); } }
From source file:be.ac.ua.comp.scarletnebula.gui.ServerListModel.java
/** * Sets the model filter to "filterString" * //from w ww. ja va 2 s. c o m * @param filterString */ public void filter(final String filterString) { final LinkedList<Server> allServers = new LinkedList<Server>(); allServers.addAll(visibleServers); allServers.addAll(invisibleServers); final int oldVisibleCount = getSize(); visibleServers.clear(); invisibleServers.clear(); fireIntervalRemoved(this, 0, oldVisibleCount - 1); // Make a collection of tokens from a filterString, pass that to each // server and ask it if matches. final Collection<String> filterTerms = SearchHelper.tokenize(filterString); for (final Server server : allServers) { if (server.match(filterTerms)) { visibleServers.add(server); } else { invisibleServers.add(server); } } fireIntervalAdded(this, 0, getSize() - 1); }
From source file:org.pdfsam.plugin.vpagereorder.listeners.RunButtonActionListener.java
public void actionPerformed(ActionEvent e) { File inputFile = panel.getSelectionPanel().getSelectedPdfDocument(); if (inputFile == null || !panel.getSelectionPanel().hasValidElements()) { JOptionPane.showMessageDialog(panel, GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "Please select a pdf document or undelete some page"), GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "Warning"), JOptionPane.WARNING_MESSAGE); return;//from w w w . j av a 2 s .c o m } if (!panel.getSameAsSourceRadio().isSelected() && StringUtils.isEmpty(panel.getDestinationFileText().getText())) { DialogUtility.showWarningNoDestinationSelected(panel, DialogUtility.FILE_DESTINATION); return; } // overwrite confirmation if (panel.getOverwriteCheckbox().isSelected() && Configuration.getInstance().isAskOverwriteConfirmation()) { int dialogRet = DialogUtility.askForOverwriteConfirmation(panel); if (JOptionPane.NO_OPTION == dialogRet) { panel.getOverwriteCheckbox().setSelected(false); } else if (JOptionPane.CANCEL_OPTION == dialogRet) { return; } } LinkedList<String> args = new LinkedList<String>(); try { args.addAll(panel.getSelectionPanel().getValidConsoleParameters()); // rotation String rotation = panel.getSelectionPanel().getRotatedElementsString(); if (rotation != null && rotation.length() > 0) { args.add("-" + ConcatParsedCommand.R_ARG); args.add(rotation); } String destination = ""; // check radio for output options if (panel.getSameAsSourceRadio().isSelected()) { if (inputFile != null) { destination = inputFile.getAbsolutePath(); } } else { // if no extension given ensurePdfExtensionOnTextField(panel.getDestinationFileText()); File destinationDir = new File(panel.getDestinationFileText().getText()); File parent = destinationDir.getParentFile(); if (!(parent != null && parent.exists())) { String suggestedDir = null; if (Configuration.getInstance().getDefaultWorkingDirectory() != null && Configuration.getInstance().getDefaultWorkingDirectory().length() > 0) { suggestedDir = new File(Configuration.getInstance().getDefaultWorkingDirectory(), destinationDir.getName()).getAbsolutePath(); } else { suggestedDir = new File(inputFile.getParent(), destinationDir.getName()).getAbsolutePath(); } if (suggestedDir != null) { int chosenOpt = DialogUtility.showConfirmOuputLocationDialog(panel, suggestedDir); if (JOptionPane.YES_OPTION == chosenOpt) { panel.getDestinationFileText().setText(suggestedDir); } else if (JOptionPane.CANCEL_OPTION == chosenOpt) { return; } } } destination = panel.getDestinationFileText().getText(); } // check if the file already exists and the user didn't select to overwrite File destFile = (destination != null) ? new File(destination) : null; if (destFile != null && destFile.exists() && !panel.getOverwriteCheckbox().isSelected()) { int chosenOpt = DialogUtility.askForOverwriteOutputFileDialog(panel, destFile.getName()); if (JOptionPane.YES_OPTION == chosenOpt) { panel.getOverwriteCheckbox().setSelected(true); } else if (JOptionPane.CANCEL_OPTION == chosenOpt) { return; } } args.add("-" + ConcatParsedCommand.O_ARG); args.add(destination); if (panel.getOverwriteCheckbox().isSelected()) args.add("-" + ConcatParsedCommand.OVERWRITE_ARG); if (panel.getOutputCompressedCheck().isSelected()) args.add("-" + ConcatParsedCommand.COMPRESSED_ARG); args.add("-" + ConcatParsedCommand.PDFVERSION_ARG); args.add(((StringItem) panel.getVersionCombo().getSelectedItem()).getId()); args.add(AbstractParsedCommand.COMMAND_CONCAT); String[] myStringArray = args.toArray(new String[args.size()]); WorkExecutor.getInstance().execute(new WorkThread(myStringArray)); } catch (Exception ex) { log.error(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "Error: "), ex); SoundPlayer.getInstance().playErrorSound(); } }
From source file:org.kevoree.platform.android.boot.view.ManagerUI.java
/** * this method is charge of restoring views during a rotation of the screen *//*w w w.j a v a 2 s .c o m*/ public void restoreViews(FragmentActivity newctx) { if (ctx.getSupportActionBar().getTabAt(selectedTab) == null) { selectedTab = ktab; } ctx.getSupportActionBar().removeAllTabs(); newctx.getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); ctx = newctx; LinkedList<ActionBar.Tab> backup = new LinkedList<ActionBar.Tab>(); backup.addAll(tabs); tabs.clear(); for (ActionBar.Tab tab : backup) { Log.i(TAG, "Restore " + tab.getText()); // if exist remove parent View contentView = (View) tab.getTag(); if (contentView.getParent() != null) { ((ViewGroup) contentView.getParent()).removeView(contentView); } LinearLayout tabLayout = (LinearLayout) contentView; int childcount = tabLayout.getChildCount(); for (int i = 0; i < childcount; i++) { View v = tabLayout.getChildAt(i); if (v != null) { // remove link to linearlayout if (v.getParent() != null) { ((ViewGroup) v.getParent()).removeView(v); } addToGroup(tab.getText().toString(), v); } } } try { ctx.getSupportActionBar().setSelectedNavigationItem(selectedTab); } catch (Exception e) { // ignore } }
From source file:org.apache.cayenne.access.loader.filters.ListFilter.java
@Override public Filter<T> join(Filter<T> filter) { LinkedList<Filter<T>> list = new LinkedList<Filter<T>>(filters); if (TRUE.equals(filter) || NULL.equals(filter)) { // Do nothing. } else if (filter instanceof ListFilter) { list.addAll(((ListFilter<T>) filter).filters); } else {//w w w.j ava 2 s . co m list.add(filter); } return new ListFilter<T>(list); }
From source file:com.amazonaws.services.logs.connectors.kinesis.KinesisTransformer.java
protected Collection<Record> createRecords(Collection<CloudWatchLogsEvent> events) throws IOException { Record one = createRecord(events);/*ww w.ja va 2 s.co m*/ if (one != null) { // can be serialized properly if (one.getData().capacity() > MAX_KINESIS_RECORD_SIZE) { if (events.size() == 1) { LOG.error("event too large for kinesis record"); // return empty } else { // best guess split and retry int bytesPerEvent = one.getData().capacity() / events.size(); // ensure split at least in half int maxEventsPerPartition = Math.min(MAX_KINESIS_RECORD_SIZE / bytesPerEvent, events.size() / 2); Collection<Collection<CloudWatchLogsEvent>> partitions = partition( new ArrayList<CloudWatchLogsEvent>(events), maxEventsPerPartition); LinkedList<Record> records = new LinkedList<Record>(); for (Collection<CloudWatchLogsEvent> partition : partitions) { records.addAll(createRecords(partition)); } return records; } } else { return Collections.singleton(one); } } return Collections.emptyList(); }
From source file:org.dspace.app.rest.link.HalLinkService.java
public void addLinks(HALResource halResource, Pageable pageable) throws Exception { LinkedList<Link> links = new LinkedList<>(); List<HalLinkFactory> supportedFactories = getSupportedFactories(halResource); for (HalLinkFactory halLinkFactory : supportedFactories) { links.addAll(halLinkFactory.getLinksFor(halResource, pageable)); }//from w w w . java 2 s . c o m links.sort((Link l1, Link l2) -> ObjectUtils.compare(l1.getRel(), l2.getRel())); halResource.add(links); for (Object obj : halResource.getEmbeddedResources().values()) { if (obj instanceof Collection) { for (Object subObj : (Collection) obj) { if (subObj instanceof HALResource) { addLinks((HALResource) subObj); } } } else if (obj instanceof Map) { for (Object subObj : ((Map) obj).values()) { if (subObj instanceof HALResource) { addLinks((HALResource) subObj); } } } else if (obj instanceof EmbeddedPage) { for (Map.Entry<String, List> pageContent : ((EmbeddedPage) obj).getPageContent().entrySet()) { for (Object subObj : CollectionUtils.emptyIfNull(pageContent.getValue())) { if (subObj instanceof HALResource) { addLinks((HALResource) subObj); } } } } else if (obj instanceof HALResource) { addLinks((HALResource) obj); } } }
From source file:org.trnltk.experiment.bruteforce.BruteForceExperiments.java
@Test public void shouldParseTbmmJournal_b0241h() throws IOException { final File tokenizedFile = new File("core/src/test/resources/tokenizer/tbmm_b0241h_tokenized.txt"); final List<String> lines = Files.readLines(tokenizedFile, Charsets.UTF_8); final LinkedList<String> words = new LinkedList<String>(); for (String line : lines) { words.addAll(Lists.newArrayList(Splitter.on(" ").trimResults().omitEmptyStrings().split(line))); }//from ww w . ja v a 2s. c o m final StopWatch stopWatch = new StopWatch(); int parseResultCount = 0; final int MAX_WORD_LENGTH = 100; int[] wordCountsByLength = new int[MAX_WORD_LENGTH]; int[] parseResultCountTotalsByTokenLength = new int[MAX_WORD_LENGTH]; stopWatch.start(); stopWatch.suspend(); for (String word : words) { stopWatch.resume(); final LinkedList<MorphemeContainer> morphemeContainers = parser.parse(new TurkishSequence(word)); stopWatch.suspend(); if (morphemeContainers.isEmpty()) System.out.println("Word is not parsable " + word); parseResultCount += morphemeContainers.size(); parseResultCountTotalsByTokenLength[word.length()] += morphemeContainers.size(); wordCountsByLength[word.length()]++; } stopWatch.stop(); final double[] parseResultCountAvgsByLength = new double[MAX_WORD_LENGTH]; for (int i = 0; i < parseResultCountTotalsByTokenLength.length; i++) { int totalParseResultCount = parseResultCountTotalsByTokenLength[i]; final int wordCount = wordCountsByLength[i]; parseResultCountAvgsByLength[i] = Double.valueOf(totalParseResultCount) / Double.valueOf(wordCount); } System.out.println("Total time :" + stopWatch.toString()); System.out.println("Nr of tokens : " + words.size()); System.out.println("Nr of parse results : " + parseResultCount); System.out.println("Avg time : " + (stopWatch.getTime() * 1.0d) / (words.size() * 1.0d) + " ms"); System.out.println("Avg parse result count : " + (parseResultCount * 1.0) / (words.size() * 1.0)); System.out.println("Word counts by token length " + "\n\t" + Arrays.toString(wordCountsByLength)); System.out.println("Parse result count totals by token length " + "\n\t" + Arrays.toString(parseResultCountTotalsByTokenLength)); System.out.println("Parse result count avgs by token length " + "\n\t" + Arrays.toString(parseResultCountAvgsByLength)); }
From source file:cn.vlabs.duckling.vwb.service.config.impl.DomainServiceImpl.java
@Override public String[] getUsedDomain(int siteId) { Map<String, String> keys = siteConfig.getInteranlPeopertyStartWith(siteId, KeyConstants.SITE_DOMAIN_KEY); LinkedList<String> keyList = new LinkedList<String>(); keyList.addAll(keys.keySet()); Collections.sort(keyList, new Comparator<String>() { public int compare(String o1, String o2) { return o1.compareTo(o2); }/*from ww w. j a v a 2 s . co m*/ }); String[] domains = new String[keys.size()]; int index = 0; for (String key : keyList) { domains[index] = keys.get(key); index++; } return domains; }