Hi,
I am a newbie in Objective C and I was wondering what is
the best way to define an immutable class in Objective-C (like NSString for example).
I want to know what are the basic rules one has to follow to make a class immutable.
I think that :
setters shouldn't be provided
if properties are used, they should be readonly
to "disa...
Hi, I am working through an example in Java Concurrency in Practice and am not understanding why a concurrent-safe container is necessary in the following code.
I'm not seeing how the container
"locations" 's state
could be modified after construction; so since it is published through an 'unmodifiableMap' wrapper, it appears to me ...
I'm building an entire application out of immutable objects so that multi-threading and undo become easier to implement. I'm using the Google Collections Library which provides immutable versions of Map, List, and Set.
My application model looks like a tree:
Scene is a top-level object that contains a reference to a root Node.
Each No...
I have three classes; Classes A and B both reference class C.
How can I make it so members of class C can be modified when referenced from class A but not modified when referenced from class B?
IE, the following should be possible;
classA myClassA = new classA();
myClassA.myClassC.IssueNumber = 3;
But this should not be possible;
c...
(For the purposes of this question, let us assume that one is intentionally not using auto(un)boxing, either because one is writing pre-Java 1.5 code, or because one feels that autounboxing makes it too easy to create NullPointerExceptions.)
Take Boolean, for example. The documentation for the Boolean(boolean) constructor says:
Note...
Consider this simplified application domain:
Criminal Investigative database
Person is anyone involved in an investigation
Report is a bit of info that is part of an investigation
A Report references a primary Person (the subject of an investigation)
A Report has accomplices who are secondarily related (and could certainly be primary i...
It's the reverse of this question: http://stackoverflow.com/questions/93091/why-cant-strings-be-mutable-in-java-and-net
Was this choice made in Ruby only because operations (appends and such) are efficient on mutable strings, or was there some other reason?
(If it's only efficiency, that would seem peculiar, since the design of Ruby se...
Hi all!
I am having problems using the update method of scala.collection.immutable.HashMap.I don't see the reason it returns a Map instead of a HashMap. How do I get a new HashMap with a new key-value pair added?
...
I have a list, and I want to provide read-only access to a collection containing its contents. How can I do this?
Something like:
public ICollection<Foo> ImmutableViewOfInventory() {
IList<Foo> inventory = new List<Foo>();
inventory.add(new Foo());
return inventory.ImmutableView();
}
Additionally, an immutable IEnumer...
Hi,
In one of my projects, I have some classes that represent entities that cannot change once created, aka. immutable classes.
Example : A class RSAKey that represent a RSA key which only has const methods. There is no point changing the existing instance: if you need another one, you just create one.
My objects sometimes are heavy a...
From a recent SO question (see http://stackoverflow.com/questions/2671211/create-a-dictionary-in-python-which-is-indexed-by-lists) I realized I probably had a wrong concept of the meaning of hashable and immutable objects in python.
What hashable means in practice?,
What the relation between hashable and immmutable is?
There are mutab...
I am getting comfortable with using plists for initializing my app. I now want to save app state back to the plist used to initialize the app and I find myself stuck. At application startup I ingest the plist into an NSDictionary which is immutable. I now want to update the NSDictionary by replacing old values with new values for existin...
A frozen set is a frozenset.
A frozen list could be a tuple.
What would be a frozen dict ? An immutable, hashable dict.
I guess it could be something like collections.namedtuple, but namedtuple is more like a frozenkeys dict (an half-frozen dict). No ?
EDIT:
A frozendict should be a frozen DICT :
it should have keys, values, get, ......
Hi, I need replace the same value for variables {place} and {other_place} in the record op.
#op{
action = [walk, from, {place}, to, {other_place}],
preconds = [[at, {place}, me], [on, floor, me],
[other_place, {place}, {other_place}]],
add_list = [[at, {other_place}, me]],
del_list = [[at, {place}, me]...
In particular an immutable List with a cons operation would be welcome.
...
Today I was reading through some Hibernate code and I encounter something interesting.
There is a class called CollectionHelper that defines the following constant varibale:
public final class CollectionHelper {
public static final List EMPTY_LIST = Collections.unmodifiableList( new ArrayList(0 ) ;
public static final Collection EMP...
What is the simplest and least obtrusive way to indicate to the compiler, whether by means of compiler options, #defines, typedefs, or templates, that every time I say T, I really mean T const? I would prefer not to make use of an external preprocessor. Since I don't use the mutable keyword, that would be acceptable to repurpose to indic...
I have tried this but it does not work:
val map:Map[String,String] = for {
tuple2 <- someList
} yield tuple2._1 -> tuple2._2
How else would I convert a List of Tuple2s into a Map?
...
I'm studying the best data structures to implement a simple open-source object temporal database, and currently I'm very fond of using Persistent Red-Black trees to do it.
My main reasons for using persistent data structures is first of all to minimize the use of locks, so the database can be as parallel as possible. Also it will be eas...
TERM Immutable Stack: I overuse stack. Poly's reply uses Collections.emptyList() as immutable list. No Collections.emptyStack(). Combining the words stack and immutability, from the last experiences, gets "immutable stack" (probably not related to functional prog).
Java Api 5 for list interface shows that Stack is an implementing class...