Example usage for java.lang CharSequence toString

List of usage examples for java.lang CharSequence toString

Introduction

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

Prototype

public String toString();

Source Link

Document

Returns a string containing the characters in this sequence in the same order as this sequence.

Usage

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

public static List<String> split(final CharSequence sequence, final Pattern pattern,
        final boolean ignoreBlank) {
    if (isBlankOrNull(sequence)) {
        return CollectionUtils.EMPTY_LIST;
    }//from ww  w. j  av  a 2s .c  om
    if (pattern == null) {
        return Collections.singletonList(sequence.toString());
    }
    final Collection<MatchEntry> occurrences = findPattern(pattern, sequence);
    final List<String> split = new ArrayList<String>(occurrences.size() + 1);
    int start = 0;
    for (MatchEntry occurrence : occurrences) {
        final CharSequence sub = sequence.subSequence(start, occurrence.getStart());
        start = occurrence.getEnd();
        if (CharSequenceUtils.isBlankOrNull(sub) && ignoreBlank) {
            continue;
        }
        split.add(sub.toString());
    }
    final CharSequence sub = sequence.subSequence(start, sequence.length());
    if (CharSequenceUtils.isNotBlank(sub) || !ignoreBlank) {
        split.add(sub.toString());
    }
    return split;
}

From source file:fr.cph.chicago.core.fragment.BikeFragment.java

private void loadList() {
    if (bikeAdapter == null) {
        List<BikeStation> bikeStations = activity.getIntent().getExtras()
                .getParcelableArrayList(bundleBikeStations);
        if (bikeStations == null) {
            bikeStations = new ArrayList<>();
        }//from   ww  w  .j av a2s. c  o m
        bikeAdapter = new BikeAdapter(bikeStations);
    }
    bikeListView.setAdapter(bikeAdapter);
    filter.addTextChangedListener(new TextWatcher() {

        private List<BikeStation> bikeStations;

        @Override
        public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) {
            bikeStations = new ArrayList<>();
        }

        @Override
        public void onTextChanged(final CharSequence s, final int start, final int before, final int count) {
            bikeStations.addAll(Stream.of(BikeFragment.this.bikeStations).filter(
                    bikeStation -> StringUtils.containsIgnoreCase(bikeStation.getName(), s.toString().trim()))
                    .collect(Collectors.toList()));
        }

        @Override
        public void afterTextChanged(final Editable s) {
            bikeAdapter.setBikeStations(this.bikeStations);
            bikeAdapter.notifyDataSetChanged();
        }
    });
    bikeListView.setVisibility(ListView.VISIBLE);
    filter.setVisibility(ListView.VISIBLE);
    loadingLayout.setVisibility(RelativeLayout.INVISIBLE);
    errorLayout.setVisibility(RelativeLayout.INVISIBLE);
}

From source file:org.tradex.jdbc.JDBCHelper.java

/**
 * Executes the passed SQL and returns the results in a 2D object array
 * @param sql The SQL query to executer//  w  ww  . j a va  2s.  c o m
 * @return the results of the query
 */
public Object[][] query(CharSequence sql) {
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rset = null;

    Vector<Object[]> rows = new Vector<Object[]>();
    try {
        conn = ds.getConnection();
        ps = conn.prepareStatement(sql.toString());
        rset = ps.executeQuery();
        int colCount = rset.getMetaData().getColumnCount();
        while (rset.next()) {
            Object[] row = new Object[colCount];
            for (int i = 1; i <= colCount; i++) {
                row[i - 1] = rset.getObject(i);
            }
            rows.add(row);
        }
        Object[][] result = new Object[rows.size()][];
        int cnt = 0;
        for (Object[] row : rows) {
            result[cnt] = row;
            cnt++;
        }
        return result;
    } catch (Exception e) {
        throw new RuntimeException("Query for [" + sql + "] failed", e);
    } finally {
        try {
            rset.close();
        } catch (Exception e) {
        }
        try {
            ps.close();
        } catch (Exception e) {
        }
        try {
            conn.close();
        } catch (Exception e) {
        }
    }

}

From source file:com.capitalone.dashboard.util.ClientUtil.java

/**
 * Converts a Jira string representation of sprint artifacts into a
 * canonical JSONArray format.//from w  w w.ja va  2  s. c o m
 * 
 * @param nativeRs
 *            a sanitized String representation of a sprint artifact link
 *            from Jira
 * @return A canonical JSONArray of Jira sprint artifacts
 */
@SuppressWarnings("unchecked")
public JSONObject toCanonicalSprintJSON(String nativeRs) {
    JSONObject canonicalRs = new JSONObject();
    CharSequence interrimChar;
    int start = 0;
    int end = 0;

    if ((nativeRs != null) && !(nativeRs.isEmpty())) {
        start = nativeRs.indexOf('[') + 1;
        end = nativeRs.length() - 1;
        StringBuffer interrimBuf = new StringBuffer(nativeRs);
        interrimChar = interrimBuf.subSequence(start, end);
        String interrimStr = interrimChar.toString();

        List<String> list = Arrays.asList(interrimStr.split(","));
        if ((list != null) && !(list.isEmpty())) {
            Iterator<String> listIt = list.iterator();
            while (listIt.hasNext()) {
                String temp = listIt.next();
                List<String> keyValuePair = Arrays.asList(temp.split("=", 2));
                if ((keyValuePair != null) && !(keyValuePair.isEmpty())) {
                    String key = keyValuePair.get(0).toString();
                    String value = keyValuePair.get(1).toString();
                    if ("<null>".equalsIgnoreCase(value)) {
                        value = "";
                    }
                    canonicalRs.put(key, value);
                }
            }
        }
    } else {
        canonicalRs.clear();
    }

    return canonicalRs;
}

From source file:net.eledge.android.europeana.gui.activity.HomeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    NewBlogNotification.cancel(this);

    PreferenceManager.setDefaultValues(this, R.xml.settings, false);

    searchController.suggestionPageSize = getResources().getInteger(R.integer.home_suggestions_pagesize);
    isLandscape = getResources().getBoolean(R.bool.home_support_landscape);

    mSuggestionsAdaptor = new SuggestionAdapter(this, new ArrayList<Item>());
    mGridViewSuggestions.setAdapter(mSuggestionsAdaptor);
    mGridViewSuggestions.setOnItemClickListener(this);

    mEditTextQuery.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override/*  www  . ja v  a  2  s  .  c o  m*/
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if ((actionId == EditorInfo.IME_ACTION_SEARCH) || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
                performSearch(v.getText().toString());
                return true;
            }
            return false;
        }
    });
    mEditTextQuery.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (s.length() > 2) {
                if (mGridViewSuggestions.isShown()) {
                    mSuggestionsAdaptor.clear();
                    mSuggestionsAdaptor.notifyDataSetChanged();
                }
                searchController.suggestions(HomeActivity.this, s.toString());
            } else {
                onTaskFinished(null);
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // ignore
        }

        @Override
        public void afterTextChanged(Editable s) {
            // ignore
        }
    });

    mProfilesAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item);
    mSpinnerProfiles.setAdapter(mProfilesAdapter);

    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    if (mBlogFragment == null) {
        mBlogFragment = new HomeBlogFragment();
    }
    fragmentTransaction.replace(R.id.activity_home_fragment_blog, mBlogFragment);
    fragmentTransaction.commit();
}

From source file:com.safi.workshop.sqlexplorer.parsers.BasicQueryParser.java

/**
 * Determines whether the next part of the SQL is a given string
 * /*ww  w.  ja  va  2s .c  om*/
 * @param str
 * @return
 */
private boolean nextIs(String str) {
    if (str == null)
        return false;
    if (str.length() > sql.length() - charIndex)
        return false;
    CharSequence sub = sql.subSequence(charIndex, charIndex + str.length());
    return str.equals(sub.toString());
}

From source file:com.example.cuisoap.agrimac.homePage.machineDetail.driverInfoFragment.java

public void addTextWatcher() {
    driver_name.addTextChangedListener(new TextWatcher() {
        @Override//from  w  ww .j a  v  a 2s .co m
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            machineDetailData.driver_name = s.toString();
        }
    });
    driver_age.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            machineDetailData.driver_age = s.toString();
        }
    });
}

From source file:$.MyValidator.java

public boolean isEmailValid(CharSequence value) {
        if (value == null || value.length() == 0) {
            return true;
        }/*from   w ww .ja v  a2 s  . c o  m*/

        // split email at '@' and consider local and domain part separately;
        // note a split limit of 3 is used as it causes all characters following
        // to an (illegal) second @ character to
        // be put into a separate array element, avoiding the regex application
        // in this case since the resulting array
        // has more than 2 elements
        String[] emailParts = value.toString().split("@", 3);
        if (emailParts.length != 2) {
            return false;
        }

        // if we have a trailing dot in local or domain part we have an invalid
        // email address.
        // the regular expression match would take care of this, but IDN.toASCII
        // drops trailing the trailing '.'
        // (imo a bug in the implementation)
        if (emailParts[0].endsWith(".") || emailParts[1].endsWith(".")) {
            return false;
        }

        if (!matchPart(emailParts[0], localEmailPattern)) {
            return false;
        }

        return matchPart(emailParts[1], emailDomainPattern);
    }

From source file:ca.etsmtl.applets.etsmobile.ProfileActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.student_profile);
    handler = new ProfileHandler(this);
    handlerBandwith = new BandwithHandler(this);
    btnLogin = (Button) findViewById(R.id.profile_login_btn);
    btnLogin.setOnClickListener(this);

    // nav bar//  ww w  . j  a va 2  s . co m
    navBar = (NavBar) findViewById(R.id.navBar1);
    navBar.setTitle(R.drawable.navbar_profil_title);
    navBar.hideRightButton();
    navBar.hideLoading();

    name = (TextView) findViewById(R.id.student_profile_name);
    lastname = (TextView) findViewById(R.id.student_profile_lastname);
    solde = (TextView) findViewById(R.id.student_profile_solde);
    codeP = (TextView) findViewById(R.id.student_profile_codePermanent);
    progess = (ProgressBar) findViewById(R.id.bandwith_progress);
    bandwith_used = (TextView) findViewById(R.id.bandwith_used_lbl);
    bandwith_max = (TextView) findViewById(R.id.bandwith_max);

    phase_input = (TextView) findViewById(R.id.bandwith_phase_input);

    credits_done = (TextView) findViewById(R.id.student_profile_credit_done);
    credit_failed = (TextView) findViewById(R.id.student_profile_credits_failed);
    credits_now = (TextView) findViewById(R.id.student_profile_credits_now);

    programme = (TextView) findViewById(R.id.student_profile_programme);
    moyenne = (TextView) findViewById(R.id.student_profile_moy);

    phase_input.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (s.length() >= 1) {
                if (appt_input.getText().length() > 4) {
                    getBandwith(s.toString(), appt_input.getText().toString());
                }
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    appt_input = (TextView) findViewById(R.id.bandwith_appt_input);

    appt_input.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (s.length() >= 3) {
                if (phase_input.getText().length() >= 1) {
                    getBandwith(phase_input.getText().toString(), s.toString());
                }
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    prefs = PreferenceManager.getDefaultSharedPreferences(this);
    creds = new UserCredentials(prefs);
    if (creds.hasBandwithInfo()) {
        phase_input.setText(creds.getPhase());
        appt_input.setText(creds.getAppt());
    }
    doLogin();
}

From source file:edu.cornell.med.icb.pca.RotationReaderWriter.java

/**
 * Given the specified parameters, return the filenames that contain
 * rotation matrices across all splits. The result is a map of
 * compound files to the filenames within the compound files.
 *
 * @param datasetEndpointName the dataset to find a table for
 * @param pathwayId          the pathwayId to find a table for
 * @return the files where rotation information is stored.
 *///from  w  w w  .  jav  a2 s.  c om
public Map<String, Set<String>> getRotationFiles(final CharSequence datasetEndpointName,
        MutableString pathwayId) {
    pathwayId = pathwayId.replace(' ', '_');
    pathwayId = pathwayId.replace('/', '_');
    final String datasetEndpointNameComparison = datasetEndpointName.toString().replace('/', '_') + "/";
    final String pathwayIdComparison = pathwayId.toString();

    final Map<String, Set<String>> results = new HashMap<String, Set<String>>();
    final File[] compoundFiles = cacheDirectoryFile.listFiles(CACHE_FILES_FILTER);
    for (final File file : compoundFiles) {
        String compoundFileName = "[uninitialized]";
        try {
            compoundFileName = file.getCanonicalPath();
            if (LOG.isTraceEnabled()) {
                LOG.trace("Scanning for rotation files within compound file " + compoundFileName);
            }
            final CompoundFileReader compoundReader = new CompoundFileReader(compoundFileName);
            final Set<String> output = new HashSet<String>();
            results.put(compoundFileName, output);

            final Set<String> names = compoundReader.getFileNames();
            for (final String name : names) {
                final Matcher m = ROTATION_MATRIX_NAME_PATTERN.matcher(name);
                if (!m.matches()) {
                    continue;
                }
                final String fileDatasetEndpointName = m.group(1);
                // String fileSplitId = m.group(2);
                final String filePathwayId = m.group(3);
                if (filePathwayId.endsWith("-map")) {
                    // A map file, not a rotation matrix file
                    continue;
                }

                if (!datasetEndpointNameComparison.equals(fileDatasetEndpointName)) {
                    // Wrong datasetEndpointName
                    continue;
                }
                if (!pathwayIdComparison.equals(filePathwayId)) {
                    // Wrong pathwayId
                    continue;
                }
                // Looks good
                output.add(name);
            }
            compoundReader.close();
        } catch (IOException e) {
            LOG.error("Error opening/reading compound file " + compoundFileName, e);
        }
    }
    return results;
}