X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2Futil%2FIntegerTopology.java;h=55ac0821fb4fdf293acee634ec444b8025a153f5;hp=ae99c083880cb7d2bda7ec5fa616422139fa66ba;hb=f069d11a0bc59d63b078df8a4aa488498c4e9cc2;hpb=61a641445b4f0916427804a6168b87fcde977abf diff --git a/src/edu/berkeley/sbp/util/IntegerTopology.java b/src/edu/berkeley/sbp/util/IntegerTopology.java index ae99c08..55ac082 100644 --- a/src/edu/berkeley/sbp/util/IntegerTopology.java +++ b/src/edu/berkeley/sbp/util/IntegerTopology.java @@ -1,3 +1,5 @@ +// Copyright 2006-2007 all rights reserved; see LICENSE file for BSD-style license + package edu.berkeley.sbp.util; import java.io.*; import java.util.*; @@ -7,7 +9,7 @@ import edu.berkeley.sbp.*; import edu.berkeley.sbp.util.*; /** implementation of Topology for any class for which there is a mapping to the ints */ -public class IntegerTopology implements Topology { +public class IntegerTopology implements Topology, Serializable { private final Range.Set rs; private final Functor f; @@ -15,6 +17,7 @@ public class IntegerTopology implements Topology { private int toInt(V v) { return f==null?((IntegerMappable)v).toInt():f.invoke(v); } public Range.Set getRanges() { return new Range.Set(rs); } + public Functor functor() { return f; } public IntegerTopology(Functor f) { this(f, new Range.Set()); } public IntegerTopology(Functor f, V a) { this(f, f==null?((IntegerMappable)a).toInt():f.invoke(a)); } @@ -23,8 +26,11 @@ public class IntegerTopology implements Topology { public IntegerTopology(Functor f, int a) { this(f, a, a); } public IntegerTopology(Functor f, int a, int b) { this(f, new Range(a, b)); } public IntegerTopology(Functor f, Range r) { this(f, new Range.Set(r)); } - public IntegerTopology(Functor f, Range.Set rs) { this.rs = rs; this.f = f; } - + public IntegerTopology(Functor f, Range.Set rs) { + this.rs = rs; + this.f = f==null?(this instanceof Functor ? (Functor)this : null):f; + } + public Topology empty() { return new IntegerTopology(f); } public boolean contains(V v) { return rs.contains(toInt(v)); }