List of usage examples for java.lang Character isLetterOrDigit
public static boolean isLetterOrDigit(int codePoint)
From source file:com.kantenkugel.discordbot.modules.AutoRespond.java
@Override public boolean handle(MessageEvent event, ServerConfig cfg) { if (event.isEdit() || event.getAuthor() == event.getJDA().getSelfInfo() || (!channels.isEmpty() && !channels.contains(event.getTextChannel().getId())) || event.getContent().startsWith(servercfg.getPrefix())) { return false; }/*from w ww.j av a2s .c om*/ String content = event.getContent().toLowerCase(); Optional<String> response = responses.values().parallelStream() .filter(r -> r.getLeft().parallelStream().allMatch(k -> { int i = content.indexOf(k); return i >= 0 //exists && (i == 0 || content.charAt(i - 1) == ' ') //at beginning or after space && (i + k.length() == content.length() //et end or no alphanumeric || !Character.isLetterOrDigit(content.charAt(i + k.length()))); })).map(Pair::getRight).findAny(); if (response.isPresent()) { respondLog.info(String.format("[%s][%s] %s: %s\n\t->%s", event.getGuild().getName(), event.getTextChannel().getName(), event.getAuthor().getUsername(), event.getContent(), response.get())); MessageUtil.replySync(event, cfg, response.get()); } return false; }
From source file:com.liferay.ide.maven.core.util.DefaultMaven2OsgiConverter.java
/** * Get the symbolic name as groupId + "." + artifactId, with the following exceptions * <ul>//from w w w.j av a 2 s .c o m * <li>if artifact.getFile is not null and the jar contains a OSGi Manifest with * Bundle-SymbolicName property then that value is returned</li> * <li>if groupId has only one section (no dots) and artifact.getFile is not null then the * first package name with classes is returned. eg. commons-logging:commons-logging -> * org.apache.commons.logging</li> * <li>if artifactId is equal to last section of groupId then groupId is returned. eg. * org.apache.maven:maven -> org.apache.maven</li> * <li>if artifactId starts with last section of groupId that portion is removed. eg. * org.apache.maven:maven-core -> org.apache.maven.core</li> * </ul> */ public String getBundleSymbolicName(Artifact artifact) { if ((artifact.getFile() != null) && artifact.getFile().exists()) { Analyzer analyzer = new Analyzer(); try { JarFile jar = new JarFile(artifact.getFile(), false); if (jar.getManifest() != null) { String symbolicNameAttribute = jar.getManifest().getMainAttributes() .getValue(Analyzer.BUNDLE_SYMBOLICNAME); Map bundleSymbolicNameHeader = analyzer.parseHeader(symbolicNameAttribute); Iterator it = bundleSymbolicNameHeader.keySet().iterator(); if (it.hasNext()) { return (String) it.next(); } } } catch (IOException e) { throw new RuntimeException("Error reading manifest in jar " + artifact.getFile().getAbsolutePath(), e); } } int i = artifact.getGroupId().lastIndexOf('.'); if ((i < 0) && (artifact.getFile() != null) && artifact.getFile().exists()) { String groupIdFromPackage = getGroupIdFromPackage(artifact.getFile()); if (groupIdFromPackage != null) { return groupIdFromPackage; } } String lastSection = artifact.getGroupId().substring(++i); if (artifact.getArtifactId().equals(lastSection)) { return artifact.getGroupId(); } if (artifact.getArtifactId().startsWith(lastSection)) { String artifactId = artifact.getArtifactId().substring(lastSection.length()); if (Character.isLetterOrDigit(artifactId.charAt(0))) { return getBundleSymbolicName(artifact.getGroupId(), artifactId); } else { return getBundleSymbolicName(artifact.getGroupId(), artifactId.substring(1)); } } return getBundleSymbolicName(artifact.getGroupId(), artifact.getArtifactId()); }
From source file:com.redhat.rhn.common.util.StringUtil.java
/** * Converts the passed in string to a valid java Class name. This basically * capitalizes each word and removes all word delimiters. * @param strIn The string to convert.//from ww w . j a va 2 s.c o m * @return The converted string. */ public static String classify(String strIn) { String str = strIn.trim(); StringBuilder result = new StringBuilder(str.length()); boolean wasWhitespace = false; for (int i = 0, j = 0; i < str.length(); i++) { char c = str.charAt(i); if (Character.isLetterOrDigit(c)) { if (i == 0) { c = Character.toUpperCase(c); } if (wasWhitespace) { c = Character.toUpperCase(c); wasWhitespace = false; } result.insert(j, c); j++; continue; } wasWhitespace = true; } return result.toString(); }
From source file:com.awt.supark.EditCar.java
@Nullable @Override/*from w w w. j a va2 s. c om*/ 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:org.tightblog.util.Utilities.java
/** * Replaces occurrences of non-alphanumeric characters with a supplied char. * Exception: apostrophes are removed with no replacement *//*from w ww.j a va 2 s .c o m*/ public static String replaceNonAlphanumeric(String str, char subst) { StringBuilder ret = new StringBuilder(str.length()); char[] testChars = str.toCharArray(); for (char aChar : testChars) { if (Character.isLetterOrDigit(aChar)) { ret.append(aChar); } else if (aChar != '\'') { ret.append(subst); } } return ret.toString(); }
From source file:org.janusgraph.core.attribute.Text.java
public static List<String> tokenize(String str) { ArrayList<String> tokens = new ArrayList<String>(); int previous = 0; for (int p = 0; p < str.length(); p++) { if (!Character.isLetterOrDigit(str.charAt(p))) { if (p > previous + MIN_TOKEN_LENGTH) tokens.add(str.substring(previous, p)); previous = p + 1;// ww w.j a va 2s. c o m } } if (previous + MIN_TOKEN_LENGTH < str.length()) tokens.add(str.substring(previous, str.length())); return tokens; }
From source file:nz.ac.otago.psyanlab.common.designer.program.operand.RenameOperandDialogueFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { Bundle args = getArguments();//from w w w .j av a 2 s .c om if (args != null) { mOperandId = args.getLong(ARG_OPERAND_ID, -1); } if (mOperandId == -1) { throw new RuntimeException("Invalid operand id."); } mOperand = mCallbacks.getOperand(mOperandId); LayoutInflater inflater = getActivity().getLayoutInflater(); View view = inflater.inflate(R.layout.dialogue_rename_variable, null); mName = (EditText) view.findViewById(R.id.name); mName.setText(mOperand.getName()); // Thanks to serwus <http://stackoverflow.com/users/1598308/serwus>, // who posted at <http://stackoverflow.com/a/20325852>. Modified to // support unicode codepoints and validating first character of input. InputFilter filter = new InputFilter() { @Override public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { boolean keepOriginal = true; StringBuilder sb = new StringBuilder(end - start); int offset = 0; String s = source.toString(); while (offset < s.length()) { final int codePoint = s.codePointAt(offset); if ((offset == 0 && isAllowedAsFirst(codePoint)) || (offset > 0 && isAllowed(codePoint))) { sb.appendCodePoint(codePoint); } else { keepOriginal = false; } offset += Character.charCount(codePoint); } if (keepOriginal) return null; else { if (source instanceof Spanned) { SpannableString sp = new SpannableString(sb); TextUtils.copySpansFrom((Spanned) source, start, sb.length(), null, sp, 0); return sp; } else { return sb; } } } private boolean isAllowed(int codePoint) { return Character.isLetterOrDigit(codePoint); } private boolean isAllowedAsFirst(int codePoint) { return Character.isLetter(codePoint); } }; mName.setFilters(new InputFilter[] { filter }); // Build dialogue. AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(getString(R.string.title_rename_variable, mOperand.getName())).setView(view) .setPositiveButton(R.string.action_rename, mPositiveListener) .setNegativeButton(R.string.action_cancel, mNegativeListener); // Create the AlertDialog object and return it Dialog dialog = builder.create(); dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); return dialog; }
From source file:us.conxio.hl7.hl7message.HL7Encoding.java
/** * Checks for valid encoding character//from ww w. java 2 s . c om * @param charV the encoding character value to check * @return true if valid, otherwise false. */ private boolean isValidEncoder(int charV) { if (charV == 0 || Character.isLetterOrDigit(charV) || Character.isWhitespace(charV)) { return false; } // if return true; }
From source file:com.microsoft.tfs.jni.helpers.LocalHost.java
/** * Only called when all techniques to get the host name fail. Simply makes * up a string based on the username./* www .j ava 2 s. c o m*/ * * @return a made-up hostname including the username running Java and some * other text. Never null. */ private static String getMadeUpShortName() { String username = System.getProperty("user.name"); //$NON-NLS-1$ /* * Scrub out non-alphanumeric characters. */ if (username != null) { final StringBuffer newUsername = new StringBuffer(); for (int i = 0; i < username.length(); i++) { final char c = username.charAt(i); if (Character.isLetterOrDigit(c)) { newUsername.append(c); } } username = newUsername.toString(); } if (username != null && username.length() != 0) { // Something like "JohnComputer". return username + "Computer"; //$NON-NLS-1$ } log.warn(MessageFormat.format( "Could not make a hostname from the username '{0}' because it had no usable characters", //$NON-NLS-1$ username)); // Everything failed. return "TEEComputer"; //$NON-NLS-1$ }
From source file:org.ajax4jsf.javascript.ScriptUtils.java
public static String getValidJavascriptName(String s) { StringBuffer buf = null;/*from ww w . j av a2 s .c o m*/ for (int i = 0, len = s.length(); i < len; i++) { char c = s.charAt(i); if (Character.isLetterOrDigit(c) || c == '_') { // allowed char if (buf != null) buf.append(c); } else { if (buf == null) { buf = new StringBuffer(s.length() + 10); buf.append(s.substring(0, i)); } buf.append('_'); if (c < 16) { // pad single hex digit values with '0' on the left buf.append('0'); } if (c < 128) { // first 128 chars match their byte representation in UTF-8 buf.append(Integer.toHexString(c).toUpperCase()); } else { byte[] bytes; try { bytes = Character.toString(c).getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } for (int j = 0; j < bytes.length; j++) { int intVal = bytes[j]; if (intVal < 0) { // intVal will be >= 128 intVal = 256 + intVal; } else if (intVal < 16) { // pad single hex digit values with '0' on the left buf.append('0'); } buf.append(Integer.toHexString(intVal).toUpperCase()); } } } } return buf == null ? s : buf.toString(); }