Search in sources :

Example 1 with ClosedOpenRange

use of org.onlab.util.ClosedOpenRange in project onos by opennetworkinglab.

the class EncodedResourcesSerializer method read.

@Override
public EncodedDiscreteResources read(Kryo kryo, Input input, Class<EncodedDiscreteResources> cls) {
    @SuppressWarnings("unchecked") List<ClosedOpenRange> ranges = kryo.readObject(input, ArrayList.class);
    DiscreteResourceCodec codec = (DiscreteResourceCodec) kryo.readClassAndObject(input);
    RangeSet<Integer> rangeSet = TreeRangeSet.create();
    ranges.stream().map(x -> Range.closedOpen(x.lowerBound(), x.upperBound())).forEach(rangeSet::add);
    return new EncodedDiscreteResources(rangeSet, codec);
}
Also used : Serializer(com.esotericsoftware.kryo.Serializer) Output(com.esotericsoftware.kryo.io.Output) DiscreteResourceCodec(org.onosproject.net.resource.DiscreteResourceCodec) List(java.util.List) RangeSet(com.google.common.collect.RangeSet) Range(com.google.common.collect.Range) Input(com.esotericsoftware.kryo.io.Input) ClosedOpenRange(org.onlab.util.ClosedOpenRange) TreeRangeSet(com.google.common.collect.TreeRangeSet) Collectors(java.util.stream.Collectors) Kryo(com.esotericsoftware.kryo.Kryo) ArrayList(java.util.ArrayList) ClosedOpenRange(org.onlab.util.ClosedOpenRange) DiscreteResourceCodec(org.onosproject.net.resource.DiscreteResourceCodec)

Aggregations

Kryo (com.esotericsoftware.kryo.Kryo)1 Serializer (com.esotericsoftware.kryo.Serializer)1 Input (com.esotericsoftware.kryo.io.Input)1 Output (com.esotericsoftware.kryo.io.Output)1 Range (com.google.common.collect.Range)1 RangeSet (com.google.common.collect.RangeSet)1 TreeRangeSet (com.google.common.collect.TreeRangeSet)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 ClosedOpenRange (org.onlab.util.ClosedOpenRange)1 DiscreteResourceCodec (org.onosproject.net.resource.DiscreteResourceCodec)1