Finding configure components

Is there a better way to do this?:

PrototypesContainer container = module.getAllDescendantComponentsOf(PrototypesContainer.class).toArray(new PrototypesContainer[0])[0];

  • M.

How about

module.getAllDescendantComponentsOf(PrototypesContainer.class).iterator().next();

Brent.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Thanks!

  • M.

On 17/02/2008, Brent Easton b.easton@exemail.com.au wrote:


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Thus spake “mkiefte”:

Not that I know of (but maybe there is and I don’t know it). Is it the
verbosity which bugs you, or that you have to construct the whole array
and then chuck it? You could do this instead:

PrototypesContainer container = module.getAllDescendantComponentsOf(PrototypesContainer.class).iterator().next();

Or, maybe we could change the return type of getAllDescendantComponentsOf()
to List, in which case you could do get(0).


J.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

It seemed unwieldy. It works fine and I’m not particularly worried.
In the ADC2Module.java code, it happens a lot.

  • M.

On 18/02/2008, Joel Uckelman uckelman@nomic.net wrote:


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Thus spake “Michael Kiefte”:

BTW, you shouldn’t do this if you’re not certain that there will be
a PrototypesContainer which is a descendant of the module, as otherwise
calling next() on an interator for which !hasNext() will cause the world
to end.


J.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

This is on a newly created game module. Newly created game modules
always have a PrototypesContainer. I guess I could check this and
create one if there isn’t… I never really thought of that.

Is there a situation when a newly created module does not have a
PrototypesContainer? I’m regularly making assumptions about what’s
already there on a newly initialised module.

  • M.

On 18/02/2008, Joel Uckelman uckelman@nomic.net wrote:


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Thus spake “Michael Kiefte”:

In general, I usually try to code defensively unless I’m certain that the
thing I’m looking for will exist. In particular, you’re dealing with code
I’ve never examined myself, so somebody else will have to tell you whether
there will always be a PrototypesContainer.


J.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Thus spake Joel Uckelman:

I did that, BTW. There’s no point in returning a Collection when we’ll
always have a List to return.


J.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Joel,

Yes, Good idea.

BTW Zoomer.java has compile errors under 1.5 compiler in eclipse. I had to remove the @Override tags from Zoomer.LevelModel.getElementAt() and Zoomer.LevelModel.getSize(). What is the purpose of the @Override tags anyway?

Brent.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

When creating a new module, BasicModule calls buildDefaultComponents() which will ensure that a PrototypesContainer exists.

When opening an old module, BasicModule calls ensureComponent(Class<?>) to make sure certain components exist, but PrototypesContainer is not one of these (GamePieceImageDefinitions, GlobalProperties and Language). So potentially, opening a very old module may result in a module without a PrototypesContainer.

Brent.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Thus spake “Brent Easton”:

The @Override tag is to indicate that you’re intending to override a
method from the superclass. The idea is that you’ll get an error if
you have a method marked @Override in case it doesn’t succeed in
overriding anything. E.g., if you left out an arugment or had a double
instead of an int, and didn’t have an @Override tag then you’d get no
indication from the compiler that something was wrong.

Looking back, those two methods aren’t actually implemented in
AbstractListModel—it inherits them from the ListModel interface. It
appears that Eclipse’s compiler is stricter about what can be marked
@Override than the standard Java compiler is.


J.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)