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:Main.java

public static LinkedList<String> uc_unserialize(String input) {

    LinkedList<String> result = new LinkedList<String>();

    DOMParser parser = new DOMParser();
    try {/* w  w  w  .  j a  va 2 s . co  m*/
        parser.parse(new InputSource(new StringReader(input)));
        Document doc = parser.getDocument();
        NodeList nl = doc.getChildNodes().item(0).getChildNodes();
        int length = nl.getLength();
        for (int i = 0; i < length; i++) {
            if (nl.item(i).getNodeType() == Document.ELEMENT_NODE)
                result.add(nl.item(i).getFirstChild().getNodeValue());
        }
    } catch (SAXException e) {

    } catch (IOException e) {

    }
    return result;
}

From source file:com.erudika.para.validation.ValidationUtils.java

/**
 * Validates objects using Hibernate Validator.
 * @param content an object to be validated
 * @return a list of error messages or empty if object is valid
 *//*  www  . j a  v a2 s  .c o  m*/
public static String[] validateObject(ParaObject content) {
    if (content == null) {
        return new String[] { "Object cannot be null." };
    }
    LinkedList<String> list = new LinkedList<String>();
    try {
        for (ConstraintViolation<ParaObject> constraintViolation : getValidator().validate(content)) {
            String prop = "'".concat(constraintViolation.getPropertyPath().toString()).concat("'");
            list.add(prop.concat(" ").concat(constraintViolation.getMessage()));
        }
    } catch (Exception e) {
        logger.error(null, e);
    }
    return list.toArray(new String[] {});
}

From source file:Main.java

/**
 * Normalize a uri containing ../ and ./ paths.
 *
 * @param uri The uri path to normalize//from w ww.ja  v  a2  s .  c om
 * @return The normalized uri
 */
public static String normalize(String uri) {
    if ("".equals(uri)) {
        return uri;
    }
    int leadingSlashes;
    for (leadingSlashes = 0; leadingSlashes < uri.length()
            && uri.charAt(leadingSlashes) == '/'; ++leadingSlashes) {
    }
    boolean isDir = (uri.charAt(uri.length() - 1) == '/');
    StringTokenizer st = new StringTokenizer(uri, "/");
    LinkedList clean = new LinkedList();
    while (st.hasMoreTokens()) {
        String token = st.nextToken();
        if ("..".equals(token)) {
            if (!clean.isEmpty() && !"..".equals(clean.getLast())) {
                clean.removeLast();
                if (!st.hasMoreTokens()) {
                    isDir = true;
                }
            } else {
                clean.add("..");
            }
        } else if (!".".equals(token) && !"".equals(token)) {
            clean.add(token);
        }
    }
    StringBuffer sb = new StringBuffer();
    while (leadingSlashes-- > 0) {
        sb.append('/');
    }
    for (Iterator it = clean.iterator(); it.hasNext();) {
        sb.append(it.next());
        if (it.hasNext()) {
            sb.append('/');
        }
    }
    if (isDir && sb.length() > 0 && sb.charAt(sb.length() - 1) != '/') {
        sb.append('/');
    }
    return sb.toString();
}

From source file:eu.stratosphere.pact.test.util.TestBase.java

protected static Collection<Object[]> toParameterList(List<Configuration> testConfigs) {
    LinkedList<Object[]> configs = new LinkedList<Object[]>();
    for (Configuration testConfig : testConfigs) {
        Object[] c = { testConfig };
        configs.add(c);
    }//w  ww  .java 2  s .c  om
    return configs;
}

From source file:de.ks.idnadrev.expimp.xls.SingleSheetImport.java

static List<Object> resolveToManyRelation(Class<?> type, String identifierProperty,
        List<String> singleIdentifiers) {
    LinkedList<Object> retval = new LinkedList<>();
    for (String identifier : singleIdentifiers) {
        Object entity = resolveEntity(type, identifierProperty, identifier);
        retval.add(entity);
    }/*from   w  w w  .  ja  va  2 s. com*/
    return retval;
}

From source file:Main.java

public static LinkedList<Pair<Integer, String>> retrieveIntegerStringPairFromCursor(Cursor cursor,
        String integerColumnName, String stringColumnName) {
    LinkedList<Pair<Integer, String>> result = new LinkedList<Pair<Integer, String>>();

    if (null == cursor || 0 == cursor.getCount()) {
        return result;
    }//from w  ww . j a va2 s.co m

    try {
        for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
            Integer integerVal = cursor.getInt(cursor.getColumnIndex(integerColumnName));
            String stringVal = cursor.getString(cursor.getColumnIndexOrThrow(stringColumnName));
            result.add(new Pair(integerVal, stringVal));
        }
    } catch (Exception e) {
        //do nothing.
    } finally {
        cursor.close();
    }

    return result;
}

From source file:view.visualization.TXTVisualization.java

public static LinkedList<String> atributi(String txt) {
    boolean kraj = false;

    LinkedList<String> atributi = new LinkedList<String>();

    try {/*from w  ww  .ja  v  a 2  s. c  o  m*/
        BufferedReader in = new BufferedReader(new FileReader(txt));

        int br = Integer.parseInt(in.readLine().split(" ")[1]);
        for (int j = 0; j < br + 1; j++) {

            String pom = in.readLine();
            if (pom.contains("@attribute") && pom.contains("numeric")) {
                atributi.add(pom.substring(11, pom.lastIndexOf("n") - 1));
            }

        }
        in.close();
    } catch (Exception e) {
        e.getMessage();
    }
    return atributi;

}

From source file:com.frostwire.android.MediaScanner.java

private static void scanFiles(final Context context, List<String> paths, int retries) {
    if (paths.size() == 0) {
        return;//from ww  w  .ja  va  2s.c om
    }

    LOG.info("About to scan files n: " + paths.size() + ", retries: " + retries);

    final LinkedList<String> failedPaths = new LinkedList<>();

    final CountDownLatch finishSignal = new CountDownLatch(paths.size());

    MediaScannerConnection.scanFile(context, paths.toArray(new String[0]), null, (path, uri) -> {
        try {
            boolean success = true;
            if (uri == null) {
                success = false;
                failedPaths.add(path);
            } else {
                // verify the stored size four faulty scan
                long size = getSize(context, uri);
                if (size == 0) {
                    LOG.warn("Scan returned an uri but stored size is 0, path: " + path + ", uri:" + uri);
                    success = false;
                    failedPaths.add(path);
                }
            }
            if (!success) {
                LOG.info("Scan failed for path: " + path + ", uri: " + uri);
            }
        } finally {
            finishSignal.countDown();
        }
    });

    try {
        finishSignal.await(10, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        // ignore
    }

    if (failedPaths.size() > 0 && retries > 0) {
        // didn't want to do this, but there is a serious timing issue with the SD
        // and storage in general
        SystemClock.sleep(2000);
        scanFiles(context, failedPaths, retries - 1);
    }
}

From source file:com.fengduo.bee.commons.core.lang.BeanUtils.java

public static LinkedList<Field> _getAllFields(LinkedList<Field> fields, Class<?> type) {
    if (Argument.isEmpty(fields)) {
        fields = new LinkedList<Field>();
    }/*  w  w w .  ja  v  a 2  s  .  c  om*/
    for (Field field : type.getDeclaredFields()) {
        fields.add(field);
    }
    if (type.getSuperclass() != null) {
        fields.addAll(_getAllFields(fields, type.getSuperclass()));
    }
    return fields;
}

From source file:com.jaeksoft.searchlib.Logging.java

public final static String readLogs(int lines, String fileName) throws IOException {
    if (fileName == null)
        return null;
    File logFile = new File(getLogDirectory(), fileName);
    if (!logFile.exists())
        return null;
    FileReader fr = null;/*w w  w . j  a  v a 2  s . c o m*/
    BufferedReader br = null;
    StringWriter sw = null;
    PrintWriter pw = null;
    LinkedList<String> list = new LinkedList<String>();
    try {
        fr = new FileReader(logFile);
        br = new BufferedReader(fr);
        String line = null;
        int size = 0;
        while ((line = br.readLine()) != null) {
            list.add(line);
            if (size++ > lines)
                list.remove();
        }
        sw = new StringWriter();
        pw = new PrintWriter(sw);
        for (String l : list)
            pw.println(StringEscapeUtils.escapeJava(l));
        return sw.toString();
    } finally {
        IOUtils.close(br, fr, pw, sw);
    }
}