Package thread.caches

Examples of thread.caches.KeyObject


        fill();
        UserOfCache.createInstance(new AdaptiveReplacementUsed<KeyObject, ValueObject>(), storage);
        int a = 0, b = 0, c = 0, d = 0;
        for (int i = 0; i < 100; i++) {
            if (i % 3 == 0) {
                UserOfCache.get(new KeyObject(3 + ""));
                a++;
            }else if (i % 5 == 0) {
                UserOfCache.get(new KeyObject(5 + ""));
                b++;
            }else if (i % 8 == 0) {
                UserOfCache.get(new KeyObject(8 + ""));
                c++;
            } else {
                UserOfCache.get(new KeyObject(i + ""));
                d++;
            }
        }

        System.out.println("a " + a);
        System.out.println("b = " + b);
        System.out.println("c = " + c);
        System.out.println("d = " + d);

        List<KeyObject> keys = UserOfCache.getAllCache();
        KeyObject[] f = {new KeyObject("3"), new KeyObject("5"), new KeyObject("8")};
        assertEquals(10, keys.size());
        assertEquals( 3 + "", keys.get(9).getKey());
        assertEquals( 5 + "", keys.get(8).getKey());
        assertEquals( 8 + "", keys.get(7).getKey());
        System.out.println(keys);
        assertTrue(keys.containsAll(Arrays.asList(f)));
        Queue<CountKey<KeyObject>> queue = new PriorityQueue<CountKey<KeyObject>>(10);
        for (KeyObject k : keys) {
            CountKey<KeyObject> countKey = new CountKey<KeyObject>(k);
            if (k.getKey().equals("5")) countKey.incrementCount();
            queue.offer(countKey);
        }
        System.out.println("------------------------------------");
        System.out.println(queue);
        CountKey countKey5 = new CountKey<KeyObject>(new KeyObject("5"));
        countKey5.incrementCount();
        CountKey countKey87 = new CountKey<KeyObject>(new KeyObject("86"));
        assertEquals(1, countKey5.compareTo(countKey87));
    }
View Full Code Here


        fill();
        UserOfCache.createInstance(new AdaptiveReplacementUsed<KeyObject, ValueObject>(), storage);
        int a = 0, b = 0, c = 0, d = 0;
        for (int i = 0; i < 100; i++) {
            if (i % 3 == 0) {
                UserOfCache.get(new KeyObject(3 + ""));
                a++;
            }else if (i % 5 == 0) {
                UserOfCache.get(new KeyObject(5 + ""));
                b++;
            }else if (i % 8 == 0) {
                UserOfCache.get(new KeyObject(8 + ""));
                c++;
            } else {
                UserOfCache.get(new KeyObject(i + ""));
                d++;
            }
        }
        Random random = new Random();
        random.nextInt(100);
        for (int i = 0; i < 500; i++){
            int k = random.nextInt(99);
            //System.out.println("i= " + i + "; k = " + k);
             UserOfCache.get(new KeyObject(k + ""));

        }
        System.out.println("a " + a);
        System.out.println("b = " + b);
        System.out.println("c = " + c);
        System.out.println("d = " + d);

        List<KeyObject> keys = UserOfCache.getAllCache();
        KeyObject[] f = {new KeyObject("3"), new KeyObject("5"), new KeyObject("8")};
        assertEquals(10, keys.size());
        assertEquals( 3 + "", keys.get(9).getKey());
        assertEquals( 5 + "", keys.get(8).getKey());
        assertEquals( 8 + "", keys.get(7).getKey());
        System.out.println(keys);
        assertTrue(keys.containsAll(Arrays.asList(f)));
        Queue<CountKey<KeyObject>> queue = new PriorityQueue<CountKey<KeyObject>>(10);
        for (KeyObject k : keys) {
            CountKey<KeyObject> countKey = new CountKey<KeyObject>(k);
            if (k.getKey().equals("5")) countKey.incrementCount();
            queue.offer(countKey);
        }
        System.out.println("------------------------------------");
        System.out.println(queue);
        CountKey countKey5 = new CountKey<KeyObject>(new KeyObject("5"));
        countKey5.incrementCount();
        CountKey countKey87 = new CountKey<KeyObject>(new KeyObject("86"));
        assertEquals(1, countKey5.compareTo(countKey87));
    }
View Full Code Here

        List<KeyObject> consumer = new ArrayList<KeyObject>();
        storage = new ArrayList<ValueObject>();
        Random random = new Random();
        random.nextInt(100);
        for (int i = 0; i < 100; i++) {
            KeyObject keyObject = new KeyObject(i + "");

            ValueObject valueObject = new ValueObject(keyObject, i + " data ");
            storage.add(valueObject);
        }
View Full Code Here

    @Test
    public void simpleTest() {
        int usingOf3 = 0, usingOf5 = 0, usingOf8 = 0, usingOfOthers = 0;
        for (int i = 0; i < 100; i++) {
            if (i % 3 == 0) {
                UserOfCache.get(new KeyObject(3 + ""));
                usingOf3++;
            } else if (i % 5 == 0) {
                UserOfCache.get(new KeyObject(5 + ""));
                usingOf5++;
            } else if (i % 8 == 0) {
                UserOfCache.get(new KeyObject(8 + ""));
                usingOf8++;
            } else {
                UserOfCache.get(new KeyObject(i + ""));
                usingOfOthers++;
            }
        }

        System.out.println("usingOf3 " + usingOf3);
        System.out.println("usingOf5 = " + usingOf5);
        System.out.println("usingOf8 = " + usingOf8);
        System.out.println("others = " + usingOfOthers);

        List<KeyObject> keys = UserOfCache.getAllCache();
        KeyObject[] f = {new KeyObject("3"), new KeyObject("5"), new KeyObject("8")};
        assertEquals(10, keys.size());
        System.out.println(keys);
        assertTrue(keys.containsAll(Arrays.asList(f)));
    }
View Full Code Here

    protected  List<ValueObject> fillStorage() {
        List<ValueObject> storage = new ArrayList< >();
        Random random = new Random();
        random.nextInt(100);
        for (int i = 0; i < 100; i++) {
            KeyObject keyObject = new KeyObject(i + "");

            ValueObject valueObject = new ValueObject(keyObject, i + " data ");
            storage.add(valueObject);
        }
        return storage;
View Full Code Here

        UserOfCache.createInstance(new LeastRecentlyUsed2<KeyObject, ValueObject>(), storage);
        int a = 0, b = 0, c = 0, d = 0;
        for (int j = 0; j < 3; j++)
            for (int i = 0; i < 100; i++) {
                if (i % 3 == 0) {
                    UserOfCache.get(new KeyObject(3 + ""));
                    a++;
                } else if (i % 5 == 0) {
                    UserOfCache.get(new KeyObject(5 + ""));
                    b++;
                } else if (i % 8 == 0) {
                    UserOfCache.get(new KeyObject(8 + ""));
                    c++;
                } else {
                    UserOfCache.get(new KeyObject(i + ""));
                    d++;
                }
            }

        System.out.println("a " + a);
        System.out.println("b = " + b);
        System.out.println("c = " + c);
        System.out.println("d = " + d);

        List<KeyObject> keys = UserOfCache.getAllCache();
        KeyObject[] f = {new KeyObject("3"), new KeyObject("5"), new KeyObject("8")};
        assertEquals(3, keys.size());
//        assertEquals( 3 + "", keys.get(9).getKey());
//        assertEquals( 5 + "", keys.get(8).getKey());
//        assertEquals( 8 + "", keys.get(7).getKey());
        System.out.println(keys);
View Full Code Here

        fill();
        UserOfCache.createInstance(new LeastRecentlyUsed2<KeyObject, ValueObject>(), storage);
        int a = 0, b = 0, c = 0, d = 0;
        for (int i = 0; i < 100; i++) {
            if (i % 3 == 0) {
                UserOfCache.get(new KeyObject(3 + ""));
                a++;
            } else if (i % 5 == 0) {
                UserOfCache.get(new KeyObject(5 + ""));
                b++;
            } else if (i % 8 == 0) {
                UserOfCache.get(new KeyObject(8 + ""));
                c++;
            } else {
                UserOfCache.get(new KeyObject(i + ""));
                d++;
            }

        }
        for (int j = 0; j < 2; j++)
        for (int i = 0; i < 20; i++) {
            if (i % 3 == 0) {
                UserOfCache.get(new KeyObject(3 + ""));
                a++;
            } else if (i % 5 == 0) {
                UserOfCache.get(new KeyObject(5 + ""));
                b++;
            } else if (i % 8 == 0) {
                UserOfCache.get(new KeyObject(8 + ""));
                c++;
            } else {
                UserOfCache.get(new KeyObject(i + ""));
                d++;
            }
        }

        System.out.println("a " + a);
        System.out.println("b = " + b);
        System.out.println("c = " + c);
        System.out.println("d = " + d);

        List<KeyObject> keys = UserOfCache.getAllCache();
        KeyObject[] f = {new KeyObject("3"), new KeyObject("5"), new KeyObject("8")};
        assertEquals(10, keys.size());
//        assertEquals( 3 + "", keys.get(9).getKey());
//        assertEquals( 5 + "", keys.get(8).getKey());
//        assertEquals( 8 + "", keys.get(7).getKey());
        System.out.println(keys);
View Full Code Here

        List<KeyObject> consumer = new ArrayList<KeyObject>();
        storage = new ArrayList<ValueObject>();
        Random random = new Random();
        random.nextInt(100);
        for (int i = 0; i < 100; i++) {
            KeyObject keyObject = new KeyObject(i + "");

            ValueObject valueObject = new ValueObject(keyObject, i + " data ");
            storage.add(valueObject);
        }
View Full Code Here

        fill();
        UserOfCache.createInstance(new LeastFrequentlyUsed<KeyObject, ValueObject>(), storage);
        int a = 0, b = 0, c = 0, d = 0;
        for (int i = 0; i < 100; i++) {
            if (i % 3 == 0) {
                UserOfCache.get(new KeyObject(3 + ""));
                a++;
            }else if (i % 5 == 0) {
                UserOfCache.get(new KeyObject(5 + ""));
                b++;
            }else if (i % 8 == 0) {
                UserOfCache.get(new KeyObject(8 + ""));
                c++;
            } else {
                UserOfCache.get(new KeyObject(i + ""));
                d++;
            }
        }

        System.out.println("a " + a);
        System.out.println("b = " + b);
        System.out.println("c = " + c);
        System.out.println("d = " + d);

        List<KeyObject> keys = UserOfCache.getAllCache();
        KeyObject[] f = {new KeyObject("3"), new KeyObject("5"), new KeyObject("8")};
        assertEquals(10, keys.size());
        assertEquals( 3 + "", keys.get(9).getKey());
        assertEquals( 5 + "", keys.get(8).getKey());
        assertEquals( 8 + "", keys.get(7).getKey());
        System.out.println(keys);
        assertTrue(keys.containsAll(Arrays.asList(f)));
        Queue<CountKey<KeyObject>> queue = new PriorityQueue<CountKey<KeyObject>>(10);
        for (KeyObject k : keys) {
            CountKey<KeyObject> countKey = new CountKey<KeyObject>(k);
            if (k.getKey().equals("5")) countKey.incrementCount();
            queue.offer(countKey);
        }
        System.out.println("------------------------------------");
        System.out.println(queue);
        CountKey countKey5 = new CountKey<KeyObject>(new KeyObject("5"));
        countKey5.incrementCount();
        CountKey countKey87 = new CountKey<KeyObject>(new KeyObject("86"));
        assertEquals(1, countKey5.compareTo(countKey87));
    }
View Full Code Here

        List<KeyObject> consumer = new ArrayList<KeyObject>();
        storage = new ArrayList<ValueObject>();
        Random random = new Random();
        random.nextInt(100);
        for (int i = 0; i < 100; i++) {
            KeyObject keyObject = new KeyObject(i + "");

            ValueObject valueObject = new ValueObject(keyObject, i + " data ");
            storage.add(valueObject);
        }
View Full Code Here

TOP

Related Classes of thread.caches.KeyObject

Copyright © 2018 www.massapicom. 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.