Example usage for java.util Set toArray

List of usage examples for java.util Set toArray

Introduction

In this page you can find the example usage for java.util Set toArray.

Prototype

<T> T[] toArray(T[] a);

Source Link

Document

Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array.

Usage

From source file:pl.softech.eav.domain.ComputerModelExampleTest.java

@Test
@Transactional/*  w  ww. j  a  v  a 2s  .  c om*/
public void testExample() {

    final MyObject computer = new MyObject(categoryRepository.findByIdentifier(cmis.getComputerCategory()),
            "MAUI");

    computer.addValue(attributeRepository.findByIdentifier(new AttributeIdentifier("make")),
            new DictionaryEntryValue(dictionaryEntryRepository.findByIdentifier(cmis.getDell())));
    computer.addValue(attributeRepository.findByIdentifier(new AttributeIdentifier("model")),
            new StringValue("Studio15"));
    computer.addValue(attributeRepository.findByIdentifier(new AttributeIdentifier("type")),
            new DictionaryEntryValue(dictionaryEntryRepository.findByIdentifier(cmis.getNotebook())));
    computer.addValue(attributeRepository.findByIdentifier(new AttributeIdentifier("cpu")),
            new StringValue("Core 2 Duo 2.4GHz"));
    computer.addValue(attributeRepository.findByIdentifier(new AttributeIdentifier("drive")),
            new StringValue("320Gb 5400rpm"));
    computer.addValue(attributeRepository.findByIdentifier(new AttributeIdentifier("video")),
            new StringValue("Intel Acc"));
    computer.addValue(attributeRepository.findByIdentifier(new AttributeIdentifier("ram")),
            new IntegerValue(4));
    computer.addValue(attributeRepository.findByIdentifier(new AttributeIdentifier("optical")),
            new StringValue("DVD RW"));
    computer.addValue(attributeRepository.findByIdentifier(new AttributeIdentifier("battery")),
            new StringValue("6 cell"));
    computer.addValue(attributeRepository.findByIdentifier(new AttributeIdentifier("screen")),
            new StringValue("15\""));
    computer.addValue(attributeRepository.findByIdentifier(new AttributeIdentifier("os")),
            new DictionaryEntryValue(dictionaryEntryRepository.findByIdentifier(cmis.getWin7())));
    computer.addValue(attributeRepository.findByIdentifier(new AttributeIdentifier("os")),
            new DictionaryEntryValue(dictionaryEntryRepository.findByIdentifier(cmis.getLinux())));
    computer.addValue(attributeRepository.findByIdentifier(new AttributeIdentifier("purshase_date")),
            new DateValue(new Date()));

    myObjectRepository.save(computer);

    final MyObject obj = myObjectRepository.findByName("MAUI");

    final ObjectValue makeValue = obj.getValueByAttribute(new AttributeIdentifier("make"));
    Assert.assertEquals("Dell", makeValue.getValueAsString());

    final ObjectValue ramValue = obj.getValueByAttribute(new AttributeIdentifier("ram"));
    Assert.assertEquals("4", ramValue.getValueAsString());

    Assert.assertFalse(obj.hasValues(new AttributeIdentifier("ramm")));
    Assert.assertTrue(obj.getValuesByAttribute((new AttributeIdentifier("ramm"))).isEmpty());

    Assert.assertNull(obj.getValueByAttribute((new AttributeIdentifier("ramm"))));

    final Set<ObjectValue> opticals = obj.getValuesByAttribute(new AttributeIdentifier("optical"));
    Assert.assertEquals(1, opticals.size());
    Assert.assertEquals("DVD RW", opticals.iterator().next().getValueAsString());

    final Set<ObjectValue> oss = obj.getValuesByAttribute(new AttributeIdentifier("os"));
    Assert.assertEquals(2, oss.size());

    final ObjectValue[] arr = oss.toArray(new ObjectValue[2]);
    Arrays.sort(arr, new Comparator<ObjectValue>() {

        @Override
        public int compare(final ObjectValue o1, final ObjectValue o2) {
            return o1.getValueAsString().compareTo(o2.getValueAsString());
        }
    });
    Assert.assertEquals("Linux", arr[0].getValueAsString());
    Assert.assertEquals("Windows 7", arr[1].getValueAsString());

}

From source file:com.temenos.interaction.loader.detector.ClassLoaderCreatingAction.java

/**
 * @param fe the file event with the directory to search for the specified file extensions
 *//*from w w  w. j  a  v  a 2s  .co m*/
@Override
public void execute(FileEvent<File> fe) {
    Collection<File> files = FileUtils.listFiles(fe.getResource(), extensions.toArray(new String[] {}), true);
    Set<URL> urls = new HashSet();
    for (File f : files) {
        try {
            urls.add(f.toURI().toURL());
        } catch (MalformedURLException ex) {
            // TODO: log properly
        }
    }
    ParentLastURLClassloader classloader = new ParentLastURLClassloader(urls.toArray(new URL[] {}));

    for (Action<ClassLoader> listener : listeners) {
        listener.execute(classloader);
    }
}

From source file:mml.handler.scratch.ScratchVersion.java

/**
 * Convert this version to JSON so it can stored in the database
 * @return the entire version as a string
 *///  w w w  .ja  v  a2 s .  c o m
public String toJSON() {
    JSONObject jObj = new JSONObject();
    if (layers != null) {
        Set<String> keys = layers.keySet();
        String[] arr = new String[keys.size()];
        keys.toArray(arr);
        Arrays.sort(arr);
        jObj.put(JSONKeys.VERSION1, version);
        if (this.longName != null)
            jObj.put(JSONKeys.LONGNAME, longName);
        Calendar cal = Calendar.getInstance();
        // timestap conversion to JSON
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        jObj.put(JSONKeys.TIME, sdf.format(cal.getTime()));
        jObj.put("dbase", dbase);
        jObj.put("dirty", dirty);
        JSONArray jArr = new JSONArray();
        jObj.put("layers", jArr);
        for (int i = 0; i < arr.length; i++) {
            JSONObject jLayer = new JSONObject();
            jLayer.put(JSONKeys.NAME, arr[i]);
            jLayer.put(JSONKeys.BODY, layers.get(arr[i]));
            jArr.add(jLayer);
        }
    }
    return jObj.toJSONString();
}

From source file:net.sf.morph.transform.converters.TextToEnumConverter.java

/**
 * {@inheritDoc}/*  w  w  w . ja  v a 2 s .c o m*/
 */
protected Class[] getDestinationClassesImpl() throws Exception {
    if (ENUM_TYPE == null) {
        return ArrayUtils.EMPTY_CLASS_ARRAY;
    }
    Set result = ContainerUtils.createOrderedSet();
    result.add(ENUM_TYPE);
    result.addAll(Arrays.asList(getTextConverter().getDestinationClasses()));
    result.add(null);
    return (Class[]) result.toArray(new Class[result.size()]);
}

From source file:jp.co.nemuzuka.service.impl.CommentServiceImpl.java

@Override
public List<CommentModelEx> getList(Key refsKey) {

    List<CommentModel> list = commentDao.getList(refsKey);
    Set<Key> memberKey = new LinkedHashSet<Key>();
    for (CommentModel target : list) {
        memberKey.add(target.getCreateMemberKey());
    }//from w w w. j a  va2s.c om

    //??
    Map<Key, MemberModel> memberMap = memberDao.getMap(memberKey.toArray(new Key[0]));

    //List?
    SimpleDateFormat sdf = DateTimeUtils.createSdf("MM/dd HH:mm");
    List<CommentModelEx> retList = new ArrayList<CommentModelEx>();
    for (CommentModel target : list) {
        CommentModelEx entity = new CommentModelEx();
        entity.setModel(target);

        String createMemberName = null;
        MemberModel memberModel = memberMap.get(target.getCreateMemberKey());
        if (memberModel != null) {
            createMemberName = memberModel.getName();
        } else {
            createMemberName = "";
        }
        entity.setCreateMemberName(createMemberName);

        entity.setCreatedAt(ConvertUtils.toString(target.getCreatedAt(), sdf));

        retList.add(entity);
    }
    return retList;
}

From source file:edu.du.penrose.systems.fedoraApp.ProgramFileProperties.java

/**
 * @see ProgramProperties#getPropertyNamesAsArray()
 *//*from  w w w  . jav  a  2s  .  com*/
public String[] getPropertyNamesAsArray() {

    String[] keySetArray = new String[1];

    if (this.getMyProperties() == null) {
        return new String[0];
    }

    Set<Object> keySet = this.getMyProperties().keySet();
    if (keySet != null) {
        keySetArray = keySet.toArray(keySetArray);
    }

    return keySetArray;
}

From source file:com.QuarkLabs.BTCeClient.services.CheckTickersService.java

@Override
protected void onHandleIntent(Intent intent) {

    SharedPreferences sh = PreferenceManager.getDefaultSharedPreferences(this);
    Set<String> x = sh.getStringSet("PairsToDisplay", new HashSet<String>());
    if (x.size() == 0) {
        return;/*from   w ww.ja v a 2 s  .c om*/
    }
    String[] pairs = x.toArray(new String[x.size()]);
    ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    String url = BASE_URL;
    for (String xx : pairs) {
        url += xx.replace("/", "_").toLowerCase(Locale.US) + "-";
    }
    SimpleRequest reqSim = new SimpleRequest();

    if (networkInfo != null && networkInfo.isConnected()) {
        JSONObject data = null;
        try {
            data = reqSim.makeRequest(url);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        if (data != null && data.optInt("success", 1) != 0) {

            ArrayList<Ticker> tickers = new ArrayList<>();
            for (@SuppressWarnings("unchecked")
            Iterator<String> iterator = data.keys(); iterator.hasNext();) {
                String key = iterator.next();
                JSONObject pairData = data.optJSONObject(key);
                Ticker ticker = new Ticker(key);
                ticker.setUpdated(pairData.optLong("updated"));
                ticker.setAvg(pairData.optDouble("avg"));
                ticker.setBuy(pairData.optDouble("buy"));
                ticker.setSell(pairData.optDouble("sell"));
                ticker.setHigh(pairData.optDouble("high"));
                ticker.setLast(pairData.optDouble("last"));
                ticker.setLow(pairData.optDouble("low"));
                ticker.setVol(pairData.optDouble("vol"));
                ticker.setVolCur(pairData.optDouble("vol_cur"));
                tickers.add(ticker);
            }

            String message = checkNotifiers(tickers, TickersStorage.loadLatestData());

            if (message.length() != 0) {
                NotificationManager notificationManager = (NotificationManager) getSystemService(
                        NOTIFICATION_SERVICE);
                NotificationCompat.Builder nb = new NotificationCompat.Builder(this)
                        .setContentTitle(getResources().getString(R.string.app_name))
                        .setSmallIcon(R.drawable.ic_stat_bitcoin_sign)
                        .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                        .setContentText(message.substring(0, message.length() - 2));
                notificationManager.notify(ConstantHolder.ALARM_NOTIF_ID, nb.build());
            }

            Map<String, Ticker> newData = new HashMap<>();
            for (Ticker ticker : tickers) {
                newData.put(ticker.getPair(), ticker);
            }
            TickersStorage.saveData(newData);
            LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent("UpdateTickers"));
        }
    } else {
        new Handler().post(new Runnable() {
            @Override
            public void run() {
                //Toast.makeText(CheckTickersService.this, "Unable to fetch data", Toast.LENGTH_SHORT).show();
            }
        });

    }
}

From source file:jp.co.nemuzuka.dao.MemberDao.java

/**
 * List?.//from w w w .j  ava  2 s . c o m
 * ??Key????????
 * @param keys Key?
 * @return Map
 */
public List<MemberModel> getList(Key... keys) {
    MemberModelMeta e = (MemberModelMeta) getModelMeta();
    Set<FilterCriterion> filterSet = new HashSet<FilterCriterion>();

    if (keys != null && keys.length != 0) {
        filterSet.add(e.key.in(keys));
    } else {
        return new ArrayList<MemberModel>();
    }

    return Datastore.query(e).filter(filterSet.toArray(new FilterCriterion[0]))
            .sortInMemory(e.authority.asc, e.key.asc).asList();
}

From source file:org.jasig.portlet.conference.program.mvc.portlet.MainController.java

@ResourceMapping
public ModelAndView updateSessions(PortletRequest request, @RequestParam String title,
        @RequestParam boolean add) throws ReadOnlyException, ValidatorException, IOException {
    PortletPreferences preferences = request.getPreferences();
    String[] sessions = preferences.getValues("mysessions", new String[] {});

    Set<String> mine = new HashSet<String>();
    for (String session : sessions) {
        mine.add(session);/*w  w w  .j ava 2s.  c  o m*/
    }
    if (add) {
        mine.add(title);
    } else {
        mine.remove(title);
    }
    preferences.setValues("mysessions", mine.toArray(new String[] {}));

    preferences.store();

    return new ModelAndView("json");
}

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./* w  w  w.jav a2 s.c  o m*/
 * 
 * @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;
}