Example usage for java.util ArrayList remove

List of usage examples for java.util ArrayList remove

Introduction

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

Prototype

public boolean remove(Object o) 

Source Link

Document

Removes the first occurrence of the specified element from this list, if it is present.

Usage

From source file:annis.visualizers.component.grid.EventExtractor.java

/**
* Merges the rows. This function uses a heuristical approach that guarantiess
* to merge all rows into one if there is no conflict at all. If there are
* conflicts the heuristic will be best-efford but with linear runtime (given
* a a number of rows)./* w ww .j  a  va2s  .c o m*/
*
* @param rows Will be altered, if no conflicts occcured this wil have only
* one element.
*/
private static void mergeAllRowsIfPossible(ArrayList<Row> rows) {
    // use fixed seed in order to get consistent results (with random properties)
    Random rand = new Random(5711l);
    int tries = 0;
    // this should be enough to be quite sure we don't miss any optimalization
    // possibility
    final int maxTries = rows.size() * 2;

    // do this loop until we successfully merged everything into one row
    // or we give up until too much tries
    while (rows.size() > 1 && tries < maxTries) {
        // choose two random entries
        int oneIdx = rand.nextInt(rows.size());
        int secondIdx = rand.nextInt(rows.size());
        if (oneIdx == secondIdx) {
            // try again if we choose the same rows by accident
            continue;
        }

        Row one = rows.get(oneIdx);
        Row second = rows.get(secondIdx);

        if (one.merge(second)) {
            // remove the second one since it is merged into the first
            rows.remove(secondIdx);

            // success: reset counter
            tries = 0;
        } else {
            // increase counter to avoid endless loops if no improvement is possible
            tries++;
        }
    }
}

From source file:com.aliyun.odps.utils.StringUtils.java

/**
 * Split a string using the given separator
 *
 * @param str/*from   w w w  .  j  a  v a  2 s.com*/
 *     a string that may have escaped separator
 * @param escapeChar
 *     a char that be used to escape the separator
 * @param separator
 *     a separator char
 * @return an array of strings
 */
public static String[] split(String str, char escapeChar, char separator) {
    if (str == null) {
        return null;
    }
    ArrayList<String> strList = new ArrayList<String>();
    StringBuilder split = new StringBuilder();
    int index = 0;
    while ((index = findNext(str, separator, escapeChar, index, split)) >= 0) {
        ++index; // move over the separator for next search
        strList.add(split.toString());
        split.setLength(0); // reset the buffer
    }
    strList.add(split.toString());
    // remove trailing empty split(s)
    int last = strList.size(); // last split
    while (--last >= 0 && "".equals(strList.get(last))) {
        strList.remove(last);
    }
    return strList.toArray(new String[strList.size()]);
}

From source file:com.o2d.pkayjava.editor.proxy.SceneDataManager.java

private void deleteScene(String sceneName) {
    ProjectManager projectManager = facade.retrieveProxy(ProjectManager.NAME);
    ArrayList<SceneVO> scenes = projectManager.currentProjectInfoVO.scenes;
    SceneVO sceneToDelete = null;/*from   w  w  w  .  j av  a  2 s  .  co m*/
    for (SceneVO scene : scenes) {
        if (scene.sceneName.equals(sceneName)) {
            sceneToDelete = scene;
            break;
        }
    }
    if (sceneToDelete != null) {
        scenes.remove(sceneToDelete);
    }
    projectManager.currentProjectInfoVO.scenes = scenes;
    String projPath = projectManager.getCurrentWorkingPath() + "/"
            + projectManager.currentProjectVO.projectName;
    try {
        FileUtils.writeStringToFile(new File(projPath + "/project.dt"),
                projectManager.currentProjectInfoVO.constructJsonString(), "utf-8");
        FileUtils.forceDelete(new File(projPath + "/scenes/" + sceneName + ".dt"));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:androidGLUESigner.ui.Fragments.SignedDocListFragment.java

/**
 * @param item/* ww  w .  j a  v  a 2  s  . co m*/
 * @param list 
 */
protected void showDeleteButton(final String item, final ArrayList<String> list) {
    if (list.size() == 0) {
        deleteButton.setVisibility(View.INVISIBLE);
    } else {
        deleteButton.setVisibility(Button.VISIBLE);
    }
    deleteButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            list.remove(item);
            adapter.notifyDataSetChanged();
            settingsHelper.removeSignedDocumentFromList(item);
            File file = new File(item);
            file.delete();
            deleteButton.setVisibility(View.INVISIBLE);
        }
    });

}

From source file:com.predic8.membrane.core.transport.http.ConnectionManager.java

public Connection getConnection(InetAddress host, int port, String localHost, SSLProvider sslProvider,
        int connectTimeout) throws UnknownHostException, IOException {

    log.debug("connection requested for host: " + host + " and port: " + port);

    log.debug("Number of connections in pool: " + numberInPool.get());

    ConnectionKey key = new ConnectionKey(host, port);
    long now = System.currentTimeMillis();

    synchronized (this) {
        ArrayList<OldConnection> l = availableConnections.get(key);
        if (l != null) {
            int i = l.size() - 1;
            while (i >= 0) {
                OldConnection c = l.get(i);
                if (c.deathTime > now) {
                    l.remove(i);
                    return c.connection;
                }// ww w . j  a va2s. co  m
                Collections.swap(l, 0, i);
                i--;
            }
        }
    }

    Connection result = Connection.open(host, port, localHost, sslProvider, this, connectTimeout);
    numberInPool.incrementAndGet();
    return result;
}

From source file:com.clustercontrol.jobmanagement.factory.JobSessionJobImpl.java

public static boolean checkRemoveForceCheck(String sessionId) {
    try {//w  w w . java 2  s . c  o m
        _lock.writeLock();

        ArrayList<String> cache = getForceCheckCache();
        boolean flag = cache.remove(sessionId);
        if (flag) {
            m_log.debug("checkRemoveForceCheck " + sessionId);
        }
        return flag; // forceCheck???????true?
    } finally {
        _lock.writeUnlock();
    }
}

From source file:de.thkwalter.et.ortskurve.Startpunktbestimmung.java

/**
 * Diese Methode bestimmt den Messpunkt mit dem kleinsten Wert der x- bzw. y-Komponente.
 * /*from   w w w .ja v  a  2 s.c  om*/
 * @param liste Eine Liste der x- bzw. y-Komponenten der Messpunkte
 * 
 * @return Der Messpunkt mit dem kleinstenbgh Wert der x- bzw. y-Komponente
 */
private static Vector2D minMesspunktBestimmen(ArrayList<? extends KomponenteMesspunkt> liste) {
    // Die Messpunkte mit der kleinsten x- bzw. y-Komponente.
    KomponenteMesspunkt minKomponenteMesspunkt = null;

    // Die x- bzw. y-Komponente eines Messwertes.
    double wert = Double.NaN;

    // Die kleinste bisher gefundene x- bzw. y-Komponente.
    double minWert = Double.POSITIVE_INFINITY;

    // Eine Schleife ber alle Messpunkte in der Liste
    for (KomponenteMesspunkt komponenteMesspunkt : liste) {
        // Die x- bzw. y-Komponente des Messpunktes wird gelesen.
        wert = komponenteMesspunkt.getWert();

        // Falls die x- bzw. y-Komponente des Messpunkts kleiner als die kleinste bisher gefundene x- bzw. y-Komponente, ...
        if (wert < minWert) {
            // Die grte bisher gefundene x- bzw. y-Komponente wird aktualisiert.  
            minWert = wert;

            // Der Messpunkt mit der kleinsten x- bzw. y-Komponente wird aktualisiert.
            minKomponenteMesspunkt = komponenteMesspunkt;
        }
    }

    // Der Messpunkt mit der kleinsten x- bzw. y-Komponente wird aus der Liste entfernt.
    liste.remove(minKomponenteMesspunkt);

    // Der Messpunkt mit der grten x- bzw. y-Komponente wird zurckgegeben.
    return minKomponenteMesspunkt.getMesspunkt();
}

From source file:com.esri.geoevent.solutions.processor.eventjoiner.EventJoinerProcessor.java

private void ConstructGeoEventDef(HashMap<String, GeoEvent> rec) throws Exception {
    try {/*from w ww  .j a  v a2  s  .c  om*/
        fldMgr = new HashMap<String, FieldItem>();
        Set<String> keys = rec.keySet();
        Iterator<String> it = keys.iterator();
        while (it.hasNext()) {
            String key = it.next();
            GeoEvent evt = rec.get(key);
            List<FieldDefinition> fldDefs = evt.getGeoEventDefinition().getFieldDefinitions();
            for (FieldDefinition fldDef : fldDefs) {
                String fldName = fldDef.getName();
                FieldType type = fldDef.getType();
                if (fldMgr.containsKey(fldName)) {
                    FieldItem item = fldMgr.get(fldName);
                    if (!fldDef.getTags().isEmpty())
                        item.appendTags(fldDef.getTags());
                    item.advance();
                } else {
                    FieldItem item = new FieldItem();
                    item.setId(fldName);
                    item.setType(type);
                    if (!fldDef.getTags().isEmpty())
                        item.appendTags(fldDef.getTags());
                    item.advance();
                    fldMgr.put(fldName, item);
                }
            }
        }
        Set<String> fldKeys = fldMgr.keySet();
        Iterator<String> fldIt = fldKeys.iterator();
        List<FieldDefinition> mergedFldDef = new ArrayList<FieldDefinition>();
        while (fldIt.hasNext()) {
            String fldName = fldIt.next();
            FieldItem item = fldMgr.get(fldName);
            FieldType type;
            FieldType fldtype = item.getType();
            ArrayList<String> tags = item.getTags();
            if (tags.contains("TRACK_ID")) {
                tags.remove("TRACK_ID");
            }
            FieldDefinition fd = null;
            if (item.getCount() > 1) {
                if (fldName.equals(joinfield)) {
                    tags.add("JOIN_ID");
                    tags.add("TRACK_ID");
                    String[] tagarr = new String[tags.size()];
                    tagarr = tags.toArray(tagarr);
                    fd = new DefaultFieldDefinition(fldName, fldtype, (String[]) tagarr);
                } else {
                    type = FieldType.Group;
                    String[] groupedTag = { "GROUPED" };
                    fd = new DefaultFieldDefinition(fldName, type, groupedTag);
                    for (Integer i = 0; i < item.getCount(); ++i) {
                        String childName = defList.get(i);
                        FieldDefinition child = null;
                        if (tags.isEmpty()) {
                            child = new DefaultFieldDefinition(childName, fldtype);
                        } else {
                            String[] tagarr = new String[tags.size()];
                            tagarr = tags.toArray(tagarr);
                            child = new DefaultFieldDefinition(childName, fldtype, tagarr);
                        }
                        fd.addChild(child);
                    }
                }
            } else {
                type = fldtype;
                if (!tags.isEmpty()) {
                    fd = new DefaultFieldDefinition(fldName, fldtype, (String[]) tags.toArray());
                } else {
                    fd = new DefaultFieldDefinition(fldName, fldtype);
                }

            }

            mergedFldDef.add(fd);
        }
        outDef = new DefaultGeoEventDefinition();
        outDef.setFieldDefinitions(mergedFldDef);
        outDef.setName(outdefname);
        outDef.setOwner(definition.getUri().toString());
        Collection<GeoEventDefinition> eventDefs = manager.searchGeoEventDefinitionByName(outdefname);
        Iterator<GeoEventDefinition> eventDefIt = eventDefs.iterator();
        while (eventDefIt.hasNext()) {
            GeoEventDefinition currentDef = eventDefIt.next();
            manager.deleteGeoEventDefinition(currentDef.getGuid());
        }
        manager.addGeoEventDefinition(outDef);
    } catch (ConfigurationException e) {
        LOG.error(e.getMessage());
        throw (e);
    } catch (GeoEventDefinitionManagerException e) {
        LOG.error(e.getMessage());
        throw (e);
    } catch (Exception e) {
        LOG.error(e.getMessage());
        throw (e);
    }
}

From source file:de.thkwalter.et.ortskurve.Startpunktbestimmung.java

/**
 * Diese Methode bestimmt den Messpunkt mit dem grten Wert der x- bzw. y-Komponente.
 * //w ww.  ja va2s. com
 * @param liste Eine Liste der x- bzw. y-Komponenten der Messpunkte
 * 
 * @return Der Messpunkt mit dem grten Wert der x- bzw. y-Komponente
 */
private static Vector2D maxMesspunktBestimmen(ArrayList<? extends KomponenteMesspunkt> liste) {
    // Die Messpunkte mit der grten x- bzw. y-Komponente.
    KomponenteMesspunkt maxKomponenteMesspunkt = null;

    // Die x- bzw. y-Komponente eines Messwertes.
    double wert = Double.NaN;

    // Die grte bisher gefundene x- bzw. y-Komponente.
    double maxWert = Double.NEGATIVE_INFINITY;

    // Eine Schleife ber alle Messpunkte in der Liste
    for (KomponenteMesspunkt komponenteMesspunkt : liste) {
        // Die x- bzw. y-Komponente des Messpunktes wird gelesen.
        wert = komponenteMesspunkt.getWert();

        // Falls die x- bzw. y-Komponente des Messpunkts grer als die grte bisher gefundene x- bzw. y-Komponente, ...
        if (wert > maxWert) {
            // Die grte bisher gefundene x- bzw. y-Komponente wird aktualisiert.  
            maxWert = wert;

            // Der Messpunkt mit der grten x- bzw. y-Komponente wird aktualisiert.
            maxKomponenteMesspunkt = komponenteMesspunkt;
        }
    }

    // Der Messpunkt mit der grten x- bzw. y-Komponente wird aus der Liste entfernt.
    liste.remove(maxKomponenteMesspunkt);

    // Der Messpunkt mit der grten x- bzw. y-Komponente wird zurckgegeben.
    return maxKomponenteMesspunkt.getMesspunkt();
}

From source file:com.amazon.janusgraph.diskstorage.dynamodb.DynamoDBDelegate.java

public static boolean areGSIsSameConfiguration(List<GlobalSecondaryIndexDescription> g1,
        List<GlobalSecondaryIndexDescription> g2) {
    if (g1 == null) {
        if (g2 == null) {
            return true;
        }/*from   w w  w  . j av  a2 s  . com*/
        return false;
    }
    if (g1.size() != g2.size()) {
        return false;
    }
    // make copy of the lists because we don't want to mutate the lists
    ArrayList<GlobalSecondaryIndexDescription> g1clone = new ArrayList<>(g1.size());
    g1clone.addAll(g1);
    ArrayList<GlobalSecondaryIndexDescription> g2clone = new ArrayList<>(g2.size());
    g1clone.addAll(g2);

    for (GlobalSecondaryIndexDescription gi1 : g1) {
        for (GlobalSecondaryIndexDescription gi2 : g2) {
            if (areGSIsSameConfiguration(gi1, gi2)) {
                g1clone.remove(gi1);
                g2clone.remove(gi2);
                break;
            }
        }
    }
    return g1clone.isEmpty() || g2clone.isEmpty();
}