class RangeLongBlock implements Comparable<RangeLongBlock>, Iterable<Long> {

    public static List<RangeLongBlock> createRangeLongBlocks(Collection<? extends Long> values)
    {
        List<RangeLongBlock> resultBlocks = new LinkedList<>();

        if (values != null && !values.isEmpty())
        {
            if (values.size() == 1)
            {
                long val = values.iterator().next().longValue();
                resultBlocks.add(new RangeLongBlock(val));
            }
            else
            {
                List<Long> valuesToUse = new ArrayList<>(values);
                Collections.sort(valuesToUse);
                Iterator<Long> valueItr = valuesToUse.iterator();
                long lastStart = valueItr.next().longValue();
                long lastVal = lastStart;
                long curVal = 0;
                while (valueItr.hasNext())
                {
                    curVal = valueItr.next().longValue();
                    if (curVal != lastVal && curVal != lastVal + 1)
                    {
                        resultBlocks.add(new RangeLongBlock(lastStart, lastVal));
                        lastStart = curVal;
                    }

                    if (!valueItr.hasNext())
                    {
                        resultBlocks.add(new RangeLongBlock(lastStart, curVal));
                    }

                    lastVal = curVal;
                }
            }
        }
        return resultBlocks;
    }

    public  RangeLongBlock(long value);
    public  RangeLongBlock(long startValue, long endValue);
    public  RangeLongBlock(RangeLongBlock other);

}