8000 Issue/5117 by szeiger · Pull Request #14 · scala/scala · GitHub
[go: up one dir, main page]

Skip to content

Issue/5117 #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 2, 2011
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Make Enumeration.ValueSet Serializable
Closes SI-5117.
  • Loading branch information
szeiger committed Dec 2, 2011
commit 66b6ad4cacf69df95499b29f49d03a7e963a9eb9
5 changes: 3 additions & 2 deletions src/library/scala/Enumeration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,11 @@ abstract class Enumeration(initial: Int,
* @param nnIds The set of ids of values (adjusted so that the lowest value does
* not fall below zero), organized as a `BitSet`.
*/
class ValueSet private[ValueSet] (val nnIds: immutable.BitSet)
class ValueSet private[ValueSet] (private[this] var nnIds: immutable.BitSet)
extends AbstractSet[Value]
with immutable.SortedSet[Value]
with SortedSetLike[Value, ValueSet] {
with SortedSetLike[Value, ValueSet]
with Serializable {

implicit def ordering: Ordering[Value] = ValueOrdering
def rangeImpl(from: Option[Value], until: Option[Value]): ValueSet =
Expand Down
24 changes: 24 additions & 0 deletions test/files/run/enums.scala
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,29 @@ object Test5 {
}
}

object SerializationTest {
object Types extends Enumeration { val X, Y = Value }
class A extends java.io.Serializable { val types = Types.values }
class B extends java.io.Serializable { val types = Set(Types.X, Types.Y) }

def serialize(obj: AnyRef) = {
val baos = new java.io.ByteArrayOutputStream()
val oos = new java.io.ObjectOutputStream(baos)
oos.writeObject(obj)
oos.close()
val bais = new java.io.ByteArrayInputStream(baos.toByteArray)
val ois = new java.io.ObjectInputStream(bais)
val prime = ois.readObject()
ois.close()
prime
}

def run {
serialize(new B())
serialize(new A())
}
}

//############################################################################
// Test code

Expand Down Expand Up @@ -125,6 +148,7 @@ object Test {
Console.println;
Test5.run;
Console.println;
SerializationTest.run;
}
}

Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
0