Tuesday, 9 July 2013

list compare

import java.util.ArrayList;

public class SampleList {
    public static void main(String[] args) {
         ArrayList<String> arl=new ArrayList<String>();
       
       
         ArrayList<String> first=new ArrayList<String>();
         ArrayList<String> second=new ArrayList<String>();
       
         first.add("checkthis");
         first.add("cat");
         first.add("dog");
         first.add("mat");
         second.add("checkthis");
         second.add("hello");
         second.add("haio");
         second.add("nameghj");
       
       
       
         for (String a : first)
            {
                for (String b : second)
                {
                    if (a.equals(b))
                    {
                        System.out.println("Equals " + a);
                       
                    }
                }
            }
       
       
       
       
       
       
         if(second.contains("checkthis"))
             System.out.println("true");
         else
             System.out.println("false");
       
         ArrayList<String> dup=new ArrayList<String>();
         String name = "abcd";
         String test ;
       
         arl.add("namratha");
         arl.add("sonu");
       
         if(arl.contains("namratha"))
         {
             System.out.println("exe");
             arl.remove("namratha");
             arl.add("namratha");
         }
       
       
         for(String sample : arl)
         {
             System.out.println("list items are "+sample);
         }
       
         dup.addAll(arl);
         for(String dupsam : dup)
         {
             System.out.println("Dup list "+dupsam);
         }
       
         if(!(name.equals(null))){
             System.out.println("executed");
         }
//         try {
//            if(test.equals(null))
//             {
//                 System.out.println("test is null");
//               
//             }
//             else
//             {
//                 System.out.println("space is executed");
//             }
//        } catch (NullPointerException e) {
//            // TODO Auto-generated catch block
//            e.printStackTrace();
//        }
       
       
       
       
    }

}



example 2 :
package com.sam;

import java.util.Collection;
import java.util.ArrayList;
import java.util.Arrays;

public class listcompare {
    public static void main(String[] args) {
        Collection listOne = new ArrayList(Arrays.asList("milan", "dingo",
                "elpha", "hafil", "meat", "iga", "neeta.peeta"));
        Collection listTwo = new ArrayList(Arrays.asList("hafil", "iga",
                "binga", "mike", "dingo"));
        listOne.retainAll(listTwo);
        System.out.println("********************"+listOne);
       
       
        //my trial
       
       
        Collection first = new ArrayList<>();
        Collection second = new ArrayList<>();
        first.add("check");
        first.add("conn");
        first.add("dog");
       
        second.add("jkl");
        second.add("check");
        second.add("name");
       
        if(first.retainAll(second))
            System.out.println("first list "+first);
        System.out.println("second list "+second);
       
        System.out.println("first list after "+first);
       
       
    }
}



example 3
package com.sam;

import java.util.*;

public class compareobj {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        List<String> al1 = new ArrayList();
        al1.add("a1");
        al1.add("a2");
        al1.add("a3");
        al1.add("a5");
        al1.add("a6");
        List<String> al2 = new ArrayList();
        al2.add("a1");
        al2.add("a2");
        al2.add("a3");
        al2.add("a4");
       
       

        for (Object objList : al1) {
            if (al2.contains(objList)) {
                System.out.println("print same "+al2.toString());
                al2.remove(objList);
            }
            else
            {
                System.out.println("diff are "+al2);
            }
        }
        System.out.println("length" + al2.size());
        System.out.println("Value in list" + al2);

    }

}

Sunday, 30 June 2013

Country Codes

CS - Czechoslovakia
BE - Belgium
ET - Ethiopia
HU - Hungary
IT - Italy
LT - Lithuania
LV - Latvia
PL - Poland
RO - Romania
RU - Russian Federation
SK - Slovak Republic
UK - United Kingdom
NL - Netherlands
SV - El Salvador

Tuesday, 18 June 2013

OnClickListener for the item in the expandable listview

public void onGroupExpand(int groupPosition) {
        try {

            if (groupPosition == 1) {

              //Do your action
            }

        } catch (Exception e) {
            e.printStackTrace();

        }
    }

Thursday, 2 May 2013

Sequence Diagram imp points

Solid arrows with full heads are synchronous calls, solid arrows with stick heads are asynchronous calls and dashed arrows with stick heads are return messages
A message sent from outside the diagram can be represented by a message originating from a filled-in circle (found message in UML) or from a border of the sequence diagram (gate in UML).

As with all UML diagrams, comments are shown in a rectangle with a folded-over corner :

UML sequence diagram with a comment.

To relate the comment to whatever diagram elements it is about, connect them with dashed lines.


Only class messages (e.g. shared or static methods in some programming languages) can be sent to a class. Note that the text of a class is not underlined, which is how you can distinguish it from an object.

Tuesday, 16 April 2013

Spinner Hint Example

package com.example.spinnerhint;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.BaseAdapter;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
import android.widget.TextView;

public class MainActivity extends Activity {

    private String TAG = "SpinnerHint";

    private Spinner typeSpinner;

    private LayoutInflater mInflator;
    private boolean selected;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initUI();
    }

    private void initUI() {
        selected = false;
        typeSpinner = (Spinner) findViewById(R.id.id_type_spinner);
        typeSpinner.setAdapter(typeSpinnerAdapter);
        typeSpinner.setOnItemSelectedListener(typeSelectedListener);
        typeSpinner.setOnTouchListener(typeSpinnerTouchListener);
        mInflator = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
        Log.d(TAG, "UI Initialized");
    }

    private SpinnerAdapter typeSpinnerAdapter = new BaseAdapter() {

        private TextView text;
        private String[] data = { "Selection 1", "Selection 2", "Selection 3" };
        private int count = 3;

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = mInflator.inflate(R.layout.row_spinner, null);
            }
            text = (TextView) convertView.findViewById(R.id.spinnerTarget);
            if (!selected) {
                text.setText("Please select a value");
            } else {
                text.setText(data[position]);
            }
            return convertView;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public Object getItem(int position) {
            return data[position];
        }

        @Override
        public int getCount() {
            return count;
        }

        public View getDropDownView(int position, View convertView,
                ViewGroup parent) {
            if (convertView == null) {
                convertView = mInflator.inflate(
                        android.R.layout.simple_spinner_dropdown_item, null);
            }
            text = (TextView) convertView.findViewById(android.R.id.text1);
            text.setText(data[position]);
            return convertView;
        };
    };

    private OnItemSelectedListener typeSelectedListener = new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view,
                int position, long id) {
            Log.d(TAG, "user selected : "
                    + typeSpinner.getSelectedItem().toString());

        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    };

    private OnTouchListener typeSpinnerTouchListener = new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            selected = true;
            ((BaseAdapter) typeSpinnerAdapter).notifyDataSetChanged();
            return false;
        }
    };

}


Layout(activity_main)
-------------
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="3dip"
            android:text="Spinner" >
        </TextView>

        <Spinner
            android:id="@+id/id_type_spinner"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/textView2"
            android:layout_below="@+id/textView2"
            android:layout_marginTop="3dip" >
        </Spinner>
    </RelativeLayout>

</RelativeLayout>


Row_spinner.xml
------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/spinnerTarget"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="left"
        android:paddingBottom="3dip"
        android:paddingLeft="6dip"
        android:paddingRight="6dip"
        android:paddingTop="3dip"
        android:text="TextView"
        android:textColor="#000000"
        android:textSize="16dp" >
    </TextView>

</LinearLayout>

Monday, 8 April 2013

Basic Java String Operations(How to remove,include double quotes..etc)

public class Checkstring {
    public static void main(String[] args) {
         
        StringBuffer buffer = new StringBuffer();
       
        String name = "Name";
        String namevalue = "xxx";
       
        buffer.append("<string name = "  +"\""+name+"\""  +">"+namevalue.trim()+"</string>");
        System.out.println("here output is "+buffer.toString());
       
       
        String s = "test" + "/" + "test2";
       
        String sampledoublequote =  "Luni";
       
        System.out.println("test here "+sampledoublequote.replaceAll("^\"|\"$", ""));
       
       
        String s1 =  "\"" +"out"+  "\"";
        System.out.println(s);
        System.out.println("double quotes "+s1);
        String testcolon = "namratha;namratha";
        System.out.println("Test colon "+testcolon.replace(";", ""));
       
       
       
       
//        String addQuotes(String in ) {
//            return "\"" + in + "\"";
//            }

    }

}

Monday, 1 April 2013

Android Spinner which displays list of countries where countries are displayed using java locale

package com.example.spinnercountries;

import java.util.ArrayList;

import java.util.Collections;
import java.util.Locale;

import android.os.Bundle;
import android.app.Activity;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

public class MainActivity extends Activity {

    private Spinner country;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        country = (Spinner) findViewById(R.id.spinner1);

        Locale[] locales = Locale.getAvailableLocales();
        ArrayList<String> countries = new ArrayList<String>();
        for (Locale locale : locales) {
            String country = locale.getDisplayCountry();
            if (country.trim().length() > 0 && !countries.contains(country)) {
                countries.add(country);
            }
        }
        Collections.sort(countries);
        for (String country : countries) {
            System.out.println(country);
        }

        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_item, countries);
        // set the view for the Drop down list
        dataAdapter
                .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        // set the ArrayAdapter to the spinner
        country.setAdapter(dataAdapter);
        country.setSelection(37);

        System.out.println("# countries found: " + countries.size());

    }

}

Activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <Spinner
        android:id="@+id/spinner1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="33dp" />

</RelativeLayout>


Sample Output
-----------------------------------

Pass a HashMap from Angular Client to Spring boot API

This example is for the case where fileData is very huge and in json format   let map = new Map<string, string>()      map.set(this.ge...