Example usage for java.util LinkedList add

List of usage examples for java.util LinkedList add

Introduction

In this page you can find the example usage for java.util LinkedList add.

Prototype

public boolean add(E e) 

Source Link

Document

Appends the specified element to the end of this list.

Usage

From source file:org.lol.reddit.reddit.RedditAPI.java

private static URI prepareActionUri(final RedditAction action, final LinkedList<NameValuePair> postFields) {
    switch (action) {
    case DOWNVOTE:
        postFields.add(new BasicNameValuePair("dir", "-1"));
        return Constants.Reddit.getUri(Constants.Reddit.PATH_VOTE);

    case UNVOTE://from   w  ww.  j ava  2 s. c  o m
        postFields.add(new BasicNameValuePair("dir", "0"));
        return Constants.Reddit.getUri(Constants.Reddit.PATH_VOTE);

    case UPVOTE:
        postFields.add(new BasicNameValuePair("dir", "1"));
        return Constants.Reddit.getUri(Constants.Reddit.PATH_VOTE);

    case SAVE:
        return Constants.Reddit.getUri(Constants.Reddit.PATH_SAVE);
    case HIDE:
        return Constants.Reddit.getUri(Constants.Reddit.PATH_HIDE);
    case UNSAVE:
        return Constants.Reddit.getUri(Constants.Reddit.PATH_UNSAVE);
    case UNHIDE:
        return Constants.Reddit.getUri(Constants.Reddit.PATH_UNHIDE);
    case REPORT:
        return Constants.Reddit.getUri(Constants.Reddit.PATH_REPORT);

    default:
        throw new RuntimeException("Unknown post/comment action");
    }
}

From source file:de.tu_berlin.dima.aim3.querysuggestion.QuerySuggTCase.java

@Parameters
public static Collection<Object[]> getConfigurations() {

    LinkedList<Configuration> tConfigs = new LinkedList<Configuration>();

    Configuration config = new Configuration();
    config.setInteger("QuerySuggestClusteringTest#NoSubtasks", 1);
    // config.setInteger("QuerySuggestClusteringTest#NoSubtasks", 4);
    config.setString("QuerySuggestClusteringTest#ProcessLevel", "sessionConstruction");
    tConfigs.add(config);

    return toParameterList(tConfigs);
}

From source file:org.lol.reddit.reddit.RedditAPI.java

public static void submit(final CacheManager cm, final APIResponseHandler.ActionResponseHandler responseHandler,
        final RedditAccount user, final boolean is_self, final String subreddit, final String title,
        final String body, final String captchaId, final String captchaText, final Context context) {

    final LinkedList<NameValuePair> postFields = new LinkedList<NameValuePair>();
    postFields.add(new BasicNameValuePair("kind", is_self ? "self" : "link"));
    postFields.add(new BasicNameValuePair("sendreplies", "true"));
    postFields.add(new BasicNameValuePair("uh", user.modhash));
    postFields.add(new BasicNameValuePair("sr", subreddit));
    postFields.add(new BasicNameValuePair("title", title));
    postFields.add(new BasicNameValuePair("captcha", captchaText));
    postFields.add(new BasicNameValuePair("iden", captchaId));

    if (is_self)//from  w  ww . jav a 2s  .co  m
        postFields.add(new BasicNameValuePair("text", body));
    else
        postFields.add(new BasicNameValuePair("url", body));

    cm.makeRequest(new APIPostRequest(Constants.Reddit.getUri("/api/submit"), user, postFields, context) {

        @Override
        public void onJsonParseStarted(JsonValue result, long timestamp, UUID session, boolean fromCache) {

            System.out.println(result.toString());

            try {
                final APIResponseHandler.APIFailureType failureType = findFailureType(result);

                if (failureType != null) {
                    responseHandler.notifyFailure(failureType);
                    return;
                }

            } catch (Throwable t) {
                notifyFailure(RequestFailureType.PARSE, t, null, "JSON failed to parse");
            }

            responseHandler.notifySuccess();
        }

        @Override
        protected void onCallbackException(Throwable t) {
            BugReportActivity.handleGlobalError(context, t);
        }

        @Override
        protected void onFailure(RequestFailureType type, Throwable t, StatusLine status,
                String readableMessage) {
            responseHandler.notifyFailure(type, t, status, readableMessage);
        }
    });
}

From source file:edu.jhu.pha.vospace.storage.SwiftKeystoneStorageManager.java

public static List<FilesContainerInfo> listContainersInfo(int limit, String marker, String endMarker)
        throws IOException, HttpException, FilesAuthorizationException, FilesException {

    HttpGet method = null;//from w w  w  .j  a va 2 s  .c  om

    LinkedList<NameValuePair> parameters = new LinkedList<NameValuePair>();
    if (limit > 0) {
        parameters.add(new BasicNameValuePair("limit", String.valueOf(limit)));
    }
    if (marker != null) {
        parameters.add(new BasicNameValuePair("marker", marker));
    }
    if (endMarker != null) {
        parameters.add(new BasicNameValuePair("end_marker", endMarker));
    }
    parameters.add(new BasicNameValuePair("format", "json"));

    String uri = makeURI(getFileUrl, parameters);

    method = new HttpGet(uri);
    method.addHeader(FilesConstants.X_AUTH_TOKEN, strToken);
    FilesResponse response = new FilesResponse(client.execute(method));
    if (response.getStatusCode() == HttpStatus.SC_OK) {

        ArrayList<FilesContainerInfo> containerList = new ArrayList<FilesContainerInfo>();

        JsonFactory jsonFactory = new JsonFactory();
        JsonParser jp = jsonFactory.createJsonParser(IOUtils.toString(response.getResponseBodyAsStream()));
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        TypeReference ref = new TypeReference<List<FilesContainerInfo>>() {
        };
        containerList = mapper.readValue(jp, ref);
        System.out.println(containerList);
        return containerList;

    } else if (response.getStatusCode() == HttpStatus.SC_NO_CONTENT) {
        return new ArrayList<FilesContainerInfo>();
    } else if (response.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
        throw new FilesNotFoundException("Account not Found", response.getResponseHeaders(),
                response.getStatusLine());
    } else {
        throw new FilesException("Unexpected Return Code", response.getResponseHeaders(),
                response.getStatusLine());
    }

}

From source file:dk.statsbiblioteket.doms.iprolemapper.rolemapper.IPRoleMapper.java

/**
 * (re-)initialise the internal database over IP ranges and roles. This
 * method should only be called for the initial initialisation and if the
 * configuration changes./*from w  w w  . j  ava2s .  c  o  m*/
 * 
 * @param ranges
 *            a list of IP range and role information to initialise the
 *            database with.
 */
public static synchronized void init(List<IPRangeRoles> ranges) {

    if (log.isTraceEnabled()) {
        log.trace("init(): Called with IPRangeRoles: " + ranges);
    }
    startAddrRangeMapList = new TreeMap<InetAddress, LinkedList<IPRangeRoles>>(new InetAddressComparator());

    roleIPRangeMapList = new TreeMap<String, LinkedList<IPRange>>();

    for (IPRangeRoles range : ranges) {

        // Add the range to the start IP address -> IPRangeRoles map.
        LinkedList<IPRangeRoles> rangeList = startAddrRangeMapList.get(range.getBeginAddress());

        if (rangeList == null) {
            // No ranges with this begin address have been registered
            // earlier. Create a container for them.
            rangeList = new LinkedList<IPRangeRoles>();
            startAddrRangeMapList.put(range.getBeginAddress(), rangeList);
        }
        rangeList.add(range);

        // Associate the range with all its roles in the role -> IPRange
        // map.
        for (String roleName : range.getRoles()) {

            LinkedList<IPRange> roleRanges = roleIPRangeMapList.get(roleName);

            if (roleRanges == null) {
                // There has not previously been associated any ranges with
                // this role name. Create a new list.
                roleRanges = new LinkedList<IPRange>();
                roleIPRangeMapList.put(roleName, roleRanges);
            }
            roleRanges.add(range);
        }
    } // end-for

    if (log.isTraceEnabled()) {
        log.trace("init(): Finished initialisation. Exiting.");
    }
}

From source file:annis.visualizers.component.grid.EventExtractor.java

/**
* Returns the annotations to display according to the mappings configuration.
*
* This will check the "annos" and "annos_regex" paramters for determining.
* the annotations to display. It also iterates over all nodes of the graph
* matching the type./* w  w  w . j  a v  a 2  s .c  o m*/
*
* @param input The input for the visualizer.
* @param type Which type of nodes to include
* @return
*/
public static List<String> computeDisplayAnnotations(VisualizerInput input, Class<? extends SNode> type) {
    if (input == null) {
        return new LinkedList<String>();
    }

    SDocumentGraph graph = input.getDocument().getSDocumentGraph();

    Set<String> annoPool = getAnnotationLevelSet(graph, input.getNamespace(), type);
    List<String> annos = new LinkedList<String>(annoPool);

    String annosConfiguration = input.getMappings().getProperty(MAPPING_ANNOS_KEY);
    if (annosConfiguration != null && annosConfiguration.trim().length() > 0) {
        String[] split = annosConfiguration.split(",");
        annos.clear();
        for (String s : split) {
            s = s.trim();
            // is regular expression?
            if (s.startsWith("/") && s.endsWith("/")) {
                // go over all remaining items in our pool of all annotations and
                // check if they match
                Pattern regex = Pattern.compile(StringUtils.strip(s, "/"));

                LinkedList<String> matchingAnnos = new LinkedList<String>();
                for (String a : annoPool) {
                    if (regex.matcher(a).matches()) {
                        matchingAnnos.add(a);
                    }
                }

                annos.addAll(matchingAnnos);
                annoPool.removeAll(matchingAnnos);

            } else {
                annos.add(s);
                annoPool.remove(s);
            }
        }
    }

    // filter already found annotation names by regular expression
    // if this was given as mapping
    String regexFilterRaw = input.getMappings().getProperty(MAPPING_ANNO_REGEX_KEY);
    if (regexFilterRaw != null) {
        try {
            Pattern regexFilter = Pattern.compile(regexFilterRaw);
            ListIterator<String> itAnnos = annos.listIterator();
            while (itAnnos.hasNext()) {
                String a = itAnnos.next();
                // remove entry if not matching
                if (!regexFilter.matcher(a).matches()) {
                    itAnnos.remove();
                }
            }
        } catch (PatternSyntaxException ex) {
            log.warn("invalid regular expression in mapping for grid visualizer", ex);
        }
    }
    return annos;
}

From source file:org.lol.reddit.reddit.RedditAPI.java

public static void action(final CacheManager cm, final APIResponseHandler.ActionResponseHandler responseHandler,
        final RedditAccount user, final String subredditCanonicalName, final RedditSubredditAction action,
        final Context context) {

    RedditSubredditManager.getInstance(context, user).getSubreddit(subredditCanonicalName, TimestampBound.ANY,
            new RequestResponseHandler<RedditSubreddit, SubredditRequestFailure>() {

                @Override//from  w w w.ja va2 s  .  c om
                public void onRequestFailed(SubredditRequestFailure failureReason) {
                    responseHandler.notifyFailure(failureReason.requestFailureType, failureReason.t,
                            failureReason.statusLine, failureReason.readableMessage);

                }

                @Override
                public void onRequestSuccess(RedditSubreddit subreddit, long timeCached) {

                    final LinkedList<NameValuePair> postFields = new LinkedList<NameValuePair>();

                    postFields.add(new BasicNameValuePair("sr", subreddit.name));
                    postFields.add(new BasicNameValuePair("uh", user.modhash));

                    final URI url = prepareActionUri(action, postFields);

                    cm.makeRequest(new APIPostRequest(url, user, postFields, context) {
                        @Override
                        protected void onCallbackException(final Throwable t) {
                            BugReportActivity.handleGlobalError(context, t);
                        }

                        @Override
                        protected void onFailure(final RequestFailureType type, final Throwable t,
                                final StatusLine status, final String readableMessage) {
                            responseHandler.notifyFailure(type, t, status, readableMessage);
                        }

                        @Override
                        public void onJsonParseStarted(final JsonValue result, final long timestamp,
                                final UUID session, final boolean fromCache) {

                            try {

                                final APIResponseHandler.APIFailureType failureType = findFailureType(result);

                                if (failureType != null) {
                                    responseHandler.notifyFailure(failureType);
                                    return;
                                }

                            } catch (Throwable t) {
                                notifyFailure(RequestFailureType.PARSE, t, null, "JSON failed to parse");
                            }

                            responseHandler.notifySuccess();
                        }
                    });
                }
            }, null);
}

From source file:de.rub.syssec.saaf.Headless.java

/**
 * Gather APKs for option-cases file, directory and recursive directory.
 *
 * @param path      APK file or directory of multiple APKs
 * @return          LinkedList of APK-Files
 * /*from  w w w.  j a v a2 s.com*/
 */
private static LinkedList<File> gatherApksFromPath(File path) {
    LinkedList<File> apks = new LinkedList<File>();
    if (path.isDirectory()) {
        Collection<File> fc = FileUtils.listFiles(path, null,
                CONFIG.getBooleanConfigValue(ConfigKeys.RECURSIVE_DIR_ANALYSIS));
        apks = new LinkedList<File>(fc);
        if (apks.size() <= 0) {
            LOGGER.info("No files found in directory. Forgot a -r?");
        }
        LOGGER.info("Read " + apks.size() + " files from Directory " + path);
    } else if (path.isFile()) {
        apks.add(path);
    }
    return apks;
}

From source file:org.zywx.wbpalmstar.plugin.uexiconlist.utils.IconListUtils.java

public static LinkedList<IconBean> getPerPageIconList(LinkedList<IconBean> iconList, int page) {
    LinkedList<IconBean> gridViewIconList = new LinkedList<IconBean>();
    int pageSize = UIConfig.getLine() * UIConfig.getRow();
    int startPos = page * pageSize;// ??
    int iEnd = startPos + pageSize;// ???
    while ((startPos < iconList.size()) && (startPos < iEnd)) {
        gridViewIconList.add(iconList.get(startPos));
        startPos++;// w ww.j  a  v  a  2 s.  co m
    }
    return gridViewIconList;
}

From source file:io.syndesis.jsondb.impl.SqlJsonDB.java

private static LinkedList<String> getAllParentPaths(String baseDBPath) {
    LinkedList<String> params = new LinkedList<String>();
    Pattern compile = Pattern.compile("/[^/]*$");
    String current = Strings.trimSuffix(baseDBPath, "/");
    while (true) {
        current = compile.matcher(current).replaceFirst("");
        if (current.isEmpty()) {
            break;
        }//from  w ww  . j a  v a2  s  .  co m
        params.add(current + "/");
    }
    return params;
}