List of usage examples for java.util LinkedList remove
public E remove(int index)
From source file:rs.fon.whibo.GDT.component.removeInsignificantAttributes.ChiSquareTestCategorical.java
@Override public LinkedList<Attribute> removeAttributes(ExampleSet exampleSet, LinkedList<Attribute> attributesForSplitting) { // checks if the example set is pure, and if it is, it exits the method Attribute label = exampleSet.getAttributes().getLabel(); if (Tools.getAllCategories(exampleSet, label).size() < 2) return attributesForSplitting; // selects the attributes to be evaluated for removal (by calculating // chi-square probability for each attribute) ArrayList<Attribute> attributesToRemove = new ArrayList<Attribute>(); ArrayList<Double> attributeProbabilities = new ArrayList<Double>(); for (Attribute attr : attributesForSplitting) if (attr.isNominal()) { // calculate chi-square probability of the attribute double probability = 0; try { long[][] matrixForAttribute = getContigencyTable(exampleSet, attr); ChiSquareTestImpl chiTest = new ChiSquareTestImpl(); probability = chiTest.chiSquareTest(matrixForAttribute); } catch (MathException me) { // System.out.println("Error in calculating math formula (chiTest)"); }/*from ww w . j a va2s . co m*/ // add the attribute to the list attributesToRemove.add(attr); attributeProbabilities.add(new Double(probability)); } // calculates the percentile of the required percentage. Percentile // variable in code represents the percentage of attributes to be kept // (not removed) double percentile; DescriptiveStatistics stat = new DescriptiveStatistics(); for (Double d : attributeProbabilities) stat.addValue(d.doubleValue()); percentile = stat.getPercentile((1 - Percentage_Remove) * 100); // evaluates attributes and chooses the ones for removal (actually saves // the ones not for removal) Iterator<Attribute> iattr = attributesToRemove.iterator(); Iterator<Double> iprob = attributeProbabilities.iterator(); while (iattr.hasNext()) { iattr.next(); Double prob = iprob.next(); if (Use_Percentage_Instead == 0) { if (prob <= Alpha_Value) { iattr.remove(); iprob.remove(); } } else { if (prob <= percentile) { iattr.remove(); iprob.remove(); } } } // removes the attributes for (Attribute attr : attributesToRemove) attributesForSplitting.remove(attr); return attributesForSplitting; }
From source file:com.oltpbenchmark.benchmarks.auctionmark.AuctionMarkProfile.java
/** * // w w w . j a va 2 s . c o m * @param itemSet * @param needCurrentPrice * @param needFutureEndDate TODO * @return */ private ItemInfo getRandomItem(LinkedList<ItemInfo> itemSet, boolean needCurrentPrice, boolean needFutureEndDate) { Timestamp currentTime = this.updateAndGetCurrentTime(); int num_items = itemSet.size(); int idx = -1; ItemInfo itemInfo = null; if (LOG.isTraceEnabled()) LOG.trace(String.format("Getting random ItemInfo [numItems=%d, currentTime=%s, needCurrentPrice=%s]", num_items, currentTime, needCurrentPrice)); long tries = 1000; tmp_seenItems.clear(); while (num_items > 0 && tries-- > 0 && tmp_seenItems.size() < num_items) { idx = this.rng.nextInt(num_items); ItemInfo temp = itemSet.get(idx); assert (temp != null); if (tmp_seenItems.contains(temp)) continue; tmp_seenItems.add(temp); // Needs to have an embedded currentPrice if (needCurrentPrice && temp.hasCurrentPrice() == false) { continue; } // If they want an item that is ending in the future, then we compare it with // the current timestamp if (needFutureEndDate) { boolean compareTo = (temp.getEndDate().compareTo(currentTime) < 0); if (LOG.isTraceEnabled()) LOG.trace("CurrentTime:" + currentTime + " / EndTime:" + temp.getEndDate() + " [compareTo=" + compareTo + "]"); if (temp.hasEndDate() == false || compareTo) { continue; } } // Uniform itemInfo = temp; break; } // WHILE if (itemInfo == null) { if (LOG.isDebugEnabled()) LOG.debug("Failed to find ItemInfo [hasCurrentPrice=" + needCurrentPrice + ", needFutureEndDate=" + needFutureEndDate + "]"); return (null); } assert (idx >= 0); // Take the item out of the set and insert back to the front // This is so that we can maintain MRU->LRU ordering itemSet.remove(idx); itemSet.addFirst(itemInfo); if (needCurrentPrice) { assert (itemInfo.hasCurrentPrice()) : "Missing currentPrice for " + itemInfo; assert (itemInfo.getCurrentPrice() > 0) : "Negative currentPrice '" + itemInfo.getCurrentPrice() + "' for " + itemInfo; } if (needFutureEndDate) { assert (itemInfo.hasEndDate()) : "Missing endDate for " + itemInfo; } return itemInfo; }
From source file:rs.fon.whibo.GDT.component.removeInsignificantAttributes.FTestNumerical.java
public LinkedList<Attribute> removeAttributes(ExampleSet exampleSet, LinkedList<Attribute> attributesForSplitting) { // checks if the example set is pure, and if it is, it exits the method Attribute label = exampleSet.getAttributes().getLabel(); if (Tools.getAllCategories(exampleSet, label).size() < 2) return attributesForSplitting; // selects the attributes to be evaluated for removal (by calculating // F-test probability for each attribute) ArrayList<Attribute> attributesToRemove = new ArrayList<Attribute>(); ArrayList<Double> attributeProbabilities = new ArrayList<Double>(); for (Attribute attr : attributesForSplitting) if (attr.isNumerical()) { // calculate F-test probability of the attribute double probability = 0; try { OneWayAnova fTest = new OneWayAnovaImpl(); List<double[]> paramForFTest = getArraysByLabel(exampleSet, attr); // tests if no arrays for f-test has fewer that 2 elements boolean fTestImpossible = false; for (double[] i : paramForFTest) if (i.length < 2) fTestImpossible = true; // calculates ftest probability if (!fTestImpossible) probability = fTest.anovaPValue(paramForFTest); } catch (Exception e) { // System.out.println("Error in calculating math formula (FTest)"); }//from w w w. j a va 2 s. c o m // add the attribute to the list attributesToRemove.add(attr); attributeProbabilities.add(new Double(probability)); } if (attributesToRemove.size() == 0) return attributesForSplitting; // calculates the percentile of the required percentage. Percentile // variable in code represents the percentage of attributes to be kept // (not removed) double percentile; DescriptiveStatistics stat = new DescriptiveStatistics(); for (Double d : attributeProbabilities) stat.addValue(d.doubleValue()); percentile = stat.getPercentile((1 - Percentage_Remove) * 100); // evaluates attributes and chooses the ones for removal (actually saves // the ones not for removal) Iterator<Attribute> iattr = attributesToRemove.iterator(); Iterator<Double> iprob = attributeProbabilities.iterator(); while (iattr.hasNext()) { iattr.next(); Double prob = iprob.next(); if (Use_Percentage_Instead == 0) { if (prob <= Alpha_Value) { iattr.remove(); iprob.remove(); } } else { if (prob <= percentile) { iattr.remove(); iprob.remove(); } } } // removes the attributes for (Attribute attr : attributesToRemove) attributesForSplitting.remove(attr); return attributesForSplitting; }
From source file:net.jenet.Peer.java
Packet receive(byte channelID) { Channel channel = selectChannel(channelID); IncomingCommand incomingCommand = null; Packet packet;// w w w. j av a 2 s .c o m LinkedList<IncomingCommand> listRemove = null; if (!channel.getIncomingUnreliableCommands().isEmpty()) { listRemove = channel.getIncomingUnreliableCommands(); incomingCommand = channel.getIncomingUnreliableCommands().getFirst(); if (incomingCommand.getUnreliableSequenceNumber() > 0) if (incomingCommand.getReliableSequenceNumber() > channel.getIncomingReliableSequenceNumber()) incomingCommand = null; else channel.setIncomingUnreliableSequenceNumber(incomingCommand.getUnreliableSequenceNumber()); } if (incomingCommand == null && !channel.getIncomingReliableCommands().isEmpty()) { listRemove = channel.getIncomingReliableCommands(); do { incomingCommand = channel.getIncomingReliableCommands().getFirst(); if (incomingCommand.getFragmentsRemaining() > 0 || incomingCommand .getReliableSequenceNumber() > channel.getIncomingReliableSequenceNumber() + 1) return null; if (incomingCommand.getReliableSequenceNumber() <= channel.getIncomingReliableSequenceNumber()) { channel.getIncomingReliableCommands().remove(incomingCommand); incomingCommand = null; } } while (incomingCommand == null && !channel.getIncomingReliableCommands().isEmpty()); if (incomingCommand == null) return null; channel.setIncomingReliableSequenceNumber(incomingCommand.getReliableSequenceNumber()); if (incomingCommand.getFragmentCount() > 0) channel.setIncomingReliableSequenceNumber( incomingCommand.getReliableSequenceNumber() + incomingCommand.getFragmentCount() - 1); } if (incomingCommand == null) return null; listRemove.remove(incomingCommand); packet = incomingCommand.getPacket(); return packet; }
From source file:org.eclipse.birt.report.model.writer.ModuleWriterImpl.java
/** * Writes the contents of a slot. The order is not the order in the slot * while we first write the ancestor and then the derived ones. The contents * are enclosed in an optional list tag. * //from w w w .jav a 2 s. com * @param obj * the container element * @param slot * the slot to write * @param tag * the optional list tag that encloses the list of contents */ protected void writeArrangedContents(DesignElement obj, int slot, String tag) { List<DesignElement> list = obj.getSlot(slot).getContents(); if (list.isEmpty()) return; LinkedList<DesignElement> newList = new LinkedList<DesignElement>(); Iterator<DesignElement> iter = list.iterator(); while (iter.hasNext()) { DesignElement element = iter.next(); DesignElement parent = element.getExtendsElement(); if (!newList.contains(element)) { newList.add(element); } if (parent != null && list.contains(parent)) { if (!newList.contains(parent)) { int index = newList.indexOf(element); newList.add(index, parent); } else if (newList.indexOf(element) < newList.indexOf(parent)) { newList.remove(parent); int index = newList.indexOf(element); newList.add(index, parent); } } } if (tag != null) writer.conditionalStartElement(tag); // Iterate over the contents using this visitor to write each one. // Note that this may result in a recursive call back into this // method as we do a depth-first traversal of the design tree. iter = newList.iterator(); while (iter.hasNext()) { (iter.next()).apply(this); } if (tag != null) writer.endElement(); }
From source file:com.sshtools.common.ui.SshToolsApplicationClientPanel.java
/** * * * @param newProfile//www . ja v a2 s.com * * @return * * @throws IOException */ protected boolean authenticateUser(boolean newProfile) throws IOException { try { // We should now authenticate int result = AuthenticationProtocolState.READY; // Our authenticated flag boolean authenticated = false; // Get the supported authentication methods java.util.List auths = SshAuthenticationClientFactory.getSupportedMethods(); // Get the available methods java.util.List supported = null; supported = ssh.getAvailableAuthMethods(getCurrentConnectionProfile().getUsername()); if (supported == null) throw new IOException( "There are no authentication methods which both the server and client understand.\n Cannot connect."); // If the server supports external key exchange then we SHOULD use it if (supported.contains("external-keyx")) { EKEYXAuthenticationClient aa = new EKEYXAuthenticationClient(); aa.setProperties(getCurrentConnectionProfile()); aa.setUsername(getCurrentConnectionProfile().getUsername()); result = ssh.authenticate(aa, getCurrentConnectionProfile().getHost()); if (result == AuthenticationProtocolState.COMPLETE) { authenticationComplete(newProfile); return true; } } // If the server supports public key lets look for an agent and try // some of his keys if (supported.contains("publickey")) { if (System.getProperty("sshtools.agent") != null) { try { SshAgentClient agent = SshAgentClient.connectLocalAgent("SSHTerm", System.getProperty("sshtools.agent") /*, 5*/); AgentAuthenticationClient aac = new AgentAuthenticationClient(); aac.setAgent(agent); aac.setUsername(getCurrentConnectionProfile().getUsername()); result = ssh.authenticate(aac, getCurrentConnectionProfile().getHost()); agent.close(); } catch (AgentNotAvailableException ex) { log.info("No agent was available for authentication"); // Just continue } if (result == AuthenticationProtocolState.COMPLETE) { authenticationComplete(newProfile); return true; } } } // Create a list for display that will contain only the // supported and available methods java.util.List display = new java.util.ArrayList(); // Did we receive a banner from the remote computer final String banner = ssh.getAuthenticationBanner(BANNER_TIMEOUT); if (banner != null) { if (!banner.trim().equals("")) { try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { BannerDialog.showBannerDialog(SshToolsApplicationClientPanel.this, banner); } }); } catch (Exception e) { log.error("Failed to invoke and wait on BannerDialog", e); } } } // Are there any authentication methods within the properties file? // Iterate through selecting only the supported and available Iterator it = supported.iterator(); LinkedList allowed = new LinkedList(); while (it.hasNext() && !authenticated) { Object obj = it.next(); if (auths.contains(obj)) { display.add(obj); allowed.add(obj); //System.out.println(obj); } } // First look to see if we have any authenticaiton methods available // in the profile properties object as this will overide a manual selection java.util.Map authMethods = (Map) ((HashMap) getCurrentConnectionProfile().getAuthenticationMethods()) .clone(); it = authMethods.entrySet().iterator(); //Iterator it2 = null; java.util.List selected; // Loop until the user either cancels or completes boolean completed = false; SshAuthenticationClient auth; Map.Entry entry; String msg = null; while (!completed && (ssh.getConnectionState().getValue() != TransportProtocolState.DISCONNECTED)) { auth = null; // Select an authentication method from the properties file or // prompt the user to choose if (it.hasNext()) { Object obj = it.next(); if (obj instanceof Map.Entry) { entry = (Map.Entry) obj; auth = (SshAuthenticationClient) entry.getValue(); } else if (obj instanceof String) { auth = SshAuthenticationClientFactory.newInstance((String) obj, getCurrentConnectionProfile()); auth.setUsername(getCurrentConnectionProfile().getUsername()); } else { closeConnection(true); throw new IOException("Iterator of Map or List of String expected"); } } else { selected = AuthenticationDialog.showAuthenticationDialog(this, display, ((msg == null) ? "" : msg)); if (selected.size() > 0) { it = selected.iterator(); } else { closeConnection(true); return false; } } if (auth != null && !allowed.contains(auth.getMethodName())) auth = null; if (auth != null) { // The password authentication client can act upon requests to change the password /* if (auth instanceof PasswordAuthenticationClient) { PasswordAuthenticationDialog dialog = new PasswordAuthenticationDialog(SshTerminalPanel.this); ((PasswordAuthenticationClient) auth).setAuthenticationPrompt(dialog); ( (PasswordAuthenticationClient) auth) .setPasswordChangePrompt(PasswordChange.getInstance()); PasswordChange.getInstance().setParentComponent( SshTerminalPanel.this); }*/ // Show the implementations dialog // if(auth.showAuthenticationDialog()) { // Authentication with the details supplied try { result = showAuthenticationPrompt(auth); //ssh.authenticate(auth); } catch (IllegalArgumentException e) {// Do not use this authentication method! allowed.remove(auth); } if (result == AuthenticationProtocolState.FAILED) { msg = auth.getMethodName() + " authentication failed, try again?"; } // If the result returned partial success then continue if (result == AuthenticationProtocolState.PARTIAL) { // We succeeded so add to the connections authenticaiton // list and continue on to the next one getCurrentConnectionProfile().addAuthenticationMethod(auth); msg = auth.getMethodName() + " authentication succeeded but another is required"; } if (result == AuthenticationProtocolState.COMPLETE) { authenticated = true; //If successfull add to the connections list so we can save later getCurrentConnectionProfile().addAuthenticationMethod(auth); // Set the completed flag completed = true; authenticationComplete(newProfile); } if (result == AuthenticationProtocolState.CANCELLED) { ssh.disconnect(); return false; } // } // else { // User has cancelled the authenticaiton // closeConnection(true); // return false; // } } // end of if } // end of while return authenticated; } catch (EOFException e) { throw new IOException( "The remote host has closed the connection.\n\nAs you are authenticating this probably means the server has given up authenticating you."); } catch (MessageStoreEOFException e) { throw new IOException( "The remote host has closed the connection.\n\nAs you are authenticating this probably means the server has given up authenticating you."); } }