[Yanel-dev] Yarep delete method
Josias Thöny
josias.thoeny at wyona.com
Mon Jul 23 16:34:14 CEST 2007
Michael Wechner wrote:
> Josias Thöny wrote:
>
>> Michael Wechner wrote:
>>
>>> Hi
>>>
>>> I have noticed that according to the API calling delete also is
>>> supposed to delete all children resp. also non-empty collections
>>>
>>> src/core/java/org/wyona/yarep/core/Node.java
>>>
>>> /**
>>> * Deletes this node and all subnodes.
>>> * The root node cannot be deleted.
>>> * @throws RepositoryException if this node is the root node or if
>>> a repository error occurs.
>>> */
>>> public void delete() throws RepositoryException;
>>>
>>>
>>> Shouldn't we introduce something like
>>>
>>>
>>> delete(boolean recursive)
>>>
>>> which would allow to block the deletion of non-empty collections when
>>> being set to delete(false)
>>>
>>
>> IIUC this would mean that a caller of delete(false) has to check
>> afterwards if the operation has been successful.
>> Then you could as well check if the node has any child nodes before
>> you call delete().
>> Where do you see the advantage of using delete(false)?
>
>
> I think it's a bit more convenient
>
> node.delete(false)
>
> versus
>
> if (node.getNodes().length == 0) node.delete()
Hm, but you also have to handle the case where the node has some children.
Then the first option becomes something like:
boolean success = node.delete(false);
if (!success) {
throw new Exception("cannot delete node, maybe it has some child-nodes");
}
and the second option:
if (node.getNodes().length == 0) {
node.delete();
} else {
throw new Exception("cannot delete node because it has child-nodes");
}
So you need the "if" in both cases and the complexity is about the same.
Personally I like the second one better, because in the first one you
don't know why a node could not be deleted if the method returns false.
Josias
>
> but I am also fine with it as it is, because one could argue that when
> using delete() within a program, one
> normally doesn't do things by accident, whereas when using the "rm" on
> the command line one often deletes stuff by accident.
>
> Cheers
>
> Michi
>
>>
>> josias
>>
>>> ?
>>>
>>> This would corrspond to rm -r
>>>
>>> WDYT?
>>>
>>> Cheers
>>>
>>> Michi
>>>
>>
>> _______________________________________________
>> Yanel-development mailing list
>> Yanel-development at wyona.com
>> http://lists.wyona.org/cgi-bin/mailman/listinfo/yanel-development
>
>
>
More information about the Yanel-development
mailing list