Example usage for org.apache.commons.collections.bidimap UnmodifiableBidiMap decorate

List of usage examples for org.apache.commons.collections.bidimap UnmodifiableBidiMap decorate

Introduction

In this page you can find the example usage for org.apache.commons.collections.bidimap UnmodifiableBidiMap decorate.

Prototype

public static BidiMap decorate(BidiMap map) 

Source Link

Document

Factory method to create an unmodifiable map.

Usage

From source file:BidiMapExample.java

public static void main(String args[]) {

    BidiMap agentToCode = new DualHashBidiMap();
    agentToCode.put("007", "Bond");
    agentToCode.put("006", "Joe");

    agentToCode = UnmodifiableBidiMap.decorate(agentToCode);
    agentToCode.put("002", "Fairbanks"); // throws Exception
    agentToCode.remove("007"); // throws Exception
    agentToCode.removeValue("Bond"); // throws Exception
}

From source file:br.ufal.cideei.soot.instrument.bitrep.SetBitConfigRep.java

public SetBitConfigRep(Collection<IConfigRep> configs, BidiMap atoms, int highestId) {
    this.atoms = (UnmodifiableBidiMap) UnmodifiableBidiMap.decorate(atoms);
    this.configs = Collections.unmodifiableSet(new HashSet<IConfigRep>(configs));
    this.highestId = highestId;
}

From source file:br.ufal.cideei.soot.instrument.bitrep.BitConfigRep.java

public BitConfigRep(int index, BidiMap atoms) {
    this.atoms = (UnmodifiableBidiMap) UnmodifiableBidiMap.decorate(atoms);
    id = index;// ww  w  .j  a  v  a2s .  c  om
    this.hashCode = new HashCodeBuilder(17, 31).append(id).toHashCode();
}

From source file:br.ufpe.cin.emergo.instrument.bitrep.BitConfigRep.java

public BitConfigRep(int identifier, BidiMap atoms) {
    this.atoms = (UnmodifiableBidiMap) UnmodifiableBidiMap.decorate(atoms);
    id = identifier;/*ww  w.j a va  2s. c  o  m*/
    this.hashCode = new HashCodeBuilder(17, 31).append(id).toHashCode();
}

From source file:br.ufal.cideei.soot.instrument.FeatureModelInstrumentorTransformer.java

@Override
protected void internalTransform(Body body, String phase, Map options) {
    preTransform(body);//from   w w w. j  av a 2  s .com

    // #ifdef METRICS
    long startTransform = System.nanoTime();
    // #endif

    /*
     * Iterate over all units, look up for their colors and add a new FeatureTag to each of them, and also compute
     * all the colors found in the whole body. Units with no colors receive an empty FeatureTag.
     */
    Iterator<Unit> unitIt = body.getUnits().iterator();

    /*
     * After the following loop, allPresentFeatures will hold all the colors found in the body. Used to calculate a
     * "local" power set.
     */
    Set<String> allPresentFeatures = new HashSet<String>();

    /*
     * The set of features are represented as bits, for a more compact representation. The mapping between a feature
     * and it's ID is stored in the FeatureTag of the body.
     * 
     * This is necessary so that clients, such as r.d. analysis, can safely iterate over all configurations without
     * explicitly invoking Set operations like containsAll();
     * 
     * TODO: check redundancy between allPresentFeatures & allPresentFeaturesId
     */

    // String->Integer
    BidiMap allPresentFeaturesId = new DualHashBidiMap();
    FeatureTag emptyFeatureTag;
    // #ifdef LAZY
    BitVectorFeatureRep emptyBitVectorRep = new BitVectorFeatureRep(Collections.EMPTY_SET,
            allPresentFeaturesId);
    emptyFeatureTag = new FeatureTag(emptyBitVectorRep);

    // #else
    //@      emptyFeatureTag = new FeatureTag(new BitFeatureRep(Collections.EMPTY_SET, allPresentFeaturesId));
    //@
    // #endif

    // #ifdef LAZY
    /*
     * in the lazy approach, the representation can only be consolidate after all features have been discovery. All
     * IFeatureRep will stored so that it is possible to consolidate later.
     */
    List<BitVectorFeatureRep> generateVectorLater = new ArrayList<BitVectorFeatureRep>();
    // #endif

    int idGen = 1;
    while (unitIt.hasNext()) {
        Unit nextUnit = unitIt.next();
        SourceLnPosTag lineTag = (SourceLnPosTag) nextUnit.getTag("SourceLnPosTag");
        if (lineTag == null) {
            nextUnit.addTag(emptyFeatureTag);
        } else {
            int unitLine = lineTag.startLn();
            Set<String> nextUnitColors = currentColorMap.get(unitLine);
            if (nextUnitColors != null) {

                for (String color : nextUnitColors) {
                    if (!allPresentFeaturesId.containsKey(color)) {
                        allPresentFeaturesId.put(color, idGen);
                        idGen = idGen << 1;
                    }
                }
                /*
                 * increment local powerset with new found colors.
                 */
                allPresentFeatures.addAll(nextUnitColors);

                IFeatureRep featRep;
                FeatureTag featureTag;
                // #ifdef LAZY
                featRep = new BitVectorFeatureRep(nextUnitColors, allPresentFeaturesId);
                generateVectorLater.add((BitVectorFeatureRep) featRep);
                featureTag = new FeatureTag(featRep);
                nextUnit.addTag(featureTag);
                // #else
                //@               
                //@                featRep = new BitFeatureRep(nextUnitColors, allPresentFeaturesId);
                //@               
                // #endif
                featureTag = new FeatureTag(featRep);
                nextUnit.addTag(featureTag);
            } else {
                nextUnit.addTag(emptyFeatureTag);
            }
        }
    }
    UnmodifiableBidiMap unmodAllPresentFeaturesId = (UnmodifiableBidiMap) UnmodifiableBidiMap
            .decorate(allPresentFeaturesId);

    // #ifdef LAZY
    /*
     * generate vectors
     */

    for (BitVectorFeatureRep featureRep : generateVectorLater) {
        featureRep.generateBitVector(idGen);
    }
    // #endif

    // #ifdef METRICS
    long transformationDelta = System.nanoTime() - startTransform;
    if (sink != null) {
        sink.flow(body, FeatureModelInstrumentorTransformer.INSTRUMENTATION, transformationDelta);
    }
    FeatureModelInstrumentorTransformer.transformationTime += transformationDelta;
    // #endif

    ConfigTag configTag;

    // #ifdef LAZY

    BitVectorConfigRep localConfigurations = BitVectorConfigRep.localConfigurations(idGen,
            unmodAllPresentFeaturesId
    // #ifdef FEATUREMODEL
    //@            , checker
    // #endif
    );
    emptyBitVectorRep.generateBitVector(idGen);

    Set<IConfigRep> lazyConfig = new HashSet<IConfigRep>();
    lazyConfig.add(localConfigurations);
    configTag = new ConfigTag(lazyConfig);
    body.addTag(configTag);

    // #else
    //@      
    //@      configTag = new ConfigTag(BitConfigRep.localConfigurations(idGen, unmodAllPresentFeaturesId
    // #ifdef FEATUREMODEL
    //@      , checker
    // #endif
    //@      ).getConfigs());
    //@      body.addTag(configTag);
    //@      
    // #endif
}