Example usage for java.util LinkedList toArray

List of usage examples for java.util LinkedList toArray

Introduction

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

Prototype

@SuppressWarnings("unchecked")
public <T> T[] toArray(T[] a) 

Source Link

Document

Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array.

Usage

From source file:org.gcaldaemon.core.ldap.ContactLoader.java

private static final GmailContact[] parseCSV(String csv) {

    // Parse lines
    if (csv == null) {
        return null;
    }/* w w w. j a  v a  2  s . co m*/
    LinkedList contactList = new LinkedList();
    StringTokenizer st = new StringTokenizer(csv, "\r\n");
    while (st.hasMoreTokens()) {
        GmailContact contact = parseLine(st.nextToken());
        if (contact != null) {
            if (contact.name.length() == 0 && contact.email.length() == 0) {
                continue;
            }
            contactList.addLast(contact);
        }
    }

    // Convert list to array
    GmailContact[] array = new GmailContact[contactList.size()];
    contactList.toArray(array);

    // Return contact array
    return array;
}

From source file:es.emergya.bbdd.dao.PatrullaHome.java

public Patrulla[] getAsigned(Incidencia i) {
    Recurso[] recursos = RecursoConsultas.getAsigned(i);
    LinkedList<Patrulla> res = new LinkedList<Patrulla>();
    for (Recurso rec : recursos)
        if (!res.contains(rec.getPatrullas()))
            res.add(rec.getPatrullas());
    return res.toArray(new Patrulla[0]);
}

From source file:com.axway.ebxml.CertificateChain.java

/**
 * Constructor// w  w w .ja  va 2s . c  o  m
 * @param certificatePath path to a p7b or DER encoded file
 * @return Array of X509Certificate
 * @throws java.io.FileNotFoundException
 * @throws java.security.cert.CertificateException
 */
public CertificateChain(String certificatePath) throws CertificateException, IOException {
    if (certificatePath == null)
        throw new IllegalArgumentException("certificatePath expected");

    logger.debug("Loading certificate from: " + certificatePath);

    LinkedList<X509Certificate> returnList = new LinkedList<X509Certificate>();
    FileInputStream fis = new FileInputStream(certificatePath);
    try {
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        Collection certificates = cf.generateCertificates(fis);
        for (Object cert : certificates) {
            returnList.add((X509Certificate) cert);
            logger.debug("Certificate: " + cert);
        }
    } finally {
        fis.close();
    }

    chain = returnList.toArray(new X509Certificate[returnList.size()]);
}

From source file:org.osframework.contract.date.fincal.holiday.producer.SingleYearProducer.java

public Holiday[] produce(FinancialCalendar... calendars) {
    // Sort calendars alphabetically by ID
    Arrays.sort(calendars, new Comparator<FinancialCalendar>() {
        public int compare(FinancialCalendar c1, FinancialCalendar c2) {
            return c1.getId().compareTo(c2.getId());
        }//from   w  w w .j  a v a 2 s. c o  m
    });
    LinkedList<Holiday> holidays = new LinkedList<Holiday>();
    for (FinancialCalendar calendar : calendars) {
        for (HolidayDefinition hd : calendar) {
            HolidayExpression expr = CentralBankDecoratorLocator.decorate(hd, calendar.getCentralBank());
            Date date = expr.evaluate(year);
            holidays.add(new Holiday(calendar, date, hd));
        }
        if (weekendsAsHolidays) {
            addWeekends(calendar, holidays);
        }
    }
    return holidays.toArray(EMPTY_ARRAY);
}

From source file:name.marcelomorales.siqisiqi.openjpa.impl.OrmFinderImpl.java

protected Predicate newFullTextPredicate(CriteriaBuilder cb, Root<T> p, String terms) {
    LinkedList<Predicate> predicatesOr = Lists.newLinkedList();
    Iterable<Path<String>> fullTexts = settings.getFullTexts(p, persistentClass);
    if (fullTexts != null) {
        for (Path<String> x : fullTexts) {
            StringTokenizer tokenizer = new StringTokenizer(terms, " \t\n\r\f,.;:/");
            LinkedList<Predicate> predicatesAnd = Lists.newLinkedList();
            while (tokenizer.hasMoreTokens()) {
                String token = "%" + tokenizer.nextToken() + "%";

                predicatesAnd.add(cb.like(cb.lower(x), StringUtils.lowerCase(token)));
            }/*ww w .ja va2 s .co m*/
            predicatesOr.add(cb.and(predicatesAnd.toArray(new Predicate[predicatesAnd.size()])));
        }
    }
    final Predicate[] restrictions = predicatesOr.toArray(new Predicate[predicatesOr.size()]);
    return cb.or(restrictions);
}

From source file:com.espertech.esper.epl.core.ResultSetProcessorSimple.java

/**
 * Applies the select-clause to the given events returning the selected events. The number of events stays the
 * same, i.e. this method does not filter it just transforms the result set.
 * <p>//from ww  w  .  j av  a2s  .  c om
 * Also applies a having clause.
 * @param exprProcessor - processes each input event and returns output event
 * @param orderByProcessor - for sorting output events according to the order-by clause
 * @param events - input events
 * @param optionalHavingNode - supplies the having-clause expression
 * @param isNewData - indicates whether we are dealing with new data (istream) or old data (rstream)
 * @param isSynthesize - set to true to indicate that synthetic events are required for an iterator result set
 * @param exprEvaluatorContext context for expression evalauation
 * @return output events, one for each input event
 */
protected static EventBean[] getSelectEventsHaving(SelectExprProcessor exprProcessor,
        OrderByProcessor orderByProcessor, EventBean[] events, ExprEvaluator optionalHavingNode,
        boolean isNewData, boolean isSynthesize, ExprEvaluatorContext exprEvaluatorContext) {
    if (events == null) {
        return null;
    }

    LinkedList<EventBean> result = new LinkedList<EventBean>();
    List<EventBean[]> eventGenerators = null;
    if (orderByProcessor != null) {
        eventGenerators = new ArrayList<EventBean[]>();
    }

    EventBean[] eventsPerStream = new EventBean[1];
    for (EventBean theEvent : events) {
        eventsPerStream[0] = theEvent;

        Boolean passesHaving = (Boolean) optionalHavingNode.evaluate(eventsPerStream, isNewData,
                exprEvaluatorContext);
        if ((passesHaving == null) || (!passesHaving)) {
            continue;
        }

        result.add(exprProcessor.process(eventsPerStream, isNewData, isSynthesize, exprEvaluatorContext));
        if (orderByProcessor != null) {
            eventGenerators.add(new EventBean[] { theEvent });
        }
    }

    if (!result.isEmpty()) {
        if (orderByProcessor != null) {
            return orderByProcessor.sort(result.toArray(new EventBean[result.size()]),
                    eventGenerators.toArray(new EventBean[eventGenerators.size()][]), isNewData,
                    exprEvaluatorContext);
        } else {
            return result.toArray(new EventBean[result.size()]);
        }
    } else {
        return null;
    }
}

From source file:com.norconex.commons.lang.io.FileUtil.java

/**
 * Returns the specified number of lines starting from the end
 * of a text file.//  w  ww.  j a  v a 2 s. c o m
 * @param file the file to read lines from
 * @param encoding the file encoding
 * @param numberOfLinesToRead the number of lines to read
 * @param stripBlankLines whether to return blank lines or not
 * @param filter InputStream filter
 * @return array of file lines
 * @throws IOException i/o problem
 */
public static String[] tail(File file, String encoding, final int numberOfLinesToRead, boolean stripBlankLines,
        IInputStreamFilter filter) throws IOException {
    assertFile(file);
    assertNumOfLinesToRead(numberOfLinesToRead);
    LinkedList<String> lines = new LinkedList<String>();
    BufferedReader reader = new BufferedReader(
            new InputStreamReader(new ReverseFileInputStream(file), encoding));
    int remainingLinesToRead = numberOfLinesToRead;
    String line = StringUtils.EMPTY;
    while (line != null && remainingLinesToRead-- > 0) {
        line = StringUtils.defaultString(reader.readLine());
        char[] chars = line.toCharArray();
        for (int j = 0, k = chars.length - 1; j < k; j++, k--) {
            char temp = chars[j];
            chars[j] = chars[k];
            chars[k] = temp;
        }
        String newLine = new String(chars);
        if (!stripBlankLines || StringUtils.isNotBlank(line)) {
            if (filter != null && filter.accept(newLine)) {
                lines.addFirst(newLine);
            } else {
                remainingLinesToRead++;
            }
        } else {
            remainingLinesToRead++;
        }
    }
    reader.close();
    return lines.toArray(ArrayUtils.EMPTY_STRING_ARRAY);
}

From source file:com.bilibili.magicasakura.utils.ColorStateListUtils.java

static ColorStateList inflateColorStateList(Context context, XmlPullParser parser, AttributeSet attrs)
        throws IOException, XmlPullParserException {
    final int innerDepth = parser.getDepth() + 1;
    int depth;//w  ww . j av  a2  s . c  om
    int type;

    LinkedList<int[]> stateList = new LinkedList<>();
    LinkedList<Integer> colorList = new LinkedList<>();

    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
            && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) {
        if (type != XmlPullParser.START_TAG || depth > innerDepth || !parser.getName().equals("item")) {
            continue;
        }

        TypedArray a1 = context.obtainStyledAttributes(attrs, new int[] { android.R.attr.color });
        final int value = a1.getResourceId(0, Color.MAGENTA);
        final int baseColor = value == Color.MAGENTA ? Color.MAGENTA
                : ThemeUtils.replaceColorById(context, value);
        a1.recycle();
        TypedArray a2 = context.obtainStyledAttributes(attrs, new int[] { android.R.attr.alpha });
        final float alphaMod = a2.getFloat(0, 1.0f);
        a2.recycle();
        colorList.add(alphaMod != 1.0f
                ? ColorUtils.setAlphaComponent(baseColor, Math.round(Color.alpha(baseColor) * alphaMod))
                : baseColor);

        stateList.add(extractStateSet(attrs));
    }

    if (stateList.size() > 0 && stateList.size() == colorList.size()) {
        int[] colors = new int[colorList.size()];
        for (int i = 0; i < colorList.size(); i++) {
            colors[i] = colorList.get(i);
        }
        return new ColorStateList(stateList.toArray(new int[stateList.size()][]), colors);
    }
    return null;
}

From source file:de.tudarmstadt.ukp.dariah.pipeline.RunPipeline.java

/**
 * Parses a parameter string that can be found in the .properties files.
 * The parameterString is of the format parameterName1,parameterType1,parameterValue2,parameterName2,parameterType2,parameterValue2
 * @param config //  w w  w . ja  v  a  2s  .  c o m
 * 
 * @param parametersString
 * @return Mapped paramaterString to an Object[] array that can be inputted to UIMA components
 */
private static Object[] parseParameters(Configuration config, String parameterName)
        throws ConfigurationException {

    LinkedList<Object> parameters = new LinkedList<>();
    List<Object> parameterList = config.getList(parameterName);

    if (parameterList.size() % 3 != 0) {
        throw new ConfigurationException(
                "Parameter String must be a multiple of 3 in the format: name, type, value. " + parameterName);
    }

    for (int i = 0; i < parameterList.size(); i += 3) {
        String name = (String) parameterList.get(i + 0);
        String type = ((String) parameterList.get(i + 1)).toLowerCase();
        String value = (String) parameterList.get(i + 2);

        Object obj;

        switch (type) {
        case "bool":
        case "boolean":
            obj = Boolean.valueOf(value);
            break;

        case "int":
        case "integer":
            obj = Integer.valueOf(value);
            break;

        default:
            obj = value;
        }

        parameters.add(name);
        parameters.add(obj);
    }

    return parameters.toArray(new Object[0]);
}

From source file:com.espertech.esper.epl.core.ResultSetProcessorSimple.java

/**
 * Applies the select-clause to the given events returning the selected events. The number of events stays the
 * same, i.e. this method does not filter it just transforms the result set.
 * <p>//from  w w  w  .  j  a v  a2s  .co  m
 * Also applies a having clause.
 * @param exprProcessor - processes each input event and returns output event
 * @param orderByProcessor - for sorting output events according to the order-by clause
 * @param events - input events
 * @param optionalHavingNode - supplies the having-clause expression
 * @param isNewData - indicates whether we are dealing with new data (istream) or old data (rstream)
 * @param isSynthesize - set to true to indicate that synthetic events are required for an iterator result set
 * @param exprEvaluatorContext context for expression evalauation
 * @return output events, one for each input event
 */
protected static EventBean[] getSelectEventsHaving(SelectExprProcessor exprProcessor,
        OrderByProcessor orderByProcessor, Set<MultiKey<EventBean>> events, ExprEvaluator optionalHavingNode,
        boolean isNewData, boolean isSynthesize, ExprEvaluatorContext exprEvaluatorContext) {
    if ((events == null) || (events.isEmpty())) {
        return null;
    }

    LinkedList<EventBean> result = new LinkedList<EventBean>();
    List<EventBean[]> eventGenerators = null;
    if (orderByProcessor != null) {
        eventGenerators = new ArrayList<EventBean[]>();
    }

    for (MultiKey<EventBean> key : events) {
        EventBean[] eventsPerStream = key.getArray();

        Boolean passesHaving = (Boolean) optionalHavingNode.evaluate(eventsPerStream, isNewData,
                exprEvaluatorContext);
        if ((passesHaving == null) || (!passesHaving)) {
            continue;
        }

        EventBean resultEvent = exprProcessor.process(eventsPerStream, isNewData, isSynthesize,
                exprEvaluatorContext);
        result.add(resultEvent);
        if (orderByProcessor != null) {
            eventGenerators.add(eventsPerStream);
        }
    }

    if (!result.isEmpty()) {
        if (orderByProcessor != null) {
            return orderByProcessor.sort(result.toArray(new EventBean[result.size()]),
                    eventGenerators.toArray(new EventBean[eventGenerators.size()][]), isNewData,
                    exprEvaluatorContext);
        } else {
            return result.toArray(new EventBean[result.size()]);
        }
    } else {
        return null;
    }
}