All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aol.cyclops.lambda.tuple.memo.Memo1 Maven / Gradle / Ivy

There is a newer version: 7.2.4
Show newest version
package com.aol.cyclops.lambda.tuple.memo;

import com.aol.cyclops.lambda.tuple.PTuple1;
import com.aol.cyclops.lambda.tuple.TupleImpl;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class Memo1 extends TupleImpl {


    private final Map values = new ConcurrentHashMap<>();
    private final PTuple1 host;

    public Memo1(PTuple1 host) {
        super(Arrays.asList(), 1);
     
        this.host = host;
    }

    public T1 v1(){
        return ( T1) values.computeIfAbsent(new Integer(0), key -> host.v1());
    }


    @Override
    public List getCachedValues() {
        return Arrays.asList(v1());
    }

    @Override
    public Iterator iterator() {
        return getCachedValues().iterator();
    }


}