LeetCode #346 - Moving Average from Data Stream (Java)

import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

class MovingAverage {
    Queue<Integer> queue;
    int maxSize = 0;
    int size = 0;
    int currentTotal = 0;

    /** Initialize your data structure here. */
    public MovingAverage(int size) {
        maxSize = size;
        queue = new LinkedList<Integer>();
    }

    public double next(int val) {
        if (size >= maxSize) {
            int toRemove = queue.poll();
            currentTotal -= toRemove;
        } else size++;

        queue.add(val);
        currentTotal += val;

        return currentTotal * 1.0 / size;
    }
}