Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Port of Python Class made in C++ to JAVA
08-26-2010, 10:50 PM (This post was last modified: 09-01-2010 09:22 AM by codecaine.)
Post: #1
Port of Python Class made in C++ to JAVA
I ported the c++ version of my python class to java. Attached is the source code.

PHP Code:
/*
 * This program was coded by codecaine aka Jerome Scott II on 25 Aug 2010
 */

import java.util.*;
import java.io.*;


public class 
Python {
    private 
String temp_str//temporary String used throughout the class
    
private ArrayList<Stringarray_list//temporary ArrayList used throughout the class
    
private final int NEGATIVE_ONE = -1;
    private final 
byte ZERO 0;
    private final 
byte ONE 1;
    private final 
String EMPTY_STR "";

    public 
Python()
    {
        
array_list = new ArrayList<String>(); //initiliaze a array_list for use in class
    
}

    
//return all lowercase letter a-z
    
public String ascii_lowercase()
    {
        return 
"abcdefghijklmnopqrstuvwxyz";
    }

    
//return all uppercase letters A-Z
    
public String ascii_uppercase()
    {
        return 
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    }

    
//return all digits 0-9
    
public String digits()
    {
        return 
"0123456789";
    }

    
//return all octal numbers 0-7
    
public String octaldigits()
    {
        return 
"01234567";
    }

    
//return all hexdigits 0-F
    
public String hexdigits()
    {
        return 
"0123456789abcdefABCDEF";
    }

    
//return all letters a-z and A-Z
    
public String ascii_letters()
    {
        return 
ascii_lowercase() + ascii_uppercase();
    }

    
//returns all punctuation characters
    
public String punctuation()
    {
        return 
"!\"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~";
    }

    
//return white spaces tab newline space and return
    
public String whitespace()
    {
        return 
"\t\n \r";
    }

    
//return all printable characters digits letters punctuation and white spaces
    
public String printable()
    {
        return 
digits() + ascii_letters() + punctuation() + whitespace();
    }

    
//return a string lowercase
    
public String lower(final String str)
    {
        return 
str.toLowerCase();
    }

    
//return a string uppercase
    
public String upper(final String str)
    {
        return 
str.toUpperCase();
    }

    
//return a string as an ArrayList string splitting each characters
    
public ArrayList<Stringsplit(final String str)
    {
        
array_list.clear();
        if(!
str.isEmpty())
        {
            for(
int x ZEROstr.length(); x++)
            {
                
array_list.add(String.valueOf(str.charAt(x)));
            }
            return 
array_list;
        }
        return 
array_list;
    }

    
//return a string as an ArrayList splits a string from a giving separator
    
public ArrayList<Stringsplit(final String str, final String sep)
    {
        
array_list.clear();
        if(!
str.isEmpty())
        {
            
String[] temp_array str.split(sep);
            
array_list.addAll(Arrays.asList(temp_array));
            return 
array_list;
        }
        return 
array_list;
    }

    
//return a string a an ArrayList of strings from a giving separator and keeps splitting it from a separator until a giving count
    
public ArrayList<Stringsplit(final String str, final String sep, final int max)
    {
        
array_list.clear();
        if(!
str.isEmpty())
        {
            
String[] temp_array str.split(sepmax);
            
array_list.addAll(Arrays.asList(temp_array));
            return 
array_list;
        }
        return 
array_list;
    }

    
//strip all white spaces from the left side of a string
    
public String lstrip(final String str)
    {
    
temp_str str;
    if (
str.length() != ZERO)
    {
        for(
int x ZEROstr.length(); x++)
        {
            
//if the starting postions of a string is a space remove it else break the loop and return the string
            
if(str.charAt(x) == ' ')
            {
                
temp_str str.substring(1,str.length()); //return the string without the space
            
}
            else
            {
                break;
            }
        }
    }
    return 
temp_str;
    }

    
//strip all whitespace characters from the right side of a string
    
public String rstrip(final String str)
    {
    
temp_str str;
    if (
str.length() != ZERO)
    {
        for(
int x str.length() - ONEZEROx--)
        {
            
//if the starting postions of a string is a space remove it else break the loop and return the string
            
if(str.charAt(x) == ' ')
            {
                
temp_str str.substring(1,str.length()); //return the string without the space
            
}
            else
            {
                break;
            }
        }
    }
    return 
temp_str;
    }

    
//strips all white spaces from the left & right side of a string
    
public String strip(final String str)
    {
        return 
str.trim();
    }

    
//remove characters from a string giving a list of characters to remove from a string
    
public String strip(String str, final String invalids)
    {
        return 
str.replaceAll("[" invalids "]"EMPTY_STR);
    }

    
//return true or false if string starts with a giving string
    
public boolean startswith(final String str, final String start)
    {
        return 
str.startsWith(start);
    }

    
//return true of false if a string ends with a giving string
    
public boolean endswith(final String str, final String end)
    {
        return 
str.endsWith(end);
    }

    
//change uppercase or lowercase letter to their opposite case
    
public String swapcase(final String str)
    {
        
StringBuilder sb = new StringBuilder(str);

        if(
sb.length() != ZERO)
        {
            for(
int x ZEROsb.length(); x++)
            {
                if(
Character.isUpperCase(sb.charAt(x)))
                    
sb.setCharAt(xCharacter.toLowerCase(sb.charAt(x)));
                else
                    
sb.setCharAt(xCharacter.toUpperCase(sb.charAt(x)));
            }
            return 
sb.toString();
        }
        return 
str;
    }

    
//capitalize the first letter of a string
    
public String capitalize(final String str)
    {

        if(
str.length() != ZERO)
        {
            
StringBuilder sb = new StringBuilder(str);
            
//if the first character of the string is lowercase convert it to uppercase
            
if(Character.isLowerCase(sb.charAt(ZERO)))
                
sb.setCharAt(ZEROCharacter.toUpperCase(sb.charAt(ZERO)));
            return 
sb.toString();
        }
        return 
str;
    }

    
//capitalize each inception character of a string
    
public String title(final String str)
    {
        if(
str.trim().length() != ZERO)
        {
            
StringBuilder sb = new StringBuilder(EMPTY_STR);
            
String[] temp_array str.split("\\s+");
            if(
temp_array.length == 1)
                return 
sb.append(capitalize(temp_array[ZERO])).toString();
            else
            {
                
sb.append(capitalize(temp_array[ZERO] + " "));
                for(
int x ONEtemp_array.lengthx++)
                    
sb.append(capitalize(temp_array[x] + " "));
                return 
sb.toString();
            }
        }
        else
            return 
str;
    }

    
//return a ArrayList of strings of words with each inception of the word capitalize
    
public ArrayList<Stringcapwords(final String str)
    {
        
array_list.clear();
        if(!
str.trim().isEmpty())
        {
            
array_list.addAll(Arrays.asList(str.split("\\s+")));
            for(
int x ZEROarray_list.size(); x++)
            {
                if(!
array_list.get(x).toString().trim().isEmpty())
                    
array_list.set(xcapitalize(array_list.get(x).toString()));
            }
            for(
int x ZEROarray_list.size(); x++)
            {
                if(
array_list.get(x).toString().trim().isEmpty())
                    
array_list.remove(x);
            }
            return 
array_list;
        }
        return 
array_list;
    }

    
//pad the let side of a string with 0's to a giving count until the string is length is the fill size
    
public String zfill(final String strint fill)
    {
        
int pad ZERO;
        
temp_str EMPTY_STR;
        
//if fill is less then the string length there is no need to pad 0's so return the string as it is
        
if(fill str.length())
            return 
str;

        
pad fill str.length(); //calculate how many 0's are need to append to the string
        
for(int x ZEROpadx++)
            
temp_str += "0"//pad the left of the string with 0's
        
return temp_str str;
    }

    
//convert a ArrayList of strings to a single string
    
public String join(final ArrayList<Stringa_list)
    {
        
temp_str EMPTY_STR;
        if(
a_list.isEmpty())
            return 
temp_str;
        else
            for(
int x ZEROa_list.size()-ONEx++)
            {
                
temp_str += a_list.get(x);
            }
            
temp_str += a_list.get(a_list.size()-ONE);
            return 
temp_str;
    }

    
//convert a ArrayList of strings to a single string adding a separator string
    
public String join(final ArrayList<Stringa_list, final String sep)
    {
        
temp_str EMPTY_STR;
        if(
a_list.isEmpty())
            return 
temp_str;
        else
        {
            for(
int x ZEROa_list.size() - ONEx++)
            {
                
temp_str += a_list.get(x) + sep;
            }
            
temp_str += a_list.get(a_list.size() - ONE);
            return 
temp_str;
        }
    }

    
//return a character from a giving index
    
public char slice(final String str, final int index)
    {
        if(!
str.isEmpty() && index >= ZERO && index str.length())
            return 
str.charAt(index);
        else
            return 
'\0';
    }

    
//return a substring froma  string from a giving start index to a end index
    
public String slice(final String str, final int start, final int end)
    {
        if(!
str.isEmpty() && start end && start ZERO)
            return 
str.substring(start,end);
        else
            return 
EMPTY_STR;
    }

    
//return a substring from a substring from a giving start index to a end index in steps
    
public String slice(final String str, final int start, final int end, final int sep)
    {
        
temp_str EMPTY_STR;
        if(!
str.isEmpty() && start end && start ZERO)
        {
            for(
int x ZEROstr.length(); += sep)
                
temp_str += str.charAt(x);
            return 
temp_str;
        }
        else
            return 
temp_str;
    }

    
//return the index of a giving substring if not found returns - if not found
    
public int find(final String str, final String substr)
    {
        return 
str.indexOf(substr);
    }

    
//return the index of a giving substring when found multiple times until a giving count is reached then returns the index returns - if not found
    
public int find(final String str, final String substr, final int count)
    {
        
int status ZEROindex ZERO;
        for(
int x ZEROcountx++)
        {
            
index str.indexOf(substr);
            if(
index == NEGATIVE_ONE)
                return 
NEGATIVE_ONE;
            else
                
status++;
        }
        return 
index;
    }

    
//return the index of a giving substring search in the reverse direction of the string returns - if not found
    
public int rfind( final String str, final String substr)
    {
        
int index ZEROlast_index NEGATIVE_ONE;
        
index str.indexOf(substr,ZERO);
        while( 
index != NEGATIVE_ONE )
        {
            
index str.indexOf(substrindex+1);
            if(
index != NEGATIVE_ONE)
                
last_index index;
        }
        return 
last_index;
    }

    
/*return the index of a giving substring searching in the reverse direction
      multiple times until a giving count is reach then returns the index returns -1
      if not found                                                                */
    
public int rfind( final String str, final String substrint count)
    {
        
int index ZERO;
        
ArrayList<Integernum_list = new ArrayList<Integer>();
        
index str.indexOf(substr,ZERO);
        
num_list.add(index);
        if(
count <= ZERO)
            return 
NEGATIVE_ONE;
        while( 
index != NEGATIVE_ONE )
        {
            
index str.indexOf(substrindex+1);
            if(
index != NEGATIVE_ONE)
                
num_list.add(index);
        }
        if(
count == num_list.size())
            return 
num_list.get(ZERO);
        else if(
count num_list.size())
            return 
num_list.get(num_list.size() - count);
        else
            return 
NEGATIVE_ONE;
    }

    
//returns the number of occurances of a substring in a string if none is found 0 is returned
    
public int count(final String str, final String substr)
    {
        
int count ZEROindex ZERO;
        
index str.indexOf(substr,ZERO);
        if(
index != -ONE)
            
count++;
        else
            return 
ZERO;
        while( 
index != NEGATIVE_ONE)
        {
            
index str.indexOf(substrindex+1);
            if(
index != NEGATIVE_ONE)
                
count++;
        }
        return 
count;
    }

    
//replace all occurances of a substring with a new string
    
public String replace(String str, final String sub_str, final String new_str)
    {
        return 
str.replaceAll(sub_strnew_str);
    }

    
//replace occurances of a substring with a new string to a giving count
    
public String replace(String str, final String sub_str, final String new_str, final int count)
    {
        
temp_str str;
        if(
count ZERO)
        {
            for(
int x ZEROcountx++)
            {
                
temp_str temp_str.replaceFirst(sub_strnew_str);
            }
            return 
temp_str;
        }
        else
        {
            return 
str;
        }
    }

    
//left justify a string with white spaces
    
public String ljust(String str, final int count)
    {
        
String pad EMPTY_STR;
        
int pad_length ZERO;
        if(
count str.length())
            return 
str;
        else
        {
            
pad_length count str.length();
            for(
int x 0pad_lengthx++)
                
pad += " ";
            return 
pad str;
        }
    }

    
//left justify a string with a giving character
    
public String ljust(String str, final int count, final char fill)
    {
        
String pad EMPTY_STR;
        
int pad_length ZERO;
        if(
count str.length())
            return 
str;
        else
        {
            
pad_length count str.length();
            for(
int x 0pad_lengthx++)
                
pad += fill;
            return 
pad str;
        }
    }

    
//right justify a string with white spaces
    
public String rjust(String str, final int count)
    {
        
String pad EMPTY_STR;
        
int pad_length ZERO;
        if(
count str.length())
            return 
str;
        else
        {
            
pad_length count str.length();
            for(
int x 0pad_lengthx++)
                
pad += " ";
            return 
str pad;
        }
    }

    
//right justify a string with a giving character
    
public String rjust(String str, final int count, final char fill)
    {
        
String pad EMPTY_STR;
        
int pad_length ZERO;
        if(
count str.length())
            return 
str;
        else
        {
            
pad_length count str.length();
            for(
int x 0pad_lengthx++)
                
pad += fill;
            return 
str pad;
        }
    }

    
//center a string with white spaces
    
public String center(String str, final int count)
    {
        
int pad ZERO;
        
boolean side true;
        
//if count is less then the string length there is no need to pad spaces so return the string as it is
        
if(count str.length())
            return 
str;
        
pad count str.length(); //calculate how many spacess are need to append to the string
        
for(int x ZEROpadx++)
        {
            if(
side == true//if else statment to swap padding to string
            
{
                
str " " str;
                
side false;
            }
            else
            {
                
str str " ";
                
side true;
            }
        }
        return 
str;
    }

    
//center a string with a giving character
    
public String center(String str, final int count, final char fill)
    {
        
int pad ZERO;
        
boolean side true;
        
//if count is less then the string length there is no need to pad spaces so return the string as it is
        
if(count str.length())
            return 
str;
        
pad count str.length(); //calculate how many spacess are need to append to the string
        
for(int x ZEROpadx++)
        {
            if(
side == true//if else statment to swap padding to string
            
{
                
str fill str;
                
side false;
            }
            else
            {
                
str str fill;
                
side true;
            }
        }
        return 
str;
    }

    
//returns true if the entire string is merely number else false
    
public boolean is_digit(final String str)
    {
        
temp_str digits(); //string of digits
        
int pos ZERO;
        for(
int x ZEROstr.length(); x++)
        {
            
pos temp_str.indexOf(str.charAt(x)); //check if the character is a digit
            
if(pos == NEGATIVE_ONE//if the string character is not a digit return false
                
return false;
        }
        return 
true;
    }

    
//returns true if the string is only letter a-z or A-Z else false
    
public boolean is_alpha(final String str)
    {
        
temp_str ascii_letters(); //string of letter a-z & A-Z
        
int pos ZERO;
        for(
int x ZEROstr.length(); x++)
        {
            
pos temp_str.indexOf(str.charAt(x)); //check if the character is a letter
            
if(pos == NEGATIVE_ONE//if the string character is not a letter return false
                
return false;
        }
        return 
true;
    }

    
//returns true if the string contains only letters or digits. else false
    
public boolean is_alphanum(final String str)
    {
        
temp_str ascii_letters() + digits(); //string of a-z & A-Z & 0-9
        
int pos ZERO;
        for(
int x ZEROstr.length(); x++)
        {
            
pos temp_str.indexOf(str.charAt(x)); //check if the character is a letter or number
            
if(pos == NEGATIVE_ONE//if the string character is not a letter return false
                
return false;
        }
        return 
true;
    }

    
//returns true is a string is merely lowercase letters a-z else false
    
public boolean is_lower(final String str)
    {
        
char temp_char ' ';
        for(
int x ZEROstr.length(); x++)
        {
            
temp_char Character.valueOf(str.charAt(x));
            if( 
is_alpha(temp_str))
                if(
Character.isLowerCase(temp_char))
                    continue;
                else
                    return 
false;
        }
        return 
true;
    }

    
//returns true is a string is merely uppercase letters A-Z else false
    
public boolean is_upper(final String str)
    {
        
char temp_char ' ';
        for(
int x ZEROstr.length(); x++)
        {
            
temp_char Character.valueOf(str.charAt(x));
            if( 
is_alpha(temp_str))
                if(
Character.isUpperCase(temp_char))
                    continue;
                else
                    return 
false;
        }
        return 
true;
    }

    
//returns true is a string is merely white spaces else false
    
public boolean is_space(final String str)
    {
        
char temp_char ' ';
        for(
int x ZEROstr.length(); x++)
        {
            
temp_char Character.valueOf(str.charAt(x));
            if( 
is_alpha(temp_str))
                if(
Character.isWhitespace(temp_char))
                    continue;
                else
                    return 
false;
        }
        return 
true;
    }

    
//returns true if the string starts with an uppercase letter else false
    
public boolean is_title(final String str)
    {
        if(
str.length() >= 0)
            return 
Character.isUpperCase(str.charAt(ZERO));
        else
            return 
false;
    }

     
//removes all occurrences of characters from a string from a giving string and returns
    
public String translate(final String str, final String remove_chars)
    {
        return 
str.replaceAll("[" remove_chars "]"EMPTY_STR);
    }
    
    
/*returns a ArrayList<String> with 3 items first item is the first part of
      the string second is the separator third is the last part of a string if no
      separator is found in the string the full string is the first time in the
      vector and the last two items are EMPTY_STR strings                     */
    
public ArrayList<Stringpartition(final String str, final String sep)
    {
        
array_list.clear();
        
int pos;
        
pos str.indexOf(sep); //find first occurance of separator in a string
        
if(pos != NEGATIVE_ONE//if the separator is found add sections of the string
        
{
            
array_list.add(str.substring(ZERO,pos)); //add first half of the string from to where the last separator is found
            
array_list.add(sep); //add separator
            
array_list.add(str.substring(pos sep.length(),str.length())); //add last half of the string from where the last separator was found
            
return array_list;
        }
        else
        {
            
array_list.add(str); //add full string
            
array_list.add(EMPTY_STR); //add EMPTY_STR string
            
array_list.add(EMPTY_STR); //add EMPTY_STR string
            
return array_list;
        }
    }

    
//same as partition except it looks for the separator from the end to the front of the string
    
public ArrayList<Stringrpartition(final String str, final String sep)
    {
            
array_list.clear();
        
int pos;
        
pos rfind(str,sep); //find last occurance of separator in a string
        
if(pos != NEGATIVE_ONE//if the separator is found add sections of the string
        
{
            
array_list.add(str.substring(ZERO,pos)); //add first half of the string from to where the last separator is found
            
array_list.add(sep); //add separator
            
array_list.add(str.substring(pos sep.length(),str.length())); //add last half of the string from where the last separator was found
            
return array_list;
        }
        else
        {
            
array_list.add(str); //add full string
            
array_list.add(EMPTY_STR); //add EMPTY_STR string
            
array_list.add(EMPTY_STR); //add EMPTY_STR string
            
return array_list;
        }
    }

    
/* The below functions are not part of python addon string functions */

    //return a string in reverse order
    
public String reverse_str(final String str)
    {
        
StringBuilder sb = new StringBuilder(str);
        return 
sb.reverse().toString();
    }

    
//returns a string with no vowel characters
    
public String delete_vowels(String str)
    {
        return 
translate(str"aeiou");
    }

    
//display all string elements in a ArrayList of strings in terminals only
    
public void list_print(final ArrayList<Stringa_list)
    {
        for(
int x ZEROa_list.size(); x++)
            
System.out.println(a_list.get(x).toString());
    }

    
//delete duplicate values in adjacent to each other and return the string
    
public String squeeze(String str)
    {
        
temp_str EMPTY_STR;
        final 
int STR_SIZE str.length(); //holds str length
        
for(int x ZEROSTR_SIZE-1x++) //loop through entire string
        
{
            if( 
str.charAt(x) != str.charAt(x+ONE)) //if string next character is not equal append the character to temp string
                
temp_str += String.valueOf(str.charAt(x));
        }
        final 
int TEMP_STR_SIZE temp_str.length(); //holds temp_str length
        
if( str.charAt(TEMP_STR_SIZE-ONE) != str.charAt(STR_SIZE-ONE) ) //check if the last character of str is not equal to temp_str if it is not append the last character
            
temp_str += str.charAt(STR_SIZE-ONE);
        return 
temp_str//return the squeezed string
    
}

    
//returns a string duplicated to a giving count
    
public String dupe_string(final String str, final int count)
    {
        
temp_str str;
        for(
int x ZEROcountx++)
        {
            
temp_str += str;
        }
        return 
temp_str;
    }

    
//convert a string tabs to a single space and return the string
    
public String tab_to_space(final String str)
    {
        return 
str.replaceAll("\t"" ");
    }

    
//returns a string in quotes
    
public String quote(final String str)
    {
        return 
"\"" str "\"";
    }

    
//insert a string in a string at a giving index
    
public String insert(final String str, final String insert_str, final int index)
    {
        
temp_str EMPTY_STR;
        if(
str.isEmpty() && index str.length()-ONE)
            return 
EMPTY_STR;
        else
        {
            
temp_str str.substring(ZERO,index);
            
temp_str += insert_str;
            
temp_str += str.substring(index,str.length());
            return 
temp_str;
        }
    }

    
//shuffle a strings characters and returns the string shuffled
    
public String shuffle(String str)
    {
        
temp_str EMPTY_STR;
        
Character[] carray = new Character[str.length()];
        for(
int x ZEROstr.length(); x++)
            
carray[x] = str.charAt(x);
        
Collections.shuffle(Arrays.asList(carray));
        for(
int x ZEROcarray.lengthx++)
            
temp_str += String.valueOf(carray[x]);
        return 
temp_str;
    }


    
/* retains the first occurrences of a string and then delete any duplicate
       characters and returns the string with no duplicates                 */
    
public String delete_duplicate_chars(final String str)
    {
        
temp_str EMPTY_STR;
        
Set<Stringset = new LinkedHashSet<String>();
        for(
int x ZEROstr.length(); x++)
        {
            
set.add(String.valueOf(str.charAt(x)));
        }
        
String[] array = set.toArray(new String[set.size()]);
        for(
int x ZERO< array.lengthx++)
        {
            
temp_str += array[x];
        }
        return 
temp_str;
    }

    
//return an ArrayList sorted
    
public ArrayList<Stringlist_sort(ArrayList<String>array)
    {
        
array_list = array;
        
Collections.sort(array_list);
        return 
array_list;
    }

    
/*reverse a list in ascending or descending set ascdec to true for ascending
      order or false for descending order                                     */
    
public ArrayList<Stringlist_sort(ArrayList<String>array, final boolean ascdec)
    {
        
array_list = array;
        
Collections.sort(array_list);
        if(
ascdec)
            return 
array_list;
        else
        {
            
Collections.reverse(array_list);
            return 
array_list;
        }
    }

    
//returns text contents into an ArrayList and return it
    
public ArrayList<Stringlist_loadfile(final String filename)
    {
        
array_list.clear();
        if(!
filename.isEmpty())
        {
            try
            {
                
BufferedReader in = new BufferedReader(new FileReader(filename));
                
String str;
                while ((
str in.readLine()) != null)
                    
array_list.add(str);
                
in.close();
                return 
array_list;
            }
            catch (
IOException e)
            {
                
System.err.print(e.getMessage());
                return 
array_list;
            }
        }
        else
            return 
array_list;
     }

    
//returns the line count in a file
    
public long file_line_count(final String filename)
    {
        
array_list list_loadfile(filename);
        return 
array_list.size();
    }

    
//returns a string with the current date and time
    
public String getDateTime()
    {
        
Date dt = new Date();
        return 
dt.toString();
    }

    
//returns the original ArrayList<String> with an appended ArrayList<string>
    
public ArrayList<Stringlist_append(ArrayList<StringoriginalArrayList<Stringappend)
    {
        
array_list original;
        
array_list.addAll(append);
        return 
array_list;
    }

    
//returns an ArrayList of strings in reverse order
    
public ArrayList<Stringlist_reverse(ArrayList<String> array)
    {
        
array_list = array;
        
Collections.reverse(array_list);
        return 
array_list;
    }

    
//returns a ArrayList of strings with its elements shuffled
    
public ArrayList<Stringlist_shuffle(ArrayList<String> array)
    {
        
array_list = array;
        
Collections.shuffle(array_list);
        return 
array_list;
    }

    
/*removes duplicate characters in each element from an ArrayList of strings
     and returns the ArrayList                                               */
    
public ArrayList<Stringlist_remove_duplicates(ArrayList<String> array)
    {
        
array_list = array;
        for(
int x ZEROarray_list.size(); x++)
            
array_list.set(xdelete_duplicate_chars(String.valueOf(array_list.get(x))));
        return 
array_list;
    }

    
//returns the numbers of string matches in an ArrayList of strings
    
public int list_count(ArrayList<String> array, String search)
    {
        
array_list = array;
        
int count 0;
        for(
int x ZEROarray_list.size(); x++)
        {
            if(
search.equals(array_list.get(x)))
                
count++;
        }
        return 
count;
    }

    
//returns an ArrayList of strings with all lowercase strings
    
public ArrayList<Stringlist_tolower(ArrayList<String>array)
    {
        
array_list = array;
        for(
int x ZEROarray_list.size(); x++)
            
array_list.set(xlower(String.valueOf(array_list.get(x))));
        return 
array_list;
    }

    
//returns an ArrayList of strings with all uppercase strings
    
public ArrayList<Stringlist_toupper(ArrayList<String>array)
    {
        
array_list = array;
        for(
int x ZEROarray_list.size(); x++)
            
array_list.set(xupper(String.valueOf(array_list.get(x))));
        return 
array_list;
    }

    
//returns an ArrayList capitalize each inception character of a string
    
public ArrayList<Stringlist_title(ArrayList<String>array)
    {
        
array_list = array;
        for(
int x ZEROarray_list.size(); x++)
            
array_list.set(xtitle(String.valueOf(array_list.get(x))));
        return 
array_list;
    }

    
//returns an ArrayList with each character in elements with swapped cases
    
public ArrayList<Stringlist_swapcase(ArrayList<String>array)
    {
        
array_list = array;
        for(
int x ZEROarray_list.size(); x++)
            
array_list.set(xswapcase(String.valueOf(array_list.get(x))));
        return 
array_list;
    }

    
//returns an ArrayList with each inception of a word capitalize
    
public ArrayList<Stringlist_capwords(ArrayList<String>array)
    {
        
array_list = array;
        for(
int x ZEROarray_list.size(); x++)
            
array_list.set(xtitle(array_list.get(x)));
        return 
array_list;
    }

    
//returns an ArrayList striping whites spaces from each element both left and right of string
    
public ArrayList<Stringlist_strip(ArrayList<String>array)
    {
        
array_list = array;
        for(
int x ZEROarray_list.size(); x++)
            
array_list.set(xstrip(String.valueOf(array_list.get(x))));
        return 
array_list;
    }

    
//returns an ArrayList striping white spaces from left side of element strings
    
public ArrayList<Stringlist_lstrip(ArrayList<String>array)
    {
        
array_list = array;
        for(
int x ZEROarray_list.size(); x++)
            
array_list.set(xlstrip(String.valueOf(array_list.get(x))));
        return 
array_list;
    }

    
//returns an ArrayList striping white spaces from right side of element strings
    
public ArrayList<Stringlist_rstrip(ArrayList<String>array)
    {
        
array_list = array;
        for(
int x ZEROarray_list.size(); x++)
            
array_list.set(xrstrip(String.valueOf(array_list.get(x))));
        return 
array_list;
    }

    
//returns an ArrayList of strings centered with white spaces to a giving count
    
public ArrayList<Stringlist_center(ArrayList<String>array, final int count)
    {
        
array_list = array;
        for(
int x ZEROarray_list.size(); x++)
            
array_list.set(xcenter(String.valueOf(array_list.get(x)),count));
        return 
array_list;
    }

    
//returns an ArrayList of strings centered with a giving character fill to a giving count
    
public ArrayList<Stringlist_center(ArrayList<String>array, final int count, final char fill)
    {
        
array_list = array;
        for(
int x ZEROarray_list.size(); x++)
            
array_list.set(xcenter(String.valueOf(array_list.get(x)),count,fill));
        return 
array_list;
    }

    
//returns an ArrayList of strings left justify with white spaces to a giving count
    
public ArrayList<Stringlist_ljust(ArrayList<String>array, final int count)
    {
        
array_list = array;
        for(
int x ZEROarray_list.size(); x++)
            
array_list.set(xljust(String.valueOf(array_list.get(x)),count));
        return 
array_list;
    }

    
//returns an ArrayList of strings left justify with a giving character to a giving count
    
public ArrayList<Stringlist_ljust(ArrayList<String>array, final int count, final char fill)
    {
        
array_list = array;
        for(
int x ZEROarray_list.size(); x++)
            
array_list.set(xljust(String.valueOf(array_list.get(x)),countfill));
        return 
array_list;
    }

    
//returns an ArrayList of strings right justify with white spaces to a giving count
    
public ArrayList<Stringlist_rjust(ArrayList<String>array, final int count)
    {
        
array_list = array;
        for(
int x ZEROarray_list.size(); x++)
            
array_list.set(xrjust(String.valueOf(array_list.get(x)),count));
        return 
array_list;
    }

    
//returns an ArrayList of strings right justify with a giving character to a giving count
    
public ArrayList<Stringlist_rjust(ArrayList<String>array, final int count, final char fill)
    {
        
array_list = array;
        for(
int x ZEROarray_list.size(); x++)
            
array_list.set(xrjust(String.valueOf(array_list.get(x)),countfill));
        return 
array_list;
    }

    
//returns an ArrayList of strings left justify with 0's to a giving count
    
public ArrayList<Stringlist_zfill(ArrayList<String>array, final int count)
    {
        
array_list = array;
        for(
int x ZEROarray_list.size(); x++)
            
array_list.set(xcenter(String.valueOf(array_list.get(x)),count));
        return 
array_list;
    }

    
//returns an ArrayList of strings removing a giving set of characters
    
public ArrayList<Stringlist_translate(ArrayList<String>array, final String remove_chars)
    {
        
array_list = array;
        for(
int x ZEROarray_list.size(); x++)
            
array_list.set(xtranslate(String.valueOf(array_list.get(x)), remove_chars));
        return 
array_list;
    }

    
//returns an ArrayList of strings removing vowel characters
    
public ArrayList<Stringlist_delete_vowels(ArrayList<String>array)
    {
        
array_list = array;
        for(
int x ZEROarray_list.size(); x++)
            
array_list.set(xdelete_vowels(String.valueOf(array_list.get(x))));
        return 
array_list;
    }

    
//removes duplicate elements from an ArrayList of strings and returns the ArrayList
    
public ArrayList<Stringlist_remove_duplicate_elements(ArrayList<String> array)
    {
        
array_list = array;
        for(
int x ZERO< array.size(); x++)
        {
            
array_list.set(xdelete_duplicate_chars(String.valueOf(array_list.get(x))));
        }
        return 
array_list;
    }

    
//returns true if every element in an ArrayList of strings contains only letters a-z or A-Z
    
public boolean list_isalapha(ArrayList<String> array)
    {
        
array_list = array;
        for(
int x ZEROarray_list.size(); x++)
        {
            if(
is_alpha(String.valueOf(array_list.get(x))))
                continue;
            else
                return 
false;
        }
        return 
true;
    }

    
//returns true if every element in an ArrayList of strings contains only digits 0-9
    
public boolean list_isdigit(ArrayList<String> array)
    {
        
array_list = array;
        for(
int x ZEROarray_list.size(); x++)
        {
            if(
is_digit(String.valueOf(array_list.get(x))))
                continue;
            else
                return 
false;
        }
        return 
true;
    }

    
//returns true if every element in an ArrayList of strings contains only digits 0-9 and letters a-z or A-Z
    
public boolean list_isalphanum(ArrayList<String> array)
    {
        
array_list = array;
        for(
int x ZEROarray_list.size(); x++)
        {
            if(
is_alphanum(String.valueOf(array_list.get(x))))
                continue;
            else
                return 
false;
        }
        return 
true;
    }


    
//returns true if every element in an ArrayList of strings is all lowercase letters
    
public boolean list_islower(ArrayList<String> array)
    {
        
array_list = array;
        for(
int x ZEROarray_list.size(); x++)
        {
            if(
is_lower(String.valueOf(array_list.get(x))))
                continue;
            else
                return 
false;
        }
        return 
true;
    }


    
//returns true if every element in an ArrayList of strings is all uppercase letters
    
public boolean list_isupper(ArrayList<String> array)
    {
        
array_list = array;
        for(
int x ZEROarray_list.size(); x++)
        {
            if(
is_upper(String.valueOf(array_list.get(x))))
                continue;
            else
                return 
false;
        }
        return 
true;
    }


    
//returns true if every element in an ArrayList of strings contains only white spaces
    
public boolean list_isspace(ArrayList<String> array)
    {
        
array_list = array;
        for(
int x ZEROarray_list.size(); x++)
        {
            if(
is_space(String.valueOf(array_list.get(x))))
                continue;
            else
                return 
false;
        }
        return 
true;
    }


    
//returns true if every element in an ArrayList of strings starts with a capital letter
    
public boolean list_istitle(ArrayList<String> array)
    {
        
array_list = array;
        for(
int x ZEROarray_list.size(); x++)
        {
            if(
is_title(String.valueOf(array_list.get(x))))
                continue;
            else
                return 
false;
        }
        return 
true;
    }

Visit this user's website Find all posts by this user
Quote this message in a reply
08-27-2010, 05:23 AM
Post: #2
RE: Port of Python Class made in C++ to JAVA
Just a quick question. Was this harder in C++ or Java? I'd assume C++ because Java has a huge API

"Character is determined more by the lack of certain experiences than by those one has had."
Friedrich Nietzsche
Visit this user's website Find all posts by this user
Quote this message in a reply
08-27-2010, 08:57 PM
Post: #3
RE: Port of Python Class made in C++ to JAVA
Yea C++ and because Java is almost the same you can pretty much just copy in paste. Somethings I change because java had built in shortcuts
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: