i want to write my code below, with new stuff. I want to use Java8 stream and functional programming.
private static void algoritmoSolC(List<Storage> freeSpaces, Double dimPacket, Double nPackets,
            int storageIndex) {
        if (nPackets == 0)
            return;
        List<Storage> list = new ArrayList(freeSpaces) {
            public Object get(int index) {
                if (index < 0) {
                    index = Math.abs(index);
                } else if (index >= size()) {
                    index = index % size();
                }
                return super.get(index);
            }
        };
        for (int i = 0; i < nPackets; i++) {
            Storage storage = list.get(storageIndex);
            if (storage.getFreeSpace() > dimPacket) {
                storage.setFreeSpace(storage.getFreeSpace() - dimPacket);
                ++storageIndex;
            } else {
                ++storageIndex;
                ++nPackets;
            }
        }
    }
I think if I convert code in functional programming, I spent less time for result. Can anyone help me to convert this snippet of code? Thanks in advance
                        
Didnt really tested it but it could go about this:
Looking at this it is really surprisingly more elegant thant your code :-)