Friday 15 August 2014

java - What improvements can be made to this? -



java - What improvements can be made to this? -

i've written function can environment variables value. input parameter follows

${machine}/bin or ${machine/bin} or ${machine}/bin${path${os}}/path need check values start ${} i've written function kinda recursive in nature, appreciate if can review code me , tell me can done improve

private string replacewithenvironmentvariables(string specialchars) { string result=""; boolean flag=true; try{ result = specialchars; string temp = ""; char loopbreaker = '}'; char dollarcheck = '$'; char slashcheck = '/'; int index = result.indexof("{"); if (index == -1){ result = result.replaceall("[{},$]", ""); homecoming result; } (int = index; < result.length(); i++) { if(slashcheck==result.charat(i)) break; temp += result.charat(i); if(dollarcheck==result.charat(i) || loopbreaker==result.charat(i)){ break; } } string sub = temp.replaceall("[{},$/]", ""); if(sub==null || sub.length()==0){ sub=""; flag=false; result = result.replace(temp, sub); } if(flag){ string returnsub = getenvironmentvariablevalue(sub); result = result.replace(temp, returnsub); } }catch(nullpointerexception nullpointer){ nullpointer.printstacktrace(); }catch(exception except){ except.printstacktrace(); } homecoming replacewithenvironmentvariables(result); }

ps: code working, i'm here know improve this. if question seems off-topic i'm terribly sorry.

java recursion

No comments:

Post a Comment