Questions tagged [unmodifiable]

67 questions
2
votes
2 answers

How to create a Java Map with unmodifiable keys?

In java, how should I create a Map that has unmodifiable keys, while keeping the values modifiable. I'd like to hand this Map through an interface for someone else to add/change the Map values, but not be able to change…
abaines
  • 224
  • 1
  • 5
  • 11
2
votes
3 answers

unmodifiableCollection changes at server while iterating at client

In a scenario where server gives a client an unmodifiableCollection of an existing Collection, and client starts iterating over it, at the same time if at server level one thread changes the List, for example removes an element of it. Will this…
m0nish
  • 95
  • 1
  • 5
2
votes
2 answers

Someone breaks my sorting of a list - now which approach to choose: return unmodifiable List or a new List altogether?

I'm using lists on a jsf web server to e.g. access the data model from web pages. The access to these lists is done from various other places as well though (web services, tools). There is a piece of code which gets broken by someone resorting the…
Toskan
  • 13,911
  • 14
  • 95
  • 185
1
vote
2 answers

Making unmodifiable objects

I have a Java application where the domain layer is decoupled from the UI by controllers. The problem is that these controllers can return domain objects, and can have domain objects as parameters. Some of these returned domain objects are mutable,…
Peter
  • 746
  • 6
  • 22
1
vote
1 answer

Unmodifiable Multimap

Is there a way to create (/return) an unmodifiable Multimap? I am using the Multimap of com.google.common.collect and need to create an unmodfiable Multimap, but I couldn't find a lib that has a method, which returns the a given Multimap as an…
1
vote
1 answer

Flutter : How change modify unmodifiable map

I have list like this in provider: List orders=[]: void getOrders(){ orders = [ {"id":1, "order":[ {"id":1,"name":"mike"}, {"id":2,"name":"john"}, {"id":3,"name":"smith"} …
1
vote
2 answers

Check if Java Collection is modifiable at Runtime

I'm trying to make a method that modifies a incoming Collection or List. The problem is that I can't check if the Collection / List is an unmodifiable Collection / List. Sure I could just "try" to write to it with set and catch the exception. But I…
RedCrafter LP
  • 174
  • 1
  • 8
1
vote
1 answer

How to forbid List add() method in Dart?

I'm building a "Favorites" manager which has only 3 public features : init(Iterable items) to initialize favorites (from preferences) toggle(T item) to add/remove any favorite contains(T item) to verify if an item is favorite This works with a…
Galactose
  • 175
  • 3
  • 8
1
vote
2 answers

Can the list returned by a Java streams collector be made unmodifiable?

When working with Java streams, we can use a collector to produce a collection such as a stream. For example, here we make a stream of the Month enum objects, and for each one generate a String holding the localized name of the month. We collect the…
Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
1
vote
1 answer

With default typing enabled, is there a way to override the type Jackson outputs?

I am serializing a class that includes an unmodifiable list with default typing enabled. The problem is that the type that Jackson uses is java.util.Collections$UnmodifiableRandomAccessList which, for some reason, the deserializer does not know…
Dan Ciarniello
  • 193
  • 1
  • 2
  • 9
1
vote
2 answers

Generic unmodifiableList

I wrote: this.array = (X[]) Array.newInstance(init.getClass(), size); // ... public List get() { return Collections.unmodifiableList(this.array); } But I get the error: unmodifiableList in Collections cannot be applied to…
Skywooo
  • 87
  • 6
1
vote
1 answer

How to make JavaFX ListProperty modifiable only through custom methods

I have a private list and I don't want that it can be modified from outside in general. Just adding from outside is allowed and only if the object is valid. Therefore I used to write it like this: private List list = new…
Arceus
  • 520
  • 6
  • 16
1
vote
3 answers

Cast an unmodifiable set

I have a java.lang.Object that I can't cast. When debugging I notice that the Object is an unmodifiable set so I tried to cast it to a set but that didn't work (ClassCastException). Instead I tried Set listOfSelectedItems = new…
Johan Wiström
  • 373
  • 1
  • 5
  • 13
1
vote
1 answer

UnmodifiableMap with Function values fails to compile

I have a reference: public final static LinkedHashMap> DELEGATES; Which I initialize like: static { LinkedHashMap> tmp = new LinkedHashMap<>(); …
Diego Martinoia
  • 4,592
  • 1
  • 17
  • 36
1
vote
1 answer

Pointer being treated as an unmodifiable lvalue in Visual Studio 2013

getNode(): Node getNode(int position) { Node *item = head; for (int i = 0; i < position; ++i) { item = item->next; } return *item; }; Node Swapping Code: Node temp; …