Example usage for java.util LinkedList LinkedList

List of usage examples for java.util LinkedList LinkedList

Introduction

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

Prototype

public LinkedList() 

Source Link

Document

Constructs an empty list.

Usage

From source file:hr.fer.tel.rovkp.homework03.task01.JokesCollection.java

public static Map<Integer, String> parseInputFile(String file) throws IOException {
    Path filePath = Paths.get(file);
    Map<Integer, String> results = new HashMap<>();

    List<String> currentJoke = new LinkedList<>();
    LinkedList<Integer> ids = new LinkedList<>();

    try (Stream<String> stream = Files.lines(filePath)) {
        stream.forEach(line -> {/*  w ww . j a  v  a  2 s. c  om*/
            if (line == null)
                return;
            line = line.trim();

            if (line.isEmpty() && !currentJoke.isEmpty()) {
                int currentId = ids.getLast();
                String jokeText = StringUtils.join(currentJoke, "\n");
                jokeText = StringEscapeUtils.unescapeXml(jokeText.toLowerCase().replaceAll("\\<.*?\\>", ""));
                if (results.putIfAbsent(currentId, jokeText) != null)
                    System.err.println("Joke with id " + currentId + "already exists. Not overwriting.");
            } else if (line.matches("^[0-9]+:$")) {
                ids.addLast(Integer.parseInt(line.substring(0, line.length() - 1)));
                currentJoke.clear();
            } else {
                currentJoke.add(line);
            }
        });
    }

    return results;
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.edit.utils.RoleLevelOptionsSetup.java

public static List<Option> getUpdateOptionsList(ResourceBean b) {
    List<Option> prohibitedFromUpdateList = new LinkedList<Option>();
    try {//from   www .  j a va 2 s .co  m
        BaseResourceBean.RoleLevel currentLevel = b.getProhibitedFromUpdateBelowRoleLevel();
        BaseResourceBean.RoleLevel roles[] = BaseResourceBean.RoleLevel.values();
        boolean someLevelSet = false;
        Option publicOption = null;
        for (BaseResourceBean.RoleLevel level : roles) {
            Option option = new Option(level.getURI(), level.getUpdateLabel(), false);
            if (level == BaseResourceBean.RoleLevel.PUBLIC) {
                publicOption = option;
            }
            if (level == currentLevel) {
                option.setSelected(true);
                someLevelSet = true;
            }
            prohibitedFromUpdateList.add(option);
        }
        if (!someLevelSet) {
            publicOption.setSelected(true);
        }
    } catch (Exception ex) {
        log.error("cannot create ProhibitedFromUpdateBelowRoleLevel options");
    }
    return prohibitedFromUpdateList;
}

From source file:minij.TestFiles.java

private static List<Object[]> getFiles(Class<? extends Exception> exceptionClass, Path... paths) {
    List<Object[]> files = new LinkedList<>();

    for (Path path : paths) {
        for (File file : FileUtils.listFiles(path.toFile(), null, true)) {
            files.add(new Object[] { file, exceptionClass });
        }// w w  w .j  a v  a2 s.  c o m
    }

    return files;
}

From source file:com.tlantic.integration.authentication.service.security.UserAuthConfigService.java

public List<GrantedAuthority> getRights(User user) {
    List<GrantedAuthority> grantedAuthority = new LinkedList<>();
    List<String> right = user.getRights();
    if (null != right && !right.isEmpty()) {
        right.stream().forEach(r -> {
            grantedAuthority.add(new SimpleGrantedAuthority(r));
        });//  www  . j  a  va  2  s  .c  o  m
    }
    return grantedAuthority;
}

From source file:Main.java

/**
 * <p>//  w w  w .ja  va 2s  .co m
 * Converts an Object reference that is known to be an array into a List.
 * Semantically very similar to {@link java.util.Arrays#asList(Object[])}
 * except that this method can deal with arrays of primitives in the same
 * manner as arrays as objects.
 * </p>
 * 
 * <p>
 * A new List is created of the same size as the array, and elements are
 * copied from the array into the List. If elements are primitives then they
 * are converted to the appropriate wrapper types in order to return a List.
 * </p>
 * 
 * @param in
 *            an array of Objects or primitives (null values are not
 *            allowed)
 * @return a List containing an element for each element in the input array
 * @throws IllegalArgumentException
 *             thrown if the in parameter is null or not an array
 */
public static List<Object> asList(Object in) {
    if (in == null || !in.getClass().isArray()) {
        throw new IllegalArgumentException("Parameter to asObjectArray must be a non-null array.");
    } else {
        int length = Array.getLength(in);
        LinkedList<Object> list = new LinkedList<Object>();
        for (int i = 0; i < length; ++i) {
            list.add(i, Array.get(in, i));
        }

        return list;
    }
}

From source file:ec.edu.espe.distribuidas.facturacion.socket.estrucMsj.tipoDato.TextV.java

public TextV(Ent ent) {
    this.numeroGrupos = ent;
    this.longitud = -1;
    datos = new LinkedList<>();
}

From source file:com.galenframework.ide.devices.tasks.DeviceTaskParser.java

private static List<DeviceCommand> parseCommands(ObjectMapper mapper, JsonNode commandsNode)
        throws InvocationTargetException, NoSuchMethodException, InstantiationException,
        IllegalAccessException {/*from  w  ww.j a v  a  2 s  .  c o  m*/
    if (commandsNode.isArray()) {
        Iterator<JsonNode> it = commandsNode.iterator();

        List<DeviceCommand> commands = new LinkedList<>();
        while (it.hasNext()) {
            commands.add(parseCommand(mapper, it.next()));
        }
        return commands;
    } else {
        throw new RuntimeException("\"commands\" should be an array");
    }
}

From source file:fr.gouv.culture.thesaurus.util.LangUtils.java

@SuppressWarnings("unchecked")
public static List<Locale> expand(Locale[] locales) {
    List<Locale> expandedLocales = new LinkedList<Locale>();
    for (Locale locale : locales) {
        if (locale != null) {
            expandedLocales.addAll(LocaleUtils.localeLookupList(locale));
        } else {//from  w  w w  .ja  va2  s .co  m
            expandedLocales.add(null);
        }
    }

    return expandedLocales;
}

From source file:model.DefaultDataManagerImpl.java

public DefaultDataManagerImpl() {
    paymentList = new LinkedList<>();
    netAmounts = new ConcurrentHashMap<>();
}

From source file:net.idlesoft.android.apps.github.adapters.JsonListAdapter.java

public JsonListAdapter(final Activity pActivity, final AbsListView pListView) {
    super(pActivity, pListView, R.layout.loading_listitem);

    mActivity = pActivity;//ww w.j a  v  a 2s  . com
    mInflater = LayoutInflater.from(pActivity);
    mListData = new LinkedList<Object>();
}