List of usage examples for java.util LinkedList addAll
public boolean addAll(Collection<? extends E> c)
From source file:org.apache.hama.ml.recommendation.cf.OnlineCF.java
@Override public List<Pair<Long, Double>> getMostSimilarUsers(long user, int count) { Comparator<Pair<Long, Double>> similarityComparator = new Comparator<Pair<Long, Double>>() { @Override//from w ww. ja va 2 s. co m public int compare(Pair<Long, Double> arg0, Pair<Long, Double> arg1) { double difference = arg0.getValue().doubleValue() - arg1.getValue().doubleValue(); return (int) (100000 * difference); } }; PriorityQueue<Pair<Long, Double>> queue = new PriorityQueue<Pair<Long, Double>>(count, similarityComparator); LinkedList<Pair<Long, Double>> results = new LinkedList<Pair<Long, Double>>(); for (Long candidateUser : modelUserFactorizedValues.keySet()) { double similarity = calculateUserSimilarity(user, candidateUser); Pair<Long, Double> targetUser = new Pair<Long, Double>(candidateUser, similarity); queue.add(targetUser); } results.addAll(queue); return results; }
From source file:org.apache.hama.ml.recommendation.cf.OnlineCF.java
@Override public List<Pair<Long, Double>> getMostSimilarItems(long item, int count) { Comparator<Pair<Long, Double>> similarityComparator = new Comparator<Pair<Long, Double>>() { @Override/*w w w .ja v a2 s. c o m*/ public int compare(Pair<Long, Double> arg0, Pair<Long, Double> arg1) { double difference = arg0.getValue().doubleValue() - arg1.getValue().doubleValue(); return (int) (100000 * difference); } }; PriorityQueue<Pair<Long, Double>> queue = new PriorityQueue<Pair<Long, Double>>(count, similarityComparator); LinkedList<Pair<Long, Double>> results = new LinkedList<Pair<Long, Double>>(); for (Long candidateItem : modelItemFactorizedValues.keySet()) { double similarity = calculateItemSimilarity(item, candidateItem); Pair<Long, Double> targetItem = new Pair<Long, Double>(candidateItem, similarity); queue.add(targetItem); } results.addAll(queue); return results; }
From source file:org.pdfsam.plugin.setviewer.listeners.RunButtonActionListener.java
public void actionPerformed(ActionEvent arg0) { if (WorkExecutor.getInstance().getRunningThreads() > 0 || panel.getSelectionPanel().isAdding()) { DialogUtility.showWarningAddingDocument(panel); return;// w ww . j a v a2 s .co m } PdfSelectionTableItem[] items = panel.getSelectionPanel().getTableRows(); if (ArrayUtils.isEmpty(items)) { DialogUtility.showWarningNoDocsSelected(panel, DialogUtility.AT_LEAST_ONE_DOC); return; } LinkedList<String> args = new LinkedList<String>(); // validation and permission check are demanded to the CmdParser object try { // 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; } } args.addAll(getInputFilesArguments(items)); args.add("-" + SetViewerParsedCommand.P_ARG); args.add(panel.getOutPrefixTextField().getText()); args.add("-" + SetViewerParsedCommand.O_ARG); if (StringUtils.isEmpty(panel.getDestFolderText().getText())) { String suggestedDir = getSuggestedDestinationDirectory(items[items.length - 1]); int chosenOpt = DialogUtility.showConfirmOuputLocationDialog(panel, suggestedDir); if (JOptionPane.YES_OPTION == chosenOpt) { panel.getDestFolderText().setText(suggestedDir); } else if (JOptionPane.CANCEL_OPTION == chosenOpt) { return; } } args.add(panel.getDestFolderText().getText()); args.add("-" + SetViewerParsedCommand.L_ARG); args.add(((StringItem) panel.getViewerLayout().getSelectedItem()).getId()); args.add("-" + SetViewerParsedCommand.M_ARG); args.add(((StringItem) panel.getViewerOpenMode().getSelectedItem()).getId()); if (panel.getNonFullScreenMode().isEnabled()) { args.add("-" + SetViewerParsedCommand.NFSM_ARG); args.add(((StringItem) panel.getNonFullScreenMode().getSelectedItem()).getId()); } if (((StringItem) panel.getDirectionCombo().getSelectedItem()).getId().length() > 0) { args.add("-" + SetViewerParsedCommand.DIRECTION_ARG); args.add(((StringItem) panel.getDirectionCombo().getSelectedItem()).getId()); } if (panel.getHideMenuBar().isSelected()) { args.add("-" + SetViewerParsedCommand.HIDEMENU_ARG); } if (panel.getHideToolBar().isSelected()) { args.add("-" + SetViewerParsedCommand.HIDETOOLBAR_ARG); } if (panel.getHideUIElements().isSelected()) { args.add("-" + SetViewerParsedCommand.HIDEWINDOWUI_ARG); } if (panel.getResizeToFit().isSelected()) { args.add("-" + SetViewerParsedCommand.FITWINDOW_ARG); } if (panel.getCenterScreen().isSelected()) { args.add("-" + SetViewerParsedCommand.CENTERWINDOW_ARG); } if (panel.getDisplayTitle().isSelected()) { args.add("-" + SetViewerParsedCommand.DOCTITLE_ARG); } if (panel.getNoPageScaling().isSelected()) { args.add("-" + SetViewerParsedCommand.NOPRINTSCALING_ARG); } if (panel.getOverwriteCheckbox().isSelected()) { args.add("-" + SetViewerParsedCommand.OVERWRITE_ARG); } if (panel.getOutputCompressedCheck().isSelected()) { args.add("-" + SetViewerParsedCommand.COMPRESSED_ARG); } args.add("-" + SetViewerParsedCommand.PDFVERSION_ARG); args.add(((StringItem) panel.getVersionCombo().getSelectedItem()).getId()); args.add(SetViewerParsedCommand.COMMAND_SETVIEWER); String[] myStringArray = (String[]) 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:com.redhat.example.rules.unittest.RuleFactWatcher.java
private void printWatchedAttributes(String ruleName, List<Object> objects, Timing timing) { List<Object> targets = objects; int actualIndex = 0; int expectIndex = 0; // if it is child watcher, require to replace targets by child attributes. if (insertedHeaderClass != null) { LinkedList<Object> subTargets = new LinkedList<Object>(); for (Object obj : objects) { if (insertedHeaderClass.isInstance(obj)) { Object child = accessFunctionFromHeader.apply(obj, accessArgs); if (child instanceof Collection<?>) { subTargets.addAll((Collection<?>) child); } else if (child instanceof Map) { for (Object key : ((Map<?, ?>) child).keySet()) { MapEntry entry = new MapEntry(); entry.key = key; entry.value = ((Map<?, ?>) child).get(key); subTargets.add(entry); }//ww w .j a v a2 s . co m } else { subTargets.add(child); } } } targets = subTargets; } List<ExpectedRecord> workExpectedRecords = new ArrayList<ExpectedRecord>(); for (ExpectedRecord e : expectedRecords) { workExpectedRecords.add(e); } // checkByIndex mode, remove other parents' records if (checkByIndex && parentRow != null) { for (int i = 0; i < workExpectedRecords.size();) { if (!parentRow.equals(workExpectedRecords.get(i).map.get(Constants.parentRowKey))) { workExpectedRecords.remove(i); } else { i++; } } } for (Object obj : targets) { actualIndex++; expectIndex = 0; if (obj != null) { for (ExpectedRecord expect : workExpectedRecords) { expectIndex++; if (expect.fact == null) { if (checkByIndex && actualIndex == expectIndex) { logger.debug( "** expeced record (null) of the actual record [{}] is not null at rule ({})", actualIndex - 1, ruleName); } // skip null record in expected records } else if (isChild && !expect.map.get(Constants.parentRowKey).equals(parentRow)) { // skip if this watcher is child, but parentRow index is not same. } else if ((checkByIndex && actualIndex == expectIndex) || (!checkByIndex && predicate.test(expect, obj))) { // checkByIndex AND index is same OR !checkByIndex AND class type and primary keys match checkAttributes(ruleName, timing, obj, expect); // call child listeners for (RuleFactWatcher childWatcher : childWatcherMap.values()) { childWatcher.parentRow = Integer.toString(expectedRecords.indexOf(expect) + 1); childWatcher.printWatchedAttributes(ruleName, Arrays.asList(obj), timing); } } } } else { if (checkByIndex) { if (workExpectedRecords.size() < actualIndex) { logger.debug( "** expeced record of the actual record [{}] (null) does not exist at rule ({})", actualIndex - 1, ruleName); } else if (workExpectedRecords.get(actualIndex - 1).fact != null) { Object expect = workExpectedRecords.get(actualIndex - 1).fact; logger.debug("** expeced record ({}) {}[{}] of the actual record [{}] is null at rule ({})", expect, clazz.getSimpleName(), actualIndex - 1, actualIndex - 1, ruleName); } } else { logger.warn("** Skipping a null record in the actual records"); } } } }
From source file:objective.taskboard.data.Issue.java
public List<User> getAssignees() { LinkedList<User> assigneeSet = new LinkedList<>(); if (getAssignee().isAssigned()) assigneeSet.add(getAssignee());//from w w w .j av a 2s .c o m assigneeSet.addAll(getCoAssignees()); return assigneeSet; }
From source file:org.pdfsam.plugin.encrypt.listeners.RunButtonActionListener.java
public void actionPerformed(ActionEvent e) { if (WorkExecutor.getInstance().getRunningThreads() > 0 || panel.getSelectionPanel().isAdding()) { DialogUtility.showWarningAddingDocument(panel); return;/* w w w . java 2s . c o m*/ } PdfSelectionTableItem[] items = panel.getSelectionPanel().getTableRows(); if (ArrayUtils.isEmpty(items)) { DialogUtility.showWarningNoDocsSelected(panel, DialogUtility.AT_LEAST_ONE_DOC); return; } LinkedList<String> args = new LinkedList<String>(); // validation and permission check are demanded to the CmdParser object try { // 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; } } args.addAll(getEncPermissions(panel.getPermissionsCheck(), panel.getAllowAllCheck())); args.addAll(getInputFilesArguments(items)); args.add("-" + EncryptParsedCommand.P_ARG); args.add(panel.getOutPrefixTextField().getText()); args.add("-" + EncryptParsedCommand.APWD_ARG); args.add(panel.getOwnerPwdField().getText()); args.add("-" + EncryptParsedCommand.UPWD_ARG); args.add(panel.getUserPwdField().getText()); // check if is needed page option args.add("-" + EncryptParsedCommand.ETYPE_ARG); args.add(EncryptionUtility.getEncAlgorithm((String) panel.getEncryptType().getSelectedItem())); args.add("-" + EncryptParsedCommand.O_ARG); if (StringUtils.isEmpty(panel.getDestFolderText().getText())) { String suggestedDir = getSuggestedDestinationDirectory(items[items.length - 1]); int chosenOpt = DialogUtility.showConfirmOuputLocationDialog(panel, suggestedDir); if (JOptionPane.YES_OPTION == chosenOpt) { panel.getDestFolderText().setText(suggestedDir); } else if (JOptionPane.CANCEL_OPTION == chosenOpt) { return; } } args.add(panel.getDestFolderText().getText()); if (panel.getOverwriteCheckbox().isSelected()) { args.add("-" + EncryptParsedCommand.OVERWRITE_ARG); } if (panel.getOutputCompressedCheck().isSelected()) { args.add("-" + EncryptParsedCommand.COMPRESSED_ARG); } args.add("-" + EncryptParsedCommand.PDFVERSION_ARG); args.add(((StringItem) panel.getVersionCombo().getSelectedItem()).getId()); args.add(AbstractParsedCommand.COMMAND_ENCRYPT); final String[] myStringArray = (String[]) 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:de.unioninvestment.eai.portal.portlet.crud.domain.model.AbstractDataContainer.java
@Override public void addFilters(List<Filter> addedFilters) { LinkedList<Filter> replacementList = new LinkedList<Filter>(filterList); replacementList.addAll(addedFilters); replaceFilters(replacementList, true); }
From source file:com.untangle.uvm.EventManagerImpl.java
/** * Send this event as an email alert notification. * @param rule Matching alert rule.//from w w w. jav a2s . co m * @param event LogEvent to send. * @return boolean if true, alert generated and sent, false if not sent. */ private static boolean sendEmailForEvent(AlertRule rule, LogEvent event) { if (rule.frequencyCheck() == false) { return false; } String companyName = UvmContextFactory.context().brandingManager().getCompanyName(); String hostName = UvmContextFactory.context().networkManager().getNetworkSettings().getHostName(); String domainName = UvmContextFactory.context().networkManager().getNetworkSettings().getDomainName(); String fullName = hostName + (domainName == null ? "" : ("." + domainName)); String serverName = companyName + " " + I18nUtil.marktr("Server"); JSONObject jsonObject = event.toJSONObject(); String jsonString; cleanupJsonObject(jsonObject); try { jsonString = jsonObject.toString(4); } catch (org.json.JSONException e) { logger.warn("Failed to pretty print.", e); jsonString = jsonObject.toString(); } String subject = serverName + " " + I18nUtil.marktr("Event!") + " [" + fullName + "] "; String messageBody = I18nUtil.marktr("The following event occurred on the") + " " + serverName + " @ " + event.getTimeStamp() + "\r\n\r\n" + rule.getDescription() + ":" + "\r\n" + event.toSummaryString() + "\r\n\r\n" + I18nUtil.marktr("Causal Event:") + " " + event.getClass().getSimpleName() + "\r\n" + jsonString + "\r\n\r\n" + I18nUtil.marktr( "This is an automated message sent because the event matched the configured Event Rules."); LinkedList<String> alertRecipients = new LinkedList<String>(); /* * Local admin users */ LinkedList<AdminUserSettings> adminManagerUsers = UvmContextFactory.context().adminManager().getSettings() .getUsers(); if (adminManagerUsers != null) { for (AdminUserSettings user : adminManagerUsers) { if (user.getEmailAddress() == null || "".equals(user.getEmailAddress())) { continue; } if (!user.getEmailAlerts()) { continue; } alertRecipients.add(user.getEmailAddress()); } } /* * Report users */ App reportsApp = UvmContextFactory.context().appManager().app("reports"); List<String> reportsEmailAddresses = ((Reporting) reportsApp).getAlertEmailAddresses(); alertRecipients.addAll(reportsEmailAddresses); for (String emailAddress : alertRecipients) { logger.warn("emailAddress=" + emailAddress); try { String[] recipients = null; recipients = new String[] { emailAddress }; UvmContextFactory.context().mailSender().sendMessage(recipients, subject, messageBody); } catch (Exception e) { logger.warn("Failed to send mail.", e); } } return true; }
From source file:org.camlistore.UploadService.java
LinkedList<QueuedFile> uploadQueue() { synchronized (this) { LinkedList<QueuedFile> copy = new LinkedList<QueuedFile>(); copy.addAll(mQueueList); return copy; }//www . j a v a 2 s .c om }
From source file:org.apache.hadoop.yarn.util.SmapsBasedProcessTree.java
/** * Update process-tree with latest state. If the root-process is not alive, * tree will be empty.//from w ww .j a v a 2s . c o m * */ @Override public void updateProcessTree() { if (!pid.equals(deadPid)) { // Get the list of processes List<String> processList = getProcessList(); Map<String, ProcessInfo> allProcessInfo = new HashMap<String, ProcessInfo>(); // cache the processTree to get the age for processes Map<String, ProcessInfo> oldProcs = new HashMap<String, ProcessInfo>(processTree); processTree.clear(); ProcessInfo me = null; for (String proc : processList) { // Get information for each process ProcessInfo pInfo = new ProcessInfo(proc); if (constructProcessInfo(pInfo, procfsDir) != null) { allProcessInfo.put(proc, pInfo); if (proc.equals(this.pid)) { me = pInfo; // cache 'me' processTree.put(proc, pInfo); } } } if (me == null) { return; } // Add each process to its parent. for (Map.Entry<String, ProcessInfo> entry : allProcessInfo.entrySet()) { String pID = entry.getKey(); if (!pID.equals("1")) { ProcessInfo pInfo = entry.getValue(); ProcessInfo parentPInfo = allProcessInfo.get(pInfo.getPpid()); if (parentPInfo != null) { parentPInfo.addChild(pInfo); } } } // now start constructing the process-tree LinkedList<ProcessInfo> pInfoQueue = new LinkedList<ProcessInfo>(); pInfoQueue.addAll(me.getChildren()); while (!pInfoQueue.isEmpty()) { ProcessInfo pInfo = pInfoQueue.remove(); if (!processTree.containsKey(pInfo.getPid())) { processTree.put(pInfo.getPid(), pInfo); } pInfoQueue.addAll(pInfo.getChildren()); } // update age values and compute the number of jiffies since last update for (Map.Entry<String, ProcessInfo> procs : processTree.entrySet()) { ProcessInfo oldInfo = oldProcs.get(procs.getKey()); if (procs.getValue() != null) { procs.getValue().updateJiffy(oldInfo); if (oldInfo != null) { procs.getValue().updateAge(oldInfo); } } } if (LOG.isDebugEnabled()) { // Log.debug the ProcfsBasedProcessTree LOG.debug(this.toString()); } } // Update PSS related information for (ProcessInfo p : processTree.values()) { if (p != null) { // Get information for each process ProcessMemInfo memInfo = new ProcessMemInfo(p.getPid()); constructProcessSMAPInfo(memInfo, procfsDir); processSMAPTree.put(p.getPid(), memInfo); } } }