Example usage for java.util HashSet removeAll

List of usage examples for java.util HashSet removeAll

Introduction

In this page you can find the example usage for java.util HashSet removeAll.

Prototype

boolean removeAll(Collection<?> c);

Source Link

Document

Removes from this set all of its elements that are contained in the specified collection (optional operation).

Usage

From source file:com.notifry.android.database.NotifrySource.java

public ArrayList<NotifrySource> syncFromJSONArray(Context context, JSONArray sourceList, String accountName)
        throws JSONException {
    ArrayList<NotifrySource> result = new ArrayList<NotifrySource>();
    HashSet<Long> seenIds = new HashSet<Long>();

    for (int i = 0; i < sourceList.length(); i++) {
        // See if we can find a local object with that ID.
        JSONObject object = sourceList.getJSONObject(i);
        Long serverId = object.getLong("id");

        NotifrySource source = NotifrySource.FACTORY.getByServerId(context, serverId);

        if (source == null) {
            // We don't have that source locally. Create it.
            source = new NotifrySource();
            source.fromJSONObject(object);
            // It's only locally enabled if the server has it enabled.
            source.setLocalEnabled(source.getServerEnabled());
            source.setAccountName(accountName);
        } else {/*from  ww  w  .jav a  2 s . co m*/
            // Server already has it. Assume the server is the most up to
            // date version.
            source.fromJSONObject(object);
        }

        // Save it in the database.
        source.save(context);

        seenIds.add(source.getId());
    }

    // Now, find out the IDs that exist in our database but were not in our
    // list.
    // Those have been deleted.
    ArrayList<NotifrySource> allSources = NotifrySource.FACTORY.listAll(context, accountName);
    HashSet<Long> allIds = new HashSet<Long>();
    for (NotifrySource source : allSources) {
        allIds.add(source.getId());
    }

    allIds.removeAll(seenIds);

    for (Long sourceId : allIds) {
        NotifrySource source = NotifrySource.FACTORY.get(context, sourceId);
        NotifryMessage.FACTORY.deleteMessagesBySource(context, source, false);
        source.delete(context);
    }

    return result;
}

From source file:voldemort.store.bdb.PartitionPrefixedBdbStorageEngineTest.java

@Test
public void testPartitionScan() {

    StoreDefinition storedef = TestUtils.makeStoreDefinition("storeA");
    RoutingStrategy strategy = TestUtils.makeSingleNodeRoutingStrategy();
    BdbStorageEngine prefixedBdbStore = (BdbStorageEngine) bdbStorage.getStore(storedef, strategy);
    try {/*from ww w  .j a  va  2  s .  c  om*/
        // insert a bunch of records
        HashMap<Integer, Set<String>> partitionToKeysMap = new HashMap<Integer, Set<String>>();
        for (int i = 0; i < 10000; i++) {
            String key = "key" + i;
            byte[] bkey = key.getBytes();

            int partition = strategy.getPartitionList(bkey).get(0);
            if (!partitionToKeysMap.containsKey(partition))
                partitionToKeysMap.put(partition, new HashSet<String>());
            partitionToKeysMap.get(partition).add(key);

            prefixedBdbStore.put(new ByteArray(bkey), new Versioned<byte[]>(("value" + i).getBytes()), null);
        }

        // check if they are properly retrieved by that partition id
        for (int p = 0; p < strategy.getNumReplicas(); p++) {

            // verify keys
            Set<String> keys = getKeys(prefixedBdbStore.keys(p));
            assertEquals(partitionToKeysMap.get(p).size(), keys.size());
            assertEquals(partitionToKeysMap.get(p), keys);

            // verify values
            keys = getEntries(prefixedBdbStore.entries(p));
            assertEquals(partitionToKeysMap.get(p).size(), keys.size());
            assertEquals(partitionToKeysMap.get(p), keys);
        }

        // make sure the entries() code path does not break.
        HashSet<String> allKeys = new HashSet<String>();
        for (Integer p : partitionToKeysMap.keySet()) {
            Set<String> pkeys = partitionToKeysMap.get(p);
            int originalSize = allKeys.size();
            allKeys.removeAll(pkeys);
            // this is to make sure the pkeys have 0 overlap
            assertEquals(allKeys.size(), originalSize);
            allKeys.addAll(pkeys);
        }
        // this makes sure all the data we put in is what you get out, not a
        // byte less or more
        Set<String> keys = getKeys(prefixedBdbStore.keys());
        assertEquals(allKeys.size(), keys.size());
        assertEquals(allKeys, keys);

        keys = getEntries(prefixedBdbStore.entries());
        assertEquals(allKeys.size(), keys.size());
        assertEquals(allKeys, keys);

    } catch (Exception e) {
        fail("Should not have thrown any exceptions" + e.getMessage());
    } finally {
        prefixedBdbStore.close();
    }
}

From source file:com.newtifry.android.database.NewtifrySource.java

public ArrayList<NewtifrySource> syncFromJSONArray(Context context, JSONArray sourceList, String accountName)
        throws JSONException {
    ArrayList<NewtifrySource> result = new ArrayList<NewtifrySource>();
    HashSet<Long> seenIds = new HashSet<Long>();

    for (int i = 0; i < sourceList.length(); i++) {
        // See if we can find a local object with that ID.
        JSONObject object = sourceList.getJSONObject(i);
        Long serverId = object.getLong("id");

        NewtifrySource source = NewtifrySource.FACTORY.getByServerId(context, serverId);

        if (source == null) {
            // We don't have that source locally. Create it.
            source = new NewtifrySource();
            source.fromJSONObject(object);
            // It's only locally enabled if the server has it enabled.
            source.setLocalEnabled(source.getServerEnabled());
            source.setAccountName(accountName);
        } else {//from   w  w w  .  j  a  v  a 2  s. c o  m
            // Server already has it. Assume the server is the most up to date version.
            source.fromJSONObject(object);
        }

        // Save it in the database.
        source.save(context);

        seenIds.add(source.getId());
    }

    // Now, find out the IDs that exist in our database but were not in our list.
    // Those have been deleted.
    ArrayList<NewtifrySource> allSources = NewtifrySource.FACTORY.listAll(context, accountName);
    HashSet<Long> allIds = new HashSet<Long>();
    for (NewtifrySource source : allSources) {
        allIds.add(source.getId());
    }

    allIds.removeAll(seenIds);

    for (Long sourceId : allIds) {
        NewtifrySource source = NewtifrySource.FACTORY.get(context, sourceId);
        NewtifryMessage.FACTORY.deleteMessagesBySource(context, source, false);
        source.delete(context);
    }

    return result;
}

From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.PushProjectDownRule.java

private static Pair<Boolean, Boolean> pushThroughOp(HashSet<LogicalVariable> toPush,
        Mutable<ILogicalOperator> opRef2, ILogicalOperator initialOp, IOptimizationContext context)
        throws AlgebricksException {
    List<LogicalVariable> initProjectList = new ArrayList<LogicalVariable>(toPush);
    AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue();
    do {/*from w  w  w  .j a  v a 2s .  c  o m*/
        if (op2.getOperatorTag() == LogicalOperatorTag.EMPTYTUPLESOURCE
                || op2.getOperatorTag() == LogicalOperatorTag.NESTEDTUPLESOURCE
                || op2.getOperatorTag() == LogicalOperatorTag.PROJECT
                || op2.getOperatorTag() == LogicalOperatorTag.REPLICATE
                || op2.getOperatorTag() == LogicalOperatorTag.UNIONALL) {
            return new Pair<Boolean, Boolean>(false, false);
        }
        if (!op2.isMap()) {
            break;
        }
        LinkedList<LogicalVariable> usedVars = new LinkedList<LogicalVariable>();
        VariableUtilities.getUsedVariables(op2, usedVars);
        toPush.addAll(usedVars);
        LinkedList<LogicalVariable> producedVars = new LinkedList<LogicalVariable>();
        VariableUtilities.getProducedVariables(op2, producedVars);
        toPush.removeAll(producedVars);
        // we assume pipelineable ops. have only one input
        opRef2 = op2.getInputs().get(0);
        op2 = (AbstractLogicalOperator) opRef2.getValue();
    } while (true);

    LinkedList<LogicalVariable> produced2 = new LinkedList<LogicalVariable>();
    VariableUtilities.getProducedVariables(op2, produced2);
    LinkedList<LogicalVariable> used2 = new LinkedList<LogicalVariable>();
    VariableUtilities.getUsedVariables(op2, used2);

    boolean canCommuteProjection = initProjectList.containsAll(toPush) && initProjectList.containsAll(produced2)
            && initProjectList.containsAll(used2);
    // if true, we can get rid of the initial projection

    // get rid of useless decor vars.
    if (!canCommuteProjection && op2.getOperatorTag() == LogicalOperatorTag.GROUP) {
        boolean gbyChanged = false;
        GroupByOperator gby = (GroupByOperator) op2;
        List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> newDecorList = new ArrayList<Pair<LogicalVariable, Mutable<ILogicalExpression>>>();
        for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : gby.getDecorList()) {
            LogicalVariable decorVar = GroupByOperator.getDecorVariable(p);
            if (!toPush.contains(decorVar)) {
                used2.remove(decorVar);
                gbyChanged = true;
            } else {
                newDecorList.add(p);
            }
        }
        gby.getDecorList().clear();
        gby.getDecorList().addAll(newDecorList);
        if (gbyChanged) {
            context.computeAndSetTypeEnvironmentForOperator(gby);
        }
    }
    used2.clear();
    VariableUtilities.getUsedVariables(op2, used2);

    toPush.addAll(used2); // remember that toPush is a Set
    toPush.removeAll(produced2);

    if (toPush.isEmpty()) {
        return new Pair<Boolean, Boolean>(false, false);
    }

    boolean smthWasPushed = false;
    for (Mutable<ILogicalOperator> c : op2.getInputs()) {
        if (pushNeededProjections(toPush, c, context, initialOp)) {
            smthWasPushed = true;
        }
    }
    if (op2.hasNestedPlans()) {
        AbstractOperatorWithNestedPlans n = (AbstractOperatorWithNestedPlans) op2;
        for (ILogicalPlan p : n.getNestedPlans()) {
            for (Mutable<ILogicalOperator> r : p.getRoots()) {
                if (pushNeededProjections(toPush, r, context, initialOp)) {
                    smthWasPushed = true;
                }
            }
        }
    }
    return new Pair<Boolean, Boolean>(smthWasPushed, canCommuteProjection);
}

From source file:edu.tum.cs.conqat.quamoco.qiesl.QIESLEngine.java

/** Validates the expression */
private HashSet<String> validate(String expressionString, Set<String> knownTechnicalNames)
        throws QIESLException {
    Parser parser = new Parser(new StringReader(";"));
    ASTJexlScript result;/* www  .  j  a  v  a2 s. com*/
    try {
        result = parser.parse(new StringReader(expressionString), null);
    } catch (ParseException e) {
        throw new QIESLException("Syntax error: " + e.getMessage(), e);
    } catch (TokenMgrError e) {
        throw new QIESLException("Error: " + e.getMessage(), e);
    } catch (Error e) {
        throw new QIESLException("Error: " + e.getMessage(), e);
    }

    HashSet<String> identifiers = getReferencedVariables(result);
    HashSet<String> declaredVariables = getDeclaredVariables(result);
    identifiers.removeAll(declaredVariables);

    Set<String> unknownTechnicalNames = difference(identifiers, knownTechnicalNames);

    for (String unknownName : unknownTechnicalNames) {
        if (!isResultVariable(unknownName)) {
            throw new QIESLException("Unknown variable: " + unknownName);
        }
    }

    return identifiers;
}

From source file:org.springframework.kafka.test.EmbeddedKafkaBroker.java

/**
 * Subscribe a consumer to one or more of the embedded topics.
 * @param consumer the consumer./*w ww. j  a  v a2 s .co m*/
 * @param topics the topics.
 */
public void consumeFromEmbeddedTopics(Consumer<?, ?> consumer, String... topics) {
    HashSet<String> diff = new HashSet<>(Arrays.asList(topics));
    diff.removeAll(new HashSet<>(this.topics));
    assertThat(this.topics).as("topic(s):'" + diff + "' are not in embedded topic list")
            .containsAll(new HashSet<>(Arrays.asList(topics)));
    final AtomicBoolean assigned = new AtomicBoolean();
    consumer.subscribe(Arrays.asList(topics), new ConsumerRebalanceListener() {

        @Override
        public void onPartitionsRevoked(Collection<TopicPartition> partitions) {
        }

        @Override
        public void onPartitionsAssigned(Collection<TopicPartition> partitions) {
            assigned.set(true);
            if (logger.isDebugEnabled()) {
                logger.debug("partitions assigned: " + partitions);
            }
        }

    });
    ConsumerRecords<?, ?> records = null;
    int n = 0;
    while (!assigned.get() && n++ < 600) { // NOSONAR magic #
        records = consumer.poll(Duration.ofMillis(100)); // force assignment NOSONAR magic #
    }
    if (records != null && records.count() > 0) {
        final ConsumerRecords<?, ?> theRecords = records;
        if (logger.isDebugEnabled()) {
            logger.debug("Records received on initial poll for assignment; re-seeking to beginning; " + records
                    .partitions().stream().flatMap(p -> theRecords.records(p).stream())
                    // map to same format as send metadata toString()
                    .map(r -> r.topic() + "-" + r.partition() + "@" + r.offset()).collect(Collectors.toList()));
        }
        consumer.seekToBeginning(records.partitions());
    }
    assertThat(assigned.get()).as("Failed to be assigned partitions from the embedded topics").isTrue();
    logger.debug("Subscription Initiated");
}

From source file:org.ecloudmanager.web.faces.DeploymentActionController.java

private void setStatusClass(CyNode node, Action.Status status) {
    String statusClass = status.name().toLowerCase();
    HashSet<String> classes = Sets.newHashSet(node.getClasses().split(" "));
    if (classes.contains(statusClass)) {
        return;//ww w.j av a2 s .  c  om
    }
    HashSet<Action.Status> classesToRemove = Sets.newHashSet(Action.Status.values());
    classesToRemove.remove(status);
    classes.removeAll(
            classesToRemove.stream().map(Enum::name).map(String::toLowerCase).collect(Collectors.toSet()));
    classes.add(statusClass);
    node.setClasses(StringUtils.join(classes, " ").trim());
}

From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.IntroduceGroupByForSubplanRule.java

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
        throws AlgebricksException {
    AbstractLogicalOperator op0 = (AbstractLogicalOperator) opRef.getValue();
    if (op0.getOperatorTag() != LogicalOperatorTag.SUBPLAN) {
        return false;
    }/*from   w  ww  .ja va  2 s.  co  m*/
    SubplanOperator subplan = (SubplanOperator) op0;

    Iterator<ILogicalPlan> plansIter = subplan.getNestedPlans().iterator();
    ILogicalPlan p = null;
    while (plansIter.hasNext()) {
        p = plansIter.next();
    }
    if (p == null) {
        return false;
    }
    if (p.getRoots().size() != 1) {
        return false;
    }
    Mutable<ILogicalOperator> subplanRoot = p.getRoots().get(0);
    AbstractLogicalOperator op1 = (AbstractLogicalOperator) subplanRoot.getValue();

    Mutable<ILogicalOperator> botRef = subplanRoot;
    AbstractLogicalOperator op2;
    // Project is optional
    if (op1.getOperatorTag() != LogicalOperatorTag.PROJECT) {
        op2 = op1;
    } else {
        ProjectOperator project = (ProjectOperator) op1;
        botRef = project.getInputs().get(0);
        op2 = (AbstractLogicalOperator) botRef.getValue();
    }
    if (op2.getOperatorTag() != LogicalOperatorTag.AGGREGATE) {
        return false;
    }
    AggregateOperator aggregate = (AggregateOperator) op2;

    Set<LogicalVariable> free = new HashSet<LogicalVariable>();
    VariableUtilities.getUsedVariables(aggregate, free);

    Mutable<ILogicalOperator> op3Ref = aggregate.getInputs().get(0);
    AbstractLogicalOperator op3 = (AbstractLogicalOperator) op3Ref.getValue();

    while (op3.getInputs().size() == 1) {
        Set<LogicalVariable> prod = new HashSet<LogicalVariable>();
        VariableUtilities.getProducedVariables(op3, prod);
        free.removeAll(prod);
        VariableUtilities.getUsedVariables(op3, free);
        botRef = op3Ref;
        op3Ref = op3.getInputs().get(0);
        op3 = (AbstractLogicalOperator) op3Ref.getValue();
    }

    if (op3.getOperatorTag() != LogicalOperatorTag.INNERJOIN
            && op3.getOperatorTag() != LogicalOperatorTag.LEFTOUTERJOIN) {
        return false;
    }
    AbstractBinaryJoinOperator join = (AbstractBinaryJoinOperator) op3;
    if (join.getCondition().getValue() == ConstantExpression.TRUE) {
        return false;
    }
    VariableUtilities.getUsedVariables(join, free);

    AbstractLogicalOperator b0 = (AbstractLogicalOperator) join.getInputs().get(0).getValue();
    // see if there's an NTS at the end of the pipeline
    NestedTupleSourceOperator outerNts = getNts(b0);
    if (outerNts == null) {
        AbstractLogicalOperator b1 = (AbstractLogicalOperator) join.getInputs().get(1).getValue();
        outerNts = getNts(b1);
        if (outerNts == null) {
            return false;
        }
    }

    Set<LogicalVariable> pkVars = computeGbyVars(outerNts, free, context);
    if (pkVars == null || pkVars.size() < 1) {
        // there is no non-trivial primary key, group-by keys are all live variables
        ILogicalOperator subplanInput = subplan.getInputs().get(0).getValue();
        pkVars = new HashSet<LogicalVariable>();
        VariableUtilities.getLiveVariables(subplanInput, pkVars);
    }
    AlgebricksConfig.ALGEBRICKS_LOGGER.fine("Found FD for introducing group-by: " + pkVars);

    Mutable<ILogicalOperator> rightRef = join.getInputs().get(1);
    LogicalVariable testForNull = null;
    AbstractLogicalOperator right = (AbstractLogicalOperator) rightRef.getValue();
    switch (right.getOperatorTag()) {
    case UNNEST: {
        UnnestOperator innerUnnest = (UnnestOperator) right;
        // Select [ $y != null ]
        testForNull = innerUnnest.getVariable();
        break;
    }
    case RUNNINGAGGREGATE: {
        ILogicalOperator inputToRunningAggregate = right.getInputs().get(0).getValue();
        Set<LogicalVariable> producedVars = new ListSet<LogicalVariable>();
        VariableUtilities.getProducedVariables(inputToRunningAggregate, producedVars);
        if (!producedVars.isEmpty()) {
            // Select [ $y != null ]
            testForNull = producedVars.iterator().next();
        }
        break;
    }
    case DATASOURCESCAN: {
        DataSourceScanOperator innerScan = (DataSourceScanOperator) right;
        // Select [ $y != null ]
        if (innerScan.getVariables().size() == 1) {
            testForNull = innerScan.getVariables().get(0);
        }
        break;
    }
    }
    if (testForNull == null) {
        testForNull = context.newVar();
        AssignOperator tmpAsgn = new AssignOperator(testForNull,
                new MutableObject<ILogicalExpression>(ConstantExpression.TRUE));
        tmpAsgn.getInputs().add(new MutableObject<ILogicalOperator>(rightRef.getValue()));
        rightRef.setValue(tmpAsgn);
        context.computeAndSetTypeEnvironmentForOperator(tmpAsgn);
    }

    IFunctionInfo finfoEq = context.getMetadataProvider().lookupFunction(AlgebricksBuiltinFunctions.IS_NULL);
    ILogicalExpression isNullTest = new ScalarFunctionCallExpression(finfoEq,
            new MutableObject<ILogicalExpression>(new VariableReferenceExpression(testForNull)));
    IFunctionInfo finfoNot = context.getMetadataProvider().lookupFunction(AlgebricksBuiltinFunctions.NOT);
    ScalarFunctionCallExpression nonNullTest = new ScalarFunctionCallExpression(finfoNot,
            new MutableObject<ILogicalExpression>(isNullTest));
    SelectOperator selectNonNull = new SelectOperator(new MutableObject<ILogicalExpression>(nonNullTest), false,
            null);
    GroupByOperator g = new GroupByOperator();
    Mutable<ILogicalOperator> newSubplanRef = new MutableObject<ILogicalOperator>(subplan);
    NestedTupleSourceOperator nts = new NestedTupleSourceOperator(new MutableObject<ILogicalOperator>(g));
    opRef.setValue(g);
    selectNonNull.getInputs().add(new MutableObject<ILogicalOperator>(nts));

    List<Mutable<ILogicalOperator>> prodInpList = botRef.getValue().getInputs();
    prodInpList.clear();
    prodInpList.add(new MutableObject<ILogicalOperator>(selectNonNull));

    ILogicalPlan gPlan = new ALogicalPlanImpl(new MutableObject<ILogicalOperator>(subplanRoot.getValue()));
    g.getNestedPlans().add(gPlan);
    subplanRoot.setValue(op3Ref.getValue());
    g.getInputs().add(newSubplanRef);

    HashSet<LogicalVariable> underVars = new HashSet<LogicalVariable>();
    VariableUtilities.getLiveVariables(subplan.getInputs().get(0).getValue(), underVars);
    underVars.removeAll(pkVars);
    Map<LogicalVariable, LogicalVariable> mappedVars = buildVarExprList(pkVars, context, g, g.getGroupByList());
    context.updatePrimaryKeys(mappedVars);
    for (LogicalVariable uv : underVars) {
        g.getDecorList().add(new Pair<LogicalVariable, Mutable<ILogicalExpression>>(null,
                new MutableObject<ILogicalExpression>(new VariableReferenceExpression(uv))));
    }
    OperatorPropertiesUtil.typeOpRec(subplanRoot, context);
    OperatorPropertiesUtil.typeOpRec(gPlan.getRoots().get(0), context);
    context.computeAndSetTypeEnvironmentForOperator(g);
    return true;
}

From source file:com.data2semantics.yasgui.mgwtlinker.linker.PermutationMapLinker.java

@Override
public ArtifactSet link(TreeLogger logger, LinkerContext context, ArtifactSet artifacts, boolean onePermutation)
        throws UnableToCompleteException {
    if (onePermutation) {
        Map<String, Set<BindingProperty>> permutationMap = buildPermutationMap(logger, context, artifacts);
        Set<Entry<String, Set<BindingProperty>>> entrySet = permutationMap.entrySet();

        // since we are in onePermutation there should be just one
        // strongName
        // better make sure..
        if (permutationMap.size() != 1) {
            logger.log(Type.ERROR, "There should be only one permutation right now, but there were: '"
                    + permutationMap.size() + "'");
            throw new UnableToCompleteException();
        }/*  www  . java 2  s.  c  om*/

        Entry<String, Set<BindingProperty>> next = entrySet.iterator().next();
        String strongName = next.getKey();
        Set<BindingProperty> bindingProperties = next.getValue();

        // all artifacts for this compilation
        Set<String> artifactsForCompilation = getArtifactsForCompilation(logger, context, artifacts);

        ArtifactSet toReturn = new ArtifactSet(artifacts);
        PermutationArtifact permutationArtifact = new PermutationArtifact(PermutationMapLinker.class,
                strongName, artifactsForCompilation, bindingProperties);

        toReturn.add(permutationArtifact);
        return toReturn;
    }

    ArtifactSet toReturn = new ArtifactSet(artifacts);
    Map<String, Set<BindingProperty>> map = buildPermutationMap(logger, context, artifacts);

    if (map.size() == 0) {
        // hosted mode
        return toReturn;
    }

    Map<String, PermutationArtifact> permutationArtifactAsMap = getPermutationArtifactAsMap(artifacts);

    //we need different file sets/manifests for our dev version (unminimized js), and our stable version
    List<String> stableExternalFiles = getStableExternalFiles(logger, context);
    List<String> devExternalFiles = getDevExternalFiles(logger, context);

    // build manifest html page for our stable version (included as iframe in our webapp)
    String appcacheService = "manifest.appcache";
    String manifestHtmlPage = buildManifestHtmlPage(appcacheService);
    toReturn.add(emitString(logger, manifestHtmlPage, appcacheService + ".html"));

    // build manifest html page for our stable version (included as iframe in our webapp)
    String devManifestHtmlPage = buildManifestHtmlPage(appcacheService + "?type=dev");
    toReturn.add(emitString(logger, devManifestHtmlPage, "manifest.dev.appcache.html"));

    Set<String> allPermutationFiles = getAllPermutationFiles(permutationArtifactAsMap);

    // get all artifacts
    Set<String> allArtifacts = getArtifactsForCompilation(logger, context, artifacts);

    for (Entry<String, PermutationArtifact> entry : permutationArtifactAsMap.entrySet()) {
        PermutationArtifact permutationArtifact = entry.getValue();
        // make a copy of all artifacts
        HashSet<String> filesForCurrentPermutation = new HashSet<String>(allArtifacts);
        // remove all permutations
        filesForCurrentPermutation.removeAll(allPermutationFiles);
        // add files of the one permutation we are interested in
        // leaving the common stuff for all permutations in...
        filesForCurrentPermutation.addAll(entry.getValue().getPermutationFiles());
        filesForCurrentPermutation = appendVersionIfNeeded(filesForCurrentPermutation);

        String permXml = buildPermXml(logger, permutationArtifact, filesForCurrentPermutation,
                stableExternalFiles);

        // emit permutation information file
        SyntheticArtifact emitString = emitString(logger, permXml,
                permutationArtifact.getPermutationName() + PERMUTATION_FILE_ENDING);
        toReturn.add(emitString);

        // build manifest for our stable version
        String manifestFile = entry.getKey() + PERMUTATION_MANIFEST_FILE_ENDING;
        @SuppressWarnings("serial")
        Map<String, String> fallbacks = new HashMap<String, String>() {
            {
                put("/", "../index.jsp");
            }
        };
        String maniFest = buildManiFest(entry.getKey(), stableExternalFiles, filesForCurrentPermutation,
                fallbacks);
        toReturn.add(emitString(logger, maniFest, manifestFile));

        // build manifest for our dev version
        String devManifestFile = entry.getKey() + ".dev" + PERMUTATION_MANIFEST_FILE_ENDING;
        String devManiFest = buildManiFest(entry.getKey(), devExternalFiles, filesForCurrentPermutation);
        toReturn.add(emitString(logger, devManiFest, devManifestFile));

    }

    toReturn.add(createPermutationMap(logger, map));
    return toReturn;

}