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

jfxtras.icalendarfx.properties.component.recurrence.rrule.byxxx.BySetPosition Maven / Gradle / Ivy

There is a newer version: 17-r1
Show newest version
package jfxtras.icalendarfx.properties.component.recurrence.rrule.byxxx;

import java.time.temporal.ChronoUnit;
import java.time.temporal.Temporal;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import jfxtras.icalendarfx.properties.component.recurrence.rrule.byxxx.ByRuleIntegerAbstract;
import jfxtras.icalendarfx.properties.component.recurrence.rrule.byxxx.BySetPosition;

public class BySetPosition extends ByRuleIntegerAbstract
{
    public BySetPosition()
    {
        super();
    }
    
    public BySetPosition(Integer... setPositions)
    {
        super(setPositions);
    }
    
    public BySetPosition(BySetPosition source)
    {
        super(source);
    }
    
    @Override
    Predicate isValidValue()
    {
        return (value) -> (value >= -366) && (value <= 366) && (value != 0);
    }
    
    @Override
    public Stream streamRecurrences(Stream inStream, ChronoUnit chronoUnit, Temporal startTemporal)
    {
        List inList = inStream.collect(Collectors.toList()); // can't be an infinite stream or will hang
        List outList = new ArrayList<>();
        for (int setPosition : getValue())
        {
            if (setPosition > 0)
            {
                outList.add(inList.get(setPosition-1));                
            } else if (setPosition < 0)
            {
                outList.add(inList.get(inList.size() + setPosition));                
            }
        }
        return outList.stream();
    }

    public static BySetPosition parse(String content)
    {
    	return BySetPosition.parse(new BySetPosition(), content);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy