Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class name {
- name(String orgName) throws Exception
- {this.orgName=orgName;
- this.fullName=removeClanTag(orgName);
- this.clanTag=generateClanTag(orgName);
- this.longNick=generateLongNick(fullName);
- this.shortNick=generateShortNick(fullName, this.longNick);}
- private String orgName;
- public String getOrgName() {
- return orgName;
- }
- public void setOrgName(String orgName) {
- this.orgName = orgName;
- }
- public String getFullName() {
- return fullName;
- }
- public void setFullName(String fullName) {
- this.fullName = fullName;
- }
- public String getLongNick() {
- return longNick;
- }
- public void setLongNick(String longNick) {
- this.longNick = longNick;
- }
- public String getShortNick() {
- return shortNick;
- }
- public void setShortNick(String shortNick) {
- this.shortNick = shortNick;
- }
- public String getClanTag() {
- return clanTag;
- }
- public void setClanTag(String clanTag) {
- this.clanTag = clanTag;
- }
- private String fullName;
- private String longNick;
- private String shortNick;
- private String clanTag;
- private String generateClanTag(String orgName)
- {orgName=orgName.trim();
- //find lastStartBrace
- int lastOpenBraceFound=0;
- int firstEndBraceFound=0;
- boolean virginBool=true;
- for (int i=0;i<orgName.length();i++)
- {char tempChar=orgName.charAt(i);
- if (tempChar=='('||tempChar=='['||tempChar=='<'||tempChar=='{'||tempChar=='~')
- {lastOpenBraceFound=i; }
- }
- //find firstEndBrace
- for (int i=0;i<orgName.length();i++)
- {
- char tempChar=orgName.charAt(i);
- if (virginBool==true)
- {
- if (tempChar==')'||tempChar==']'||tempChar=='>'||tempChar=='}')
- {firstEndBraceFound=i;
- virginBool=false;}
- }
- }
- if (lastOpenBraceFound+1<firstEndBraceFound){
- String returnString= orgName.substring(lastOpenBraceFound+1, firstEndBraceFound);
- return returnString;}
- else
- return "";
- }
- private static boolean checkChar(char char2Check)
- {
- if ( char2Check>=65&&char2Check<=90||char2Check>=97&&char2Check<=122)
- {return true;}
- else
- {return false;}
- }
- private static boolean checkVokal(char char2Check)
- {
- if (char2Check=='a'||char2Check=='o'||char2Check=='u'||char2Check=='i'||char2Check=='e')
- {return true;}
- else
- return false;
- }
- private String removeClanTag(String orgName)
- {orgName=orgName.trim();
- //find lastStartBrace
- int lastOpenBraceFound=0;
- int firstEndBraceFound=0;
- boolean virginBool=true;
- for (int i=0;i<orgName.length();i++)
- {char tempChar=orgName.charAt(i);
- if (tempChar=='('||tempChar=='['||tempChar=='<'||tempChar=='{'||tempChar=='~')
- {lastOpenBraceFound=i;}
- }
- //find firstEndBrace
- for (int i=0;i<orgName.length();i++)
- {
- char tempChar=orgName.charAt(i);
- if (virginBool==true)
- {
- if (tempChar==')'||tempChar==']'||tempChar=='>'||tempChar=='}')
- {firstEndBraceFound=i;
- virginBool=false;}
- }
- }
- String returnOfTheString= orgName.substring(0, lastOpenBraceFound+1)+ orgName.substring(firstEndBraceFound,orgName.length());
- for (int i=0;i<returnOfTheString.length();i++)
- {
- if (checkChar(returnOfTheString.charAt(i))==false)
- {
- returnOfTheString=returnOfTheString.substring(0,i)+returnOfTheString.substring(i+1,returnOfTheString.length());
- i=i-1;
- }
- }
- return returnOfTheString;
- }
- /**Function: Generates the long Nick from the full Name
- **/
- private static String generateLongNick(String fullName)
- {fullName=fullName.trim();
- fullName=fullName.toLowerCase();
- String returnNick = "";
- boolean firstVokalFound=false;
- breakPointer:
- for (int i=0;i<fullName.length();i++)
- {
- if (checkVokal(fullName.charAt(i))==true)
- {if (firstVokalFound==true&&i+1<fullName.length())
- {returnNick=fullName.substring(0,i+1);break breakPointer; }
- else
- {firstVokalFound=true;}
- }
- }
- return returnNick;
- }
- /**
- Function to generate a Short Version of the estimated Nick. Needs the fullname, and the long Nick.
- * @throws Exception
- */
- private static String generateShortNick(String fullName,String longNick) throws Exception
- {if (longNick==null)
- longNick=generateLongNick(fullName);
- if (fullName==null)
- throw new Exception("Player Name is emptyString");
- fullName=fullName.toLowerCase();
- for (int i=0;i<fullName.length();i++)
- {
- if (checkVokal(fullName.charAt(i))==true&&(i+1)*2<fullName.length())
- {return fullName.substring(0, (i+1)*2); }
- }
- return "";
- }
- }
Add Comment
Please, Sign In to add comment