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:cn.fql.utility.FileUtility.java

/**
 * do delete all files under specified file's dir
 *
 * @param root specified file root/* w w w. j  av a 2  s. co  m*/
 */
public static void deleteDirs(File root) throws Exception {
    System.setSecurityManager(SECURITYMANAGER);
    if (root.isDirectory()) {
        List allFiles = deleteAll(root);
        if (allFiles != null) {
            for (int i = allFiles.size() - 1; i >= 0; i--) {
                java.io.File f = (java.io.File) allFiles.remove(i);
                String fileName = f.toString();
                if (!f.delete()) {
                    throw new Exception("Exception: delete file " + fileName + " false!");
                }
            }
        }
    }
    System.setSecurityManager(SYSSECURITYMANAGER);
}

From source file:de.tor.tribes.util.AttackToTextWriter.java

public static boolean writeAttacks(Attack[] pAttacks, File pPath, int pAttacksPerFile, boolean pExtendedInfo,
        boolean pZipResults) {

    HashMap<Tribe, List<Attack>> attacks = new HashMap<>();

    for (Attack a : pAttacks) {
        Tribe t = a.getSource().getTribe();
        List<Attack> attsForTribe = attacks.get(t);
        if (attsForTribe == null) {
            attsForTribe = new LinkedList<>();
            attacks.put(t, attsForTribe);
        }//from w  w  w  .  j  a  v  a 2  s.c o m
        attsForTribe.add(a);
    }

    Set<Entry<Tribe, List<Attack>>> entries = attacks.entrySet();
    for (Entry<Tribe, List<Attack>> entry : entries) {
        Tribe t = entry.getKey();
        List<Attack> tribeAttacks = entry.getValue();
        List<String> blocks = new LinkedList<>();

        while (!tribeAttacks.isEmpty()) {
            List<Attack> attsForBlock = new LinkedList<>();
            for (int i = 0; i < pAttacksPerFile; i++) {
                if (!tribeAttacks.isEmpty()) {
                    attsForBlock.add(tribeAttacks.remove(0));
                }
            }

            String fileContent = new AttackListFormatter().formatElements(attsForBlock, pExtendedInfo);
            blocks.add(fileContent);
        }
        if (!pZipResults) {
            writeBlocksToFiles(blocks, t, pPath);
        } else {
            writeBlocksToZip(blocks, t, pPath);
        }

    }
    return true;
}

From source file:com.hangum.tadpole.engine.define.DBDefine.java

/**
 * get driver list//from ww w.  j  a  v  a2  s  .  co  m
 * 
 * @return
 */
public static List<DBDefine> getDriver() {
    List<DBDefine> listSupportDb = userDBValues();
    listSupportDb.remove(DBDefine.AMAZONRDS_DEFAULT);
    listSupportDb.remove(DBDefine.TAJO_DEFAULT);
    listSupportDb.remove(DBDefine.HIVE_DEFAULT);
    return listSupportDb;
}

From source file:com.netflix.config.util.ConfigurationUtils.java

/**
 * Gets all named sub-configuration from a configuration in a map. This method examines each sub-configuration
 * which is an instance of {@link ConcurrentCompositeConfiguration} or CombinedConfiguration and extract the 
 * named configurations out of them.// w w w.j  a v a2  s  . c o m
 *  
 * @param conf Configuration to get all the named sub-configurations
 * @return map where key is the name of the sub-configuration and value is the sub-configuration
 */
public static Map<String, Configuration> getAllNamedConfiguration(Configuration conf) {
    List<Configuration> toProcess = new ArrayList<Configuration>();
    Map<String, Configuration> map = new HashMap<String, Configuration>();
    toProcess.add(conf);
    while (!toProcess.isEmpty()) {
        Configuration current = toProcess.remove(0);
        if (current instanceof ConcurrentCompositeConfiguration) {
            ConcurrentCompositeConfiguration composite = (ConcurrentCompositeConfiguration) current;
            for (String name : composite.getConfigurationNames()) {
                map.put(name, composite.getConfiguration(name));
            }
            for (Configuration c : composite.getConfigurations()) {
                toProcess.add(c);
            }
        } else if (current instanceof CombinedConfiguration) {
            CombinedConfiguration combined = (CombinedConfiguration) current;
            for (String name : (Set<String>) combined.getConfigurationNames()) {
                map.put(name, combined.getConfiguration(name));
            }
            for (int i = 0; i < combined.getNumberOfConfigurations(); i++) {
                toProcess.add(combined.getConfiguration(i));
            }
        }
    }
    return map;
}

From source file:org.dozer.eclipse.plugin.sourcepage.util.DozerPluginUtils.java

public static IType hasWriteProperty(String property, String className, IProject project)
        throws JavaModelException {
    IType javaType = JdtUtils.getJavaType(project, className);
    String checkProperty = property;

    String[] propertySplitted = checkProperty.split("\\.");
    if (propertySplitted.length > 1) {
        List<String> l = new ArrayList(Arrays.asList(propertySplitted));
        checkProperty = l.get(l.size() - 1);
        l.remove(l.size() - 1);
        property = StringUtils.collectionToDelimitedString(l, ".");

        javaType = DozerPluginUtils.hasReadProperty(property, className, project, false);
        if (javaType == null)
            return null;
    }/*from www. ja  v a  2 s.c o m*/
    //if we are doing indexed property mapping, we remove the []
    checkProperty = checkProperty.replaceAll("\\[\\]", "");

    Collection<?> methods = Introspector.findWritableProperties(javaType, checkProperty, true);

    boolean retVal = methods.size() > 0;
    if (!retVal)
        return null;
    else
        return javaType;
}

From source file:de.willuhn.jameica.hbci.io.csv.ProfileUtil.java

/**
 * Loescht das angegebene Profil./*from  w w w . j  a va 2 s.co  m*/
 * @param format das Format.
 * @param profile das zu speichernde Profil.
 * @return true, wenn das Profil geloescht wurde.
 */
public static boolean delete(Format format, Profile profile) {
    if (profile == null || format == null)
        return false;

    try {
        if (profile.isSystem()) {
            Application.getCallback().notifyUser(i18n.tr("Das Default-Profil darf nicht gelscht werden"));
            return false;
        }

        List<Profile> profiles = ProfileUtil.read(format);
        boolean found = false;
        for (Profile p : profiles) {
            if (p.isSystem())
                continue;

            if (p.getName().equals(profile.getName())) {
                profiles.remove(p);
                found = true;
                break;
            }
        }

        // Nichts zum Loeschen gefunden
        if (!found)
            return false;

        // Speichern
        ProfileUtil.store(format, profiles);
        return true;
    } catch (OperationCanceledException oce) {
        // ignore
    } catch (Exception e) {
        Logger.error("unable to delete profile", e);
    }
    return false;
}

From source file:org.dozer.eclipse.plugin.sourcepage.util.DozerPluginUtils.java

public static IType hasReadProperty(String property, String className, IProject project, boolean noGetter)
        throws JavaModelException {
    IType javaType = JdtUtils.getJavaType(project, className);
    String checkProperty = property;

    String[] propertySplitted = checkProperty.split("\\.");
    //we only check the first level, if there is some x.y.z property
    if (propertySplitted.length > 1) {
        checkProperty = propertySplitted[0];
    }// w  ww .  ja v  a 2 s.c  o m
    //if we are doing indexed property mapping, we remove the []
    checkProperty = checkProperty.replaceAll("\\[\\]", "");

    if (noGetter) {
        IField[] fields = javaType.getFields();
        for (IField field : fields) {
            if (field.getElementName().equals(property)) {
                return field.getDeclaringType();
            }
        }
        return null;
    }

    Collection<IMethod> methods = Introspector.findReadableProperties(javaType, checkProperty, true);

    boolean retVal = methods.size() > 0;
    if (!retVal)
        return null;
    else {
        try {
            //className = JdtUtils.resolveClassName(className, javaType);
            if (!Class.forName(className).isPrimitive())
                className = null;
        } catch (Throwable t) {
            //className = null;
        }

        Iterator<?> iterator = methods.iterator();
        while (iterator.hasNext()) {
            IMethod method = (IMethod) iterator.next();
            IType returnType = JdtUtils.getJavaTypeForMethodReturnType(method, javaType);

            if (className == null) {
                if (returnType != null)
                    className = returnType.getFullyQualifiedName();
            }
            if (className != null) {
                if (propertySplitted.length > 1) {
                    List<String> l = new ArrayList<String>(Arrays.asList(propertySplitted));
                    l.remove(0);
                    property = StringUtils.collectionToDelimitedString(l, ".");

                    return hasReadProperty(property, returnType.getFullyQualifiedName(), project, false);
                } else {
                    return returnType;
                }
            }
        }
    }

    return null;
}

From source file:jackrabbit.repository.RepositoryManager.java

public static List<String> getDestinationWorkspaces(Session src, Session dest)
        throws IOException, RepositoryException {
    List<String> wsNames = new ArrayList<String>();
    List<String> srcWorkpaces = Arrays.asList(src.getWorkspace().getAccessibleWorkspaceNames());
    List<String> destWorkpaces = Arrays.asList(dest.getWorkspace().getAccessibleWorkspaceNames());

    for (String workspace : srcWorkpaces) {
        if (!destWorkpaces.contains(workspace)) {
            dest.getWorkspace().createWorkspace(workspace);
        }//  w  w  w.j av a 2 s  .  co  m
        wsNames.add(workspace);
    }
    wsNames.remove(DEFAULT_WORKSPACE);
    wsNames.remove(SECURITY_WORKSPACE);
    return wsNames;
}

From source file:Main.java

public static <T> Set<T> inter(final List<Set<T>> sets) {
    final List<Set<T>> mutable = new ArrayList<Set<T>>(sets.size());
    for (final Set<T> s : sets) {
        // ignore nulls
        if (s != null)
            mutable.add(s);//  w  w w .  j  a va 2 s  .  c  o m
    }

    if (mutable.isEmpty())
        return null;
    else if (mutable.size() == 1)
        return mutable.get(0);

    final int indexMin = indexOfMinSize(mutable);
    if (indexMin != 0) {
        mutable.add(0, mutable.remove(indexMin));
        return inter(mutable);
    }

    if (mutable.get(0).isEmpty())
        return Collections.emptySet();

    // replace the first 2 by their intersection
    // (inter will swap as appropriate if java doesn't evalute args in source order)
    mutable.add(0, inter(mutable.remove(0), mutable.remove(0)));
    return inter(mutable);
}

From source file:gov.nih.nci.cagrid.identifiers.test.StressTestUtil.java

private static void addElement2List(List<String> list, String value) {

    if (list.size() < size)
        list.add(value);//from w  w w  .j  a v  a 2s  . co  m
    else {
        int num = rand.nextInt(1000);
        if (num < size) {
            list.remove(num);
            list.add(value);
        }
    }
}