List of usage examples for java.util LinkedList size
int size
To view the source code for java.util LinkedList size.
Click Source Link
From source file:appeng.items.tools.powered.ToolColorApplicator.java
private ItemStack findNextColor(final ItemStack is, final ItemStack anchor, final int scrollOffset) { ItemStack newColor = null;/*from w ww . j a va2 s.com*/ final IMEInventory<IAEItemStack> inv = AEApi.instance().registries().cell().getCellInventory(is, null, StorageChannel.ITEMS); if (inv != null) { final IItemList<IAEItemStack> itemList = inv .getAvailableItems(AEApi.instance().storage().createItemList()); if (anchor == null) { final IAEItemStack firstItem = itemList.getFirstItem(); if (firstItem != null) { newColor = firstItem.getItemStack(); } } else { final LinkedList<IAEItemStack> list = new LinkedList<IAEItemStack>(); for (final IAEItemStack i : itemList) { list.add(i); } Collections.sort(list, new Comparator<IAEItemStack>() { @Override public int compare(final IAEItemStack a, final IAEItemStack b) { return ItemSorters.compareInt(a.getItemDamage(), b.getItemDamage()); } }); if (list.size() <= 0) { return null; } IAEItemStack where = list.getFirst(); int cycles = 1 + list.size(); while (cycles > 0 && !where.equals(anchor)) { list.addLast(list.removeFirst()); cycles--; where = list.getFirst(); } if (scrollOffset > 0) { list.addLast(list.removeFirst()); } if (scrollOffset < 0) { list.addFirst(list.removeLast()); } return list.get(0).getItemStack(); } } if (newColor != null) { this.setColor(is, newColor); } return newColor; }
From source file:com.evolveum.midpoint.test.ldap.OpenDJController.java
public Entry searchByEntryUuid(String entryUuid) throws DirectoryException { InternalSearchOperation op = getInternalConnection().processSearch("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, DereferencePolicy.NEVER_DEREF_ALIASES, 100, 100, false, "(entryUUID=" + entryUuid + ")", getSearchAttributes()); LinkedList<SearchResultEntry> searchEntries = op.getSearchEntries(); if (searchEntries == null || searchEntries.isEmpty()) { return null; }//from www. j av a2 s. c o m if (searchEntries.size() > 1) { AssertJUnit.fail("Multiple matches for Entry UUID " + entryUuid + ": " + searchEntries); } return searchEntries.get(0); }
From source file:com.facebook.presto.accumulo.examples.TpcHClerkSearch.java
@Override public int run(AccumuloConfig config, CommandLine cmd) throws Exception { String[] searchTerms = cmd.getOptionValues(CLERK_ID); ZooKeeperInstance inst = new ZooKeeperInstance(config.getInstance(), config.getZooKeepers()); Connector conn = inst.getConnector(config.getUsername(), new PasswordToken(config.getPassword())); // Ensure both tables exists validateExists(conn, DATA_TABLE);/* w w w.j a v a 2 s. c o m*/ validateExists(conn, INDEX_TABLE); long start = System.currentTimeMillis(); // Create a scanner against the index table BatchScanner idxScanner = conn.createBatchScanner(INDEX_TABLE, new Authorizations(), 10); LinkedList<Range> searchRanges = new LinkedList<Range>(); // Create a search Range from the command line args for (String searchTerm : searchTerms) { if (clerkRegex.matcher(searchTerm).matches()) { searchRanges.add(new Range(searchTerm)); } else { throw new InvalidParameterException( format("Search term %s does not match regex Clerk#[0-9]{9}", searchTerm)); } } // Set the search ranges for our scanner idxScanner.setRanges(searchRanges); // A list to hold all of the order IDs LinkedList<Range> orderIds = new LinkedList<Range>(); String orderId; // Process all of the records returned by the batch scanner for (Map.Entry<Key, Value> record : idxScanner) { // Get the order ID and add it to the list of order IDs orderIds.add(new Range(record.getKey().getColumnQualifier())); } // Close the batch scanner idxScanner.close(); // If clerkIDs is empty, log a message and return 0 if (orderIds.isEmpty()) { System.out.println("Found no orders with the given Clerk ID(s)"); return 0; } else { System.out.println(format("Searching data table for %d orders", orderIds.size())); } // Initialize the batch scanner to scan the data table with // the previously found order IDs as the ranges BatchScanner dataScanner = conn.createBatchScanner(DATA_TABLE, new Authorizations(), 10); dataScanner.setRanges(orderIds); dataScanner.addScanIterator(new IteratorSetting(1, WholeRowIterator.class)); Text row = new Text(); // The row ID Text colQual = new Text(); // The column qualifier of the current record Long orderkey = null; Long custkey = null; String orderstatus = null; Double totalprice = null; Date orderdate = null; String orderpriority = null; String clerk = null; Long shippriority = null; String comment = null; int numTweets = 0; // Process all of the records returned by the batch scanner for (Map.Entry<Key, Value> entry : dataScanner) { entry.getKey().getRow(row); orderkey = decode(Long.class, row.getBytes(), row.getLength()); SortedMap<Key, Value> rowMap = WholeRowIterator.decodeRow(entry.getKey(), entry.getValue()); for (Map.Entry<Key, Value> record : rowMap.entrySet()) { // Get the column qualifier from the record's key record.getKey().getColumnQualifier(colQual); switch (colQual.toString()) { case CUSTKEY_STR: custkey = decode(Long.class, record.getValue().get()); break; case ORDERSTATUS_STR: orderstatus = decode(String.class, record.getValue().get()); break; case TOTALPRICE_STR: totalprice = decode(Double.class, record.getValue().get()); break; case ORDERDATE_STR: orderdate = decode(Date.class, record.getValue().get()); break; case ORDERPRIORITY_STR: orderpriority = decode(String.class, record.getValue().get()); break; case CLERK_STR: clerk = decode(String.class, record.getValue().get()); break; case SHIPPRIORITY_STR: shippriority = decode(Long.class, record.getValue().get()); break; case COMMENT_STR: comment = decode(String.class, record.getValue().get()); break; default: throw new RuntimeException("Unknown column qualifier " + colQual); } } ++numTweets; // Write the screen name and text to stdout System.out.println(format("%d|%d|%s|%f|%s|%s|%s|%d|%s", orderkey, custkey, orderstatus, totalprice, orderdate, orderpriority, clerk, shippriority, comment)); custkey = null; shippriority = null; orderstatus = null; orderpriority = null; clerk = null; comment = null; totalprice = null; orderdate = null; } // Close the batch scanner dataScanner.close(); long finish = System.currentTimeMillis(); System.out.format("Found %d orders in %s ms\n", numTweets, (finish - start)); return 0; }
From source file:com.addthis.hydra.data.filter.value.ValueFilterHttpGet.java
@Override public void postDecode() { if (persist) { persistTo = LessFiles.initDirectory(persistDir); LinkedList<CacheObject> list = new LinkedList<>(); for (File file : persistTo.listFiles()) { if (file.isFile()) { try { CacheObject cached = codec.decode(CacheObject.class, LessFiles.read(file)); cached.hash = file.getName(); list.add(cached);// w ww . j a v a 2 s . c o m if (log.isDebugEnabled()) { log.debug("restored " + cached.hash + " as " + cached.key); } } catch (Exception e) { e.printStackTrace(); } } } // sort so that hot map has the most recent inserted last CacheObject[] sort = new CacheObject[list.size()]; list.toArray(sort); Arrays.sort(sort); for (CacheObject cached : sort) { if (log.isDebugEnabled()) { log.debug("insert into hot " + cached.hash + " as " + cached.key); } cache.put(cached.key, cached); } } }
From source file:edu.umass.cs.msocket.gns.GnsSocketAddress.java
/** * Get all IP address/port number for the given service belonging to the guid. * // w w w. j a va 2 s .co m * @param guid guid to lookup * @param serviceName service to access * @return array of InetSocketAddres or null if no address was found * @throws Exception if a GNS error occurs */ public GnsSocketAddress[] getAllByGuid(String guid, String serviceName) throws Exception { JSONArray addresses = gnsClient.fieldRead(guid, serviceName, myGuid); if (addresses.length() == 0) return null; LinkedList<GnsSocketAddress> addrList = new LinkedList<GnsSocketAddress>(); for (int i = 0; i < addresses.length(); i++) { GnsSocketAddress sock = new GnsSocketAddress(gnsClient, myGuid); String ipPort = addresses.getString(i); if (ipPort.startsWith("P")) { sock.setProxy(true); ipPort = ipPort.substring(1); } else sock.setProxy(false); int colon = ipPort.indexOf(':'); if (colon == -1) throw new Exception("Invalid IP:Port value " + ipPort + " for service " + serviceName); sock.setIp(ipPort.substring(0, colon)); sock.setPort(Integer.valueOf(ipPort.substring(colon + 1))); addrList.add(sock); } return addrList.toArray(new GnsSocketAddress[addrList.size()]); }
From source file:net.joaopeixoto.geode.server.functions.PatternFunctions.java
/** * Replace here with your favorite algorithm *///from w w w.j a v a 2 s . c o m @GemfireFunction public DistanceResult distance(List<Metric> metrics) { Assert.notEmpty(metrics); Metric first = metrics.get(0); LinkedList<Metric> currentWindow = new LinkedList<>(); LinkedList<Metric> matchedWindow = new LinkedList<>(); double minDistance = THRESHOLD; int matchCount = 0; log.debug("Checking for patterns comparing with {}", metrics); List<Metric> localValues = new ArrayList<>(metricRegion.values()); /** * Ensure the local values are ordered. {@link Region#values()} does not guarantee it. */ Collections.sort(localValues); for (Metric metric : localValues) { // Ignore overlapping points or noise if (metric.getTimestamp() >= first.getTimestamp() || metric.getValue().compareTo(BigDecimal.TEN) < 1) { if (!currentWindow.isEmpty()) { currentWindow.pop(); } continue; } currentWindow.add(metric); if (currentWindow.size() > 13) { currentWindow.pop(); } /** * We only compare windows the same size (for now) */ if (currentWindow.size() == 13) { TimeWarpInfo compare = DTW.compare(metricToSeries(currentWindow), metricToSeries(metrics), Distances.EUCLIDEAN_DISTANCE); if (compare.getDistance() <= 1D) { matchCount++; matchedWindow = new LinkedList<>(currentWindow); } } } if (matchCount > 0) { return new DistanceResult(matchedWindow, minDistance, matchCount); } return null; }
From source file:com.demo.wondersdaili.mvp.utils.ThemeUtils.java
static TintInfo parseColorStateList(ColorStateList origin) { if (origin == null) return null; boolean hasDisable = false; int originDefaultColor = origin.getDefaultColor(); LinkedList<int[]> stateList = new LinkedList<>(); LinkedList<Integer> colorList = new LinkedList<>(); int disableColor = origin.getColorForState(DISABLED_STATE_SET, 0); if (disableColor != originDefaultColor) { hasDisable = true;//from ww w . j a v a 2 s .c om stateList.add(DISABLED_STATE_SET); colorList.add(disableColor); } int pressedColor = origin.getColorForState(wrapState(hasDisable, PRESSED_STATE_SET), 0); if (pressedColor != originDefaultColor) { stateList.add(PRESSED_STATE_SET); colorList.add(pressedColor); } int focusColor = origin.getColorForState(wrapState(hasDisable, FOCUSED_STATE_SET), 0); if (focusColor != originDefaultColor) { stateList.add(FOCUSED_STATE_SET); colorList.add(focusColor); } int checkedColor = origin.getColorForState(wrapState(hasDisable, CHECKED_STATE_SET), 0); if (checkedColor != originDefaultColor) { stateList.add(CHECKED_STATE_SET); colorList.add(checkedColor); } int selectedColor = origin.getColorForState(wrapState(hasDisable, SELECTED_STATE_SET), 0); if (selectedColor != originDefaultColor) { stateList.add(SELECTED_STATE_SET); colorList.add(selectedColor); } int normalColor = origin.getColorForState(wrapState(hasDisable, EMPTY_STATE_SET), 0); if (normalColor != 0) { stateList.add(EMPTY_STATE_SET); colorList.add(normalColor); } if (colorList.size() > 1) { return new TintInfo(stateList, colorList); } else { return null; } }
From source file:analysis.postRun.PostRunWindow.java
/** * Method which writes the text passed to the file specified. * @param fileName// ww w. j av a 2s . co m * Which file to write to. * text * List of string arrays to write. */ private void writeToFile(String fileName, LinkedList<String[]> text) { //append text to file fileName try { BufferedWriter b = new BufferedWriter(new FileWriter(fileName)); for (int k = 0; k < text.size(); k++) { for (int l = 0; l < text.get(0).length; l++) { b.append(text.get(k)[l]); } if (k != (text.size() - 1)) { b.append('\n'); } } b.close(); } catch (IOException e) { System.err.println(e.getMessage()); } }
From source file:annis.gui.resultview.ResultViewPanel.java
@Override public boolean onCompononentLoaded(AbstractClientConnector source) { if (source != null) { if (projectQueue != null && currentQuery != null) { LinkedList<SaltProject> subgraphs = new LinkedList<>(); SaltProject p;//from w w w.j a v a 2s . c o m while ((p = projectQueue.poll()) != null) { log.debug("Polling queue for SaltProject graph"); subgraphs.add(p); } if (subgraphs.isEmpty()) { log.debug("no SaltProject graph in queue"); return false; } log.debug("taken {} SaltProject graph(s) from queue", subgraphs.size()); addQueryResult(currentQuery, subgraphs); return true; } } return true; }
From source file:nf.frex.android.FrexActivity.java
@Override public void onBackPressed() { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); boolean navigateOnBack = preferences.getBoolean("navigate_on_back", false); if (!navigateOnBack) { super.onBackPressed(); return;/*ww w . j ava2 s .c om*/ } LinkedList<Region> regionHistory = view.getRegionHistory(); if (regionHistory.size() > 0) { Region region; if (regionHistory.size() == 1) { region = regionHistory.get(0); alert(getString(R.string.first_region_msg)); } else { region = regionHistory.pollLast(); } view.setRegionRecordingDisabled(true); view.regenerateRegion(region); view.setRegionRecordingDisabled(false); } else { alert(getString(R.string.empty_region_history_msg)); } }