Example usage for java.lang String subSequence

List of usage examples for java.lang String subSequence

Introduction

In this page you can find the example usage for java.lang String subSequence.

Prototype

public CharSequence subSequence(int beginIndex, int endIndex) 

Source Link

Document

Returns a character sequence that is a subsequence of this sequence.

Usage

From source file:org.kalypso.kalypsomodel1d2d.sim.ResultManager.java

private Date getStepMapDate(final FileObject file) {
    final String baseName = file.getName().getBaseName();
    if (baseName.equals("steady.2d")) //$NON-NLS-1$
        return STEADY_DATE;

    if (baseName.equals("maxi.2d")) //$NON-NLS-1$
        return MAXI_DATE;

    if (baseName.equals("steady.2d") || baseName.equals("maxi.2d") || baseName.equals("mini.2d") //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
            || baseName.equals("model.2d")) //$NON-NLS-1$
        return null;

    if (baseName.endsWith(".2d.zip")) //$NON-NLS-1$
        return ResultMeta1d2dHelper.resolveDateFromResultStep(file);

    final String resultFileName = baseName;
    final int index = resultFileName.indexOf("."); //$NON-NLS-1$
    final CharSequence sequence = resultFileName.subSequence(1, index);
    final String string = sequence.toString();
    final int step = Integer.parseInt(string);

    return getDateOfTimeStepNr(step);

}

From source file:pt.ist.expenditureTrackingSystem.domain.organization.Person.java

public String getFirstAndLastName() {
    final String name = super.getUser().getName();
    if (name != null) {
        int s1 = name.indexOf(' ');
        int s2 = name.lastIndexOf(' ');
        return s1 < 0 || s1 == s2 ? name : name.subSequence(0, s1) + name.substring(s2);
    }//from  w w w.j  ava2s  . com
    return null;
}

From source file:com.marcohc.robotocalendar.RobotoCalendarView.java

@SuppressLint("DefaultLocale")
private void initializeTitleLayout() {

    String dateText = new DateFormatSymbols(locale).getMonths()[currentCalendar.get(Calendar.MONTH)];
    dateText = dateText.substring(0, 1).toUpperCase() + dateText.subSequence(1, dateText.length());
    Calendar calendar = Calendar.getInstance();
    //        if (currentCalendar.get(Calendar.YEAR) == calendar.get(Calendar.YEAR)) {
    //            dateTitle.setText(dateText);
    //        } else {
    dateTitle.setText(String.format("%s %s", dateText, currentCalendar.get(Calendar.YEAR)));
    //        }/*from w w w.  j a va  2  s  .  c  o  m*/
}

From source file:org.getobjects.rules.RuleParser.java

public Object parseAction(String _s, String _forceClassName) {
    if (_s == null || _s.length() == 0)
        return null;

    Class enforcedClass = null;//w ww . ja  v  a  2 s  .co  m
    if (_s.charAt(0) == '(') {
        // TODO: parse an Assignment type cast
        int sidx = _s.indexOf(')');
        if (sidx == -1)
            log.error("typecast is not closed: " + _s);
        else {
            String clsname = _s.substring(1, sidx);
            enforcedClass = this.classLookup.lookupClass(clsname);
        }
    } else if (_forceClassName != null)
        enforcedClass = this.classLookup.lookupClass(_forceClassName);

    int idx = UString.indexOfStringBySkippingQuotes(_s, "=", "\"'", '\\');
    if (idx < 1) {
        log.info("could not parse assignment: '" + _s + "'");
        return null;
    }

    String key = _s.substring(0, idx).trim();
    String valstr = _s.substring(idx + 1).trim();

    Class assignmentClass = enforcedClass != null ? enforcedClass : RuleKeyAssignment.class;
    Object value = valstr;

    /* parse value */

    if (enforcedClass == null && valstr.length() > 0) {
        char c0 = valstr.charAt(0);

        if (c0 == '"' || c0 == '\'') { /* quoted string */
            if (valstr.charAt(valstr.length() - 1) != c0) {
                log.error("string value of assignment misses a closing quote");
                value = valstr.substring(1);
            } else
                value = valstr.subSequence(1, valstr.length() - 1);
        } else if (Character.isDigit(c0) || c0 == '-') { /* number */
            value = UObject.intValue(valstr);
        } else if (c0 == '{' || c0 == '(') { /* property list */
            NSPropertyListParser p = new NSPropertyListParser();
            value = p.parse(valstr);
            if (value == null)
                log.error("could not parse plist of assignment: " + valstr);
        } else {
            if (valstr.equals("true"))
                value = Boolean.TRUE;
            else if (valstr.equals("false"))
                value = Boolean.FALSE;
            else if (valstr.equals("YES"))
                value = Boolean.TRUE;
            else if (valstr.equals("NO"))
                value = Boolean.FALSE;
            else if (valstr.equals("null"))
                value = null;
            else if (valstr.equals("nil"))
                value = null;
        }

        if (value != valstr)
            assignmentClass = RuleAssignment.class;
    }

    /* construct */

    return NSJavaRuntime.NSAllocateObject(assignmentClass, AssiCtorSig, new Object[] { key, value });
}

From source file:com.manoj.fragments.SongCustomFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    final View v = inflater.inflate(R.layout.song, container, false);
    mGridView = (ListView) v.findViewById(R.id.song_list);
    edittext = (EditText) v.findViewById(R.id.song_search);
    mGridView.setAdapter(mAdapter);//from w  w w .j ava  2 s.c o m

    homeScreen = (LinearLayout) v.findViewById(R.id.song_layout);
    utilities.colorSeter(homeScreen, activity.getApplicationContext());

    edittext.addTextChangedListener(new TextWatcher() {

        public void afterTextChanged(Editable s) {

        }

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

        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            scroll = false;
            filteredSongMap.clear();
            try {

                textlength = edittext.getText().length();
                if (textlength == 0) {
                    mAdapter = new ImageAdapter(getActivity(), songsListData);
                    mGridView.setAdapter(mAdapter);
                } else {
                    for (int i = 0; i < songsListData.size(); i++) {
                        HashMap songMap = (HashMap) songsListData.get(i);
                        String toFilterText = songMap.get("KEY_TITLE").toString();
                        if (textlength <= toFilterText.length()) {
                            if (edittext.getText().toString()
                                    .equalsIgnoreCase((String) toFilterText.subSequence(0, textlength))) {
                                filteredSongMap.add(songMap);
                            }
                        }
                    }

                    mAdapter = new ImageAdapter(getActivity(), filteredSongMap);
                    mGridView.setAdapter(mAdapter);
                }
            } catch (Exception e) {
                Log.i("", e.toString());
            }

            //mAdapter.songsListData = filteredSongMap;
            /*mAdapter = new ImageAdapter(getActivity(),filteredSongMap);
                    
            ImageCacheParams cacheParams = new ImageCacheParams(getActivity(), IMAGE_CACHE_DIR);
                    
            cacheParams.setMemCacheSizePercent(0.25f); // Set memory cache to 25% of app memory
                    
            // The ImageFetcher takes care of loading images into our ImageView children asynchronously
            mImageFetcher = new ImageFetcher(getActivity(), mImageThumbSize,activity);
            mImageFetcher.setLoadingImage(R.drawable.adele);
            mImageFetcher.addImageCache(getActivity().getSupportFragmentManager(), cacheParams);
            */

            /*  for (int i = 0; i < text.length; i++)
              {
              if (textlength <= text[i].length())
              {
              if (edittext.getText().toString().
              equalsIgnoreCase((String) text[i].subSequence(0, textlength)))
              {
              text_sort.add(text[i]);
              image_sort.add(image[i]);
              }
              }*/
        }
    });

    mGridView.setOnScrollListener(new OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView absListView, int scrollState) {
            // Pause fetcher to ensure smoother scrolling when flinging
            if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING) {
                mImageFetcher.setPauseWork(true);
            } else {
                mImageFetcher.setPauseWork(false);
            }
        }

        @Override
        public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                int totalItemCount) {
        }
    });

    // select single listview item
    mGridView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

        }
    });

    // This listener is used to get the final width of the GridView and then calculate the
    // number of columns and the width of each column. The width of each column is variable
    // as the GridView has stretchMode=columnWidth. The column width is used to set the height
    // of each view so we get nice square thumbnails.
    /*mGridView.getViewTreeObserver().addOnGlobalLayoutListener(
        new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                if (mAdapter.getNumColumns() == 0) {
                    final int numColumns = (int) Math.floor(
                            mGridView.getWidth() / (mImageThumbSize + mImageThumbSpacing));
                    if (numColumns > 0) {
                        final int columnWidth =
                                (mGridView.getWidth() / numColumns) - mImageThumbSpacing;
                        mAdapter.setNumColumns(numColumns);
                        mAdapter.setItemHeight(columnWidth);
                        if (BuildConfig.DEBUG) {
                            Log.d(TAG, "onCreateView - numColumns set to " + numColumns);
                        }
                    }
                }
            }
        });*/

    return v;
}

From source file:de.iai.ilcd.xml.read.DataSetImporter.java

private boolean importFile(String fileName, DataSetReader reader, DataSetDao dao, PrintWriter out,
        RootDataStock rds) {//from w w w  . j  a v  a2  s.  c  o m
    if (rds == null) {
        out.println("Cannot create data set without a root data stock");
        return false;
    }
    // EntityManager em = PersistenceUtil.getEntityManager();
    boolean persisted = false;

    DataSet dataset;
    try {
        dataset = reader.readFromFile(fileName, out);
        dataset.setRootDataStock(rds);
    } catch (Exception ex) {
        if (out != null) {
            out.println("Warning: Cannot import data set "
                    + fileName.subSequence(fileName.lastIndexOf(File.separator), fileName.length() - 1));
            out.flush();
        }
        logger.error("Cannot read data set {}", fileName);
        logger.error("Exception is: ", ex);
        return false;
    }

    // dao.persist(dataset);
    persisted = dao.checkAndPersist(dataset, PersistType.ONLYNEW, out);
    if (out != null) {
        out.flush();
    }

    PersistenceUtil.closeEntityManager();

    return persisted;
}

From source file:org.freaknet.gtrends.api.GoogleTrendsCsvParser.java

/**
 * Gets the specified section from the CSV.
 *
 * @param section Section of the CSV to retrieve
 * @param header If the section has a header. If <code>true</code> the first
 * line will be skipped./*from  w w  w  . j a va2 s  .c  o  m*/
 * @return content The content of the section
 */
public String getSectionAsString(String section, boolean header) {
    String ret = null;
    Logger.getLogger(GoogleConfigurator.getLoggerPrefix()).log(Level.FINE, "Parsing CSV for section: {0}",
            section);

    Pattern startSectionPattern = Pattern.compile("^" + section + ".*$", Pattern.MULTILINE);
    Matcher matcher = startSectionPattern.matcher(_csv);

    if (matcher.find()) {
        ret = _csv.subSequence(matcher.start(), _csv.length()).toString();

        int end = ret.length();

        Pattern endSectionPattern = Pattern.compile("\n\n", Pattern.MULTILINE);
        matcher = endSectionPattern.matcher(ret);
        if (matcher.find()) {
            end = matcher.start();
        }

        ret = ret.subSequence(0, end).toString().substring(ret.indexOf('\n') + 1);

        if (header) {
            ret = ret.substring(ret.indexOf('\n') + 1);
        }
    } else {
        Logger.getLogger(GoogleConfigurator.getLoggerPrefix()).log(Level.WARNING,
                "Writing the full CSV file. Section not found: #{0}", section);
        return "";
    }

    return ret;
}

From source file:org.jgrapht.io.DOTImporter.java

/**
 * Unescape a string DOT identifier./*from   w w w . j  a v  a 2s  .  c  om*/
 *
 * @param input the input
 * @return the unescaped output
 */
private String unescapeId(String input) {
    final char QUOTE = '"';
    if (input.charAt(0) != QUOTE || input.charAt(input.length() - 1) != QUOTE) {
        return input;
    }
    String noQuotes = input.subSequence(1, input.length() - 1).toString();
    String unescaped = UNESCAPE_ID.translate(noQuotes);
    return unescaped;
}

From source file:dk.dma.epd.shore.EPDShore.java

/**
 * Returns the MMSI of the shore center, or null if not defined
 * //from  ww  w  .j  a  v a  2  s  .  co m
 * @return the MMSI of the shore center
 */
@Override
public Long getMmsi() {
    String shoreID = getSettings().getEnavSettings().getShoreId();
    if (shoreID == null || !StringUtils.isNumeric(shoreID)
            || !shoreID.startsWith(MaritimeCloudUtils.STCC_MMSI_PREFIX)) {
        return null;
    }
    return Long.parseLong((String) shoreID.subSequence(0, 9));
}

From source file:ca.mudar.parkcatcher.ui.fragments.DetailsFragment.java

private TextView getPanel(String desc, LayoutParams params, int textColor) {
    desc = desc.trim().toUpperCase();/*ww w  .jav a  2  s.  c o m*/
    final TextView panelUi = new TextView(getSherlockActivity());

    panelUi.setGravity(Gravity.CENTER_HORIZONTAL);
    panelUi.setLayoutParams(params);
    panelUi.setTextColor(textColor);

    String prefix = (String) desc.subSequence(0, 2);
    prefix = prefix.trim();
    try {
        // Start with a figure: authorized duration
        Integer.valueOf(prefix.trim());
        panelUi.setBackgroundResource(R.drawable.bg_panel_parking);
    } catch (NumberFormatException e) {
        if (desc.subSequence(0, 1).equals("P")) {
            // Starts with "P " (trimmed): authorized
            panelUi.setBackgroundResource(R.drawable.bg_panel_parking);
            desc = desc.substring(1);
        } else if (desc.subSequence(0, 2).equals("\\A")) {
            panelUi.setBackgroundResource(R.drawable.bg_panel_no_stopping);
            desc = desc.substring(2);
        } else if (desc.subSequence(0, 2).equals("\\P")) {
            panelUi.setBackgroundResource(R.drawable.bg_panel_no_parking);
            desc = desc.substring(2);
        } else {
            panelUi.setBackgroundResource(R.drawable.bg_panel_no_parking);
        }
    }

    panelUi.setText(desc.trim());

    return panelUi;
}