Logo Search packages:      
Sourcecode: jenkins-trilead-ssh2 version File versions  Download package

String [] com::trilead::ssh2::Connection::removeDuplicates ( String[]  list ) [inline, private]

Removes duplicates from a String array, keeps only first occurence of each element. Does not destroy order of elements; can handle nulls. Uses a very efficient O(N^2) algorithm =)

Parameters:
lista String array.
Returns:
a cleaned String array.

Definition at line 1098 of file Connection.java.

Referenced by setClient2ServerCiphers(), setClient2ServerMACs(), setServer2ClientCiphers(), setServer2ClientMACs(), and setServerHostKeyAlgorithms().

      {
            if ((list == null) || (list.length < 2))
                  return list;

            String[] list2 = new String[list.length];

            int count = 0;

            for (int i = 0; i < list.length; i++)
            {
                  boolean duplicate = false;

                  String element = list[i];

                  for (int j = 0; j < count; j++)
                  {
                        if (((element == null) && (list2[j] == null)) || ((element != null) && (element.equals(list2[j]))))
                        {
                              duplicate = true;
                              break;
                        }
                  }

                  if (duplicate)
                        continue;

                  list2[count++] = list[i];
            }

            if (count == list2.length)
                  return list2;

            String[] tmp = new String[count];
            System.arraycopy(list2, 0, tmp, 0, count);

            return tmp;
      }

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index