Package eas.users.lukas.primeProperties

Source Code of eas.users.lukas.primeProperties.PrimePropertiesReverse

/*
* File name:        PrimePropertiesReverse.java (package eas.miscellaneous.primeProperties)
* Author(s):        lko
* Java version:     7.0
* Generation date:  02.11.2012 (16:23:25)
*
* (c) This file and the EAS (Easy Agent Simulation) framework containing it
* is protected by Creative Commons by-nc-sa license. Any altered or
* further developed versions of this file have to meet the agreements
* stated by the license conditions.
*
* In a nutshell
* -------------
* You are free:
* - to Share -- to copy, distribute and transmit the work
* - to Remix -- to adapt the work
*
* Under the following conditions:
* - Attribution -- You must attribute the work in the manner specified by the
*   author or licensor (but not in any way that suggests that they endorse
*   you or your use of the work).
* - Noncommercial -- You may not use this work for commercial purposes.
* - Share Alike -- If you alter, transform, or build upon this work, you may
*   distribute the resulting work only under the same or a similar license to
*   this one.
*
* + Detailed license conditions (Germany):
*   http://creativecommons.org/licenses/by-nc-sa/3.0/de/
* + Detailed license conditions (unported):
*   http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en
*
* This header must be placed in the beginning of any version of this file.
*/

package eas.users.lukas.primeProperties;

import java.math.BigInteger;
import java.util.LinkedList;
import java.util.List;

import eas.miscellaneous.StaticMethods;
import eas.plugins.masterScheduler.AbstractDefaultMaster;
import eas.simulation.ConstantsSimulation;
import eas.simulation.Wink;
import eas.simulation.standardEnvironments.DummyEnvironment;
import eas.startSetup.ParCollection;
import eas.startSetup.SingleParameter;
import eas.startSetup.parameterDatatypes.Datatypes;

/**
* @author lko
*/
public class PrimePropertiesReverse extends AbstractDefaultMaster<DummyEnvironment> {

    /**
     *
     */
    private static final long serialVersionUID = -8265690203467712154L;

    @Override
    public List<SingleParameter> getParameters() {
        List<SingleParameter> list = super.getParameters();
        list.add(new SingleParameter("base", Datatypes.integerRange(2, 36), 10, "Basis", this.id().toUpperCase()));
        return list;
    }
   
    private LinkedList<String> findLukePrimesOneLonger(LinkedList<String> nums, int base) {
        LinkedList<String> newSet = new LinkedList<String>();
       
        for (String num : nums) {
            for (int i = 1; i < base; i++) {
                String newNum = num + new BigInteger("" + i).toString(base);
                if (new BigInteger(newNum, base).isProbablePrime(10)) {
                    newSet.add(newNum);
                }
            }
        }
       
        return newSet;
    }
   
    private LinkedList<String> set = new LinkedList<String>();
    private LinkedList<String> speicherArray = new LinkedList<String>();
   
    @Override
    public synchronized void runDuringSimulation(DummyEnvironment env,
            Wink simZyk, ParCollection params) {
        super.runDuringSimulation(env, simZyk, params);
//        String elemente = "";
        set = this.findLukePrimesOneLonger(set, params.getParValueInt("base"));
//        if (set.size() < 100) {
//            elemente = set.toString();
//        }
        String els = set.size() + ""; // + ": " + elemente;
        params.logInfo(set.size() + "");
        speicherArray.add(els);
        StaticMethods.speichereTextAusArray(".", "lukesPrimesReverse" + params.getParValueInt("base") + ".txt", speicherArray, params);
    }

    @Override
    public void runBeforeSimulation(DummyEnvironment umg,
            ParCollection params) {
        super.runBeforeSimulation(umg, params);
        set.add("");
    }
   
    @Override
    public DummyEnvironment[] generateRunnables(ParCollection params) {
        return new DummyEnvironment[] {new DummyEnvironment(0, params)};
    }

    @Override
    public String id() {
        return ConstantsSimulation.DEFAULT_MASTER_SCHEDULER_ID + "-lukesPrimesReverse";
    }
   
    @Override
    public boolean isTerminationRequested(DummyEnvironment runnable,
            Wink currentTime, ParCollection params) {
        return set.isEmpty();
    }
}
TOP

Related Classes of eas.users.lukas.primeProperties.PrimePropertiesReverse

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.