And now if I use changeState(State.NOT_ACTIVE) it will change state in SomeObjects and in all Objects in list or only in SomeObjects?
I'm not entirely sure what your line of thought is here.
If you call changeState(NOT_ACTIVE) on some instance of SomeObjects, then as per the definition of the method it will set that object's state field to be NOT_ACTIVE. There is no way that this single method call would change multiple objects, as it's performing a single assignment on a single variable.
If only in SomeObjects, what should I do to change state in all Objects in list with changeState()?
If you want the changeState method to apply the state to all of the objects contained within the objects field, then you can make it do this with a simple loop:
public void changeState(State state) {
this.state = state;
for (SomeObject obj : objects) {
obj.state = state;
}
}
Is the creating of class, containing that enum, the only way in this case?
Again it isn't clear to me exactly what you're thinking of here. Don't you want to set the state value of all the SomeObject instances contained within a SomeObjects instance? That is, set values on instances that already exist, of a class that's already defined?
If so then this can be done as above by setting the values in a loop. The fact that the field is an enum makes no difference; any primitive or reference type would behave identically here.
Edit to answer comment: Ah, it sounds like the root problem was using a field in the first place.
Given that you want all of the contents of the objects collection to have exactly the same state at all times, it is probably wrong for them to all have an individual state field. It's a modelling error, in that a SomeObject instance doesn't really independently hold/control its own state.
Something I was going to suggest earlier is that you should have implemented methods rather than accessing the fields directly - and that's something that comes to the fore now. Rather than SomeObject having a state field, it should have a getState() method. With a given instance you have a way to get its current state - but this isn't necessarily implemented as a direct object reference.
And the implementation of this method should simply be to get the state of the wrapping SomeObjects instance (that's not a particularly informative class name). So it might be implemented as following:
public class SomeObject {
private final SomeObjects parent;
public SomeObject(SomeObjects parent) {
this.parent = parent;
}
public State getState() {
return parent.state; // Ideally accessed via method too
}
}
This is consistent with how I understand your design - each SomeObject has the same state as its wrapping SomeObjects (and so implicitly must have exactly one parent SomeObjects instance defined at all times). The code above is an almost exact representation of that design.
(And there's still nothing special here with enums; things would work identically if you were returning int or String or Map<MyFoo, Set<Future<ResultSet>>.)