meine methode getnode sagt aus, das es eine IllegalArgument Exception gibt ,wenn der Pfad name ungültig ist!
aber wie kann ich das richtig einbinden in meine methode???
Java:
@OverridepublicbooleannodeExists(String pathName)throwsIllegalArgumentException{try{if(isValidPath(pathName)==true)System.out.println("Wir haben einen gültigen PfadName!");}catch(IllegalArgumentException e){System.out.println(e.getMessage());}if(pathName.isEmpty()){returnfalse;}int index = pathName.indexOf("/");if(index ==0){// absoluter Pfad// zum relativen pfad machen zur weiter verarbeitung
pathName = pathName.substring(index +1);}SimplePreferences value = nodeMap.get(pathName);if(value !=null)returntrue;
index = pathName.indexOf("/");if(index <0){// Wenn der index < 0 ist wurde kein Slash mehr// gefunden, dann ist es der letzte Knoten
value = nodeMap.get(pathName);// prüfen ob knoten// vorhanden istif(value !=null)returntrue;returnfalse;}String[] split = pathName.split("/");for(int i =0; i < split.length; i++){
value = nodeMap.get(split[i]);// prüfen ob knoten// vorhanden istif(value !=null)returntrue;}returnfalse;}publicbooleanisValidPath(String pathnName){if(pathnName.endsWith("/")){returnfalse;}int index =pathnName.indexOf("//");if(index >-1){returnfalse;}returntrue;}
sorry ich meinte in meiner nodeExists methode nodeExists
public abstract boolean nodeExists(String pathName)
throws BackingStoreExceptionReturns true if the named preference node exists in the same tree as this node. Relative path names (which do not begin with the slash character ('/')) are interpreted relative to this preference node.
If this node (or an ancestor) has already been removed with the removeNode() method, it is legal to invoke this method, but only with the path name ""; the invocation will return false. Thus, the idiom p.nodeExists("") may be used to test whether p has been removed.
Parameters:
pathName - the path name of the node whose existence is to be checked.
Returns:
true if the specified node exists.
Throws:
BackingStoreException - if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it. IllegalArgumentException - if the path name is invalid (i.e., it contains multiple consecutive slash characters, or ends with a slash character and is more than one character long). NullPointerException - if path name is null. s * @throws IllegalStateException if this node (or an ancestor) has been removed with the removeNode() method and pathName is not the empty string ("").
dazu habe ich jetzt ne mthode geschrieben(siehe code) isValidPath um zu ermitteln ob es ein gültiger pfad name ist!ich habe jetzt aber keine ehnung wie ich die exception in meine MEthode nodeExists kriege!
so das meine junit tests grün werden
Ich habe ihn so verstanden, dass er die Exception in der isValidPath-Methode werfen möchte. Immerhin behandelt er diese schon in der nodeExists-Methode.
aber habe noch ne kleine frage,
wollte jetzt noch für die methode isValidPAth junit test schreiben
aber es geht nicht!
er sagt immer The method isValidPath(String) is undefined for the type SimplePreferencesTest
also ich kann die methode noicht richtig aufrufen!?
WHY????:L
ja undefiniert sagt er....aber :bahnhof:???:L