Back to The tech awesomeness
Table of contents
Endeavor chapters

The article for today.

In Turkish language (Türk dili; Türkçe), there are the words Birim (İngilizce; unit) and Döviz.

And in https://tr.wikipedia.org/wiki/Döviz article as of 2020-04-01 the words containing "Birim" are occuring 24 times.

In https://en.wikipedia.org/wiki/Currency article as of 2020-04-01 the words containing "Unit" are occurring 28 times.


public class UnitSampleTest796187365734 {
    class Unit {
        public String id = "";
        List < String > givingOperations = new ArrayList < >();
        List < String > takingOperations = new ArrayList < >();
    }
    class Agent {
        private List < Unit > agentUnits = new ArrayList < >();
        
        public void takeUnits(String nameForWhat, List < Unit > unitsToTake) {
            for (Unit unitToTake: unitsToTake) {
                unitToTake.takingOperations.add(nameForWhat + 
                        " " + new Date().toString());
                agentUnits.add(unitToTake);
            }
        }
        
        public List < Unit > giveUnits(String nameForWhat, Integer amount) {
            
            if (amount > agentUnits.size()) {
                throw new RuntimeException("not enough units");
            }
            
            List < Unit > unitsToGive = new ArrayList < >();
            
            for (int i = 0; i < amount; i++) {
                Unit unit = agentUnits.remove(0);//for example taking out the first from the array
                unit.givingOperations.add(nameForWhat +
                        " " + new Date().toString());
                unitsToGive.add(unit);
            }
            
            return unitsToGive;
        }
    }
    class Market {
        void exchangeUnits(String nameForWhat, Agent givingAgent,
                Agent receivingAgent, int amount) {
            List < Unit > unitsToGive =
            givingAgent.giveUnits(nameForWhat, amount);
            try {
                Thread.sleep(500);
            } catch (InterruptedException ex) {
                System.out.println("while sleeping there was: " + ex.getMessage());
            }
            receivingAgent.takeUnits(nameForWhat, unitsToGive);
            try {
                Thread.sleep(500);
            } catch (InterruptedException ex) {
                System.out.println("while sleeping there was: " + ex.getMessage());
            }
        }
    }
    
    public static void main(String[] args) {
        UnitSampleTest796187365734 unitSampleTest796187365734 =
                new UnitSampleTest796187365734();
        Agent firstMarketAgent = unitSampleTest796187365734.new Agent();
        Agent secondMarketAgent = unitSampleTest796187365734.new Agent();
        
        Market market = unitSampleTest796187365734.new Market();
        
        List < Unit > unitsToTake = new ArrayList < >();
        for (int i = 0; i < 10; i++) {
            Unit unit = unitSampleTest796187365734.new Unit();
            unit.id = UUID.randomUUID().toString();
            unitsToTake.add(unit);
        }
        List < Unit > otherUnitsToTake = new ArrayList < >();
        for (int i = 0; i < 10; i++) {
            Unit unit = unitSampleTest796187365734.new Unit();
            unit.id = UUID.randomUUID().toString();
            unitsToTake.add(unit);
        }
        firstMarketAgent.takeUnits("initial", unitsToTake);
        
        secondMarketAgent.takeUnits("initial", otherUnitsToTake);
        
        for (int test = 1; test <= 10; test++) {
            try {
                int unitAmount = new Random().nextInt((10 - 1) + 1) + 1;
                market.exchangeUnits("test " + test, firstMarketAgent, secondMarketAgent, unitAmount);
                System.out.println(test + " test result: " 
                        + "firstMarketAgent.agentUnits.size " + firstMarketAgent.agentUnits.size()
                        + "secondMarketAgent.agentUnits.size " + secondMarketAgent.agentUnits.size()
                );
            } catch (Exception e) {
                System.out.println(test + " test result: " + e.getMessage());
            }
        }
        
        System.out.println("firstMarketAgent unit history");
        for (Unit agentUnit : firstMarketAgent.agentUnits) {
            System.out.println("giving operations");
            outputAgentUnitOperations(agentUnit, agentUnit.givingOperations);
            System.out.println("taking operations");
            outputAgentUnitOperations(agentUnit, agentUnit.takingOperations);
        }
        
        System.out.println("secondMarketAgent unit history");
        for (Unit agentUnit : secondMarketAgent.agentUnits) {
            System.out.println("giving operations");
            outputAgentUnitOperations(agentUnit, agentUnit.givingOperations);
            System.out.println("taking operations");
            outputAgentUnitOperations(agentUnit, agentUnit.takingOperations);
        }
    }
    
    /**
     *
     * @param agentUnit
     * @param operations
     */
    public static void outputAgentUnitOperations (Unit agentUnit, List < String > operations) {
        operations.forEach((agentUnitOperation) -> {
            System.out.println("unit id: " + agentUnit.id +
                    "unit operation: " + agentUnitOperation);
        });
    }
}
The sample palette for the greener grass and rose coloured glasses.  
 
 
 
 
 
 
 
 
 
 
 

Оновлення від 2021-05-12.

Update from 2021-05-12.

Розвиток зразка одиниці