Example usage for org.apache.commons.collections Transformer Transformer

List of usage examples for org.apache.commons.collections Transformer Transformer

Introduction

In this page you can find the example usage for org.apache.commons.collections Transformer Transformer.

Prototype

Transformer

Source Link

Usage

From source file:com.utdallas.s3lab.smvhunter.monkey.MonkeyMe.java

/**
 * @param args//  ww w  .j a  va  2 s.c o  m
 */
public static void main(String[] args) throws Exception {

    logger.info("start time ==== " + System.currentTimeMillis());

    try {
        //load the adb location from the props file
        Properties props = new Properties();
        props.load(new FileInputStream(new File("adb.props")));

        //set the adb location
        WindowUpdate.adbLocation = props.getProperty("adb_location");
        adbLocation = props.getProperty("adb_location");
        //set root dir
        ROOT_DIRECTORY = props.getProperty("root_dir");
        //completed txt
        completedFile = new File(ROOT_DIRECTORY + "tested.txt");
        //db location for static analysis
        dbLocation = props.getProperty("db_location");
        //location for smart input generation output
        smartInputLocation = props.getProperty("smart_input_location");

        //udp dump location
        udpDumpLocation = props.getProperty("udp_dump_location");
        //logcat dump location
        logCatLocation = props.getProperty("log_cat_location");
        //strace output location
        straceOutputLocation = props.getProperty("strace_output_location");
        //strace dump location
        straceDumpLocation = props.getProperty("strace_output_location");

        //set x and y coords
        UIEnumerator.screenX = props.getProperty("x");
        UIEnumerator.screenY = props.getProperty("y");

        DeviceOfflineMonitor.START_EMULATOR = props.getProperty("restart");

        //read output of static analysis
        readFromStaticAnalysisText();
        logger.info("Read static analysis output");

        readFromSmartInputText();
        logger.info("Read smart input generation output");

        //populate the queue with apps which are only present in the static analysis
        @SuppressWarnings("unchecked")
        final Set<? extends String> sslApps = new HashSet<String>(
                CollectionUtils.collect(FileUtils.readLines(new File(dbLocation)), new Transformer() {
                    @Override
                    public Object transform(Object input) {
                        //get app file name
                        String temp = StringUtils.substringBefore(input.toString(), " ");
                        return StringUtils.substringAfterLast(temp, "/");
                    }
                }));
        Collection<File> fileList = FileUtils.listFiles(new File(ROOT_DIRECTORY), new String[] { "apk" },
                false);
        CollectionUtils.filter(fileList, new Predicate() {
            @Override
            public boolean evaluate(Object object) {
                return sslApps.contains(StringUtils.substringAfterLast(object.toString(), "/"));
            }
        });
        apkQueue = new LinkedBlockingDeque<File>(fileList);

        logger.info("finished listing files from the root directory");

        try {
            //populate the tested apk list
            completedApps.addAll(FileUtils.readLines(completedFile));
        } catch (Exception e) {
            //pass except
            logger.info("No tested.txt file found");

            //create new file
            if (completedFile.createNewFile()) {
                logger.info("tested.txt created in root directory");
            } else {
                logger.info("tested.txt file could not be created");
            }

        }

        //get the executors for managing the emulators
        executors = Executors.newCachedThreadPool();

        //set the devicemonitor exec
        DeviceOfflineMonitor.exec = executors;

        final List<Future<?>> futureList = new ArrayList<Future<?>>();

        //start the offline device monitor (emulator management thread)
        logger.info("Starting Device Offline Monitor Thread");
        executors.submit(new DeviceOfflineMonitor());

        //get ADB backend object for device change listener
        AdbBackend adb = new AdbBackend();

        //register for device change and wait for events
        //once event is received, start the MonkeyMe thread
        MonkeyDeviceChangeListener deviceChangeListener = new MonkeyDeviceChangeListener(executors, futureList);
        AndroidDebugBridge.addDeviceChangeListener(deviceChangeListener);
        logger.info("Listening to changes in devices (emulators)");

        //wait for the latch to come down
        //this means that all the apks have been processed
        cdl.await();

        logger.info("Finished testing all apps waiting for threads to join");

        //now wait for every thread to finish
        for (Future<?> future : futureList) {
            future.get();
        }

        logger.info("All threads terminated");

        //stop listening for device update
        AndroidDebugBridge.removeDeviceChangeListener(deviceChangeListener);

        //stop the debug bridge
        AndroidDebugBridge.terminate();

        //stop offline device monitor
        DeviceOfflineMonitor.stop = true;

        logger.info("adb and listeners terminated");

    } finally {
        logger.info("Executing this finally");
        executors.shutdownNow();
    }

    logger.info("THE END!!");
}

From source file:net.sourceforge.fenixedu.applicationTier.Servico.resourceAllocationManager.ReadShiftsByClass.java

@Atomic
public static Object run(InfoClass infoClass) {
    check(RolePredicates.RESOURCE_ALLOCATION_MANAGER_PREDICATE);
    SchoolClass schoolClass = FenixFramework.getDomainObject(infoClass.getExternalId());

    Collection<Shift> shifts = schoolClass.getAssociatedShiftsSet();

    return CollectionUtils.collect(shifts, new Transformer() {
        @Override/*from  www. j a v  a 2s  . com*/
        public Object transform(Object arg0) {
            Shift shift = (Shift) arg0;
            InfoShift infoShift = InfoShift.newInfoFromDomain(shift);
            return infoShift;
        }
    });
}

From source file:net.sourceforge.fenixedu.applicationTier.Servico.resourceAllocationManager.ReadAvailableShiftsForClass.java

@Atomic
public static Object run(InfoClass infoClass) {
    check(RolePredicates.RESOURCE_ALLOCATION_MANAGER_PREDICATE);

    List infoShifts = null;/*from   w  ww  .j a  va 2  s.c  o  m*/

    SchoolClass schoolClass = FenixFramework.getDomainObject(infoClass.getExternalId());
    Set<Shift> shifts = schoolClass.findAvailableShifts();

    infoShifts = (List) CollectionUtils.collect(shifts, new Transformer() {
        @Override
        public Object transform(Object arg0) {
            Shift shift = (Shift) arg0;
            return InfoShift.newInfoFromDomain(shift);
        }
    });

    return infoShifts;
}

From source file:net.sourceforge.fenixedu.applicationTier.Servico.commons.ReadExecutionYearsByDegreeCurricularPlanID.java

@Atomic
public static List run(String degreeCurricularPlanID) {
    DegreeCurricularPlan degreeCurricularPlan = FenixFramework.getDomainObject(degreeCurricularPlanID);

    List<ExecutionYear> executionYears = (List<ExecutionYear>) CollectionUtils
            .collect(degreeCurricularPlan.getExecutionDegreesSet(), new Transformer() {

                @Override/*w ww. j  a  va2  s .co  m*/
                public Object transform(Object arg0) {
                    ExecutionDegree executionDegree = (ExecutionDegree) arg0;
                    return InfoExecutionYear.newInfoFromDomain(executionDegree.getExecutionYear());
                }

            });

    return executionYears;
}

From source file:edu.harvard.med.screensaver.util.CollectionUtilsTest.java

public void testIndexCollection() {
    Transformer getKey = new Transformer() {
        public Object transform(Object e) {
            return ((Struct) e).key;
        }/*from w  w  w .  j  av a2s  .  c o m*/
    };
    List<Struct> c = new ArrayList<Struct>();
    c.add(new Struct(1, "A"));
    c.add(new Struct(2, "B"));
    c.add(new Struct(3, "C"));

    Map<Integer, Struct> index = CollectionUtils.indexCollection(c, getKey, Integer.class, Struct.class);
    assertEquals(c.get(0), index.get(1));
    assertEquals(c.get(1), index.get(2));
    assertEquals(c.get(2), index.get(3));
}

From source file:com.texeltek.accumulocloudbaseshim.ByteSequenceShim.java

@SuppressWarnings("unchecked")
public static Set<cloudbase.core.data.ByteSequence> cloudbaseSet(Set<ByteSequence> byteSequenceSet) {
    return SetUtils.transformedSet(byteSequenceSet, new Transformer() {
        @Override//from  w w w.j a v a 2s .co  m
        public Object transform(Object o) {
            return ((ByteSequence) o).impl;
        }
    });
}

From source file:net.sourceforge.fenixedu.applicationTier.Servico.publico.inquiries.ReadOldIquiriesSummaryByDegreeID.java

@Atomic
public static Collection run(String degreeID) throws FenixServiceException {
    Degree degree = FenixFramework.getDomainObject(degreeID);

    if (degree == null) {
        throw new FenixServiceException("nullDegreeId");
    }//from w  ww .  j  a  v a  2 s.c om

    Collection<OldInquiriesSummary> oldInquiriesSummaryList = degree.getAssociatedOldInquiriesSummariesSet();

    CollectionUtils.transform(oldInquiriesSummaryList, new Transformer() {

        @Override
        public Object transform(Object oldInquiriesSummary) {
            InfoOldInquiriesSummary iois = new InfoOldInquiriesSummary();
            try {
                iois.copyFromDomain((OldInquiriesSummary) oldInquiriesSummary);

            } catch (Exception ex) {
                logger.error(ex.getMessage(), ex);
            }

            return iois;
        }
    });

    return oldInquiriesSummaryList;
}

From source file:de.hybris.platform.acceleratorservices.urlencoder.attributes.impl.DefaultStoreFrontAttributeManager.java

@Override
public Collection<String> getAllAvailableValues() {
    return CollectionUtils.collect(getCmsSiteService().getCurrentSite().getStores(), new Transformer() {
        @Override//from  w w  w  .j ava2  s .c om
        public Object transform(final Object object) {
            return ((BaseStoreModel) object).getUid();
        }
    });
}

From source file:com.texeltek.accumulocloudbaseshim.KeyValueWrappingIterator.java

public KeyValueWrappingIterator(Iterator<Map.Entry<Key, Value>> iter) {
    super(iter, new Transformer() {
        public Object transform(Object input) {
            Map.Entry<cloudbase.core.data.Key, cloudbase.core.data.Value> entry = (Map.Entry<cloudbase.core.data.Key, cloudbase.core.data.Value>) input;
            return new CloudbaseEntryShim(new Key(entry.getKey()), new Value(entry.getValue()));
        }/*from w  ww.  ja va 2  s  .  c  o  m*/
    });
}

From source file:de.hybris.platform.acceleratorservices.urlencoder.attributes.impl.DefaultCurrencyAttributeManager.java

@Override
public Collection<String> getAllAvailableValues() {
    return CollectionUtils.collect(getCommerceCommonI18NService().getAllCurrencies(), new Transformer() {
        @Override//w w w  . java  2 s .com
        public Object transform(final Object object) {
            return ((CurrencyModel) object).getIsocode();
        }
    });
}