[Preferences]What is the use of .nodeExists?

D

Daniel Moyne

I am developing a module called "NamesPartitionsPlugin" with NetBeans. I get
module Preferences with :

myModulePreferences = NbPreferences.forModule(NamesPartitionsPlugin.class);

Each time I open a file I want to save and retrieve some data in preferences
associated with this file.

I do this to create a specific node.
myModulePreferences.node(myGedcomFile);
This will either create the node if it does not exists yet or initialize it
with existing data if it already exists.

I want to know in some cases if a particular node already exists. If I do :
Boolean flag=myModulePreferences.nodeExists(myGedcomName);
It returns always false until I do :
myModulePreferences.node(myGedcomFile);

Then here is ma question :
What is the use of nodeExists(myGedcomName) if you have to use it after node
creation and more generally how can I test whether I have already data
stored in Preferences associated with a particular file.
Thanks.
 
J

Joerg Meier

I do this to create a specific node.
myModulePreferences.node(myGedcomFile);
This will either create the node if it does not exists yet or initialize it
with existing data if it already exists.
I want to know in some cases if a particular node already exists. If I do :
Boolean flag=myModulePreferences.nodeExists(myGedcomName);
It returns always false until I do :
myModulePreferences.node(myGedcomFile);
Then here is ma question :
What is the use of nodeExists(myGedcomName) if you have to use it after node
creation and more generally how can I test whether I have already data
stored in Preferences associated with a particular file.

You seem to randomly mix "myGedcomName" and "myGedcomFile". I'm not sure if
that is intentional, but if it is, you of course can't check if you have a
nome myGedcomFile by using nodeExists(myGedcomName) - that doesn't even
make any sense. The use of nodeExists is to check if a node exists.
Obviously, nodeExists will return false if the node does not exist, and
obviously, if you want it to return true, you have to call if after you add
the node.

Your question is confusing and seems to lack some detail that you consider
obvious and didn't include. You describe the normal and expected behaviour,
and then ask "what the use of that" is, which makes no sense to me. The use
of nodeExists is exactly the use you have described in the lines above. You
can use it the way you do and the answer to your question "how can I test
whether I have already data" is "with the code you provided above".

More details seem to be needed, as that is likely not what you wanted to
hear.

Liebe Gruesse,
Joerg
 
D

Daniel Moyne

Joerg said:
You seem to randomly mix "myGedcomName" and "myGedcomFile". I'm not sure
if that is intentional, but if it is, you of course can't check if you
have a nome myGedcomFile by using nodeExists(myGedcomName) - that doesn't
even make any sense.
Sorry, it was unintentional. It is the same because as a matter of fact
myGedcomName is the name of a gedcom file. Let us keep it myGedcomName.
The use of nodeExists is to check if a node exists.
Obviously, nodeExists will return false if the node does not exist, and
obviously, if you want it to return true, you have to call if after you
add the node.

Your question is confusing and seems to lack some detail that you consider
obvious and didn't include. You describe the normal and expected
behaviour, and then ask "what the use of that" is, which makes no sense to
me. The use of nodeExists is exactly the use you have described in the
lines above. You can use it the way you do and the answer to your question
"how can I test whether I have already data" is "with the code you
provided above".

More details seem to be needed, as that is likely not what you wanted to
hear.

Liebe Gruesse,
Joerg
Joerg, once I have done:
myGedcomPreferences = myModulePreferences.node(myGedcomName);
I have either created a node or reinitialized it if it already exists, but I
thought that before I could check whether this node containing my data (if
already used to store data) already existed. Maybe I have not understood the
use of :
myModulePreferences.nodeExists(myGedcomName);

Basically what I am interested in is once I open my gedcom file is there
already some data stored in preferences to discriminate in my code between
both cases:
(1) I have no data stored yet,
(2) I have some data stored.

Is there a simple way to know? Otherwise I have to check for the presence of
a particular key in myGedcomPreferences to know in which case I am standing.
Daniel.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top