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.gui.Messages.java

public static final String[][] getTranslatorTable(Locale locale) {
    Enumeration keyEnumerator = DEFAULT_RESOURCE_BUNDLE.getKeys();
    LinkedList list = new LinkedList();
    while (keyEnumerator.hasMoreElements()) {
        list.addLast(keyEnumerator.nextElement());
    }/*from   w w  w .ja  v a2s  . c  o  m*/
    String[] keys = new String[list.size()];
    list.toArray(keys);
    Arrays.sort(keys, String.CASE_INSENSITIVE_ORDER);
    String[][] data = new String[keys.length][3];
    PropertyResourceBundle localeBundle = null;
    try {
        String programDir = System.getProperty("gcaldaemon.program.dir", "/Progra~1/GCALDaemon");
        File langDir = new File(programDir, "lang");
        if (!langDir.isDirectory()) {
            langDir.mkdir();
        } else {
            File msgFile = new File(langDir, "messages-" + locale.getLanguage().toLowerCase() + ".txt");
            if (msgFile.isFile()) {
                InputStream in = new BufferedInputStream(new FileInputStream(msgFile));
                localeBundle = new PropertyResourceBundle(in);
                in.close();
            }
        }
    } catch (Exception ignored) {
        log.warn("Unable to load messages!", ignored);
    }
    for (int i = 0; i < keys.length; i++) {
        data[i][0] = keys[i];
        data[i][1] = DEFAULT_RESOURCE_BUNDLE.getString(keys[i]);
        if (localeBundle != null) {
            try {
                data[i][2] = localeBundle.getString(keys[i]);
            } catch (Exception ignored) {
            }
        }
        if (data[i][2] == null) {
            data[i][2] = data[i][1];
        }
    }
    return data;
}

From source file:es.emergya.cliente.constants.LogicConstants.java

public static String[] getPriorities(boolean b) {
    LinkedList<String> res = new LinkedList<String>();
    if (b)//  w w w . j av a 2 s.com
        res.add("");
    for (Integer i = LogicConstants.getInt("LOWEST_PRIORITY", 0); i < LogicConstants.getInt("HIGHEST_PRIORITY",
            9); i++)
        res.add(i.toString());
    return res.toArray(new String[0]);
}

From source file:es.emergya.cliente.constants.LogicConstantsUI.java

public static String[] getPriorities(boolean b) {
    LinkedList<String> res = new LinkedList<String>();
    if (b)/*from  ww  w.  j a v  a  2 s .  com*/
        res.add("");
    for (Integer i = LogicConstantsUI.getInt("LOWEST_PRIORITY", 0); i < LogicConstantsUI
            .getInt("HIGHEST_PRIORITY", 9); i++)
        res.add(i.toString());
    return res.toArray(new String[0]);
}

From source file:Main.java

public static String[] intersect(String[] arr1, String[] arr2) {
    Map<String, Boolean> map = new HashMap<>();
    LinkedList<String> list = new LinkedList<>();
    for (String str : arr1) {
        if (!map.containsKey(str)) {
            map.put(str, Boolean.FALSE);
        }//from w  w w  .j  a  va 2 s.c  o m
    }

    for (String str : arr2) {
        if (map.containsKey(str)) {
            map.put(str, Boolean.TRUE);
        }
    }

    for (Map.Entry<String, Boolean> e : map.entrySet()) {
        if (e.getValue().equals(Boolean.TRUE)) {
            list.add(e.getKey());
        }
    }
    String[] result = {};
    return list.toArray(result);
}

From source file:Main.java

public static String[] intersect(String[] arr1, String[] arr2) {
    Map<String, Boolean> map = new HashMap<String, Boolean>();
    LinkedList<String> list = new LinkedList<String>();
    for (String str : arr1) {
        if (!map.containsKey(str)) {
            map.put(str, Boolean.FALSE);
        }//from w  w  w.j  a  v  a  2s.c  om
    }

    for (String str : arr2) {
        if (map.containsKey(str)) {
            map.put(str, Boolean.TRUE);
        }
    }

    for (Map.Entry<String, Boolean> e : map.entrySet()) {
        if (e.getValue().equals(Boolean.TRUE)) {
            list.add(e.getKey());
        }
    }

    String[] result = {};
    return list.toArray(result);
}

From source file:org.paxle.se.index.lucene.impl.Converter.java

private static Object[] field2array(Fieldable lfield, org.paxle.core.doc.Field<?> pfield) throws IOException {
    final LinkedList<Object> r = new LinkedList<Object>();
    final TokenStream ts = lfield.tokenStreamValue();
    Token token = new Token();
    while ((token = ts.next(token)) != null)
        r.add(String.valueOf(token.termBuffer(), 0, token.termLength()));
    return r.toArray(new Object[r.size()]);
}

From source file:at.bitfire.davdroid.resource.LocalTaskList.java

public static LocalTaskList[] findAll(Account account, ContentProviderClient providerClient)
        throws RemoteException {
    @Cleanup/*from  www . j  ava  2 s  .c  o  m*/
    Cursor cursor = providerClient.query(taskListsURI(account),
            new String[] { TaskContract.TaskLists._ID, TaskContract.TaskLists._SYNC_ID }, null, null, null);

    LinkedList<LocalTaskList> taskList = new LinkedList<>();
    while (cursor != null && cursor.moveToNext())
        taskList.add(new LocalTaskList(account, providerClient, cursor.getInt(0), cursor.getString(1)));
    return taskList.toArray(new LocalTaskList[taskList.size()]);
}

From source file:org.opennms.test.mock.MockLogAppender.java

/**
 * <p>getEventsGreaterOrEqual</p>
 *
 * @param level a {@link org.apache.log4j.Level} object.
 * @return an array of {@link org.apache.log4j.spi.LoggingEvent} objects.
 *//*w w w.ja va2 s  . c om*/
public static LoggingEvent[] getEventsGreaterOrEqual(final Level level) {
    LinkedList<LoggingEvent> matching = new LinkedList<LoggingEvent>();

    synchronized (s_events) {
        for (final LoggingEvent event : s_events) {
            if (event.getLevel().isGreaterOrEqual(level)) {
                matching.add(event);
            }
        }
    }

    return matching.toArray(new LoggingEvent[0]);
}

From source file:org.opennms.test.mock.MockLogAppender.java

/**
 * <p>getEventsAtLevel</p>/*from  www  .ja  v  a2s .  c  o  m*/
 *
 * Returns events that were logged at the specified level
 * 
 * @param level a {@link org.apache.log4j.Level} object.
 * @return an array of {@link org.apache.log4j.spi.LoggingEvent} objects.
 */
public static LoggingEvent[] getEventsAtLevel(final Level level) {
    LinkedList<LoggingEvent> matching = new LinkedList<LoggingEvent>();

    synchronized (s_events) {
        for (final LoggingEvent event : s_events) {
            if (event.getLevel().isGreaterOrEqual(level)) {
                matching.add(event);
            }
        }
    }

    return matching.toArray(new LoggingEvent[0]);
}

From source file:org.opennms.core.test.MockLogAppender.java

/**
 * <p>getEventsGreaterOrEqual</p>
 *
 *//*from ww  w . j av  a  2s  .  co m*/
public static LoggingEvent[] getEventsGreaterOrEqual(final Level level) {
    LinkedList<LoggingEvent> matching = new LinkedList<LoggingEvent>();

    synchronized (s_events) {
        for (final LoggingEvent event : s_events) {
            if (event.getLevel().ge(level)) {
                matching.add(event);
            }
        }
    }

    return matching.toArray(EMPTY_LOGGING_EVENT);
}