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:forge.game.combat.CombatUtil.java

/**
 * <p>// w ww  .j av a2s.  co m
 * mustBlockAnAttacker.
 * </p>
 * 
 * @param blocker
 *            a {@link forge.game.card.Card} object.
 * @param combat
 *            a {@link forge.game.combat.Combat} object.
 * @return a boolean.
 */
public static boolean mustBlockAnAttacker(final Card blocker, final Combat combat) {
    if (blocker == null || combat == null) {
        return false;
    }

    if (!CombatUtil.canBlock(blocker, combat)) {
        return false;
    }

    final CardCollectionView attackers = combat.getAttackers();
    final CardCollection attackersWithLure = new CardCollection();
    for (final Card attacker : attackers) {
        if (attacker.hasStartOfKeyword("All creatures able to block CARDNAME do so.")
                || (attacker.hasStartOfKeyword("All Walls able to block CARDNAME do so.")
                        && blocker.getType().hasSubtype("Wall"))
                || (attacker.hasStartOfKeyword("All creatures with flying able to block CARDNAME do so.")
                        && blocker.hasKeyword("Flying"))
                || (attacker.hasStartOfKeyword("CARDNAME must be blocked if able.")
                        && combat.getBlockers(attacker).isEmpty())) {
            attackersWithLure.add(attacker);
        }
    }

    final Player defender = blocker.getController();
    for (final Card attacker : attackersWithLure) {
        if (CombatUtil.canBeBlocked(attacker, combat, defender) && CombatUtil.canBlock(attacker, blocker)) {
            boolean canBe = true;
            if (attacker.hasStartOfKeyword("CantBeBlockedByAmount LT") || attacker.hasKeyword("Menace")) {
                final List<Card> blockers = combat.getDefenderPlayerByAttacker(attacker).getCreaturesInPlay();
                blockers.remove(blocker);
                if (!CombatUtil.canBeBlocked(attacker, blockers, combat)) {
                    canBe = false;
                }
            }
            if (canBe) {
                return true;
            }
        }
    }

    if (blocker.getMustBlockCards() != null) {
        for (final Card attacker : blocker.getMustBlockCards()) {
            if (CombatUtil.canBeBlocked(attacker, combat, defender) && CombatUtil.canBlock(attacker, blocker)
                    && combat.isAttacking(attacker)) {
                boolean canBe = true;
                if (attacker.hasStartOfKeyword("CantBeBlockedByAmount LT") || attacker.hasKeyword("Menace")) {
                    final List<Card> blockers = combat.getDefenderPlayerByAttacker(attacker)
                            .getCreaturesInPlay();
                    blockers.remove(blocker);
                    if (!CombatUtil.canBeBlocked(attacker, blockers, combat)) {
                        canBe = false;
                    }
                }
                if (canBe) {
                    return true;
                }
            }
        }
    }

    return false;
}

From source file:de.static_interface.sinkirc.IrcListener.java

@EventHandler(priority = EventPriority.MONITOR)
public void onIrcReceiveMessage(IrcReceiveMessageEvent event) {
    Debug.logMethodCall(event.getUser().getNick(), event.getChannel().getName(), event.getMessage());
    String label = event.getMessage();
    Channel channel = event.getChannel();

    if (!label.toLowerCase().startsWith(IrcUtil.getCommandPrefix())) {
        return;//from  ww w. j a v a2  s . c  om
    }
    label = label.replaceFirst(IrcUtil.getCommandPrefix(), "");
    String[] args = label.split(" ");
    String cmd = args[0];
    List<String> tmp = new ArrayList<>(Arrays.asList(args));
    tmp.remove(0);
    args = tmp.toArray(new String[tmp.size()]);
    IrcUtil.handleCommand(cmd, args, channel.getName(), event.getUser(), label);
}

From source file:net.chrisrichardson.foodToGo.viewOrdersTransactionScripts.dao.OrderDAOIBatisImpl.java

/** 
 * This is another example from the book
 * It uses a query that does not use ROWNUM
 * /* w w  w.jav a2  s .  c o m*/
 * @param startingIndex
 * @param pageSize
 * @param criteria
 * @return
 */
public PagedQueryResult findOrdersInlineWithoutRownum(int startingIndex, int pageSize,
        OrderSearchCriteria criteria) {
    Map map = new HashMap();
    map.put("pageSize", new Integer(pageSize + startingIndex));
    map.put("criteria", criteria);
    List result = getSqlMapClientTemplate().queryForList("findOrders", map, startingIndex, pageSize);
    boolean more = result.size() > pageSize;
    if (more) {
        result.remove(pageSize);
    }
    return new PagedQueryResult(result, more);
}

From source file:com.bc.fiduceo.matchup.MatchupTool.java

static void applyExcludesAndRenames(IOVariablesList ioVariablesList,
        VariablesConfiguration variablesConfiguration) {
    final List<String> sensorNames = ioVariablesList.getSensorNames();

    for (final String sensorName : sensorNames) {
        final List<IOVariable> ioVariables = ioVariablesList.getVariablesFor(sensorName);
        final Map<String, String> renames = variablesConfiguration.getRenames(sensorName);
        for (Map.Entry<String, String> rename : renames.entrySet()) {
            final String sourceName = rename.getKey();
            final IOVariable variable = getVariable(sourceName, ioVariables);
            if (variable != null) {
                variable.setTargetVariableName(rename.getValue());
            }//from  w  ww  .  j  a va 2 s  .  c om
        }

        final List<String> excludes = variablesConfiguration.getExcludes(sensorName);
        for (final String sourceName : excludes) {
            final IOVariable variable = getVariable(sourceName, ioVariables);
            if (variable != null) {
                ioVariables.remove(variable);
            }
        }
    }
}

From source file:edu.unc.lib.dl.services.FolderManager.java

/**
 * Given a repository path string, creates any folders that do not yet exist along this path.
 * /* w ww  .  j  a v  a  2 s . co m*/
 * @param path
 *           the desired folder path
 * @throws IngestException
 *            if the path cannot be created
 */
public PID createPath(String path, String owner, String user) throws IngestException {
    log.debug("attempting to create path: " + path);
    if (path.endsWith("/")) {
        path = path.substring(0, path.length() - 1);
    }
    if (!PathUtil.isValidPathString(path)) {
        throw new IngestException("The proposed path is not valid: " + path);
    }
    List<String> slugs = new ArrayList<String>();
    slugs.addAll(Arrays.asList(path.split("/")));
    slugs.remove(0);
    Stack<String> createFolders = new Stack<String>();
    String containerPath = null;
    for (int i = slugs.size(); i >= 0; i--) {
        String test = "/" + StringUtils.join(slugs.subList(0, i), "/");
        PID pid = this.getTripleStoreQueryService().fetchByRepositoryPath(test);
        if (pid == null) {
            // does not exist yet, must create it
            createFolders.add(slugs.get(i - 1));
        } else {
            List<URI> types = this.getTripleStoreQueryService().lookupContentModels(pid);
            if (!types.contains(ContentModelHelper.Model.CONTAINER.getURI())) {
                StringBuffer s = new StringBuffer();
                for (URI type : types) {
                    s.append(type.toString()).append("\t");
                }
                throw new IngestException("The object at the path '" + test
                        + "' is not a folder.  It has these content models:\n" + s.toString());
            }
            containerPath = test;
            break;
        }
    }

    // add folders
    PID lastpid = null;
    while (createFolders.size() > 0) {
        String slug = createFolders.pop();
        SingleFolderSIP sip = new SingleFolderSIP();
        PID containerPID = this.getTripleStoreQueryService().fetchByRepositoryPath(containerPath);
        sip.setContainerPID(containerPID);
        if ("/".equals(containerPath)) {
            containerPath = containerPath + slug;
        } else {
            containerPath = containerPath + "/" + slug;
        }
        sip.setSlug(slug);
        sip.setAllowIndexing(true);
        DepositRecord record = new DepositRecord(user, owner, DepositMethod.Unspecified);
        record.setMessage("creating a new folder path");
        IngestResult result = this.getDigitalObjectManager().addWhileBlocking(sip, record);
        lastpid = result.derivedPIDs.iterator().next();
    }
    return lastpid;
}

From source file:com.jeroensteenbeeke.hyperion.events.DefaultEventDispatcher.java

@SuppressWarnings("unchecked")
@Override// w  ww.  j  a v  a2 s .  c  o m
public void dispatchEvent(@Nonnull Event<?> event) {
    AutowireCapableBeanFactory factory = applicationContext.getAutowireCapableBeanFactory();
    List<Event<?>> queue = Lists.<Event<?>>newArrayList(event);

    while (!queue.isEmpty()) {
        Event<?> evt = queue.remove(0);

        for (Class<? extends EventHandler<?>> eventHandler : handlers
                .get((Class<? extends Event<?>>) evt.getClass())) {
            EventHandler<Event<?>> handler = (EventHandler<Event<?>>) factory.autowire(eventHandler,
                    AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);

            EventResult result = handler.onEvent(evt);

            if (result.isAbort()) {
                throw new RuntimeException(String.format("Handler %s aborted event %s with message: %s",
                        handler, evt, result.getMessage()));
            }

            queue.addAll(result.getTriggeredEvents());
        }
    }
}

From source file:org.nekorp.workflow.desktop.view.binding.imp.BindingManagerImp.java

@Override
public void removeBind(Object target, String property, Bindable component) {
    //recupera el objeto del proxy
    Object obj = proxyUtil.getTarget(target);
    Map<String, List<Bindable>> objectBindings = this.bindings.get(obj);
    if (objectBindings != null) {
        List<Bindable> bnds = objectBindings.get(property);
        if (bnds != null) {
            bnds.remove(component);
            if (bnds.isEmpty()) {
                objectBindings.remove(property);
                if (objectBindings.isEmpty()) {
                    this.bindings.remove(obj);
                }/*  ww  w  .j a va  2s  .c  om*/
            }
        }
    }
}

From source file:HSqlManager.java

@SuppressWarnings("Duplicates")
@Deprecated/*from   ww w  .  ja va2s  .c o  m*/
private static void mycoCommonInitialize(int bps, Connection connection) throws SQLException, IOException {
    long time = System.currentTimeMillis();
    String base = new File("").getAbsolutePath();
    CSV.makeDirectory(new File(base + "/PhageData"));
    INSTANCE = ImportPhagelist.getInstance();
    //        INSTANCE.parseAllPhages(bps);
    written = true;
    Connection db = connection;
    db.setAutoCommit(false);
    Statement stat = db.createStatement();
    stat.execute("SET FILES LOG FALSE\n");
    PreparedStatement st = db.prepareStatement("Insert INTO Primerdb.Primers"
            + "(Bp,Sequence, CommonP, UniqueP, Picked, Strain, Cluster)" + " Values(?,?,true,false,false,?,?)");
    ResultSet call = stat.executeQuery("Select * From Primerdb.Phages;");
    List<String[]> phages = new ArrayList<>();
    String strain = "";
    while (call.next()) {
        String[] r = new String[3];
        r[0] = call.getString("Strain");
        r[1] = call.getString("Cluster");
        r[2] = call.getString("Name");
        phages.add(r);
        if (r[2].equals("xkcd")) {
            strain = r[0];
        }
    }
    call.close();
    String x = strain;
    Set<String> clust = phages.stream().filter(y -> y[0].equals(x)).map(y -> y[1]).collect(Collectors.toSet());
    Map<String, List<String>> clusters = new HashMap<>();
    clust.parallelStream().forEach(cluster -> clusters.put(cluster, phages.stream()
            .filter(a -> a[0].equals(x) && a[1].equals(cluster)).map(a -> a[2]).collect(Collectors.toList())));
    for (String z : clusters.keySet()) {
        try {
            List<String> clustphages = clusters.get(z);
            Set<String> primers = Collections.synchronizedSet(
                    CSV.readCSV(base + "/PhageData/" + Integer.toString(bps) + clustphages.get(0) + ".csv"));
            clustphages.remove(0);
            for (String phage : clustphages) {
                //                    String[] seqs = Fasta.parse(base + "/Fastas/" + phage + ".fasta");
                //                    String sequence =seqs[0]+seqs[1];
                //                    Map<String, List<Integer>> seqInd = new HashMap<>();
                //                    for (int i = 0; i <= sequence.length()-bps; i++) {
                //                        String sub=sequence.substring(i,i+bps);
                //                        if(seqInd.containsKey(sub)){
                //                            seqInd.get(sub).add(i);
                //                        }else {
                //                            List<Integer> list = new ArrayList<>();
                //                            list.add(i);
                //                            seqInd.put(sub,list);
                //                        }
                //                    }
                //                    primers = primers.stream().filter(seqInd::containsKey).collect(Collectors.toSet());
                //                    primers =Sets.intersection(primers,CSV.readCSV(base + "/PhageData/"+Integer.toString(bps)
                //                            + phage + ".csv"));
                //                    System.gc();
                //                            String[] seqs = Fasta.parse(base + "/Fastas/" + phage + ".fasta");
                //                            String sequence =seqs[0]+seqs[1];
                //                            primers.stream().filter(sequence::contains);
                primers.retainAll(CSV.readCSV(base + "/PhageData/" + Integer.toString(bps) + phage + ".csv"));
                //                    Set<CharSequence> prim = primers;
                //                    for (CharSequence primer: primers){
                //                        if(seqInd.containsKey(primer)){
                //                            prim.remove(primer);
                //                        }
                //                    }
                //                    primers=prim;
            }
            int i = 0;
            for (String a : primers) {
                try {
                    //finish update
                    st.setInt(1, bps);
                    st.setString(2, a);
                    st.setString(3, x);
                    st.setString(4, z);
                    st.addBatch();
                } catch (SQLException e) {
                    e.printStackTrace();
                    System.out.println("Error occurred at " + x + " " + z);
                }
                i++;
                if (i == 1000) {
                    i = 0;
                    st.executeBatch();
                    db.commit();
                }
            }
            if (i > 0) {
                st.executeBatch();
                db.commit();
            }
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println("Error occurred at " + x + " " + z);
        }
        System.out.println(z);
    }
    stat.execute("SET FILES LOG TRUE\n");
    st.close();
    stat.close();
    System.out.println("Common Updated");
    System.out.println((System.currentTimeMillis() - time) / Math.pow(10, 3) / 60);
}

From source file:com.google.code.ssm.test.dao.AppUserDAOImpl.java

@Override
@InvalidateSingleCache(namespace = SINGLE_NS)
public void remove(@ParameterValueKeyProvider AppUserPK pk) {
    AppUser appUser = MAP.remove(pk);//from   w  w  w.j  a  v a  2  s. com
    List<AppUser> list = USER_ID_MAP.get(pk.getUserId());
    if (list != null) {
        list.remove(appUser);
    }
}

From source file:com.o19s.solr.swan.nodes.SwanXOrOperationNode.java

@Override
public Query getQuery(String[] fields) {
    BooleanQuery query = new BooleanQuery();

    List<SwanNode> inc;
    for (int x = 0; x < _nodes.size(); x++) {
        inc = new ArrayList<SwanNode>();
        inc.addAll(_nodes);//from   www.  j  a  va2  s.c  o  m
        inc.remove(x);

        BooleanQuery inner = new BooleanQuery();
        for (SwanNode n : inc) {
            inner.add(n.getQuery(), BooleanClause.Occur.MUST_NOT);
        }
        inner.add(_nodes.get(x).getQuery(), BooleanClause.Occur.MUST);
        query.add(inner, BooleanClause.Occur.SHOULD);
    }

    return query;
}