Example usage for java.lang CharSequence charAt

List of usage examples for java.lang CharSequence charAt

Introduction

In this page you can find the example usage for java.lang CharSequence charAt.

Prototype

char charAt(int index);

Source Link

Document

Returns the char value at the specified index.

Usage

From source file:dkpro.similarity.algorithms.lexical.string.LevenshteinComparator.java

private int computeLevenshteinDistance(CharSequence str1, CharSequence str2) {
    int[][] distance = new int[str1.length() + 1][str2.length() + 1];

    for (int i = 0; i <= str1.length(); i++) {
        distance[i][0] = i;/*from   w  ww.  j a  va  2s. c om*/
    }
    for (int j = 0; j <= str2.length(); j++) {
        distance[0][j] = j;
    }

    for (int i = 1; i <= str1.length(); i++) {
        for (int j = 1; j <= str2.length(); j++) {
            distance[i][j] = minimum(distance[i - 1][j] + 1, distance[i][j - 1] + 1,
                    distance[i - 1][j - 1] + ((str1.charAt(i - 1) == str2.charAt(j - 1)) ? 0 : 1));
        }
    }

    return distance[str1.length()][str2.length()];
}

From source file:org.openqa.selendroid.server.model.AndroidNativeElement.java

protected void send(CharSequence string) {
    int currentIndex = 0;

    instrumentation.waitForIdleSync();/* w  w w . jav a 2s. c  o m*/

    while (currentIndex < string.length()) {
        char currentCharacter = string.charAt(currentIndex);
        if (AndroidKeys.hasAndroidKeyEvent(currentCharacter)) {
            // The next character is special and must be sent individually
            instrumentation.sendKeyDownUpSync(AndroidKeys.keyCodeFor(currentCharacter));
            currentIndex++;
        } else {
            // There is at least one "normal" character, that is a character
            // represented by a plain Unicode character that can be sent
            // with
            // sendStringSync. So send as many such consecutive normal
            // characters
            // as possible in a single String.
            int nextSpecialKey = indexOfSpecialKey(string, currentIndex);
            instrumentation.sendStringSync(string.subSequence(currentIndex, nextSpecialKey).toString());
            currentIndex = nextSpecialKey;
        }
    }
}

From source file:br.msf.commons.util.CharSequenceUtils.java

public static int countAscendingChain(final CharSequence sequence) {
    if (length(sequence) < 2) {
        return length(sequence);
    }//from  w w w . j  av  a2s.  com
    int max = 1;
    int count = 1;
    for (int i = 1; i < sequence.length(); i++) {
        if (sequence.charAt(i) == (sequence.charAt(i - 1) + 1)) {
            count++;
        } else {
            if (count > max) {
                max = count;
            }
            count = 1;
        }
    }
    if (count > max) {
        max = count;
    }
    return max;
}

From source file:br.msf.commons.util.CharSequenceUtils.java

public static int countDescendingChain(final CharSequence sequence) {
    if (length(sequence) < 2) {
        return length(sequence);
    }//from  w  w w  . j ava 2 s.com
    int max = 1;
    int count = 1;
    for (int i = 1; i < sequence.length(); i++) {
        if (sequence.charAt(i) == (sequence.charAt(i - 1) - 1)) {
            count++;
        } else {
            if (count > max) {
                max = count;
            }
            count = 1;
        }
    }
    if (count > max) {
        max = count;
    }
    return max;
}

From source file:de.ktran.anno1404warenrechner.views.PopulationNumberDialog.java

@SuppressLint({ "SetTextI18n", "InflateParams" })
@NonNull/*from   w  w  w.ja v a  2  s  .c  om*/
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    TypedArray attributes = getContext().obtainStyledAttributes(theme, R.styleable.SimpleNumberPicker);

    LayoutInflater inflater = getActivity().getLayoutInflater();

    View view;
    if (populationType instanceof PopulationType) {
        view = inflater.inflate(R.layout.number_picker, null);
    } else {
        view = inflater.inflate(R.layout.house_number_picker, null);
        seekBar = (SeekBar) view.findViewById(R.id.houseNumberPickerPopLimit);
        advancementText = (TextView) view.findViewById(R.id.houseNumberPickerPopLimitDesc);

        if (seekBar == null || advancementText == null)
            throw new IllegalStateException("Not all views could be found.");
        if (populationType == PopulationType.Civilization.OCCIDENTAL) {
            seekBar.setMax(3);
            seekBar.setProgress(3);

            setAdvancementText(3, PopulationType.Civilization.OCCIDENTAL);
            seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                    setAdvancementText(progress, PopulationType.Civilization.OCCIDENTAL);
                }

                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {
                }

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                }
            });
        } else if (populationType == PopulationType.Civilization.ORIENTAL) {
            seekBar.setMax(1);
            seekBar.setProgress(1);

            setAdvancementText(1, PopulationType.Civilization.ORIENTAL);
            seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                    setAdvancementText(progress, PopulationType.Civilization.ORIENTAL);
                }

                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {
                }

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                }
            });
        }
    }

    // Init number
    int color = attributes.getColor(R.styleable.SimpleNumberPicker_snpKeyColor,
            ContextCompat.getColor(getContext(), android.R.color.secondary_text_light));
    numberTextView = (TextView) view.findViewById(R.id.tv_hex_number);
    numberTextView.setTextColor(color);
    if (null != savedInstanceState && savedInstanceState.containsKey(ARG_SAVED_VALUE))
        numberTextView.setText(savedInstanceState.getString(ARG_SAVED_VALUE));
    else if (forceHouse)
        numberTextView.setText("");
    // Init backspace
    color = attributes.getColor(R.styleable.SimpleNumberPicker_snpBackspaceColor,
            ContextCompat.getColor(getContext(), android.R.color.secondary_text_light));
    backspaceButton = (ImageButton) view.findViewById(R.id.key_backspace);
    backspaceButton.setImageDrawable(
            ThemeUtil.makeSelector(getContext(), R.drawable.snp_ic_backspace_black_24dp, color));
    backspaceButton.setOnClickListener(v -> {
        if (numberTextView.getText().length() == 1 && forceHouse)
            return;

        CharSequence number = numberTextView.getText().subSequence(0, numberTextView.getText().length() - 1);
        if (1 == number.length() && '-' == number.charAt(0))
            number = "";
        numberTextView.setText(number);
        onNumberChanged();
    });
    backspaceButton.setOnLongClickListener(v -> {
        numberTextView.setText("");
        onNumberChanged();
        return true;
    });

    // Create dialog
    dialog = new AlertDialog.Builder(getContext(), theme).setView(view)
            .setPositiveButton(android.R.string.ok, (dialog12, which) -> {
                String result = numberTextView.getText().toString();
                if (result.isEmpty())
                    result = "0";
                result = result.replace(',', '.');
                result = result.replace("", "-");
                if (result.equals("-"))
                    result = "0";
                final int number = Integer.parseInt(result);

                handleDialogFinish(number);
                dismiss();
            }).setNegativeButton(android.R.string.cancel, (dialog1, which) -> dismiss()).create();

    // Init dialog
    color = attributes.getColor(R.styleable.SimpleNumberPicker_snpDialogBackground,
            ContextCompat.getColor(getContext(), android.R.color.white));
    if (dialog.getWindow() != null) {
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(color));
    }

    // Init keys
    View.OnClickListener listener = v -> {
        int key = (int) v.getTag();
        String id = numberTextView.getText() + Integer.toString(key);
        numberTextView.setText(id);
        onNumberChanged();
    };

    color = attributes.getColor(R.styleable.SimpleNumberPicker_snpKeyColor,
            ThemeUtil.getThemeAccentColor(getContext()));
    TypedArray ids = getResources().obtainTypedArray(R.array.snp_key_ids);
    for (int i = 0; i < NB_KEYS; i++) {
        TextView key = (TextView) view.findViewById(ids.getResourceId(i, -1));
        key.setTag(i);
        key.setOnClickListener(listener);
        key.setTextColor(color);
    }

    // Init sign
    TextView sign = (TextView) view.findViewById(R.id.key_house);
    if (!this.forceHouse) {
        sign.setTextColor(color);
        sign.setOnClickListener(v -> {
            String number = numberTextView.getText().toString();
            if (number.startsWith("")) {
                numberTextView.setText(number.substring(1));
            } else {
                numberTextView.setText("" + number);
            }
            onNumberChanged();
        });
    } else {
        sign.setVisibility(View.GONE);
    }

    ids.recycle();
    attributes.recycle();

    return dialog;
}

From source file:org.cosmo.common.util.Util.java

public static String replaceEntityReference(Object obj) {
    if (obj == null) {
        return "";
    }//from   ww w  .j  ava 2  s . com
    CharSequence str = obj instanceof CharSequence ? (CharSequence) obj : obj.toString();

    StringBuilder fsb = new StringBuilder();
    for (int i = 0; i < str.length(); i++) {
        char c = str.charAt(i);
        if (c == '>' || c == '<' || c == '&' || c == '\'' || c == '\"') {
            fsb.append(EntityReferences[(byte) c]);
        } else {
            fsb.append(c);
        }
    }
    return fsb.toString();
}

From source file:CharArrayMap.java

private int getHashCode(CharSequence text) {
    int code;/*from   ww w.j a  v a 2 s.  c  o m*/
    if (ignoreCase) {
        code = 0;
        int len = text.length();
        for (int i = 0; i < len; i++) {
            code = code * 31 + Character.toLowerCase(text.charAt(i));
        }
    } else {
        if (false && text instanceof String) {
            code = text.hashCode();
        } else {
            code = 0;
            int len = text.length();
            for (int i = 0; i < len; i++) {
                code = code * 31 + text.charAt(i);
            }
        }
    }
    return code;
}

From source file:com.awt.supark.EditCar.java

@Nullable
@Override/*from   ww  w. ja va2  s. co  m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.edit_car, container, false);

    addCarButton = (Button) view.findViewById(R.id.DoneButton);
    deleteButton = (Button) view.findViewById(R.id.DeleteButton);
    cancelButton = (Button) view.findViewById(R.id.cancelButton);
    carName = (EditText) view.findViewById(R.id.carName);
    carLicense = (EditText) view.findViewById(R.id.carLicense);
    txtCity = (TextView) view.findViewById(R.id.city);
    txtNum = (TextView) view.findViewById(R.id.number);
    radioNewSrb = (RadioButton) view.findViewById(R.id.radioNewSrb);
    radioGeneric = (RadioButton) view.findViewById(R.id.radioGeneric);
    radioLicenseGroup = (RadioGroup) view.findViewById(R.id.radioLicenseGroup);
    licensePlate = (LinearLayout) view.findViewById(R.id.licensePlate);
    licenseNum = "";
    context = getContext();

    // Setting the custom font
    Typeface licenseFont = Typeface.createFromAsset(getContext().getAssets(), "fonts/LicensePlate.ttf");
    txtCity.setTypeface(licenseFont);
    txtNum.setTypeface(licenseFont);

    db = SQLiteDatabase.openDatabase(getContext().getFilesDir().getPath() + "/carDB.db", null,
            SQLiteDatabase.CREATE_IF_NECESSARY);
    final Bundle b = getArguments();

    if (b.getInt("editid") != -1) {
        editid = b.getInt("editid");
        Cursor d = db.rawQuery("SELECT * FROM cars WHERE car_id = " + editid, null);
        d.moveToFirst();

        carName.setText(d.getString(d.getColumnIndex("car_name")));
        licenseNum = d.getString(d.getColumnIndex("car_license"));
        carLicense.setText(licenseNum);

        if (d.getInt(d.getColumnIndex("isgeneric")) == 0) {
            radioNewSrb.setChecked(true);
            radioGeneric.setChecked(false);
            radioListener();
        } else {
            radioGeneric.setChecked(true);
            radioNewSrb.setChecked(false);
            radioListener();
        }

        deleteButton.setVisibility(View.VISIBLE);
        if (isCarParked(editid)) {
            deleteButton.setEnabled(false);
        }
        TextView text = (TextView) view.findViewById(R.id.text1);
        text.setText(context.getResources().getString(R.string.edit_car));
        d.close();
    } else {
        radioNewSrb.setChecked(true);
        radioListener();
    }

    addCarButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (editid == -1) {
                addCar(v);
            } else {
                editCar(v);
            }
        }
    });

    deleteButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showDeleteQuestionDialog("", getResources().getString(R.string.are_you_sure), v);
        }
    });

    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ((MainActivity) context).openCarFragment(null, true);
        }
    });

    // Filters the emojis and other unwanted characters
    filter = new InputFilter() {
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                int dend) {
            for (int i = start; i < end; i++) {
                if (!Character.isLetterOrDigit(source.charAt(i))) {
                    return "";
                }
            }
            return null;
        }
    };
    carName.setFilters(new InputFilter[] { filter });
    //carLicense.setFilters(new InputFilter[] { filter });

    // License number filler
    carLicense.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            licenseNum = charSequence.toString();
            updateLicensePlate(charSequence);
        }

        @Override
        public void afterTextChanged(Editable editable) {

        }
    });

    radioLicenseGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup radioGroup, int i) {
            radioListener();
        }
    });

    return view;
}

From source file:CharArrayMap.java

private boolean equals(CharSequence text1, char[] text2) {
    int len = text1.length();
    if (len != text2.length)
        return false;
    if (ignoreCase) {
        for (int i = 0; i < len; i++) {
            if (Character.toLowerCase(text1.charAt(i)) != text2[i])
                return false;
        }/*from   w w w.j  a  v  a  2  s.  com*/
    } else {
        for (int i = 0; i < len; i++) {
            if (text1.charAt(i) != text2[i])
                return false;
        }
    }
    return true;
}

From source file:br.msf.commons.util.CharSequenceUtils.java

/**
 * Removes accents and graphical symbols from words, like tilde, cute, and so on.
 *
 * @param sequence Sequence witch the its accents must be removed.
 * @return The sequence without accents.
 *///  ww  w  . j a va  2 s .c  om
protected static StringBuilder reverseInternal(final CharSequence sequence) {
    if (sequence == null) {
        return null;
    }
    final StringBuilder builder = new StringBuilder(sequence.length());
    for (int i = indexOfLastChar(sequence); i >= 0; i--) {
        builder.append(sequence.charAt(i));
    }
    return builder;
}