List of usage examples for java.util LinkedList isEmpty
boolean isEmpty();
From source file:sanghoon.flickr.photos.Dump.java
public static void main(String[] args) throws FileNotFoundException { // args = new String[] { "-b", "-122.373971375,47.55575575,-122.3455185,47.585350625000004" }; if (args.length < 1) { String header = "\n" + "Download all photos matching some criteria, using flickr.photos.search API." + "\n\n"; HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java " + Dump.class.getName() + " [OPTIONS]...", header, createOptions(), ""); return;//from w ww . j a v a 2 s.co m } CommandLineParser parser = new DefaultParser(); CommandLine line; try { line = parser.parse(createOptions(), args); } catch (ParseException exp) { System.err.println("Parsing failed. Reason: " + exp.getMessage()); return; } String tags = line.hasOption("tags") ? line.getOptionValue("tags") : null; String minTakenDate = line.hasOption("min-taken-date") ? line.getOptionValue("min-taken-date") : null; String maxTakenDate = line.hasOption("max-taken-date") ? line.getOptionValue("max-taken-date") : null; String bbox = line.hasOption("bounding-box") ? line.getOptionValue("bounding-box") : null; if (bbox == null) { System.err.println("bounding box parameter is required"); return; } // TODO: places.find places.getInfo ? id bounding box // String woeID = line.hasOption("woe-id") ? line.getOptionValue("woe-id") : null; // String placeID = line.hasOption("place-id") ? line.getOptionValue("place-id") : null; String outputFilePrefix = line.hasOption("output-file-prefix") ? line.getOptionValue("output-file-prefix") : "output"; ApiKey key = ApiKey.load(ClassLoader.getSystemResourceAsStream("flickr_api_key.properties")); Map<String, String> outputs = new HashMap<>(); String[] coords = bbox.split(","); double minimum_longitude = Double.parseDouble(coords[0]); double minimum_latitude = Double.parseDouble(coords[1]); double maximum_longitude = Double.parseDouble(coords[2]); double maximum_latitude = Double.parseDouble(coords[3]); LinkedList<BoundingBox> bboxes = new LinkedList<>(); bboxes.add(new BoundingBox(minimum_longitude, minimum_latitude, maximum_longitude, maximum_latitude)); int index = 0; while (bboxes.isEmpty() == false) { BoundingBox box = bboxes.pollFirst(); int page = 1; System.out.print("searching for " + box.toString() + " ."); Integer total = search(key, box, tags, minTakenDate, maxTakenDate, page, outputs); if (total == null) { bboxes.addLast(box); System.out.println(" failed, retry later"); continue; } else if (MAX_PHOTOS_IN_A_BBOX < total) { // Please note that Flickr will return at most the first 4,000 results for any given search query. // If this is an issue, we recommend trying a more specific query. // List<BoundingBox> splitBoxes = box.split(); for (BoundingBox splitBox : splitBoxes) bboxes.addLast(splitBox); System.out.print(" " + total + " photos (>" + MAX_PHOTOS_IN_A_BBOX + "), split "); System.out.print("{"); for (int i = 0; i < splitBoxes.size(); i++) { if (0 < i) System.out.print(","); System.out.print("["); System.out.print(splitBoxes.get(i).toString()); System.out.print("]"); } System.out.print("}"); System.out.println(); continue; } else if (PER_PAGE < total) { // ? search box ? ? ? ? // (? ? PER_PAGE ?), // page ? while (page * PER_PAGE < total) { page++; search(key, box, tags, minTakenDate, maxTakenDate, page, outputs); System.out.print("."); } System.out.println(" " + total + " photos in " + page + " pages"); } if (MAX_PHOTOS_IN_AN_OUTPUT < outputs.size()) { // ? ? ? ? ? String filename = outputFilePrefix + "_" + index++ + ".json"; write(outputs, filename); outputs.clear(); } } String filename = outputFilePrefix + "_" + index++ + ".json"; write(outputs, filename); System.out.println("finished"); }
From source file:example.Publisher.java
public static void main(String[] args) throws Exception { String user = env("ACTIVEMQ_USER", "admin"); String password = env("ACTIVEMQ_PASSWORD", "password"); String host = env("ACTIVEMQ_HOST", "localhost"); int port = Integer.parseInt(env("ACTIVEMQ_PORT", "1883")); final String destination = arg(args, 0, "/topic/event"); int messages = 10000; int size = 256; String DATA = "abcdefghijklmnopqrstuvwxyz"; String body = ""; for (int i = 0; i < size; i++) { body += DATA.charAt(i % DATA.length()); }//from w ww. ja v a2s . c om Buffer msg = new AsciiBuffer(body); MQTT mqtt = new MQTT(); mqtt.setHost(host, port); mqtt.setUserName(user); mqtt.setPassword(password); FutureConnection connection = mqtt.futureConnection(); connection.connect().await(); final LinkedList<Future<Void>> queue = new LinkedList<Future<Void>>(); UTF8Buffer topic = new UTF8Buffer(destination); for (int i = 1; i <= messages; i++) { // Send the publish without waiting for it to complete. This allows us // to send multiple message without blocking.. queue.add(connection.publish(topic, msg, QoS.AT_LEAST_ONCE, false)); // Eventually we start waiting for old publish futures to complete // so that we don't create a large in memory buffer of outgoing message.s if (queue.size() >= 1000) { queue.removeFirst().await(); } if (i % 1000 == 0) { System.out.println(String.format("Sent %d messages.", i)); } } queue.add(connection.publish(topic, new AsciiBuffer("SHUTDOWN"), QoS.AT_LEAST_ONCE, false)); while (!queue.isEmpty()) { queue.removeFirst().await(); } connection.disconnect().await(); System.exit(0); }
From source file:org.zoneproject.extractor.plugin.spotlight.App.java
public static void main(String[] args) { LinkedList<Item> itemsPending = new LinkedList<Item>(); Prop[] fr = { new Prop(ZoneOntology.PLUGIN_LANG, "\"fr\"") }; Prop[] en = { new Prop(ZoneOntology.PLUGIN_LANG, "\"en\"") }; LinkedBlockingQueue<AnnotationThread> annotationThreads; HashMap<String, ArrayList<Prop>> propsToSave; propsPendingSave = new HashMap<String, ArrayList<Prop>>(); while (true) { annotationThreads = new LinkedBlockingQueue<AnnotationThread>(); while (true) {//while we can download items Item[] enItems = Database.getItemsNotAnotatedForPluginsWithDeps(PLUGIN_URI, en, SIM_DOWNLOADS / 2); Item[] frItems = Database.getItemsNotAnotatedForPluginsWithDeps(PLUGIN_URI, fr, SIM_DOWNLOADS / 2); Item[] items = (Item[]) ArrayUtils.addAll(enItems, frItems); if (items != null && items.length > 0) { //check if the item is in annotation process for (Item i : items) { boolean exist = false; for (AnnotationThread a : annotationThreads) { if (a.item.getUri().equals(i.getUri())) { exist = true; }//from ww w . j a v a 2 s . c om } if (!exist) { itemsPending.add(i); } } } if (itemsPending.isEmpty()) { break; } while (!itemsPending.isEmpty()) { //we add new thread until the limit length is thrown while (annotationThreads.size() < SIM_ANNOTATE && !itemsPending.isEmpty()) { AnnotationThread newAnnot = new AnnotationThread(itemsPending.removeFirst()); newAnnot.start(); annotationThreads.add(newAnnot); } //try{ //we try to end some terminated threads //synchronized(annotationThreads){ for (AnnotationThread a : annotationThreads) { if (!a.isAlive()) { annotationThreads.remove(a); } else if (a.getDuration() > LIMIT_TIME_FOR_DOWN) { a.interrupt(); } else if (a.getDuration() > 10) { logger.info("is alive[" + a.getDuration() + "]: " + a.item.getUri()); } //try{Thread.currentThread().sleep(1000);}catch(Exception ie){}//TODO remove } //} //}catch(java.util.ConcurrentModificationException concurrentAccess){ // logger.warn("concurrent access!"); //} if (annotationThreads.size() >= SIM_ANNOTATE) { try { Thread.currentThread().sleep(1000); } catch (Exception ie) { } } } logger.info("start saving"); synchronized (propsPendingSave) { propsToSave = (HashMap<String, ArrayList<Prop>>) propsPendingSave.clone(); propsPendingSave.clear(); } Database.addAnnotations(propsToSave); logger.info("end saving"); } logger.info("no more items to annotate"); try { Thread.currentThread().sleep(1000); } catch (Exception ie) { } } }
From source file:Main.java
/** * Returns the last element of list. If the given list is empty, the * returned value will be null.//from w w w . j av a 2s .c o m * * @param <T> Class type * @param collection List of elements * @return Last element of list */ public static <T> T getLastElement(Collection<T> collection) { LinkedList<T> elements = collection == null ? new LinkedList<>() : new LinkedList<>(collection); return elements.isEmpty() ? null : elements.getLast(); }
From source file:com.thinkbiganalytics.metadata.jpa.support.QueryDslPathInspector.java
private static Object getFieldObject(BeanPath basePath, LinkedList<String> paths) throws IllegalAccessException { if (!paths.isEmpty()) { String currPath = paths.pop(); Object o = getObjectForField(basePath, currPath); if (o != null && o instanceof BeanPath && !paths.isEmpty()) { return getFieldObject((BeanPath) o, paths); }//w ww .j av a 2 s. co m return o; } return null; }
From source file:com.smallnn.input.FileUtil.java
public static List<File> find(File file, FileFilter filter) { List<File> result = new ArrayList<File>(); LinkedList<File> stack = new LinkedList<File>(); stack.push(file);/*from ww w . j ava2 s. c om*/ while (!stack.isEmpty()) { File f = stack.pop(); if (filter == null || filter.accept(f)) { result.add(f); } if (f.isDirectory() && f.exists()) { stack.addAll(Arrays.asList(f.listFiles())); } } return result; }
From source file:com.abuabdul.notedovn.util.NoteDovnUtil.java
public static LinkedList<ScratchNote> filterAndSortByCategory(LinkedList<ScratchNote> notes) { if (!notes.isEmpty()) { LinkedList<ScratchNote> category = newLinkedList(filter(notes, categoryPredicate())); sort(category, categoryComparator()); return category; }/*from ww w . j a v a2 s .com*/ return notes; }
From source file:com.abuabdul.notedovn.util.NoteDovnUtil.java
public static LinkedList<ScratchNote> filterAndSortByUpdatedDate(LinkedList<ScratchNote> notes) { if (!notes.isEmpty()) { LinkedList<ScratchNote> updateDate = newLinkedList(filter(notes, categoryPredicateNulls())); sort(updateDate, updatedDateComparator()); return updateDate; }/* w w w. j av a2s .com*/ return notes; }
From source file:Main.java
public static int insertX(int numb, int random) { long result = 0; LinkedList<Integer> stack = new LinkedList<Integer>(); while (numb > 0) { stack.push(numb % 10);//from w w w .java 2s . com numb = numb / 10; } while (!stack.isEmpty()) { result = (int) combinedTwoNumber(result, stack.pop()); result = (int) combinedTwoNumber(result, random); } return (int) (result /= 10); }
From source file:org.diorite.config.impl.NestedNodesHelper.java
@Nullable @SuppressWarnings("unchecked") static Object remove(Object object, LinkedList<String> path) { while (true) { if (path.isEmpty()) { throw new IllegalArgumentException("Empty path given"); }/*w w w . ja va 2s. c om*/ String current = path.removeFirst(); try { Object val; if (object instanceof Config) { val = ((Config) object).remove(current); } else if (object instanceof Map) { val = ((Map<Object, Object>) object).remove(current); } else if (object instanceof List) { val = ((List<Object>) object).remove(Integer.parseInt(current)); } else { throw new IllegalStateException("Can't remove class property!"); } if (path.isEmpty()) { return val; } Validate.notNull(val, "Value on: " + current + " in " + object + " is null"); object = val; } catch (Exception e) { throw new IllegalStateException("Can't find property: " + current + " (" + path + ") in: " + object, e); } } }