Example usage for java.util LinkedList size

List of usage examples for java.util LinkedList size

Introduction

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

Prototype

int size

To view the source code for java.util LinkedList size.

Click Source Link

Usage

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
 * //  w w w  .  j ava2s  . co m
 */
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:com.k42b3.aletheia.protocol.http.Util.java

public static String buildMessage(String statusLine, LinkedList<Header> header, String body, String delimter) {
    StringBuilder str = new StringBuilder();

    // status line
    str.append(statusLine);/*from w  ww . j a  va2s . com*/
    str.append(delimter);

    // headers
    for (int i = 0; i < header.size(); i++) {
        str.append(header.get(i).getName() + ": " + header.get(i).getValue() + delimter);
    }

    str.append(delimter);

    // body
    if (body != null && !body.isEmpty()) {
        str.append(body);
    }

    return str.toString();
}

From source file:com.machinepublishers.jbrowserdriver.LogsServer.java

private static void handleMessage(String message, LinkedList<Entry> entries, Level level, String type,
        Settings settings) {//from   w  ww  . j  a v a  2 s .c  o  m
    if (settings != null && settings.logsMax() > 0) {
        final Entry entry = new Entry(level, System.currentTimeMillis(), message);
        synchronized (entries) {
            entries.add(entry);
            if (entries.size() > settings.logsMax()) {
                entries.removeFirst();
            }
        }
    }
    if (settings == null || level.intValue() >= settings.loggerLevel()) {
        System.err.println(">" + level.getName() + "/" + type + "/" + message);
    }
}

From source file:com.frochr123.helper.CachedFileDownloader.java

public synchronized static SimpleEntry<String, SimpleEntry<String, File>> downloadFile(String url,
        String commaSeperatedAllowedFileTypes) throws IOException {
    // On invalid URL return null
    if (url == null || url.isEmpty()) {
        return null;
    }//from   w  w w  . j  ava2s .  c om

    // Prepare check file extensions
    String allowedFileTypesString = commaSeperatedAllowedFileTypes;

    // Fallback to default allowed file types
    if (allowedFileTypesString == null || allowedFileTypesString.isEmpty()) {
        allowedFileTypesString = CACHE_DOWNLOADER_DEFAULT_FILETYPES;
    }

    // Get seperate file types from string and normalize to lowercase
    String[] allowedFileTypesArray = allowedFileTypesString.split(",");

    if (allowedFileTypesArray.length > 0) {
        // Normalize file extensions to lower case
        for (int i = 0; i < allowedFileTypesArray.length; ++i) {
            if (allowedFileTypesArray[i] != null && !allowedFileTypesArray[i].isEmpty()) {
                allowedFileTypesArray[i] = allowedFileTypesArray[i].toLowerCase();
            }
        }
    }

    File file = null;
    String finalUrl = null;
    String fileExtension = null;
    String fileBaseName = null;
    SimpleEntry<String, File> innerResult = null;
    SimpleEntry<String, SimpleEntry<String, File>> finalResult = null;

    // Check if URL is already stored in cache map
    if (cacheMap.containsKey(url)) {
        if (cacheMap.get(url) != null) {
            innerResult = cacheMap.get(url);
            file = (File) (cacheMap.get(url).getValue());
        }
    }
    // URL is not stored in cache, download and store it in cache
    else {
        // Resize cache if needed, LinkedHashMap keeps insertion order, oldest entries are first entries
        // Temporary store keys in list and remove afterwards to avoid read / write issues
        // Get one free space for new download
        LinkedList<String> deleteKeys = new LinkedList<String>();
        for (Entry<String, SimpleEntry<String, File>> cacheEntry : cacheMap.entrySet()) {
            if ((cacheMap.size() - deleteKeys.size()) >= CACHE_DOWNLOADER_MAX_ENTRIES) {
                deleteKeys.add(cacheEntry.getKey());
            } else {
                break;
            }
        }

        // Remove keys
        if (!deleteKeys.isEmpty()) {
            for (String key : deleteKeys) {
                // Delete old files
                if (cacheMap.get(key) != null && cacheMap.get(key).getValue() != null) {
                    cacheMap.get(key).getValue().delete();
                }

                // Remove entry in cache map
                cacheMap.remove(key);
            }
        }

        // Download file
        SimpleEntry<String, ByteArrayOutputStream> download = getResultFromURL(url);

        if (download == null || download.getKey() == null || download.getKey().isEmpty()
                || download.getValue() == null) {
            return null;
        }

        // Check for file type
        if (allowedFileTypesArray.length > 0) {
            finalUrl = download.getKey();
            fileExtension = FilenameUtils.getExtension(finalUrl);

            // Check for valid fileExtension
            if (fileExtension == null || fileExtension.isEmpty()) {
                return null;
            }

            // Check if fileExtension is contained in allowed file extensions
            // Normalize file extensions to lower case
            boolean foundAllowedFileExtension = false;

            for (int i = 0; i < allowedFileTypesArray.length; ++i) {
                if (allowedFileTypesArray[i].equals(fileExtension)) {
                    foundAllowedFileExtension = true;
                    break;
                }
            }

            // File extension was not found, abort
            if (!foundAllowedFileExtension) {
                return null;
            }
        }

        // Write result to file, it is allowed file type
        fileBaseName = FilenameUtils.getBaseName(finalUrl);
        file = FileUtils.getNonexistingWritableFile(fileBaseName + "." + fileExtension);
        file.deleteOnExit();
        FileOutputStream filestream = new FileOutputStream(file);
        download.getValue().writeTo(filestream);

        // Insert into cache and result variable
        innerResult = new SimpleEntry<String, File>(finalUrl, file);
        cacheMap.put(url, innerResult);
    }

    if (innerResult != null) {
        finalResult = new SimpleEntry<String, SimpleEntry<String, File>>(url, innerResult);
    }

    return finalResult;
}

From source file:Main.java

/**
 * Inserts into an ascending sorted list an element.
 *
 * Preconditions: The element has to implement the {@code Comparable}
 * interface and the list have to be sorted ascending. Both conditions will
 * not be checked: At runtime a class cast exception will be thrown
 * if the element does not implement the comparable interface and and if the
 * list is not sorted, the element can't be insert sorted.
 *
 * @param <T>     element type/*w w w  . j a  v  a 2 s .c  o  m*/
 * @param list
 * @param element
 */
@SuppressWarnings("unchecked")
public static <T> void binaryInsert(LinkedList<? super T> list, T element) {
    if (list == null) {
        throw new NullPointerException("list == null");
    }

    if (element == null) {
        throw new NullPointerException("element == null");
    }

    boolean isComparable = element instanceof Comparable<?>;

    if (!isComparable) {
        throw new IllegalArgumentException("Not a comparable: " + element);
    }

    int size = list.size();
    int low = 0;
    int high = size - 1;
    int index = size;
    int cmp = 1;

    while ((low <= high) && (cmp > 0)) {
        int mid = (low + high) >>> 1;
        Comparable<? super T> midVal = (Comparable<? super T>) list.get(mid);

        cmp = midVal.compareTo(element);

        if (cmp < 0) {
            low = mid + 1;
        } else if (cmp > 0) {
            high = mid - 1;
        }
    }

    for (int i = low; (i >= 0) && (i < size) && (index == size); i++) {
        Comparable<? super T> elt = (Comparable<? super T>) list.get(i);

        if (elt.compareTo(element) >= 0) {
            index = i;
        }
    }

    list.add(index, element);
}

From source file:Main.java

/**
 * //from www.j a v  a2 s .c o m
 * @param aFile
 * @return
 */
public static String getLastLines(String filename, int number) {
    File aFile = new File(filename);
    StringBuilder contents = new StringBuilder();
    LinkedList<String> ll = new LinkedList<String>();

    try {
        BufferedReader input = new BufferedReader(new FileReader(aFile));
        try {
            String line = null;
            while ((line = input.readLine()) != null) {
                ll.add(line);
            }
        } finally {
            input.close();
        }
    } catch (IOException ex) {
        Log.e(TAG, ex.getMessage());
    }

    if ((ll.size() - number) <= 0) {
        Log.e(TAG, "Requested number of lines exceeds lines of file");
        return "Requested number of lines exceeds lines of file";
    }

    for (int i = (ll.size() - 1); i >= (ll.size() - number); i--) {
        contents.append(ll.get(i - 1));
        contents.append("\n");
    }

    return contents.toString();
}

From source file:com.arman.efficientqhalgoforch.SuperAwesomeCardFragment.java

public static String[] DtoString(LinkedList<Double> d) {
    String[] s = new String[d.size() + 1];
    s[0] = "";//  w w  w  . j  a  v a 2  s.c  o  m
    for (int i = 1, j = 0; i < s.length; i++, j++)
        s[i] = String.valueOf(d.get(j));

    return s;
}

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

public static String getJsonStrFromIconList(LinkedList<IconBean> list) {
    JSONArray jsonArry = new JSONArray();
    JSONObject json = new JSONObject();
    try {//from   w  ww .ja  va2s .c  om
        for (int i = 0; i < list.size(); i++) {
            jsonArry.put(i, getJsonFromIcon(list.get(i)));
        }
        json.put(JK_LIST_ITEM, jsonArry);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return json.toString();
}

From source file:com.arman.efficientqhalgoforch.SuperAwesomeCardFragment.java

public static float[] DtoFloat(LinkedList<Double> d) {
    float[] floatArray = new float[d.size() + 1];
    for (int i = 0; i < floatArray.length; i++) {
        floatArray[i] = (float) (d.get(i) / 1.0);
    }//from w  ww .  j ava  2s . c  om
    return floatArray;
}

From source file:msearch.filmeSuchen.sender.MediathekReader.java

static void listeSort(LinkedList<String[]> liste, int stelle) {
    //Stringliste alphabetisch sortieren
    GermanStringSorter sorter = GermanStringSorter.getInstance();
    if (liste != null) {
        String str1;/*from  ww w .ja  va 2s  . c o  m*/
        String str2;
        for (int i = 1; i < liste.size(); ++i) {
            for (int k = i; k > 0; --k) {
                str1 = liste.get(k - 1)[stelle];
                str2 = liste.get(k)[stelle];
                // if (str1.compareToIgnoreCase(str2) > 0) {
                if (sorter.compare(str1, str2) > 0) {
                    liste.add(k - 1, liste.remove(k));
                } else {
                    break;
                }
            }
        }
    }
}