Skip to content

Instantly share code, notes, and snippets.

@sharifulislam52
Created March 1, 2018 16:44
Show Gist options
  • Save sharifulislam52/bbcde15e291082971474c489abcb84dc to your computer and use it in GitHub Desktop.
Save sharifulislam52/bbcde15e291082971474c489abcb84dc to your computer and use it in GitHub Desktop.
/**
* @author Shariful Islam
* From : 11/01/2018
*/
/**
* java_po
* -> array_po
* ---> checkArrays (all data)
* ---> arrangement (String)
*/
public class java_po {
static class array_po{
static class checkArrays{
/**
* Methods :
* isEmptyArray()
* Input Type : Array (boolean,byte,char,short,int,long,float,double,String)
* Return Type : boolean
*/
/**
* Description :
* * using "isEmptyArray()" method we can check any data type array is the array empty or not.
* * if the array empty it will return "true"
* * else it will return "false"
* Parameters :
* * It takes only one parameter. The array. Which we want to check.
* * Array Type : any data type.
*/
/**
* for boolean
*/
public boolean isEmptyArray(boolean array[]){
for (boolean e : array) {
if (e != false) {return false;}
}
return true;
}
/**
* for Byte
*/
public boolean isEmptyArray(byte array[]){
for (byte e : array) {
if (e != 0) {return false;}
}
return true;
}
/**
* for char
*/
public boolean isEmptyArray(char array[]){
for (char e : array) {
if (e != '\u0000') {return false;}
}
return true;
}
/**
* for short
*/
public boolean isEmptyArray(short array[]){
for (short e : array) {
if (e != 0) {return false;}
}
return true;
}
/**
* for integer
*/
public boolean isEmptyArray(int array[]){
for (int e : array) {
if (e != 0) {return false;}
}
return true;
}
/**
* for long
*/
public boolean isEmptyArray(long array[]){
for (long e : array) {
if (e != 0) {return false;}
}
return true;
}
/**
* for float
*/
public boolean isEmptyArray(float array[]){
for (float e : array) {
if (e != 0.0) {return false;}
}
return true;
}
/**
* for double
*/
public boolean isEmptyArray(double array[]){
for (double e : array) {
if (e != 0.0) {return false;}
}
return true;
}
/**
* for String
*/
public boolean isEmptyArray(String array[]){
for (String e : array) {
if (e != null) {return false;}
}
return true;
}
}
static class arrangement{
/**
* Methods :
* po_arrange(String start_element, String custom_array[],String standard_array[])
* * Input Type : String;
* * Retun Type : String;
*/
/**
* Method Name : po_arrange()
* Return Type : String [for String]
* Description : The 'po_arrange' method arrange any data from array. Suppose we want to arrange our week from Monday it help to do this.
* Parameters : This method takes three parameters.
* * 1. start_element. Example : Monday [for week]
* * * Type : String
* * 2. custom_array. Which we want to arrange.
* * * Type : String Array
* * 3. standard_array. Which we want to follow for arrange.
* * * Type : String Array
*/
StringBuffer element_without_null = new StringBuffer();
String keep_data_from_buffer, check_first_elemnt="yes";
int start_element_number, keep_first_element_position;
/**
* Method for String
*/
public String po_arrange(String start_element, String custom_array[],String standard_array[]){
String seven_days[] = new String[standard_array.length], days_with_null[] = new String[standard_array.length];
System.arraycopy(standard_array, 0, seven_days, 0, standard_array.length);
/**
* get start day position
*/
for (int i=0; i<standard_array.length; i++){
if (start_element.equals(seven_days[i])){
start_element_number = i;
break;
}
}
/**
* get arrange days with null value
*/
for (int j = 0; j<standard_array.length; j++){
if ((j+start_element_number)>(standard_array.length-1)){
keep_first_element_position = j+start_element_number-standard_array.length;
}
else {keep_first_element_position = j+start_element_number;}
for (String custom_element : custom_array) {
if(custom_element != null){
if (custom_element.equals(seven_days[keep_first_element_position])) {
days_with_null[j] = custom_element;
}
}
}
}
/**
* remove the null values
* and append days into stringBuffer
*/
for(int k=0; k<standard_array.length; k++){
if(days_with_null[k] != null){
if(check_first_elemnt.equals("yes")){
element_without_null.append(days_with_null[k]);
}
else{
element_without_null.append(", ");
element_without_null.append(days_with_null[k]);
}
check_first_elemnt = "no";
}
days_with_null[k] = null;
}
keep_data_from_buffer = element_without_null.toString(); /* keep arrange days from stringBuffer */
element_without_null.delete(0,element_without_null.length()); /* delete stringBuffer (re-active) */
check_first_elemnt = "yes"; /* re-active */
return keep_data_from_buffer; /* return arrange values */
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment