python748 / alternate-java-bridge-library

Automatically exported from code.google.com/p/alternate-java-bridge-library
Apache License 2.0
0 stars 0 forks source link

Alphabetize() method for DoubleList and/or ListPicker - ALREADY DONE, PLEASE ADD TO BRIDGE #155

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I have created a few helper classes in my baseform, but it would be a lot 
better if they were adapted to the bridge as a method in doublelist(and I could 
see this being useful in listpicker too, but not entirely necessary).

There's also a alphabetize method for arraylist.  Super simple, but would be 
nice if added as a method for ArrayList<String>

public ArrayList<String> AlphabetizeArrayList(ArrayList<String> array) {
        java.util.Collections.sort(array);
        return array;
    }

    public DoubleList AlphabetizeDoubleListByListOne(DoubleList doubleList) {
        int size = doubleList.size();

        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

        //This for loop adds the values from the doublelist to this nameValuePair list for easy sorting.
        //We do this to link together the items from the doublelist
        for (int i =0; i < size; i++) {
            nameValuePairs.add(new BasicNameValuePair((doubleList.get(i)[0].toString()), (doubleList.get(i)[1]).toString()));
        }

        //Compare the lists while keeping the values paired together
        Comparator<NameValuePair> comp = new Comparator<NameValuePair>() {        
            public int compare(NameValuePair p1, NameValuePair p2) {
              return p1.getName().compareTo(p2.getName());
            }
        };

        // and then
        Collections.sort(nameValuePairs, comp);

        doubleList.clearDoubleList();

        //Now we have our sorted list in the form of "nameValuePairs"
        //We need to convert it to a doublelist
        for (int j=0; j < size; j++) {
            NameValuePair nvp = nameValuePairs.get(j);
            String object1 = nvp.getName();
            String object2 = nvp.getValue();

            doubleList.add(object1, object2);
        }
        return doubleList;
    }

    public DoubleList AlphabetizeDoubleListByListTwo(DoubleList doubleList) {
        int size = doubleList.size();

        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

        //This for loop adds the values from the doublelist to this nameValuePair list for easy sorting.
        //We do this to link together the items from the doublelist
        for (int i =0; i < size; i++) {
            nameValuePairs.add(new BasicNameValuePair((doubleList.get(i)[1].toString()), (doubleList.get(i)[0]).toString()));
        }

        //Compare the lists while keeping the values paired together
        Comparator<NameValuePair> comp = new Comparator<NameValuePair>() {       
            public int compare(NameValuePair p1, NameValuePair p2) {
              return p1.getName().compareTo(p2.getName());
            }
        };

        // and then
        Collections.sort(nameValuePairs, comp);

        doubleList.clearDoubleList();

        //Now we have our sorted list in the form of "nameValuePairs"
        //We need to convert it to a doublelist
        for (int j=0; j < size; j++) {
            NameValuePair nvp = nameValuePairs.get(j);
            String object2 = nvp.getName();
            String object1 = nvp.getValue();

            doubleList.add(object1, object2);
        }
        return doubleList;
    }

Original issue reported on code.google.com by bric...@gmail.com on 14 May 2013 at 3:38

GoogleCodeExporter commented 8 years ago
Also please add the following methods that I found lacking that will be helpful 
for the future:

DoubleListGetStringArrayList(DoubleList dl, int oneortwo) {
            ArrayList<String> tempArray1 = new ArrayList<String>();
        ArrayList<String> tempArray2 = new ArrayList<String>();
        tempArray1 = dl.getStringList(1);
        tempArray2 = dl.getStringList(2);

        int arraySize = dl.size();
        String[] list1 = new String[arraySize];
        String[] list2 = new String[arraySize];

        tempArray1.toArray(list1);
        tempArray2.toArray(list2);

                if (oneortwo == 1)
                    return list1;
                else if (oneortwo ==2)
                    return list2;
}

Original comment by bric...@gmail.com on 15 May 2013 at 2:05

GoogleCodeExporter commented 8 years ago
This has been done, although I shortened a bit of what you had.

The alphabetize methods are in the Lists class. 

Lists.alphabetize(ArrayList<String> list); - This will return the alphabetized 
list.
Lists.alphabetizeByFirst(DoubleList list); - This will return the doublelist 
sorted by the first list.
Lists.alphabetizeBySecond(DoubleList list); - Same as above, only sorts by 
second list.

These are in the jar now, if you update the jar file. However, I'm going to 
consolidate the doublelist alphabetizers to one method instead of having two.

I added the getListAsStringArray(int list) to the DoubleList class, but this 
wasnt in the jar when I last updated the server. It'll be there next time I do.

Original comment by IMPINC...@gmail.com on 16 May 2013 at 12:28

GoogleCodeExporter commented 8 years ago
Also, contributions should be done through bitbucket;
https://bitbucket.org/RyanBis/altbridge

Original comment by IMPINC...@gmail.com on 16 May 2013 at 1:00

GoogleCodeExporter commented 8 years ago

Original comment by IMPINC...@gmail.com on 30 May 2013 at 12:43