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:edu.cornell.med.icb.goby.util.SimulateBisulfiteReads.java

private MutableString context(int i, CharSequence segmentBases) {
    MutableString context = new MutableString();
    int contextLength = 10;
    int start = Math.max(0, i - contextLength);
    int end = Math.min(segmentBases.length(), i + contextLength);

    final String bases = segmentBases.toString();
    context.append(bases.subSequence(start, i));
    context.append('>');
    context.append(bases.charAt(i));/*from   w w  w.  j  ava2  s. c om*/
    context.append('<');
    final int a = i + 1;
    if (a < end) {
        final CharSequence sequence = bases.subSequence(a, end);
        context.append(sequence);
    }
    return context;
}

From source file:com.simiacryptus.mindseye.models.Hdf5Archive.java

/**
 * Read data setBytes as ND4J array from HDF5 group.
 *
 * @param fileGroup   HDF5 file or group
 * @param datasetName Name of data setBytes
 * @return//  w ww.  ja  v  a2  s  .c  o m
 */
@Nullable
private Tensor readDataSet(@Nonnull Group fileGroup, CharSequence datasetName) {
    DataSet dataset = fileGroup.openDataSet(datasetName.toString());
    DataSpace space = dataset.getSpace();
    int nbDims = space.getSimpleExtentNdims();
    @Nonnull
    long[] dims = new long[nbDims];
    space.getSimpleExtentDims(dims);
    @Nullable
    float[] dataBuffer = null;
    @Nullable
    FloatPointer fp = null;
    int j = 0;
    @Nonnull
    DataType dataType = new DataType(PredType.NATIVE_FLOAT());
    @Nullable
    Tensor data = null;
    switch (nbDims) {
    case 4: /* 2D Convolution weights */
        dataBuffer = new float[(int) (dims[0] * dims[1] * dims[2] * dims[3])];
        fp = new FloatPointer(dataBuffer);
        dataset.read(fp, dataType);
        fp.get(dataBuffer);
        data = new Tensor((int) dims[0], (int) dims[1], (int) dims[2], (int) dims[3]);
        j = 0;
        for (int i1 = 0; i1 < dims[0]; i1++)
            for (int i2 = 0; i2 < dims[1]; i2++)
                for (int i3 = 0; i3 < dims[2]; i3++)
                    for (int i4 = 0; i4 < dims[3]; i4++)
                        data.set(i1, i2, i3, i4, (double) dataBuffer[j++]);
        break;
    case 3:
        dataBuffer = new float[(int) (dims[0] * dims[1] * dims[2])];
        fp = new FloatPointer(dataBuffer);
        dataset.read(fp, dataType);
        fp.get(dataBuffer);
        data = new Tensor((int) dims[0], (int) dims[1], (int) dims[2]);
        j = 0;
        for (int i1 = 0; i1 < dims[0]; i1++)
            for (int i2 = 0; i2 < dims[1]; i2++)
                for (int i3 = 0; i3 < dims[2]; i3++)
                    data.set(i1, i2, i3, dataBuffer[j++]);
        break;
    case 2: /* Dense and Recurrent weights */
        dataBuffer = new float[(int) (dims[0] * dims[1])];
        fp = new FloatPointer(dataBuffer);
        dataset.read(fp, dataType);
        fp.get(dataBuffer);
        data = new Tensor((int) dims[0], (int) dims[1]);
        j = 0;
        for (int i1 = 0; i1 < dims[0]; i1++)
            for (int i2 = 0; i2 < dims[1]; i2++)
                data.set(i1, i2, dataBuffer[j++]);
        break;
    case 1: /* Bias */
        dataBuffer = new float[(int) dims[0]];
        fp = new FloatPointer(dataBuffer);
        dataset.read(fp, dataType);
        fp.get(dataBuffer);
        data = new Tensor((int) dims[0]);
        j = 0;
        for (int i1 = 0; i1 < dims[0]; i1++)
            data.set(i1, dataBuffer[j++]);
        break;
    default:
        throw new RuntimeException("Cannot import weights apply rank " + nbDims);
    }
    space.deallocate();
    dataset.deallocate();
    return data;
}

From source file:com.example.carrie.carrie_test1.druginfo.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_druginfo);
    Bundle bundle = getIntent().getExtras();
    my_id = bundle.getString("my_id");//get  id
    my_google_id = bundle.getString("my_google_id");//get google_ id
    my_mon_id = bundle.getString("my_supervise_id");
    m_calid = bundle.getString("m_calid", "not found");

    Log.d("qqqqq", m_calid);

    btmbar = (RelativeLayout) findViewById(R.id.btmbar);
    if (my_id.equals("0") && my_google_id.equals("0") && my_mon_id.equals("0")) {
        //???????
        btmbar.setVisibility(View.GONE);
    } else {/*  ww w .  j  a v  a 2s.co  m*/
        BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottomNavView_Bar);
        BottomNavigationViewHelper.disableShiftMode(bottomNavigationView);
        Menu menu = bottomNavigationView.getMenu();
        MenuItem menuItem = menu.getItem(3);
        menuItem.setChecked(true);

        bottomNavigationView.setOnNavigationItemSelectedListener(
                new BottomNavigationView.OnNavigationItemSelectedListener() {
                    @Override
                    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                        switch (item.getItemId()) {
                        case R.id.ic_list:
                            Intent intent0 = new Intent(druginfo.this, Choice.class);
                            Bundle bundle0 = new Bundle();
                            bundle0.putString("memberid", my_id);
                            bundle0.putString("my_google_id", my_google_id);
                            bundle0.putString("my_supervise_id", my_mon_id);
                            intent0.putExtras(bundle0); // put???
                            startActivity(intent0);
                            break;

                        case R.id.ic_eye:
                            Intent intent1 = new Intent(druginfo.this, MonitorActivity.class);
                            Bundle bundle1 = new Bundle();
                            bundle1.putString("my_id", my_id);
                            bundle1.putString("my_google_id", my_google_id);
                            bundle1.putString("my_supervise_id", my_mon_id);
                            intent1.putExtras(bundle1);
                            startActivity(intent1);
                            break;

                        case R.id.ic_home:
                            Intent intent2 = new Intent(druginfo.this, MainActivity.class);
                            Bundle bundle2 = new Bundle();
                            bundle2.putString("googleid", my_google_id);
                            intent2.putExtras(bundle2);
                            startActivity(intent2);
                            break;

                        case R.id.ic_information:
                            Intent intent3 = new Intent(druginfo.this, druginfo.class);
                            Bundle bundle3 = new Bundle();
                            bundle3.putString("my_id", my_id);
                            bundle3.putString("my_google_id", my_google_id);
                            bundle3.putString("my_supervise_id", my_mon_id);
                            intent3.putExtras(bundle3);
                            startActivity(intent3);
                            break;

                        case R.id.ic_beacon:
                            Intent intent4 = new Intent(druginfo.this, Beacon.class);
                            Bundle bundle4 = new Bundle();
                            bundle4.putString("my_id", my_id);
                            bundle4.putString("my_google_id", my_google_id);
                            bundle4.putString("my_supervise_id", my_mon_id);
                            intent4.putExtras(bundle4);
                            startActivity(intent4);
                            break;
                        }

                        return false;
                    }
                });
    }

    listView = (ListView) findViewById(R.id.listview);
    editText = (EditText) findViewById(R.id.textsearch);

    editText.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) {
            if (!s.toString().equals("")) {
                //reset listview

                //                    recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
                //                    data_list = new ArrayList<>();
                //                    load_data_from_server(0);
                //
                //                    gridLayoutManager = new GridLayoutManager(getBaseContext(), 2);
                //                    recyclerView.setLayoutManager(gridLayoutManager);
                //
                //                    adapter = new CustomAdapter2(getBaseContext(), data_list);
                //                    recyclerView.setAdapter(adapter);
                //
                //                    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
                //                        @Override
                //                        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                //
                //                            if (gridLayoutManager.findLastCompletelyVisibleItemPosition() == data_list.size() - 1) {
                //                                load_data_from_server(data_list.get(data_list.size() - 1).getId());
                //                            }
                //
                //                        }
                //                    });
                recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
                data_list2 = new ArrayList<>();
                Log.d("searchtest", "3");
                load_data_from_server_search(s.toString());

                Log.d("searchtest", "1");
                gridLayoutManager = new GridLayoutManager(getBaseContext(), 2);
                recyclerView.setLayoutManager(gridLayoutManager);
                Log.d("searchtest", "2");
                adapter = new CustomAdapter2(getBaseContext(), data_list2, m_calid);
                recyclerView.setAdapter(adapter);
            } else {
                recyclerView = (RecyclerView) findViewById(R.id.recycler_view);

                gridLayoutManager = new GridLayoutManager(getBaseContext(), 2);
                recyclerView.setLayoutManager(gridLayoutManager);

                adapter = new CustomAdapter2(getBaseContext(), data_list, m_calid);
                recyclerView.setAdapter(adapter);

            }

        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

    recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    data_list = new ArrayList<>();
    load_data_from_server(0);

    gridLayoutManager = new GridLayoutManager(this, 2);
    recyclerView.setLayoutManager(gridLayoutManager);

    adapter = new CustomAdapter2(this, data_list, m_calid);
    recyclerView.setAdapter(adapter);

    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {

            if (gridLayoutManager.findLastCompletelyVisibleItemPosition() == data_list.size() - 1) {
                load_data_from_server(data_list.get(data_list.size() - 1).getId());
            }

        }
    });

}

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

public static boolean isNumber(final CharSequence sequence, final Locale locale) {
    if (sequence == null) {
        return false;
    }/*from   www  .j  ava 2s .c om*/
    try {
        DecimalFormat formater = (DecimalFormat) DecimalFormat
                .getInstance(LocaleUtils.getNullSafeLocale(locale));
        formater.setParseBigDecimal(true);
        formater.parse(sequence.toString());
        return true;
    } catch (ParseException ex) {
        return false;
    }
}

From source file:io.engine.EngineIO.java

void transportPacket(IOTransport transport, String data) {
    LOGGER.info("< " + data);
    try {//from w  w w .ja  v  a 2s.  c o m
        char type = data.charAt(0);
        CharSequence message = data.subSequence(1, data.length());
        switch (type) {
        case TYPE_OPEN:
            receivedOpen(transport, message);
            break;
        case TYPE_CLOSE:
            receivedClose(transport);
            break;
        case TYPE_PING:
            send(transport, TYPE_PONG, message.toString());
            break;
        case TYPE_PONG:
            receivedPong(transport, message);
            break;
        case TYPE_MESSAGE:
            onMessage(message.toString());
            break;
        // We're not supposed to handle them
        case TYPE_UPGRADE:
        default:
            LOGGER.warning("Received package type " + type + ". We can't handle this.");
        }
        resetPingTimeout();
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "Garbaged packet. Ignoring...", e);
    }
}

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

private final void loadList() {
    EditText filter = (EditText) mRootView.findViewById(R.id.bike_filter);
    if (mAdapter == null) {
        mAdapter = new BikeAdapter(mActivity);
    }/*from   ww w  .j  a  va 2  s. co m*/
    mListView.setAdapter(mAdapter);
    filter.addTextChangedListener(new TextWatcher() {

        private List<BikeStation> bikeStations = null;

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

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            for (BikeStation bikeStation : BikeFragment.this.mBikeStations) {
                if (StringUtils.containsIgnoreCase(bikeStation.getName(), s.toString().trim())) {
                    this.bikeStations.add(bikeStation);
                }
            }
        }

        @Override
        public void afterTextChanged(Editable s) {
            mAdapter.setBikeStations(this.bikeStations);
            mAdapter.notifyDataSetChanged();
        }
    });
    mListView.setVisibility(ListView.VISIBLE);
    mFilterView.setVisibility(ListView.VISIBLE);
    mLoadingLayout.setVisibility(RelativeLayout.INVISIBLE);
    RelativeLayout errorLayout = (RelativeLayout) mRootView.findViewById(R.id.error_layout);
    errorLayout.setVisibility(RelativeLayout.INVISIBLE);
}

From source file:com.manning.androidhacks.hack017.CreateAccountAdapter.java

private EditText createEditText(String hint, int inputType, int imeOption, boolean shouldMoveToNext,
        final String key) {

    EditText ret = new EditText(mContext);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT);//www.  j  a  va  2s  .c o  m
    ret.setLayoutParams(params);
    ret.setHint(hint);

    ret.setInputType(inputType);
    ret.setImeOptions(imeOption);

    if (shouldMoveToNext) {
        ret.setOnEditorActionListener(new OnEditorActionListener() {

            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (mDelegate != null) {
                    if (EditorInfo.IME_ACTION_NEXT == actionId) {
                        mDelegate.scroll(CreateAccountDelegate.FORWARD);
                    } else {
                        processForm();
                    }

                    return true;
                } else {
                    return false;
                }
            }
        });
    }

    ret.addTextChangedListener(new TextWatcher() {

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

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

        @Override
        public void afterTextChanged(Editable s) {
            mFormData.put(key, s.toString());
        }
    });

    return ret;
}

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

/**
 * Executes the passed SQL and returns the resulting rows maps of values keyed by column name within a map keyed by rownumber (starting with zero)  
 * @param sql The SQL to execute/*ww  w.j a v a  2 s. c om*/
 * @return the results
 */
public Map<Integer, Map<String, Object>> result(CharSequence sql) {
    Map<Integer, Map<String, Object>> results = new TreeMap<Integer, Map<String, Object>>();
    Map<Integer, String> colNumToName;
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rset = null;
    try {
        conn = ds.getConnection();
        ps = conn.prepareStatement(sql.toString());
        rset = ps.executeQuery();
        int colCount = rset.getMetaData().getColumnCount();
        colNumToName = new HashMap<Integer, String>(colCount);
        ResultSetMetaData rsmd = rset.getMetaData();
        for (int i = 1; i <= colCount; i++) {
            colNumToName.put(i, rsmd.getColumnLabel(i));
        }
        int rowNum = 0;
        while (rset.next()) {
            Map<String, Object> row = new HashMap<String, Object>(colCount);
            results.put(rowNum, row);
            for (int i = 1; i <= colCount; i++) {
                row.put(colNumToName.get(i), rset.getObject(i));
            }
            rowNum++;
        }
        return results;
    } 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.romanenco.gitt.BrowserActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_browse);

    filterBar = findViewById(R.id.filter_bar);

    findViewById(R.id.filter_close).setOnClickListener(new View.OnClickListener() {

        @Override/*from  w  w w  .  ja  v a2  s  . com*/
        public void onClick(View v) {
            showFilterBar(false);
        }
    });

    filterText = (EditText) findViewById(R.id.filter_text);
    filterText.addTextChangedListener(new TextWatcher() {

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

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

        @Override
        public void afterTextChanged(Editable s) {
            adapter.reFilter(s.toString());
        }

    });

    if (savedInstanceState == null) {
        current = (Repo) getIntent().getSerializableExtra(REPO);
        path = browseCache.get(current.getFolder());
        if (path == null) {
            path = ".";
        }
    } else {
        current = (Repo) savedInstanceState.getSerializable(REPO);
        path = savedInstanceState.getString(PATH);
        filterBar.setVisibility(savedInstanceState.getInt(FILTER));
    }

    updateTitleWithPath();
    adapter = new FileListAdapter(this, current, path);
    getListView().setAdapter(adapter);
}

From source file:com.intellij.lang.jsgraphql.ide.annotator.JSGraphQLAnnotator.java

@Nullable
@Override/*  ww w.  j a v a 2  s.  c o m*/
public JSGraphQLAnnotationResult collectInformation(@NotNull PsiFile file, @NotNull Editor editor,
        boolean hasErrors) {
    try {
        boolean isJavaScript = file instanceof JSFile;
        if (isJavaScript || file instanceof JSGraphQLFile) {
            CharSequence buffer = editor.getDocument().getCharsSequence();
            if (isJavaScript) {
                // replace the JS with line-preserving whitespace to be ignored by GraphQL
                buffer = getWhitespacePaddedGraphQL(file, buffer);
            }
            if (buffer.length() > 0) {
                final String environment = JSGraphQLLanguageInjectionUtil.getEnvironment(file);
                final AnnotationsResponse annotations = JSGraphQLNodeLanguageServiceClient
                        .getAnnotations(buffer.toString(), file.getProject(), environment);
                return new JSGraphQLAnnotationResult(annotations, editor);
            }
        } else if (file instanceof JSGraphQLSchemaFile) {
            // no external annotation support yet for schema files
            return new JSGraphQLAnnotationResult(new AnnotationsResponse(), editor);
        }
    } catch (Throwable e) {
        if (e instanceof ProcessCanceledException) {
            // annotation was cancelled, e.g. due to an editor being closed
            return null;
        }
        log.error("Error during doAnnotate", e);
    }
    return null;
}