Commit 25387a88 authored by Richard Pánek's avatar Richard Pánek
Browse files

Repair Checkstyle errors

parent cc5be8d7
Loading
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -6,6 +6,12 @@ import cz.muni.fi.pb162.hw02.CacheType;

import java.io.IOException;

/**
 * @author Richard Panek
 *
 * @param <K> Key type
 * @param <V> Value type
 */
public class DefaultCacheFactory<K, V> implements CacheFactory<K, V> {
    /**
     * Creates an instance of a cache
@@ -29,8 +35,7 @@ public class DefaultCacheFactory<K, V> implements CacheFactory<K, V> {
                default:
                    return null;
            }
        }
        catch (IOException e) {
        } catch (IOException e) {
            System.out.println(e.toString());
            return null;
        }
+16 −10
Original line number Diff line number Diff line
@@ -5,16 +5,22 @@ import cz.muni.fi.pb162.hw02.CacheType;
import java.io.IOException;
import java.util.ArrayList;

/**
 * @author Richard Panek
 *
 * @param <K> Key type
 * @param <V> Value type
 */
public class FIFOCache <K, V> extends RegularCache<K, V>{
    /**
     * List for FIFO
     */
    private final ArrayList<Integer> FIFO;
    private final ArrayList<Integer> fifo;

    /**
     * Type of cache
     */
    private static final CacheType type = CacheType.FIFO;
    private static final CacheType TYPE = CacheType.FIFO;

    /**
     * FIFO cache constructor
@@ -24,7 +30,7 @@ public class FIFOCache <K, V> extends RegularCache<K, V>{
     */
    public FIFOCache(int maxSize) throws IOException {
        super(maxSize);
        this.FIFO = new ArrayList<>(maxSize);
        this.fifo = new ArrayList<>(maxSize);
    }

    /**
@@ -53,18 +59,18 @@ public class FIFOCache <K, V> extends RegularCache<K, V>{
        int index = this.getIndex(key);
        if (index != -1){
            this.refreshIndex(key, value, index);
            this.FIFO.remove((Integer) index);
            this.FIFO.add(index);
            this.fifo.remove((Integer) index);
            this.fifo.add(index);
            return;
        }
        if (this.capacity() > this.size()){
            this.add(key, value);
            this.FIFO.add(this.getIndex(key));
            this.fifo.add(this.getIndex(key));
            return;
        }
        this.refreshIndex(key, value, this.FIFO.get(0));
        this.FIFO.remove(0);
        this.FIFO.add(this.getIndex(key));
        this.refreshIndex(key, value, this.fifo.get(0));
        this.fifo.remove(0);
        this.fifo.add(this.getIndex(key));
    }

    /**
@@ -74,6 +80,6 @@ public class FIFOCache <K, V> extends RegularCache<K, V>{
     */
    @Override
    public CacheType getEvictionType() {
        return type;
        return TYPE;
    }
}
+10 −3
Original line number Diff line number Diff line
@@ -5,6 +5,12 @@ import cz.muni.fi.pb162.hw02.CacheType;
import java.io.IOException;
import java.util.ArrayList;

/**
 * @author Richard Panek
 *
 * @param <K> Key type
 * @param <V> Value type
 */
public class LRUCache <K, V> extends RegularCache<K, V> {

    /**
@@ -15,7 +21,7 @@ public class LRUCache <K, V> extends RegularCache<K, V> {
    /**
     * Type of cache
     */
    private static final CacheType type = CacheType.LRU;
    private static final CacheType TYPE = CacheType.LRU;

    /**
     * Constructor
@@ -76,7 +82,7 @@ public class LRUCache <K, V> extends RegularCache<K, V> {
     */
    @Override
    public CacheType getEvictionType() {
        return type;
        return TYPE;
    }

    /**
@@ -87,10 +93,11 @@ public class LRUCache <K, V> extends RegularCache<K, V> {
    private int min() {
        int result = 0;
        for (int i = 1; i < this.capacity(); i++) {
            if (this.usage.get(result) >= 1 && this.usage.get(i) >= 1)
            if (this.usage.get(result) >= 1 && this.usage.get(i) >= 1) {
                if (this.usage.get(result) > this.usage.get(i)) {
                    result = i;
                }
            }
        }
        return result;
    }
+12 −5
Original line number Diff line number Diff line
@@ -5,6 +5,12 @@ import cz.muni.fi.pb162.hw02.CacheType;
import java.io.IOException;
import java.util.ArrayList;

/**
 * @author Richard Panek
 *
 * @param <K> Key type
 * @param <V> Value type
 */
public class MRUCache <K, V> extends RegularCache<K, V>{

    /**
@@ -15,7 +21,7 @@ public class MRUCache <K, V> extends RegularCache<K, V>{
    /**
     * Type of cache
     */
    private static final CacheType type = CacheType.MRU;
    private static final CacheType TYPE = CacheType.MRU;

    /**
     * Constructor
@@ -64,7 +70,7 @@ public class MRUCache <K, V> extends RegularCache<K, V>{
            this.usage.add(index, 1);
            return;
        }
        this.refreshIndex(key, value, this.min());
        this.refreshIndex(key, value, this.max());
        index = this.getIndex(key);
        this.usage.set(index, 1);
    }
@@ -76,7 +82,7 @@ public class MRUCache <K, V> extends RegularCache<K, V>{
     */
    @Override
    public CacheType getEvictionType() {
        return type;
        return TYPE;
    }

    /**
@@ -84,13 +90,14 @@ public class MRUCache <K, V> extends RegularCache<K, V>{
     *
     * @return index of MRU
     */
    private int min() {
    private int max() {
        int result = 0;
        for (int i = 1; i < this.capacity(); i++) {
            if (this.usage.get(result) >= 1 && this.usage.get(i) >= 1)
            if (this.usage.get(result) >= 1 && this.usage.get(i) >= 1) {
                if (this.usage.get(result) <= this.usage.get(i)) {
                    result = i;
                }
            }
        }
        return result;
    }
+8 −2
Original line number Diff line number Diff line
@@ -5,11 +5,17 @@ import cz.muni.fi.pb162.hw02.CacheType;
import java.io.IOException;
import java.util.Random;

/**
 * @author Richard Panek
 *
 * @param <K> Key type
 * @param <V> Value type
 */
public class RandomCache <K, V> extends RegularCache<K, V> {
    /**
     * Type of cache
     */
    private static final CacheType type = CacheType.RANDOM;
    private static final CacheType TYPE = CacheType.RANDOM;

    /**
     * Constructor
@@ -63,7 +69,7 @@ public class RandomCache <K, V> extends RegularCache<K, V> {
     */
    @Override
    public CacheType getEvictionType() {
        return type;
        return TYPE;
    }

}
Loading