List of usage examples for java.util LinkedList remove
public E remove(int index)
From source file:org.zlogic.vogon.web.controller.AccountsController.java
/** * Updates account list// ww w . java2 s . c om * * @param accounts the new updated accounts list * @param user the authenticated user * @return the accounts list from database after update */ @RequestMapping(method = RequestMethod.POST, produces = "application/json") public @ResponseBody Collection<FinanceAccount> updateAccounts(@RequestBody Collection<FinanceAccount> accounts, @AuthenticationPrincipal VogonSecurityUser user) { List<FinanceAccount> existingAccounts = new ArrayList<>(accountRepository.findByOwner(user.getUser())); LinkedList<FinanceAccount> removedAccounts = new LinkedList<>(existingAccounts); //Merge with database for (FinanceAccount newAccount : accounts) { if (newAccount.getId() == null || !existingAccounts.contains(newAccount)) { FinanceAccount createdAccount = new FinanceAccount(user.getUser(), newAccount); accountRepository.save(createdAccount); } else { FinanceAccount existingAccount = existingAccounts.get(existingAccounts.indexOf(newAccount)); existingAccount.merge(newAccount); removedAccounts.remove(newAccount); } } //Delete removed accounts for (FinanceAccount removedAccount : removedAccounts) { accountRepository.delete(removedAccount); //Delete all related transaction components for (FinanceTransaction transaction : transactionRepository.findByOwner(user.getUser())) { boolean save = false; for (TransactionComponent component : transaction.getComponentsForAccount(removedAccount)) { transaction.removeComponent(component); save = true; } if (save) transactionRepository.save(transaction); } } accountRepository.flush(); transactionRepository.flush(); return accountRepository.findByOwner(user.getUser()); }
From source file:eu.uqasar.model.qmtree.QMTreeNode.java
@SuppressWarnings("unchecked") @Override// w w w. j a v a 2s . c o m public boolean changePositionWithNextSibling(boolean changeParents) { LinkedList<QMTreeNode> directSiblings = (LinkedList<QMTreeNode>) getMutableSiblings(); int currentIndex = directSiblings.indexOf(this); int newIndex = currentIndex + 1; if (newIndex < directSiblings.size()) { // switch currently selected node with the next one QMTreeNode movedNode = directSiblings.remove(currentIndex); directSiblings.add(newIndex, movedNode); getParent().setChildren(directSiblings); logger.info(String.format("Moving %s from index %s to %s", this, currentIndex, newIndex)); return true; } else if (newIndex >= directSiblings.size() && changeParents) { // add currently selected node as first entry to the next parent // sibling LinkedList<QMTreeNode> parentSiblings = (LinkedList<QMTreeNode>) this.getParent().getMutableSiblings(); int parentIndex = parentSiblings.indexOf(this.getParent()); int newParentIndex = parentIndex + 1; if (newParentIndex < parentSiblings.size()) { QMTreeNode oldParent = this.getParent(); LinkedList<QMTreeNode> oldParentChildren = (LinkedList) oldParent.getChildren(); oldParentChildren.removeLast(); oldParent.setChildren(oldParentChildren); QMTreeNode newParent = parentSiblings.get(newParentIndex); logger.info(String.format("Moving %s from parent %s to %s", this, this.getParent(), newParent)); this.setParent(newParent); return true; } } return false; }
From source file:com.gargoylesoftware.htmlunit.WebConsole.java
/** * This method is used by all the public method to process the passed * parameters.//from w ww. j a va 2 s. c o m * * If the last parameter implements the Formatter interface, it will be * used to format the parameters and print the object. * @param objs the logging parameters * @return a String to be printed using the logger */ private String process(final Object[] objs) { if (objs == null) { return "null"; } final StringBuffer sb = new StringBuffer(); final LinkedList<Object> args = new LinkedList<>(Arrays.asList(objs)); final Formatter formatter = getFormatter(); if (args.size() > 1 && args.get(0) instanceof String) { final StringBuilder msg = new StringBuilder((String) args.remove(0)); int startPos = msg.indexOf("%"); while (startPos > -1 && startPos < msg.length() - 1 && args.size() > 0) { if (startPos != 0 && msg.charAt(startPos - 1) == '%') { // double % msg.replace(startPos, startPos + 1, ""); } else { final char type = msg.charAt(startPos + 1); String replacement = null; switch (type) { case 'o': case 's': replacement = formatter.parameterAsString(pop(args)); break; case 'd': case 'i': replacement = formatter.parameterAsInteger(pop(args)); break; case 'f': replacement = formatter.parameterAsFloat(pop(args)); break; default: break; } if (replacement != null) { msg.replace(startPos, startPos + 2, replacement); startPos = startPos + replacement.length(); } else { startPos++; } } startPos = msg.indexOf("%", startPos); } sb.append(msg); } for (final Object o : args) { if (sb.length() != 0) { sb.append(' '); } sb.append(formatter.printObject(o)); } return sb.toString(); }
From source file:strat.mining.stratum.proxy.utils.mining.SHA256HashingUtils.java
/** * Compute the SHA256 midstate of the given 64 bytes of data and return the * 32 bytes midstate. This algorithm is the Java implementation of the * Python implementation got from the Slush0 stratum proxy. * /*from ww w.ja v a2 s. c om*/ * @param data * @return */ public static final byte[] midstateSHA256(byte[] data) { if (data.length != 64) { throw new IndexOutOfBoundsException("Data must be 64 bytes long"); } LinkedList<Long> w = new LinkedList<>(); for (int i = 0; i < 16; i++) { int dataIndex = i * 4; w.add(Longs.fromBytes((byte) 0, (byte) 0, (byte) 0, (byte) 0, data[dataIndex + 3], data[dataIndex + 2], data[dataIndex + 1], data[dataIndex])); } long a = A0; long b = B0; long c = C0; long d = D0; long e = E0; long f = F0; long g = G0; long h = H0; for (long k : K) { long s0 = rotateRight(a, 2) ^ rotateRight(a, 13) ^ rotateRight(a, 22); long s1 = rotateRight(e, 6) ^ rotateRight(e, 11) ^ rotateRight(e, 25); long ma = (a & b) ^ (a & c) ^ (b & c); long ch = (e & f) ^ ((~e) & g); h = addu32(h, w.get(0), k, ch, s1); d = addu32(d, h); h = addu32(h, ma, s0); long tempa = a; a = h; h = g; g = f; f = e; e = d; d = c; c = b; b = tempa; long w1 = w.get(1); long w14 = w.get(14); s0 = rotateRight(w1, 7) ^ rotateRight(w1, 18) ^ (w1 >> 3); s1 = rotateRight(w14, 17) ^ rotateRight(w14, 19) ^ (w14 >> 10); w.add(addu32(w.get(0), s0, w.get(9), s1)); w.remove(0); } a = addu32(a, A0); b = addu32(b, B0); c = addu32(c, C0); d = addu32(d, D0); e = addu32(e, E0); f = addu32(f, F0); g = addu32(g, G0); h = addu32(h, H0); byte[] result = new byte[32]; byte[] bytes = Longs.toByteArray(a); result[0] = bytes[7]; result[1] = bytes[6]; result[2] = bytes[5]; result[3] = bytes[4]; bytes = Longs.toByteArray(b); result[4] = bytes[7]; result[5] = bytes[6]; result[6] = bytes[5]; result[7] = bytes[4]; bytes = Longs.toByteArray(c); result[8] = bytes[7]; result[9] = bytes[6]; result[10] = bytes[5]; result[11] = bytes[4]; bytes = Longs.toByteArray(d); result[12] = bytes[7]; result[13] = bytes[6]; result[14] = bytes[5]; result[15] = bytes[4]; bytes = Longs.toByteArray(e); result[16] = bytes[7]; result[17] = bytes[6]; result[18] = bytes[5]; result[19] = bytes[4]; bytes = Longs.toByteArray(f); result[20] = bytes[7]; result[21] = bytes[6]; result[22] = bytes[5]; result[23] = bytes[4]; bytes = Longs.toByteArray(g); result[24] = bytes[7]; result[25] = bytes[6]; result[26] = bytes[5]; result[27] = bytes[4]; bytes = Longs.toByteArray(h); result[28] = bytes[7]; result[29] = bytes[6]; result[30] = bytes[5]; result[31] = bytes[4]; return result; }
From source file:ldbc.snb.datagen.generator.BTERKnowsGenerator.java
private void generateRemainingEdges() { LinkedList<Integer> stubs = new LinkedList<Integer>(); for (int i = 0; i < graphSize; ++i) { long difference = expectedDegree[i] - adjacencyMatrix[i].getCardinality(); if (difference > 0) { for (int j = 0; j < difference; ++j) { stubs.add(i);/*from ww w . jav a 2 s . c o m*/ } } } Collections.shuffle(stubs, random); while (!stubs.isEmpty()) { int node1 = stubs.get(0); stubs.remove(0); if (!stubs.isEmpty()) { int node2 = stubs.get(0); stubs.remove(0); if (node1 != node2) { adjacencyMatrix[node1].add(node2); adjacencyMatrix[node2].add(node1); } } } }
From source file:com.helpinput.spring.SourceScaner.java
private void replaceList(LinkedList<Node> list, Node oldNode, Node newNode) { int idx = list.indexOf(oldNode); list.remove(idx); list.add(idx, newNode);// w w w .ja v a 2s . c o m }
From source file:com.sun.portal.rssportlet.SettingsHandler.java
private LinkedList fileterFeeds(SettingsBean delta, String[] feedFilter) { LinkedList feeds = delta.getFeeds(); if (null != feedFilter && feedFilter.length != 0) { for (int i = 0; i < feedFilter.length; i++) { for (int j = 0; j < delta.getFeedsSize(); j++) { if (((String) feeds.get(j)).equalsIgnoreCase(feedFilter[i])) { feeds.remove(j); break; }//w w w. j a va 2 s . c om } } } return feeds; }
From source file:org.easyrec.plugin.profileduke.ProfileDukeGenerator.java
@Override protected void doExecute(ExecutionControl executionControl, ProfileDukeStats stats) throws Exception { // when doExecute() is called, the generator has been initialized with the configuration we should use ProfileDukeConfiguration config = getConfiguration(); TypeMappingService typeMappingService = (TypeMappingService) super.getTypeMappingService(); int sourceType = typeMappingService.getIdOfSourceType(config.getTenantId(), this.getId().toString()); itemType = typeMappingService.getIdOfItemType(config.getTenantId(), config.getItemType()); tenantId = config.getTenantId();//w ww. j a v a 2 s.c o m ItemAssocDAO itemAssocDAO = getItemAssocDAO(); // the generator needs to check periodically if abort was requested and stop operation in a clean manner if (executionControl.isAbortRequested()) return; List<ItemVO<Integer, Integer>> itemList = profileService.getItemsByItemType(config.getTenantId(), config.getItemType(), 0); stats.setNumberOfItems(itemList.size()); logger.info("BlockMode: " + config.getBlockCalculationMode()); logger.info("BlockModeBlockSize: " + config.getBlockCalculationBlockSize()); logger.info("ItemListSize: " + itemList.size()); logger.info("Duke Configuration: \n" + config.getDukeConfiguration()); if ("true".equals(config.getBlockCalculationMode())) { LinkedList<ItemVO<Integer, Integer>> itemPot = new LinkedList<ItemVO<Integer, Integer>>(); for (ItemVO<Integer, Integer> item : itemList) { itemPot.add(item); } Random random = new Random(); int blockSize = config.getBlockCalculationBlockSize(); List<ItemVO<Integer, Integer>> itemTempList = new Vector<ItemVO<Integer, Integer>>(); while (itemPot.size() > 0) { itemTempList.add(itemPot.remove(random.nextInt(itemPot.size()))); if (itemPot.size() == 0 || (itemTempList.size() >= blockSize && itemPot.size() > ((float) blockSize * 0.1))) { executionControl.updateProgress(itemList.size() - itemPot.size(), itemList.size() * 2, "calculating item similarity"); if (!prepareAndStartDuke(itemTempList)) { executionControl.updateProgress(1, 1, "Due to an error execution has been aborted!"); return; } itemTempList.clear(); } } } else { executionControl.updateProgress(1, 2, "calculating item similarity"); if (!prepareAndStartDuke(itemList)) { executionControl.updateProgress(1, 1, "Due to an error execution has been aborted!"); return; } } stats.setNumberOfRulesCreated(numberOfAssociationsCreated); // delete associations below the threshold int associationType = typeMappingService.getIdOfAssocType(tenantId, config.getAssociationType()); itemAssocDAO.removeItemAssocByTenant(config.getTenantId(), associationType, sourceType, stats.getStartDate()); }
From source file:eu.uqasar.model.tree.TreeNode.java
@SuppressWarnings("unchecked") @Override/* w ww .jav a 2 s . c o m*/ public boolean changePositionWithPreviousSibling(boolean changeParents) { LinkedList<TreeNode> directSiblings = (LinkedList<TreeNode>) getMutableSiblings(); int currentIndex = directSiblings.indexOf(this); int newIndex = currentIndex - 1; if (currentIndex > 0) { // switch currently selected node with the previous one TreeNode movedNode = directSiblings.remove(currentIndex); directSiblings.add(newIndex, movedNode); getParent().setChildren(directSiblings); logger.info(String.format("Moving %s from index %s to %s", this, currentIndex, newIndex)); return true; } else if (currentIndex == 0 && changeParents) { // add currently selected node as last entry to the previous // parent sibling LinkedList<TreeNode> parentSiblings = (LinkedList<TreeNode>) this.getParent().getMutableSiblings(); int parentIndex = parentSiblings.indexOf(this.getParent()); int newParentIndex = parentIndex - 1; if (parentIndex > 0) { TreeNode oldParent = this.getParent(); LinkedList<TreeNode> oldParentChildren = oldParent.getChildren(); oldParentChildren.remove(0); oldParent.setChildren(oldParentChildren); TreeNode newParent = parentSiblings.get(newParentIndex); logger.info(String.format("Moving %s from parent %s to %s", this, this.getParent(), newParent)); this.setParent(newParent); return true; } } return false; }
From source file:se.backede.jeconomix.forms.report.SingleTransactionReport.java
public void filter() { companyComboBox.setEnabled(false);//from ww w . j a v a 2 s .c o m yearComboBox.setEnabled(false); monthComboBox.setEnabled(false); LinkedList<TransactionDto> allTrasactions = new LinkedList<TransactionDto>(reports.getTransctions()); CompanyDto company = (CompanyDto) companyComboBox.getSelectedItem(); String yearString = (String) yearComboBox.getSelectedItem(); Integer year = Integer.parseInt("0"); if (yearString != null) { if (!yearString.equals(ALL_YEARS)) { year = Integer.parseInt(yearString); } } String monthString = (String) monthComboBox.getSelectedItem(); Month month = null; if (monthString != null) { if (!monthString.equals(ALL_MONTHS)) { month = Month.valueOf(monthString); } } LinkedList<TransactionDto> filteredCompanies = new LinkedList<>(reports.getTransctions()); if (company != null) { if (!company.getName().equals(ALL_COMPANIES)) { filteredCompanies = allTrasactions.stream().filter(line -> line.getCompany().equals(company)) .collect(Collectors.toCollection(LinkedList::new)); } } LinkedList<TransactionDto> filteredByYear = (LinkedList) filteredCompanies.clone(); if (yearString != null) { if (!yearString.equals(ALL_YEARS)) { for (TransactionDto filteredTransaction : filteredCompanies) { if (!Objects.equals(filteredTransaction.getBudgetYear(), year)) { filteredByYear.remove(filteredTransaction); } } } } LinkedList<TransactionDto> filteredByMonth = (LinkedList) filteredByYear.clone(); if (monthString != null) { if (!monthString.equals(ALL_MONTHS)) { for (TransactionDto filteredTransaction : filteredByYear) { if (filteredTransaction.getBudgetMonth() != month) { filteredByMonth.remove(filteredTransaction); } } } } DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer(); rightRenderer.setHorizontalAlignment(JLabel.RIGHT); TransactionCompanyModel transModel = new TransactionCompanyModel(new HashSet<>(filteredByMonth)); transactionTable.setModel(transModel); transactionTable.getColumnModel().getColumn(2).setCellRenderer(rightRenderer); transactionSumLabel.setText(transModel.getSum().toString().concat(" Kr")); categoryNameLabel.setText(reports.getCategory()); companyComboBox.setEnabled(true); yearComboBox.setEnabled(true); monthComboBox.setEnabled(true); }