/** * Returns a namespace based on the arbitrary ID determined by the getArbitraryId method * You probably don't want to use this. Use getNameSpaceByValue instead. * * @param id the arbitrary ID of the namespace * @return the namespace */ public static NameSpace getNameSpaceByArbitraryId(int id) { return NameSpace.values()[id]; }
/** * Returns a namespace based on the value of that namespace defined by Wikipedia. * Never returns a disambiguation. * @param value the numeric value of the NameSpace as defined by Wikipedia * @return the corresponding NameSpace if it exists, else null */ public static NameSpace getNameSpaceByValue(int value){ if(value == 0) return NameSpace.ARTICLE; for (NameSpace v : NameSpace.values()){ if (value == v.getValue()) {return v;} } return null; } }
/** * Takes in a string and returns the correspond * @param s * @return null if the string does not match a namespace */ public static NameSpace getNameSpaceByName(String s){ s=s.toUpperCase(); for (NameSpace ns : NameSpace.values()){ if (ns.toString().replace("_"," ").equals(s)){ return ns; } } if (s.equals("")) return NameSpace.ARTICLE; else if (s.equals("WP")) return NameSpace.WIKIPEDIA; else if (s.equals("WT")) return NameSpace.WIKIPEDIA_TALK; else if (s.equals("IMAGE")) return NameSpace.FILE; else if (s.equals("IMAGE TALK")) return NameSpace.FILE_TALK; else if (s.equals("PROJECT")) return NameSpace.WIKIPEDIA; else if (s.equals("PROJECT TALK")) return NameSpace.WIKIPEDIA_TALK; else if (s.equals("MEDIAWIKI")) return NameSpace.MEDIA_WIKI; else if (s.equals("MEDIAWIKI TALK")) return NameSpace.MEDIA_WIKI_TALK; else if (s.equals("CAT")) return NameSpace.CATEGORY; else if (s.equals("MOS")) return NameSpace.WIKIPEDIA; else if (s.equals("H")) return NameSpace.HELP; else if (s.equals("P")) return NameSpace.PORTAL; else if (s.equals("T")) return NameSpace.TALK; else return null; }