Example usage for java.util List clear

List of usage examples for java.util List clear

Introduction

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

Prototype

void clear();

Source Link

Document

Removes all of the elements from this list (optional operation).

Usage

From source file:ch.unibas.charmmtools.generate.inputs.CHARMM_Generator_DGHydr.java

private void genInputPythonSolvent(boolean genOnly) {
    List<String> args = new ArrayList<>();
    args.clear();

    args.add("--ti");
    args.add(this.ti_type);
    args.add("--tps");
    args.add(this.solu_top);
    //        args.add("--top");
    //        args.add(this.solv_top);
    args.add("--slu");
    args.add(this.solu_cor);
    args.add("--slv");
    args.add(this.solv_cor);
    args.add("--par");
    args.add(this.par);
    args.add("--lpun");
    args.add(this.lpun);
    if (genOnly) {
        args.add("--chm");
        args.add("../../scripts/charmm");
    } else {// w ww  . j a v a2  s  .  c  o m
        args.add("--rem");
        args.add("studix");
        args.add("--num");
        args.add("8");
    }

    args.add("--lmb");
    args.add(Double.toString(this.l_min));
    args.add(Double.toString(this.l_space));
    args.add(Double.toString(this.l_max));
    //        args.add("--nst");
    //        args.add("5000");
    //        args.add("--neq");
    //        args.add("1000");

    if (genOnly) {
        args.add("--generate");
    }

    File script = new File("scripts/charmm-ti/perform-ti.py");
    //File output = null;

    if (genOnly) {
        output = new File(myDir + "/dg_gen_" + this.ti_type + "_solv" + ".out");
        logger.info("OUTPUT file from perform-ti generate is : " + output.getAbsolutePath());
    } else {
        output = new File(myDir + "/dg_run_" + this.ti_type + "_solv" + ".out");
        logger.info("OUTPUT file from perform-ti running  is : " + output.getAbsolutePath());
    }

    int returnCode;
    //        if (genOnly) {
    returnCode = runner.exec(script, args, output);
    //        } else {
    //        returnCode = runner.exec(script, args);
    //        }

    String[] exts = { "inp" };
    myFiles.addAll(FileUtils.listFiles(myDir, exts, false));
}

From source file:ezbake.data.common.classification.VisibilityUtils.java

/**
 * Based on Accumulo's VisibilityEvaluator.java's "evaluate" method; From the Accumulo-style boolean expression
 * string, generates the security tagging field format for Mongo's $redact operator. The final returned list should
 * be inserted into another list to make the double array format.
 *//*w ww  .  jav a  2s .c  o  m*/
private static void evaluateAccumuloExpression(final byte[] expression, final Node root, List<Object> list)
        throws VisibilityParseException {
    switch (root.getType()) {
    case TERM:
        final String term = ClassificationUtils.getAccumuloNodeTermString(expression, root);
        list.add(term);
        break;
    case AND:
        if (root.getChildren() == null || root.getChildren().size() < 2) {
            throw new VisibilityParseException("AND has less than 2 children", expression, root.getTermStart());
        }
        final List<Object> andList = new ArrayList<>();

        for (final Node child : root.getChildren()) {
            evaluateAccumuloExpression(expression, child, andList);
        }

        // TODO: i shouldn't have to do this; should just be an add
        if (andList.get(0) instanceof List) {
            list.addAll(andList);
        } else {
            list.add(andList);
        }

        break;
    case OR:
        if (root.getChildren() == null || root.getChildren().size() < 2) {
            throw new VisibilityParseException("OR has less than 2 children", expression, root.getTermStart());
        }
        final List<Object> saved = new ArrayList<>();
        saved.addAll(list);
        list.clear();

        for (final Node child : root.getChildren()) {
            final List<Object> orList = new ArrayList<>();
            orList.addAll(saved);

            evaluateAccumuloExpression(expression, child, orList);

            list.add(orList);
        }

        break;
    // $CASES-OMITTED$
    default:
        throw new VisibilityParseException("No such node type", expression, root.getTermStart());
    }
}

From source file:edu.isi.pfindr.learn.util.CleanDataUtil.java

public static String preprocessStemAndTokenizeReturnDistinctTokens(String data) {
    //System.out.println("Preprocess data, remove stop words, stem, tokenize ..");
    Set<String> transformedSet = new LinkedHashSet<String>();
    List<String> stemmedList = new ArrayList<String>();

    Tokenizer analyzer = new Tokenizer(Version.LUCENE_30);
    TokenStream tokenStream = analyzer.tokenStream("", new StringReader(data));
    TermAttribute termAttribute;//from  www  .  j a va 2  s .c o m
    String term;
    try {
        while (tokenStream.incrementToken()) {
            termAttribute = tokenStream.getAttribute(TermAttribute.class);
            term = termAttribute.term();
            if (digitPattern.matcher(term).find()) //ignore digits
                continue;
            if (stopwords.contains(term)) //ignore stopwords
                continue;
            if (term.length() <= 1) //ignore single letter words
                continue;
            stemmer.setCurrent(term);
            stemmer.stem();
            stemmedList.add(stemmer.getCurrent());
        }
        transformedSet.addAll(stemmedList);
    } catch (Exception e) {
        e.printStackTrace();
    }
    stemmedList.clear();
    stemmedList = null;

    return StringUtils.join(transformedSet.toArray(), " ");
}

From source file:psiprobe.model.stats.StatsCollection.java

/**
 * Reset stats.//  w w  w. j  a  va  2s  .c  o  m
 *
 * @param name the name
 */
public synchronized void resetStats(String name) {
    List<XYDataItem> stats = getStats(name);
    if (stats != null) {
        stats.clear();
    }
}

From source file:com.googlecode.osde.internal.editors.locale.SuportedLocalePart.java

public void setValuesToModule() {
    Module module = getModule();//from  www .j a v  a2s  .c  om
    ModulePrefs modulePrefs = module.getModulePrefs();
    List<Locale> locales = modulePrefs.getLocales();
    locales.clear();
    List<LocaleModel> models = getLocaleModels();
    IFile file = (IFile) page.getEditorInput().getAdapter(IResource.class);
    IProject project = file.getProject();
    removeAllMessageBundleFiles(project);
    for (LocaleModel model : models) {
        Locale locale = new Locale();
        String country = model.getCountry();
        if (!StringUtils.isEmpty(country)) {
            locale.setCountry(country);
        }
        String lang = model.getLang();
        if (!StringUtils.isEmpty(lang)) {
            locale.setLang(lang);
        }
        if (model.isInternal()) {
            List<Msg> msgs = locale.getInlineMessages();
            Map<String, String> messages = model.getMessages();
            for (Map.Entry<String, String> entry : messages.entrySet()) {
                Msg msg = new Msg();
                msg.setName(entry.getKey());
                msg.setContent(entry.getValue());
                msgs.add(msg);
            }
        } else {
            try {
                String fileName = LocaleModel.MESSAGE_BUNDLE_FILENAME_PREFIX + model.getLang() + "_"
                        + model.getCountry() + ".xml";
                IFile bundleFile = project.getFile(fileName);
                if (bundleFile.exists()) {
                    bundleFile.delete(true, new NullProgressMonitor());
                }
                MessageBundle msgBundle = new MessageBundle();
                Map<String, String> messages = model.getMessages();
                for (Map.Entry<String, String> entry : messages.entrySet()) {
                    msgBundle.addMessage(new Msg(entry.getKey(), entry.getValue()));
                }

                ByteArrayInputStream in = new ByteArrayInputStream(msgBundle.toString().getBytes("UTF-8"));
                bundleFile.create(in, true, new NullProgressMonitor());

                locale.setMessages("http://localhost:" + ShindigServer.DEFAULT_SHINDIG_PORT + "/"
                        + project.getName() + "/" + fileName);
                locale.setMessageBundle(msgBundle);
            } catch (CoreException e) {
                logger.warn("Creating the message bundle file failed.", e);
            } catch (UnsupportedEncodingException e) {
                logger.warn("Creating the message bundle file failed.", e);
            }
        }
        locales.add(locale);
    }
}

From source file:org.wte4j.ui.server.services.TemplateServiceImpl.java

@Override
public List<String> listUniqueContentIds(String pathToFile) throws TemplateServiceException {
    Path filePath = Paths.get(pathToFile);
    if (!Files.exists(filePath)) {
        throw createServiceException(MessageKey.TEMPLATE_NOT_FOUND);
    }/*  w w  w . j  a va  2s.  co  m*/
    try {
        TemplateFile templateFile = templateEngine.asTemplateFile(filePath);
        List<String> contentIds = templateFile.listContentIds();
        Set<String> uniqueContentIds = new HashSet<String>(contentIds);
        contentIds.clear();
        contentIds.addAll(uniqueContentIds);
        return contentIds;
    } catch (IOException e) {
        throw createServiceException(MessageKey.INTERNAL_SERVER_ERROR, e);
    } catch (WteException e) {
        logger.debug("error on parsing file {}", pathToFile, e);
        throw createServiceException(MessageKey.UPLOADED_FILE_NOT_VALID, e);
    }
}

From source file:com.buddycloud.mediaserver.web.MediaResource.java

private void addCacheHeaders(int maxAge) {
    List<CacheDirective> cacheDirectives = getResponse().getCacheDirectives();
    // Clear old directives
    cacheDirectives.clear();

    // Add max-age and public
    cacheDirectives.add(CacheDirective.maxAge(maxAge));
    cacheDirectives.add(CacheDirective.publicInfo());
}

From source file:edu.northwestern.bioinformatics.studycalendar.xml.writers.AmendmentXmlValidationTest.java

public void testValidateForWrongNumberOfPlannedActivities() throws IOException, SAXException {
    amendment.getDeltas().add(plannedCalendarDelta);
    eAmendment = amendmentSerializer.createElement(amendment);

    List<PlannedActivity> plannedActivities = ((Epoch) add1.getChild()).getStudySegments().get(0).getPeriods()
            .first().getPlannedActivities();
    plannedActivities.clear();
    plannedActivities.add(plannedActivity1);

    String message = amendmentSerializer.validate(amendment, eAmendment);

    assertTrue(message.contains(/*from  w  w w  .j  av  a  2s . c  om*/
            "Period[id=null] present in the system and in the imported document must have identical number of planned activities"));

}

From source file:forge.game.staticability.StaticAbilityContinuous.java

/**
 * Apply the effects of a static ability that apply in a particular layer to
 * a predefined set of cards.// www.j ava2  s . c om
 * 
 * @param stAb
 *            a {@link StaticAbility}.
 * @param affectedCards
 *            a {@link CardCollectionView} of cards that are to be affected.
 * @param layer
 *            the {@link StaticAbilityLayer} of effects to apply.
 * @return a {@link CardCollectionView} of cards that have been affected,
 *         identical to {@code affectedCards}.
 */
public static CardCollectionView applyContinuousAbility(final StaticAbility stAb,
        final CardCollectionView affectedCards, final StaticAbilityLayer layer) {
    final Map<String, String> params = stAb.getMapParams();
    final Card hostCard = stAb.getHostCard();
    final Player controller = hostCard.getController();

    final List<Player> affectedPlayers = StaticAbilityContinuous.getAffectedPlayers(stAb);
    final Game game = hostCard.getGame();

    final StaticEffect se = game.getStaticEffects().getStaticEffect(stAb);
    se.setAffectedCards(affectedCards);
    se.setAffectedPlayers(affectedPlayers);
    se.setParams(params);
    se.setTimestamp(hostCard.getTimestamp());

    String changeColorWordsTo = null;

    String addP = "";
    int powerBonus = 0;
    String addT = "";
    int toughnessBonus = 0;
    String setP = "";
    int setPower = -1;
    String setT = "";
    int setToughness = -1;
    int keywordMultiplier = 1;

    String[] addKeywords = null;
    String[] addHiddenKeywords = null;
    String[] removeKeywords = null;
    String[] addAbilities = null;
    String[] addReplacements = null;
    String[] addSVars = null;
    String[] addTypes = null;
    String[] removeTypes = null;
    String addColors = null;
    String[] addTriggers = null;
    String[] addStatics = null;
    List<SpellAbility> addFullAbs = null;
    boolean removeAllAbilities = false;
    boolean removeSuperTypes = false;
    boolean removeCardTypes = false;
    boolean removeSubTypes = false;
    boolean removeCreatureTypes = false;
    boolean controllerMayLookAt = false;
    boolean controllerMayPlay = false, mayPlayWithoutManaCost = false, mayPlayIgnoreColor = false;

    //Global rules changes
    if (layer == StaticAbilityLayer.RULES && params.containsKey("GlobalRule")) {
        final StaticEffects effects = game.getStaticEffects();
        effects.setGlobalRuleChange(GlobalRuleChange.fromString(params.get("GlobalRule")));
    }

    if (layer == StaticAbilityLayer.TEXT && params.containsKey("ChangeColorWordsTo")) {
        changeColorWordsTo = params.get("ChangeColorWordsTo");
    }

    if (layer == StaticAbilityLayer.SETPT && params.containsKey("SetPower")) {
        setP = params.get("SetPower");
        setPower = AbilityUtils.calculateAmount(hostCard, setP, stAb);
    }

    if (layer == StaticAbilityLayer.SETPT && params.containsKey("SetToughness")) {
        setT = params.get("SetToughness");
        setToughness = AbilityUtils.calculateAmount(hostCard, setT, stAb);
    }

    if (layer == StaticAbilityLayer.MODIFYPT && params.containsKey("AddPower")) {
        addP = params.get("AddPower");
        powerBonus = AbilityUtils.calculateAmount(hostCard, addP, stAb);
        if (!StringUtils.isNumeric(addP) && !addP.equals("AffectedX")) {
            se.setXValue(powerBonus);
        }
    }

    if (layer == StaticAbilityLayer.MODIFYPT && params.containsKey("AddToughness")) {
        addT = params.get("AddToughness");
        toughnessBonus = AbilityUtils.calculateAmount(hostCard, addT, stAb);
        if (!StringUtils.isNumeric(addT) && !addT.equals("AffectedX")) {
            se.setYValue(toughnessBonus);
        }
    }

    if (layer == StaticAbilityLayer.ABILITIES2 && params.containsKey("KeywordMultiplier")) {
        final String multiplier = params.get("KeywordMultiplier");
        if (multiplier.equals("X")) {
            se.setXValue(AbilityUtils.calculateAmount(hostCard, "X", stAb));
        } else {
            keywordMultiplier = Integer.valueOf(multiplier);
        }
    }

    if (layer == StaticAbilityLayer.ABILITIES2 && params.containsKey("AddKeyword")) {
        addKeywords = params.get("AddKeyword").split(" & ");
        final Iterable<String> chosencolors = hostCard.getChosenColors();
        for (final String color : chosencolors) {
            for (int w = 0; w < addKeywords.length; w++) {
                addKeywords[w] = addKeywords[w].replaceAll("ChosenColor",
                        color.substring(0, 1).toUpperCase().concat(color.substring(1, color.length())));
            }
        }
        final String chosenType = hostCard.getChosenType();
        for (int w = 0; w < addKeywords.length; w++) {
            addKeywords[w] = addKeywords[w].replaceAll("ChosenType", chosenType);
        }
        final String chosenName = hostCard.getNamedCard();
        final String hostCardUID = Integer.toString(hostCard.getId()); // Protection with "doesn't remove" effect
        for (int w = 0; w < addKeywords.length; w++) {
            if (addKeywords[w].startsWith("Protection:")) {
                addKeywords[w] = addKeywords[w].replaceAll("ChosenName", "Card.named" + chosenName)
                        .replace("HostCardUID", hostCardUID);
            }
        }
        if (params.containsKey("SharedKeywordsZone")) {
            List<ZoneType> zones = ZoneType.listValueOf(params.get("SharedKeywordsZone"));
            String[] restrictions = params.containsKey("SharedRestrictions")
                    ? params.get("SharedRestrictions").split(",")
                    : new String[] { "Card" };
            List<String> kw = CardFactoryUtil.sharedKeywords(addKeywords, restrictions, zones, hostCard);
            addKeywords = kw.toArray(new String[kw.size()]);
        }
    }

    if (layer == StaticAbilityLayer.RULES && params.containsKey("AddHiddenKeyword")) {
        addHiddenKeywords = params.get("AddHiddenKeyword").split(" & ");
    }

    if (layer == StaticAbilityLayer.ABILITIES2 && params.containsKey("RemoveKeyword")) {
        removeKeywords = params.get("RemoveKeyword").split(" & ");
    }

    if (layer == StaticAbilityLayer.ABILITIES1 && params.containsKey("RemoveAllAbilities")) {
        removeAllAbilities = true;
    }

    if (layer == StaticAbilityLayer.ABILITIES2 && params.containsKey("AddAbility")) {
        final String[] sVars = params.get("AddAbility").split(" & ");
        for (int i = 0; i < sVars.length; i++) {
            sVars[i] = hostCard.getSVar(sVars[i]);
        }
        addAbilities = sVars;
    }

    if (layer == StaticAbilityLayer.ABILITIES2 && params.containsKey("AddReplacementEffects")) {
        final String[] sVars = params.get("AddReplacementEffects").split(" & ");
        for (int i = 0; i < sVars.length; i++) {
            sVars[i] = hostCard.getSVar(sVars[i]);
        }
        addReplacements = sVars;
    }

    if (layer == StaticAbilityLayer.ABILITIES2 && params.containsKey("AddSVar")) {
        addSVars = params.get("AddSVar").split(" & ");
    }

    if (layer == StaticAbilityLayer.TYPE && params.containsKey("AddType")) {
        addTypes = params.get("AddType").split(" & ");
        if (addTypes[0].equals("ChosenType")) {
            final String chosenType = hostCard.getChosenType();
            addTypes[0] = chosenType;
            se.setChosenType(chosenType);
        } else if (addTypes[0].equals("ImprintedCreatureType")) {
            if (hostCard.hasImprintedCard()) {
                final Set<String> imprinted = hostCard.getImprintedCards().getFirst().getType()
                        .getCreatureTypes();
                addTypes = imprinted.toArray(new String[imprinted.size()]);
            }
        }
    }

    if (layer == StaticAbilityLayer.TYPE && params.containsKey("RemoveType")) {
        removeTypes = params.get("RemoveType").split(" & ");
        if (removeTypes[0].equals("ChosenType")) {
            final String chosenType = hostCard.getChosenType();
            removeTypes[0] = chosenType;
            se.setChosenType(chosenType);
        }
    }

    if (layer == StaticAbilityLayer.TYPE) {
        if (params.containsKey("RemoveSuperTypes")) {
            removeSuperTypes = true;
        }

        if (params.containsKey("RemoveCardTypes")) {
            removeCardTypes = true;
        }

        if (params.containsKey("RemoveSubTypes")) {
            removeSubTypes = true;
        }

        if (params.containsKey("RemoveCreatureTypes")) {
            removeCreatureTypes = true;
        }
    }

    if (layer == StaticAbilityLayer.COLOR) {
        if (params.containsKey("AddColor")) {
            final String colors = params.get("AddColor");
            if (colors.equals("ChosenColor")) {
                addColors = CardUtil.getShortColorsString(hostCard.getChosenColors());
            } else {
                addColors = CardUtil
                        .getShortColorsString(new ArrayList<String>(Arrays.asList(colors.split(" & "))));
            }
        }

        if (params.containsKey("SetColor")) {
            final String colors = params.get("SetColor");
            if (colors.equals("ChosenColor")) {
                addColors = CardUtil.getShortColorsString(hostCard.getChosenColors());
            } else {
                addColors = CardUtil
                        .getShortColorsString(new ArrayList<String>(Arrays.asList(colors.split(" & "))));
            }
            se.setOverwriteColors(true);
        }
    }

    if (layer == StaticAbilityLayer.ABILITIES2) {
        if (params.containsKey("AddTrigger")) {
            final String[] sVars = params.get("AddTrigger").split(" & ");
            for (int i = 0; i < sVars.length; i++) {
                sVars[i] = hostCard.getSVar(sVars[i]);
            }
            addTriggers = sVars;
        }

        if (params.containsKey("AddStaticAbility")) {
            final String[] sVars = params.get("AddStaticAbility").split(" & ");
            for (int i = 0; i < sVars.length; i++) {
                sVars[i] = hostCard.getSVar(sVars[i]);
            }
            addStatics = sVars;
        }
    }

    if (layer == StaticAbilityLayer.ABILITIES1 && params.containsKey("GainsAbilitiesOf")) {
        final String[] valids = params.get("GainsAbilitiesOf").split(",");
        List<ZoneType> validZones = new ArrayList<ZoneType>();
        validZones.add(ZoneType.Battlefield);
        if (params.containsKey("GainsAbilitiesOfZones")) {
            validZones.clear();
            for (String s : params.get("GainsAbilitiesOfZones").split(",")) {
                validZones.add(ZoneType.smartValueOf(s));
            }
        }

        CardCollectionView cardsIGainedAbilitiesFrom = game.getCardsIn(validZones);
        cardsIGainedAbilitiesFrom = CardLists.getValidCards(cardsIGainedAbilitiesFrom, valids,
                hostCard.getController(), hostCard);

        if (cardsIGainedAbilitiesFrom.size() > 0) {
            addFullAbs = new ArrayList<SpellAbility>();

            for (Card c : cardsIGainedAbilitiesFrom) {
                for (SpellAbility sa : c.getSpellAbilities()) {
                    if (sa instanceof AbilityActivated) {
                        SpellAbility newSA = ((AbilityActivated) sa).getCopy();
                        newSA.setIntrinsic(false);
                        newSA.setTemporary(true);
                        CardFactoryUtil.correctAbilityChainSourceCard(newSA, hostCard);
                        addFullAbs.add(newSA);
                    }
                }
            }
        }
    }

    if (layer == StaticAbilityLayer.RULES) {
        // These fall under Rule changes, as they don't fit any other category
        if (params.containsKey("MayLookAt")) {
            controllerMayLookAt = true;
        }
        if (params.containsKey("MayPlay")) {
            controllerMayPlay = true;
            if (params.containsKey("MayPlayWithoutManaCost")) {
                mayPlayWithoutManaCost = true;
            } else if (params.containsKey("MayPlayIgnoreColor")) {
                mayPlayIgnoreColor = true;
            }
        }

        if (params.containsKey("IgnoreEffectCost")) {
            String cost = params.get("IgnoreEffectCost");
            buildIgnorEffectAbility(stAb, cost, affectedPlayers, affectedCards);
        }
    }

    // modify players
    for (final Player p : affectedPlayers) {

        // add keywords
        if (addKeywords != null) {
            for (int i = 0; i < keywordMultiplier; i++) {
                p.addChangedKeywords(addKeywords, removeKeywords == null ? new String[0] : removeKeywords,
                        se.getTimestamp());
            }
        }

        if (layer == StaticAbilityLayer.RULES) {
            if (params.containsKey("SetMaxHandSize")) {
                String mhs = params.get("SetMaxHandSize");
                if (mhs.equals("Unlimited")) {
                    p.setUnlimitedHandSize(true);
                } else {
                    int max = AbilityUtils.calculateAmount(hostCard, mhs, stAb);
                    p.setMaxHandSize(max);
                }
            }

            if (params.containsKey("RaiseMaxHandSize")) {
                String rmhs = params.get("RaiseMaxHandSize");
                int rmax = AbilityUtils.calculateAmount(hostCard, rmhs, stAb);
                p.setMaxHandSize(p.getMaxHandSize() + rmax);
            }

            if (params.containsKey("ManaColorConversion")) {
                AbilityUtils.applyManaColorConversion(p, params);
            }
        }
    }

    // start modifying the cards
    for (int i = 0; i < affectedCards.size(); i++) {
        final Card affectedCard = affectedCards.get(i);

        // Gain control
        if (layer == StaticAbilityLayer.CONTROL && params.containsKey("GainControl")) {
            affectedCard.addTempController(hostCard.getController(), hostCard.getTimestamp());
        }

        // Change color words
        if (changeColorWordsTo != null) {
            final byte color;
            if (changeColorWordsTo.equals("ChosenColor")) {
                if (hostCard.hasChosenColor()) {
                    color = MagicColor.fromName(Iterables.getFirst(hostCard.getChosenColors(), null));
                } else {
                    color = 0;
                }
            } else {
                color = MagicColor.fromName(changeColorWordsTo);
            }

            if (color != 0) {
                final String colorName = MagicColor.toLongString(color);
                affectedCard.addChangedTextColorWord("Any", colorName, se.getTimestamp());
            }
        }

        // set P/T
        if (layer == StaticAbilityLayer.SETPT) {
            if (params.containsKey("CharacteristicDefining")) {
                if (setPower != -1) {
                    affectedCard.setBasePower(setPower);
                }
                if (setToughness != -1) {
                    affectedCard.setBaseToughness(setToughness);
                }
            } else if ((setPower != -1) || (setToughness != -1)) {
                // non CharacteristicDefining
                if (setP.startsWith("AffectedX")) {
                    setPower = CardFactoryUtil.xCount(affectedCard, AbilityUtils.getSVar(stAb, setP));
                }
                if (setT.startsWith("AffectedX")) {
                    setToughness = CardFactoryUtil.xCount(affectedCard, AbilityUtils.getSVar(stAb, setT));
                }
                affectedCard.addNewPT(setPower, setToughness, hostCard.getTimestamp());
            }
        }

        // add P/T bonus
        if (layer == StaticAbilityLayer.MODIFYPT) {
            if (addP.startsWith("AffectedX")) {
                powerBonus = CardFactoryUtil.xCount(affectedCard, AbilityUtils.getSVar(stAb, addP));
                se.addXMapValue(affectedCard, powerBonus);
            }
            if (addT.startsWith("AffectedX")) {
                toughnessBonus = CardFactoryUtil.xCount(affectedCard, AbilityUtils.getSVar(stAb, addT));
                se.addXMapValue(affectedCard, toughnessBonus);
            }
            affectedCard.addSemiPermanentPowerBoost(powerBonus);
            affectedCard.addSemiPermanentToughnessBoost(toughnessBonus);
        }

        // add keywords
        // TODO regular keywords currently don't try to use keyword multiplier
        // (Although nothing uses it at this time)
        if ((addKeywords != null) || (removeKeywords != null) || removeAllAbilities) {
            affectedCard.addChangedCardKeywords(addKeywords, removeKeywords, removeAllAbilities,
                    hostCard.getTimestamp());
        }

        // add HIDDEN keywords
        if (addHiddenKeywords != null) {
            for (final String k : addHiddenKeywords) {
                for (int j = 0; j < keywordMultiplier; j++) {
                    affectedCard.addHiddenExtrinsicKeyword(k);
                }
            }
        }

        // add SVars
        if (addSVars != null) {
            for (final String sVar : addSVars) {
                String actualSVar = hostCard.getSVar(sVar);
                String name = sVar;
                if (actualSVar.startsWith("SVar:")) {
                    actualSVar = actualSVar.split("SVar:")[1];
                    name = actualSVar.split(":")[0];
                    actualSVar = actualSVar.split(":")[1];
                }
                affectedCard.setSVar(name, actualSVar);
            }
        }

        if (addFullAbs != null) {
            for (final SpellAbility ab : addFullAbs) {
                affectedCard.addSpellAbility(ab);
            }
        }

        // add abilities
        if (addAbilities != null) {
            for (String abilty : addAbilities) {
                if (abilty.contains("CardManaCost")) {
                    StringBuilder sb = new StringBuilder();
                    int generic = affectedCard.getManaCost().getGenericCost();
                    if (generic > 0) {
                        sb.append(generic);
                    }
                    for (ManaCostShard s : affectedCard.getManaCost()) {
                        ColorSet cs = ColorSet.fromMask(s.getColorMask());
                        if (cs.isColorless())
                            continue;
                        sb.append(' ');
                        sb.append(s);
                    }
                    abilty = abilty.replace("CardManaCost", sb.toString().trim());
                } else if (abilty.contains("ConvertedManaCost")) {
                    final String costcmc = Integer.toString(affectedCard.getCMC());
                    abilty = abilty.replace("ConvertedManaCost", costcmc);
                }
                if (abilty.startsWith("AB") || abilty.startsWith("ST")) { // grant the ability
                    final SpellAbility sa = AbilityFactory.getAbility(abilty, affectedCard);
                    sa.setTemporary(true);
                    sa.setIntrinsic(false);
                    sa.setOriginalHost(hostCard);
                    affectedCard.addSpellAbility(sa);
                }
            }
        }

        // add Replacement effects
        if (addReplacements != null) {
            for (String rep : addReplacements) {
                final ReplacementEffect actualRep = ReplacementHandler.parseReplacement(rep, affectedCard,
                        false);
                actualRep.setIntrinsic(false);
                affectedCard.addReplacementEffect(actualRep).setTemporary(true);
                ;
            }
        }

        // add Types
        if ((addTypes != null) || (removeTypes != null)) {
            affectedCard.addChangedCardTypes(addTypes, removeTypes, removeSuperTypes, removeCardTypes,
                    removeSubTypes, removeCreatureTypes, hostCard.getTimestamp());
        }

        // add colors
        if (addColors != null) {
            affectedCard.addColor(addColors, !se.isOverwriteColors(), hostCard.getTimestamp());
        }

        // add triggers
        if (addTriggers != null) {
            for (final String trigger : addTriggers) {
                final Trigger actualTrigger = TriggerHandler.parseTrigger(trigger, affectedCard, false);
                actualTrigger.setIntrinsic(false);
                affectedCard.addTrigger(actualTrigger).setTemporary(true);
            }
        }

        // add static abilities
        if (addStatics != null) {
            for (String s : addStatics) {
                if (s.contains("ConvertedManaCost")) {
                    final String costcmc = Integer.toString(affectedCard.getCMC());
                    s = s.replace("ConvertedManaCost", costcmc);
                }

                StaticAbility stat = affectedCard.addStaticAbility(s);
                stat.setTemporary(true);
                stat.setIntrinsic(false);
            }
        }

        // remove triggers
        if ((layer == StaticAbilityLayer.ABILITIES2 && (params.containsKey("RemoveTriggers"))
                || removeAllAbilities)) {
            for (final Trigger trigger : affectedCard.getTriggers()) {
                trigger.setTemporarilySuppressed(true);
            }
        }

        // remove activated and static abilities
        if (removeAllAbilities) {
            for (final SpellAbility ab : affectedCard.getSpellAbilities()) {
                ab.setTemporarilySuppressed(true);
            }
            for (final StaticAbility stA : affectedCard.getStaticAbilities()) {
                stA.setTemporarilySuppressed(true);
            }
            for (final ReplacementEffect rE : affectedCard.getReplacementEffects()) {
                rE.setTemporarilySuppressed(true);
            }
        }

        if (controllerMayLookAt) {
            affectedCard.setMayLookAt(controller, true);
        }
        if (controllerMayPlay) {
            affectedCard.setMayPlay(controller, mayPlayWithoutManaCost, mayPlayIgnoreColor);
        }

        affectedCard.updateStateForView();
    }

    return affectedCards;
}

From source file:com.streamsets.pipeline.stage.destination.mapreduce.MapreduceUtils.java

@VisibleForTesting
static void addJarsToJob(Configuration conf, boolean allowMultiple, URL[] jarUrls, String... jarPatterns) {

    final List<String> allMatches = new LinkedList<>();
    final List<URL> patternMatches = new LinkedList<>();

    for (String pattern : jarPatterns) {
        if (LOG.isTraceEnabled()) {
            LOG.trace("Looking for pattern {}", pattern);
        }/* w ww.ja v  a2  s.  c o m*/
        for (URL url : jarUrls) {
            if (LOG.isTraceEnabled()) {
                LOG.trace("Looking in jar {}", url);
            }
            final String file = url.getFile();
            if (StringUtils.endsWithIgnoreCase(file, ".jar") && StringUtils.containsIgnoreCase(file, pattern)) {
                allMatches.add(url.toString());
                patternMatches.add(url);

                if (LOG.isDebugEnabled()) {
                    LOG.debug("Found jar {} for pattern {}", url, pattern);
                }
            }
        }

        if (patternMatches.isEmpty()) {
            throw new IllegalArgumentException(String.format("Did not find any jars for pattern %s", pattern));
        } else if (!allowMultiple && patternMatches.size() > 1) {
            throw new IllegalArgumentException(String.format("Found multiple jars for pattern %s: %s", pattern,
                    StringUtils.join(patternMatches, JAR_SEPARATOR)));
        }
        patternMatches.clear();
    }

    appendJars(conf, allMatches);
}