Example usage for java.util List remove

List of usage examples for java.util List remove

Introduction

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

Prototype

E remove(int index);

Source Link

Document

Removes the element at the specified position in this list (optional operation).

Usage

From source file:com.ikon.omr.OMRHelper.java

/**
 * storeMetadata//from  ww w.j  av  a 2s .  com
 */
public static void storeMetadata(Map<String, String> results, String docPath)
        throws IOException, ParseException, PathNotFoundException, RepositoryException, DatabaseException,
        NoSuchGroupException, LockException, AccessDeniedException, ExtensionException, AutomationException,
        NoSuchPropertyException, OMRException {
    List<String> groups = new ArrayList<String>();

    for (String key : results.keySet()) {
        if (key.contains(":")) {
            String grpName = key.substring(0, key.indexOf("."));

            // convert to okg (group name always start with okg )
            grpName = grpName.replace("okp", "okg");
            if (!groups.contains(grpName)) {
                groups.add(grpName);
            }
        }
    }

    // Add missing groups
    for (PropertyGroup registeredGroup : OKMPropertyGroup.getInstance().getGroups(null, docPath)) {
        if (groups.contains(registeredGroup.getName())) {
            groups.remove(registeredGroup.getName());
        }
    }
    // Add properties
    for (String grpName : groups) {
        OKMPropertyGroup.getInstance().addGroup(null, docPath, grpName);

        // convert okg to okp ( property format )
        String propertyBeginning = grpName.replace("okg", "okp");
        Map<String, String> properties = new HashMap<String, String>();

        for (String key : results.keySet()) {
            if (key.startsWith(propertyBeginning)) {
                String value = results.get(key);

                // Evaluate select multiple otherside throw exception
                if (value.contains(" ")) {
                    for (FormElement formElement : OKMPropertyGroup.getInstance().getPropertyGroupForm(null,
                            grpName)) {
                        if (formElement.getName().equals(key) && formElement instanceof Select) {
                            if (!((Select) formElement).getType().equals(Select.TYPE_MULTIPLE)) {
                                throw new OMRException(
                                        "Found multiple value in a non multiple select. White space indicates multiple value");
                            } else {
                                // Change " " to ";" the way to pass
                                // multiple values into setPropertiesSimple
                                value = value.replaceAll(" ", ";");
                            }
                        }
                    }
                }

                properties.put(key, value);
            }
        }

        OKMPropertyGroup.getInstance().setPropertiesSimple(null, docPath, grpName, properties);
    }
}

From source file:com.jxva.exception.ExceptionUtil.java

/**
 * <p>Removes from the list of method names used in the search for <code>Throwable</code>
 * objects.</p>//  ww  w  .j  a  v  a2s.  c o m
 * 
 * @param methodName  the methodName to remove from the list, <code>null</code>
 *  and empty strings are ignored
 * @since 2.1
 */
public static void removeCauseMethodName(String methodName) {
    if (!StringUtil.isEmpty(methodName)) {
        List<String> list = getCauseMethodNameList();
        if (list.remove(methodName)) {
            synchronized (CAUSE_METHOD_NAMES) {
                CAUSE_METHOD_NAMES = toArray(list);
            }
        }
    }
}

From source file:Main.java

/**
 * Remove identical adjacent tags from {@code decorations}.
 * /*from  w w  w .j a  v  a2 s .c  o m*/
 * @param decorations see {@link prettify.parser.Job#decorations}
 * @param source the source code
 * 
 * @return the {@code decorations} after treatment
 * 
 * @throws IllegalArgumentException the size of {@code decoration} is not
 * a multiple of 2
 */
public static List<Object> removeDuplicates(List<Object> decorations, String source) {
    if (decorations == null) {
        throw new NullPointerException("argument 'decorations' cannot be null");
    }
    if (source == null) {
        throw new NullPointerException("argument 'source' cannot be null");
    }
    if ((decorations.size() & 0x1) != 0) {
        throw new IllegalArgumentException("the size of argument 'decorations' should be a multiple of 2");
    }

    List<Object> returnList = new ArrayList<Object>();

    // use TreeMap to remove entrys with same pos
    Map<Integer, Object> orderedMap = new TreeMap<Integer, Object>();
    for (int i = 0, iEnd = decorations.size(); i < iEnd; i += 2) {
        orderedMap.put((Integer) decorations.get(i), decorations.get(i + 1));
    }

    // remove adjacent style
    String previousStyle = null;
    for (Integer pos : orderedMap.keySet()) {
        String style = (String) orderedMap.get(pos);
        if (previousStyle != null && previousStyle.equals(style)) {
            continue;
        }
        returnList.add(pos);
        returnList.add(style);
        previousStyle = style;
    }

    // remove last zero length tag
    int returnListSize = returnList.size();
    if (returnListSize >= 4 && returnList.get(returnListSize - 2).equals(source.length())) {
        returnList.remove(returnListSize - 2);
        returnList.remove(returnListSize - 2);
    }

    return returnList;
}

From source file:gov.nih.nci.caintegrator.application.lists.UserListGenerator.java

public static List<String> generateList(FileItem formFile) throws IOException {

    List<String> tempList = new ArrayList<String>();

    if ((formFile != null) && (formFile.getName().endsWith(".txt") || formFile.getName().endsWith(".TXT"))) {

        try {/*from  w  w  w .ja v  a 2 s  . c o  m*/
            InputStream stream = formFile.getInputStream();
            String inputLine = null;
            BufferedReader inFile = new BufferedReader(new InputStreamReader(stream));

            do {
                inputLine = inFile.readLine();

                if (inputLine != null) {
                    if (isAscii(inputLine)) { // make sure all data is ASCII                                                        
                        tempList.add(inputLine);
                    }
                } else {
                    System.out.println("null line");
                    while (tempList.contains("")) {
                        tempList.remove("");
                    }
                    inFile.close();
                    break;
                }

            } while (true);
        } catch (EOFException eof) {
            logger.error("Errors when reading empty lines in file:" + eof.getMessage());
        } catch (IOException ex) {
            logger.error("Errors when uploading file:" + ex.getMessage());
        }

    }

    return tempList;

}

From source file:com.deliciousdroid.platform.ContactManager.java

/**
 * Synchronize raw contacts/*from   www .j  a  va 2 s .  c  o m*/
 * 
 * @param context The context of Authenticator Activity
 * @param account The username for the account
 * @param users The list of users
 */
public static synchronized void syncContacts(Context context, String account, List<User> users) {
    String userName;
    long rawContactId = 0;
    final ContentResolver resolver = context.getContentResolver();

    List<Long> currentContacts = lookupAllContacts(resolver);

    final BatchOperation batchOperation = new BatchOperation(context, resolver);
    Log.d(TAG, "In SyncContacts");
    for (final User user : users) {
        userName = user.getUserName();
        // Check to see if the contact needs to be inserted or updated
        rawContactId = lookupRawContact(resolver, userName);
        if (rawContactId == 0) {
            // add new contact
            Log.d(TAG, "In addContact");
            addContact(context, account, user, batchOperation);
        } else {
            currentContacts.remove(rawContactId);
        }
        // A sync adapter should batch operations on multiple contacts,
        // because it will make a dramatic performance difference.
        if (batchOperation.size() >= 50) {
            batchOperation.execute();
        }
    }

    for (final Long l : currentContacts) {
        Log.d(TAG, "Deleting contact");
        deleteContact(context, l, batchOperation);
    }

    batchOperation.execute();
}

From source file:fr.zcraft.zlib.tools.mojang.UUIDFetcher.java

/**
 * Fetches the UUIDs of the given list of player names from the Mojang API with one request for
 * them all.// w ww  . j  a  v a2 s .  c o  m
 *
 * <p><b>WARNING: this method needs to be called from a dedicated thread, as the requests to
 * Mojang are executed directly in the current thread and, due to the Mojang API rate limit, the
 * thread may be frozen to wait a bit between requests if a lot of UUID are requested.</b></p>
 *
 * This method may not be able to retrieve UUIDs for some players with old accounts. For them,
 * use {@link #fetchRemaining(Collection, Map)}.
 *
 * @param names A list of player names.
 *
 * @return A map linking a player name to his Mojang {@link UUID}.
 * @throws IOException If an exception occurs while contacting the Mojang API.
 */
static private Map<String, UUID> rawFetch(List<String> names) throws IOException {
    Map<String, UUID> uuidMap = new HashMap<>();
    HttpURLConnection connection = getPOSTConnection(PROFILE_URL);

    writeBody(connection, names);
    JSONArray array;
    try {
        array = (JSONArray) readResponse(connection);
    } catch (ParseException ex) {
        throw new IOException("Invalid response from server, unable to parse received JSON : " + ex.toString());
    }

    if (array == null)
        return uuidMap;

    List<String> remainingNames = new ArrayList<String>();
    remainingNames.addAll(names);

    for (Object profile : array) {
        JSONObject jsonProfile = (JSONObject) profile;
        String foundName = (String) jsonProfile.get("name");
        String name = null;
        for (String requestedName : remainingNames) {
            if (requestedName.equalsIgnoreCase(foundName)) {
                name = requestedName;
                break;
            }
        }

        if (name == null) {
            name = foundName;
        } else {
            remainingNames.remove(name);
        }

        String id = (String) jsonProfile.get("id");
        uuidMap.put(name, fromMojangUUID(id));
    }

    return uuidMap;
}

From source file:com.nzion.util.UtilMisc.java

public static <T> T removeFirst(List<T> lst) {
    return lst.remove(0);
}

From source file:Lists.java

public static <T> List<T> remove(List<T> list, int toRemove) {
    switch (list.size()) {
    case 0://from  w  w w  . jav a  2 s .c o m
        // Empty
        throw newIndexOutOfBounds(list, toRemove);
    case 1:
        // Singleton -> Empty
        if (toRemove == 0) {
            return Collections.emptyList();
        } else {
            throw newIndexOutOfBounds(list, toRemove);
        }
    case 2:
        // ArrayList -> Singleton
        switch (toRemove) {
        case 0:
            return Collections.singletonList(list.get(1));
        case 1:
            return Collections.singletonList(list.get(0));
        default:
            throw newIndexOutOfBounds(list, toRemove);
        }
    default:
        // ArrayList
        list.remove(toRemove);
        return list;
    }
}

From source file:io.dockstore.client.cli.Client.java

private static boolean flag(List<String> args, String flag) {
    boolean found = false;
    for (int i = 0; i < args.size(); i++) {
        if (flag.equals(args.get(i))) {
            if (found) {
                kill("consonance: multiple instances of '%s'.", flag);
            } else {
                found = true;//  ww  w .  java2s . c o m
                args.remove(i);
            }
        }
    }
    return found;
}

From source file:com.nextep.datadesigner.vcs.services.VersionHelper.java

/**
 * Checks if the specified version is available. This method will query the database to check
 * that the specified version number has not already been created (for example on another view)
 * //from w ww. j av  a 2  s.  c  o  m
 * @param version version to check the availability of
 * @return a flag indicating the version number availability
 */
@SuppressWarnings("unchecked")
public static boolean isVersionAvailable(IVersionInfo version) {
    final long versionNo = computeVersion(version);
    List<IVersionInfo> versions = (List<IVersionInfo>) CorePlugin.getIdentifiableDao()
            .loadForeignKey(VersionInfo.class, version.getReference().getReferenceId(), "reference"); //$NON-NLS-1$

    // Checking availability of this version
    for (IVersionInfo info : new ArrayList<IVersionInfo>(versions)) {
        if (info.isDropped()) {
            versions.remove(info);
        } else {
            // Comparing values
            if (versionNo == computeVersion(info)) {
                return false;
            }
        }
    }
    return true;

}