Example usage for java.lang Character isLetterOrDigit

List of usage examples for java.lang Character isLetterOrDigit

Introduction

In this page you can find the example usage for java.lang Character isLetterOrDigit.

Prototype

public static boolean isLetterOrDigit(int codePoint) 

Source Link

Document

Determines if the specified character (Unicode code point) is a letter or digit.

Usage

From source file:net.sf.jabref.logic.groups.KeywordGroup.java

/**
 * Look for the given non-regexp string in another string, but check whether a
 * match concerns a complete word, not part of a word.
 *
 * @param word The word to look for.//w  ww.ja  va  2  s.  c  o m
 * @param text The string to look in.
 * @return true if the word was found, false otherwise.
 */
public static boolean containsWord(String word, String text) {
    int piv = 0;
    while (piv < text.length()) {
        int index = text.indexOf(word, piv);
        if (index < 0) {
            return false;
        }
        // Found a match. See if it is a complete word:
        if (((index == 0) || !Character.isLetterOrDigit(text.charAt(index - 1)))
                && (((index + word.length()) == text.length())
                        || !Character.isLetterOrDigit(text.charAt(index + word.length())))) {
            return true;
        } else {
            piv = index + 1;
        }
    }
    return false;
}

From source file:net.sf.taverna.t2.activities.beanshell.BeanshellActivity.java

@Override
public void executeAsynch(final Map<String, T2Reference> data, final AsynchronousActivityCallback callback) {
    callback.requestRun(new Runnable() {

        public void run() {

            // Workflow run identifier (needed when classloader sharing is
            // set to 'workflow').
            String procID = callback.getParentProcessIdentifier();
            String workflowRunID;
            if (procID.contains(":")) {
                workflowRunID = procID.substring(0, procID.indexOf(':'));
            } else {
                workflowRunID = procID; // for tests, will be an empty
                // string
            }/*w  ww  .  ja v a 2s . c  o m*/

            synchronized (interpreter) {

                // Configure the classloader for executing the Beanshell
                if (classLoader == null) {
                    try {
                        classLoader = findClassLoader(json, workflowRunID);
                        interpreter.setClassLoader(classLoader);
                    } catch (RuntimeException rex) {
                        String message = "Unable to obtain the classloader for Beanshell service";
                        callback.fail(message, rex);
                        return;
                    }
                }

                ReferenceService referenceService = callback.getContext().getReferenceService();

                Map<String, T2Reference> outputData = new HashMap<String, T2Reference>();

                clearInterpreter();
                try {
                    // set inputs
                    for (String inputName : data.keySet()) {
                        ActivityInputPort inputPort = getInputPort(inputName);
                        Object input = referenceService.renderIdentifier(data.get(inputName),
                                inputPort.getTranslatedElementClass(), callback.getContext());
                        inputName = sanatisePortName(inputName);
                        interpreter.set(inputName, input);
                    }
                    // run
                    interpreter.eval(json.get("script").asText());
                    // get outputs
                    for (OutputPort outputPort : getOutputPorts()) {
                        String name = outputPort.getName();
                        Object value = interpreter.get(name);
                        if (value == null) {
                            ErrorDocumentService errorDocService = referenceService.getErrorDocumentService();
                            value = errorDocService.registerError(
                                    "No value produced for output variable " + name, outputPort.getDepth(),
                                    callback.getContext());
                        }
                        outputData.put(name, referenceService.register(value, outputPort.getDepth(), true,
                                callback.getContext()));
                    }
                    callback.receiveResult(outputData, new int[0]);
                } catch (EvalError e) {
                    logger.error(e);
                    try {
                        int lineNumber = e.getErrorLineNumber();

                        callback.fail("Line " + lineNumber + ": " + determineMessage(e));
                    } catch (NullPointerException e2) {
                        callback.fail(determineMessage(e));
                    }
                } catch (ReferenceServiceException e) {
                    callback.fail("Error accessing beanshell input/output data for " + this, e);
                }
                clearInterpreter();
            }
        }

        /**
         * Removes any invalid characters from the port name. For example,
         * xml-text would become xmltext.
         * 
         * @param name
         * @return
         */
        private String sanatisePortName(String name) {
            String result = name;
            if (Pattern.matches("\\w++", name) == false) {
                result = "";
                for (char c : name.toCharArray()) {
                    if (Character.isLetterOrDigit(c) || c == '_') {
                        result += c;
                    }
                }
            }
            return result;
        }
    });

}

From source file:pl.edu.icm.coansys.commons.java.StringTools.java

/**
 * Normalizes the given value. The normalized strings are better suited for
 * not strict comparisons, in which we don't care about characters that are
 * not letters or digits, about accidental spaces, or about different
 * diacritics etc. <br/><br/>
 * This method: <br/>//from  w w  w.j  av a2 s . c  o m
 * - Replaces some greek letters by theirs "word" equivalend (eg. alpha, beta) <br/>
 * - Replaces all characters that are not letters, digits by spaces<br/>
 * - Replaces white spaces with spaces <br/>
 * - Trims <br />
 * - Compacts many-spaces gaps to one-space gaps <br/>
 * - Removes diacritics <br/>
 * - Lower cases <br/>
 *
 * Returns null if the value is null
 *
 * @see DiacriticsRemover#removeDiacritics(String, boolean)
 *
 *
 */
public static String normalize(final String value) {
    if (value == null || value.isEmpty()) {
        return value;
    }
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < value.length(); ++i) {
        char c = value.charAt(i);
        if (greekLetters.keySet().contains(c)) {
            sb.append(greekLetters.get(c));
        } else if (Character.isLetterOrDigit(c)) {
            sb.append(c);
        } else {
            sb.append(" ");
        }
    }
    String result = sb.toString();
    result = DiacriticsRemover.removeDiacritics(result);
    result = removeStopWords(result);
    result = result.toLowerCase();
    result = result.trim().replaceAll(" +", " ");
    return result;
}

From source file:de.micromata.genome.gwiki.page.impl.wiki.parser.GWikiWikiParser.java

protected boolean isDecorateStart(GWikiWikiTokens tks) {
    char pk = tks.peekToken(-1);
    if (pk != 0 && Character.isLetterOrDigit(pk) == true) {
        return false;
    }//from  ww w.  j  a  v a2 s .c o  m
    pk = tks.peekToken(1);
    if (pk == 0) {
        return false;
    }
    if (Character.isWhitespace(pk) == true) {
        return false;
    }
    return true;

}

From source file:org.sakaiproject.search.util.DocumentIndexingUtils.java

private static String filterPunctuation(String term) {
    if (term == null) {
        return "";
    }// w w  w . ja  v  a2  s .  c  om
    char[] endTerm = term.toCharArray();
    for (int i = 0; i < endTerm.length; i++) {
        if (!Character.isLetterOrDigit(endTerm[i])) {
            endTerm[i] = ' ';
        }
    }
    return new String(endTerm);
}

From source file:com.subgraph.vega.impl.scanner.urls.ResponseAnalyzer.java

private void checkJavascriptXSS(IInjectionModuleContext ctx, HttpUriRequest req, IHttpResponse res,
        String text) {//w  w  w .ja va2  s  .  c o  m
    if (text == null)
        return;
    int lastWordIdx = 0;
    int idx = 0;
    boolean inQuote = false;
    boolean prevSpace = true;
    while (idx < text.length()) {
        idx = maybeSkipJavascriptComment(text, idx);
        if (idx >= text.length())
            return;
        char c = text.charAt(idx);
        if (!inQuote && (c == '\'' || c == '"')) {
            inQuote = true;
            if (matchStartsWith(text, lastWordIdx, "innerHTML", "open", "url", "href", "write")
                    && matchStartsWith(text, idx + 1, "//vega.invalid/", "http://vega.invalid", "vega:")) {
                alert(ctx, "vinfo-url-inject", "Injected URL in JS/CSS code", req, res);
            }
        } else if (c == '\'' || c == '"') {
            inQuote = false;
        } else if (!inQuote && text.startsWith("vvv", idx)) {
            possibleXssAlert(ctx, req, res, text, idx, "vinfo-xss-inject", "Injected syntax into JS/CSS code");
        } else if (Character.isWhitespace(c) || c == '.') {
            prevSpace = true;
        } else if (prevSpace && Character.isLetterOrDigit(c)) {
            lastWordIdx = idx;
            prevSpace = false;
        }
        idx += 1;
    }
}

From source file:net.sf.jabref.groups.structure.KeywordGroup.java

/**
 * Look for the given non-regexp string in another string, but check whether a
 * match concerns a complete word, not part of a word.
 *
 * @param word The word to look for.//from   www.  j a v  a  2s . c  o  m
 * @param text The string to look in.
 * @return true if the word was found, false otherwise.
 */
private static boolean containsWord(String word, String text) {
    int piv = 0;
    while (piv < text.length()) {
        int index = text.indexOf(word, piv);
        if (index < 0) {
            return false;
        }
        // Found a match. See if it is a complete word:
        if (((index == 0) || !Character.isLetterOrDigit(text.charAt(index - 1)))
                && (((index + word.length()) == text.length())
                        || !Character.isLetterOrDigit(text.charAt(index + word.length())))) {
            return true;
        } else {
            piv = index + 1;
        }
    }
    return false;
}

From source file:com.df.dfcarchecker.CarCheck.CarCheckBasicInfoFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //        Random r=new Random();
    //        int uniqueNumber =(r.nextInt(999) + 100);
    //        uniqueId = Integer.toString(uniqueNumber);

    // ?uniqueId/*from  ww w  . j ava  2  s  .  c  o m*/
    UUID uuid = UUID.randomUUID();
    uniqueId = uuid.toString();

    this.inflater = inflater;
    rootView = inflater.inflate(R.layout.fragment_car_check_basic_info, container, false);

    // <editor-fold defaultstate="collapsed" desc="??View?">
    tableLayout = (TableLayout) rootView.findViewById(R.id.bi_content_table);

    contentLayout = (LinearLayout) rootView.findViewById(R.id.brand_input);

    Button vinButton = (Button) rootView.findViewById(R.id.bi_vin_button);
    vinButton.setOnClickListener(this);

    brandOkButton = (Button) rootView.findViewById(R.id.bi_brand_ok_button);
    brandOkButton.setEnabled(false);
    brandOkButton.setOnClickListener(this);

    brandSelectButton = (Button) rootView.findViewById(R.id.bi_brand_select_button);
    brandSelectButton.setEnabled(false);
    brandSelectButton.setOnClickListener(this);

    // ??
    sketchPhotoEntities = new ArrayList<PhotoEntity>();

    // 
    Button matchButton = (Button) rootView.findViewById(R.id.ct_licencePhotoMatch_button);
    matchButton.setOnClickListener(this);

    // vin???
    InputFilter alphaNumericFilter = new InputFilter() {
        @Override
        public CharSequence filter(CharSequence arg0, int arg1, int arg2, Spanned arg3, int arg4, int arg5) {
            for (int k = arg1; k < arg2; k++) {
                if (!Character.isLetterOrDigit(arg0.charAt(k))) {
                    return "";
                }
            }
            return null;
        }
    };
    vin_edit = (EditText) rootView.findViewById(R.id.bi_vin_edit);
    vin_edit.setFilters(new InputFilter[] { alphaNumericFilter, new InputFilter.AllCaps() });

    brandEdit = (EditText) rootView.findViewById(R.id.bi_brand_edit);
    displacementEdit = (EditText) rootView.findViewById(R.id.csi_displacement_edit);
    transmissionEdit = (EditText) rootView.findViewById(R.id.csi_transmission_edit);
    runEdit = (EditText) rootView.findViewById(R.id.bi_mileage_edit);
    //
    //        transmissionSpinner = (Spinner)rootView.findViewById(R.id.csi_transmission_spinner);
    //        transmissionSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
    //            @Override
    //            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
    //                transmissionEdit.setText(adapterView.getSelectedItem().toString());
    //            }
    //
    //            @Override
    //            public void onNothingSelected(AdapterView<?> adapterView) {
    //
    //            }
    //        });

    // ??????
    ScrollView view = (ScrollView) rootView.findViewById(R.id.root);
    view.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    view.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            v.requestFocusFromTouch();
            return false;
        }
    });

    // ????????2?
    runEdit.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable edt) {
            String temp = edt.toString();

            if (temp.contains(".")) {
                int posDot = temp.indexOf(".");
                if (posDot <= 0)
                    return;
                if (temp.length() - posDot - 1 > 2) {
                    edt.delete(posDot + 3, posDot + 4);
                }
            } else {
                if (temp.length() > 2) {
                    edt.clear();
                    edt.append(temp.substring(0, 2));
                }
            }
        }

        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
        }

        public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
        }
    });

    licencePhotoMatchEdit = (EditText) rootView.findViewById(R.id.ct_licencePhotoMatch_edit);
    licencePhotoMatchEdit.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            licencePhotoMatchEdit.setError(null);
        }

        @Override
        public void afterTextChanged(Editable editable) {
            licencePhotoMatchEdit.setError(null);
        }
    });

    // ??
    carNumberEdit = (EditText) rootView.findViewById(R.id.ci_plateNumber_edit);
    carNumberEdit.setFilters(new InputFilter[] { new InputFilter.AllCaps(), new InputFilter.LengthFilter(10) });

    // ?
    portedProcedureRow = (TableRow) rootView.findViewById(R.id.ct_ported_procedure);

    // ?Spinner
    setRegLocationSpinner();
    setCarColorSpinner();
    setFirstLogTimeSpinner();
    setManufactureTimeSpinner();
    setTransferCountSpinner();
    setLastTransferTimeSpinner();
    setYearlyCheckAvailableDateSpinner();
    setAvailableDateYearSpinner();
    setBusinessInsuranceAvailableDateYearSpinner();
    setOtherSpinners();
    // </editor-fold>

    mCarSettings = new CarSettings();

    // ??xml
    if (vehicleModel == null) {
        mProgressDialog = ProgressDialog.show(rootView.getContext(), null, "?..", false, false);

        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    ParseXml();

                    // jsonData??
                    if (!jsonData.equals("")) {
                        modifyMode = true;
                        letsEnterModifyMode();
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

        thread.start();
    }

    return rootView;
}

From source file:de.bund.bfr.knime.pmm.common.math.MathUtilities.java

public static boolean isVariableCharacter(char ch) {
    return Character.isLetterOrDigit(ch) || ch == '_' || ch == '$';
}

From source file:tsapalos.bill.play4share.UrlUtils.java

private static boolean isApprovedCharacter(char c) {
    char[] approved = new char[] { '-', '_' };
    if (Character.isLetterOrDigit(c)) {
        return true;
    } else {//from   w  w  w .  j  av a 2 s .c o  m
        for (int i = 0; i < approved.length; i++) {
            if (c == approved[i]) {
                return true;
            }
        }
    }
    return false;
}