public int compare(Object o1, Object o2) {
   AddressBookEntry address1 = (AddressBookEntry) o1;
   AddressBookEntry address2 = (AddressBookEntry) o2;
   if (address1 == null || address2 == null) {
     return 0;
   }
   return address1.getName().toLowerCase().compareTo(address2.getName().toLowerCase());
 }
  /**
   * This method is called on onTextChangeListener() of the search box. This method will show only
   * the filtered contacts to the user.
   *
   * @param string
   */
  private void searchContactlist(String string) {
    String searchString = string.trim();
    if (!TextUtils.isEmpty(searchString)) {
      inviteVector.removeAllElements();
      String validatedNum = Validator.validatePhoneString(searchString);
      if (validatedNum != null) {
        boolean isValidLength =
            validatedNum.length() - (AppState.getUserDetails().getCountryCode().length() + 1)
                    >= CharLimit.PHONE_NUMBER_MIN
                && validatedNum.length() <= CharLimit.PHONE_NUMBER_MAX;
        String msisdn = isValidLength ? UNKNOWN_CONTACT_INVITE_MESSAGE : UNKNOWN_CONTACT_NAME;
        String name = isValidLength ? validatedNum : searchString;
        String phone = isValidLength ? validatedNum : null;
        AddressBookEntry addressBookentry =
            new AddressBookEntry(UNKNOWN_CONTACT_ID, phone, name, msisdn, false);
        inviteVector.addElement(addressBookentry);
      }

      Vector list = AddressBookList.getInstance().getInviteList();
      Enumeration enums = list.elements();
      while (enums.hasMoreElements()) {
        AddressBookEntry entry = (AddressBookEntry) enums.nextElement();
        String contactName = entry.getName().toUpperCase();
        String contactNumber = entry.getMsisdn();
        searchString = searchString.toUpperCase();
        if (contactName.indexOf(searchString) >= 0 || contactNumber.indexOf(searchString) >= 0) {
          inviteVector.addElement(entry);
        }
      }
    } else {
      inviteVector.removeAllElements();
      Vector list = AddressBookList.getInstance().getInviteList();
      Enumeration enums = list.elements();
      while (enums.hasMoreElements()) {
        AddressBookEntry entry = (AddressBookEntry) enums.nextElement();
        inviteVector.addElement(entry);
      }
    }
    // flushReplace();
    revalidate();
    inviteList.setShouldCalcPreferredSize(true);
  }
    public Component getListCellRendererComponent(
        List list, Object value, int index, boolean isSelected) {
      if (value != null) {
        addressEntry = (AddressBookEntry) value;

        Log.v(TAG, "AddressBookEntry: " + addressEntry);

        Log.v(TAG, "Index is:" + index);
        onFocusLbl.getStyle().setBgTransparency(20, true);

        Container namephnumContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
        namephnumContainer.getStyle().setPadding(Component.LEFT, 3, true);
        namephnumContainer.getStyle().setPadding(Component.TOP, 5, true);
        namephnumContainer.getStyle().setPadding(Component.BOTTOM, 8, true);

        Label contactName = new Label(addressEntry.getName());
        contactName.getStyle().setBgTransparency(0, true);
        contactName.getStyle().setFgColor(ColorCodes.selectContactNameGrey, true);
        contactName.getStyle().setPadding(Component.BOTTOM, 0, true);

        contactName.getSelectedStyle().setFont(Fonts.MONO_MEDIUM, true);
        contactName.getStyle().setFont(Fonts.MONO_MEDIUM, true);
        contactName.getSelectedStyle().setBorder(null, true);
        contactName.setPreferredSize(
            new Dimension(
                (Display.getInstance().getDisplayWidth() - inviteImage.getWidth() - 25), 30));

        Label phoneNum = new Label(addressEntry.getMsisdn());
        phoneNum.getStyle().setBgTransparency(0, true);
        phoneNum.getStyle().setPadding(Component.TOP, 0, true);
        phoneNum.getSelectedStyle().setBorder(null, true);
        phoneNum.getSelectedStyle().setFont(Fonts.MONO_SMALL, true);
        phoneNum.getStyle().setFont(Fonts.MONO_SMALL, true);
        phoneNum.getStyle().setFgColor(ColorCodes.selectContactNumberGrey);

        namephnumContainer.addComponent(contactName);
        namephnumContainer.addComponent(phoneNum);

        inviteButton = new Button(inviteImage);
        inviteButton.getStyle().setBgTransparency(0, true);
        inviteButton.getSelectedStyle().setBgTransparency(0, true);
        inviteButton.getPressedStyle().setBgTransparency(0, true);
        inviteButton.getPressedStyle().setBorder(null, true);
        inviteButton.getStyle().setBorder(null, true);
        inviteButton.getSelectedStyle().setBorder(null, true);
        inviteButton.getStyle().setAlignment(CENTER);

        tickMark = new Label(sentInviteImage);
        tickMark.getStyle().setAlignment(Component.CENTER);
        tickMark.getStyle().setBgTransparency(0, true);
        tickMark.getSelectedStyle().setBgTransparency(0, true);
        tickMark.getPressedStyle().setBgTransparency(0, true);
        tickMark.getPressedStyle().setBorder(null, true);
        tickMark.getStyle().setBorder(null, true);
        tickMark.getSelectedStyle().setBorder(null, true);
        tickMark.getStyle().setAlignment(CENTER);
        tickMark.getStyle().setPadding(Component.RIGHT, 30, true);

        mainContainer = new Container(new BorderLayout());
        mainContainer
            .getStyle()
            .setBorder(
                Border.createCompoundBorder(
                    null,
                    Border.createEtchedRaised(
                        ColorCodes.selectContactSeperator, ColorCodes.selectContactSeperatorShadow),
                    null,
                    null),
                true);

        mainContainer.addComponent(BorderLayout.WEST, namephnumContainer);
        if (inviteButton.getParent() == null) {
          mainContainer.addComponent(BorderLayout.EAST, inviteButton);
        }

        getStyle().setPadding(Component.RIGHT, 0, true);
        getUnselectedStyle().setPadding(Component.RIGHT, 0, true);
        getPressedStyle().setPadding(Component.RIGHT, 0, true);
        getSelectedStyle().setPadding(Component.RIGHT, 0, true);

        if (addressEntry.isInvited()) {
          mainContainer.removeComponent(inviteButton);
          mainContainer.addComponent(BorderLayout.EAST, tickMark);
        }
      }

      return mainContainer;
    }