List of usage examples for java.lang CharSequence toString
public String toString();
From source file:com.github.magicsky.sya.checkers.TestSourceReader.java
/** * Creates a file with content at the given path inside the given container. * If the file exists its content is replaced. * * @param container a container to create the file in * @param filePath the path relative to the container to create the file at * @param contents the content for the file * @return a file object./*from www . j av a2s.c o m*/ * @throws CoreException * @since 4.0 */ public static IFile createFile(final IContainer container, final IPath filePath, final CharSequence contents) throws CoreException { final IWorkspace ws = ResourcesPlugin.getWorkspace(); final IFile result[] = new IFile[1]; ws.run(new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { // Obtain file handle IFile file = container.getFile(filePath); InputStream stream; try { stream = new ByteArrayInputStream(contents.toString().getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new CoreException(new Status(IStatus.ERROR, CTestPlugin.PLUGIN_ID, null, e)); } // Create file input stream if (file.exists()) { long timestamp = file.getLocalTimeStamp(); file.setContents(stream, false, false, new NullProgressMonitor()); if (file.getLocalTimeStamp() == timestamp) { file.setLocalTimeStamp(timestamp + 1000); } } else { createFolders(file); file.create(stream, true, new NullProgressMonitor()); } result[0] = file; } private void createFolders(IResource res) throws CoreException { IContainer container = res.getParent(); if (!container.exists() && container instanceof IFolder) { createFolders(container); ((IFolder) container).create(true, true, new NullProgressMonitor()); } } }, null); return result[0]; }
From source file:org.cleverbus.common.Strings.java
/** * @param input the input// w ww. j ava 2 s . c o m * @param text the searched text * @return the index or -1 * @since 3.8.2 */ public static int indexOf(CharSequence input, String text) { if (input instanceof String) { return ((String) input).indexOf(text); } if (input instanceof StringBuilder) { return ((StringBuilder) input).indexOf(text); } if (input instanceof StringBuffer) { return ((StringBuffer) input).indexOf(text); } return input.toString().indexOf(text); }
From source file:it.unimi.di.big.mg4j.index.DiskBasedIndex.java
/** Commodity method for loading a big list of binary longs with specified endianness into a {@linkplain LongBigArrays long big array}. * /*from ww w .j av a 2 s .co m*/ * @param ioFactory the factory that will be used to perform I/O. * @param filename the file containing the longs. * @param byteOrder the endianness of the longs. * @return a big list of longs containing the longs in <code>file</code>. */ public static LongBigArrayBigList loadLongBigList(final IOFactory ioFactory, final CharSequence filename, final ByteOrder byteOrder) throws IOException { final long length = ioFactory.length(filename.toString()) / (Long.SIZE / Byte.SIZE); ReadableByteChannel channel = ioFactory.getReadableByteChannel(filename.toString()); final LongBigArrayBigList loadLongBigList = loadLongBigList(channel, length, byteOrder); channel.close(); return loadLongBigList; }
From source file:it.unimi.di.big.mg4j.index.DiskBasedIndex.java
/** Utility method to load a compressed offset file into a list. * * @param ioFactory the factory that will be used to perform I/O. * @param filename the file containing the offsets (see {@link BitStreamIndexWriter}). * @param T the number of terms indexed. * @return a list of longs backed by an array; the list has * an additional final element of index <code>T</code> that gives the number * of bytes of the index file.//from w ww . jav a 2s . c o m */ public static LongBigList readOffsets(final IOFactory ioFactory, final CharSequence filename, final long T) throws IOException { final InputBitStream in = new InputBitStream(ioFactory.getInputStream(filename.toString()), false); final LongBigList offsets = readOffsets(in, T); in.close(); return offsets; }
From source file:com.heliosapm.tsdblite.json.JSON.java
/** * Parses the passed stringy into a JsonNode * @param jsonStr The stringy to parse/*from www. j a va 2s.c o m*/ * @return the parsed JsonNode */ public static JsonNode parseToNode(final CharSequence jsonStr) { if (jsonStr == null) throw new IllegalArgumentException("Incoming data was null"); final String str = jsonStr.toString().trim(); if (str.isEmpty()) throw new IllegalArgumentException("Incoming data was empty"); try { return jsonMapper.readTree(str); } catch (JsonParseException e) { throw new IllegalArgumentException(e); } catch (IOException e) { throw new JSONException(e); } }
From source file:com.liferay.events.global.mobile.Utils.java
/** * This method returns the Jaro-Winkler score for string matching. * * @param first the first string to be matched * @param second the second string to be machted * @return matching score without scaling factor impact *///ww w . j av a2 s .co m private static double score(final CharSequence first, final CharSequence second) { String shorter; String longer; // Determine which String is longer. if (first.length() > second.length()) { longer = first.toString().toLowerCase(); shorter = second.toString().toLowerCase(); } else { longer = second.toString().toLowerCase(); shorter = first.toString().toLowerCase(); } // Calculate the half length() distance of the shorter String. final int halflength = shorter.length() / 2 + 1; // Find the set of matching characters between the shorter and longer strings. Note that // the set of matching characters may be different depending on the order of the strings. final String m1 = getSetOfMatchingCharacterWithin(shorter, longer, halflength); final String m2 = getSetOfMatchingCharacterWithin(longer, shorter, halflength); // If one or both of the sets of common characters is empty, then // there is no similarity between the two strings. if (m1.length() == 0 || m2.length() == 0) { return 0.0; } // If the set of common characters is not the same size, then // there is no similarity between the two strings, either. if (m1.length() != m2.length()) { return 0.0; } // Calculate the number of transposition between the two sets // of common characters. final int transpositions = transpositions(m1, m2); // Calculate the distance. return (m1.length() / ((double) shorter.length()) + m2.length() / ((double) longer.length()) + (m1.length() - transpositions) / ((double) m1.length())) / 3.0; }
From source file:com.arellomobile.android.push.PushGCMIntentService.java
private static void generateNotification(Context context, Intent intent, Handler handler) { Bundle extras = intent.getExtras();/*ww w .j a v a 2 s . c om*/ if (extras == null) { return; } extras.putBoolean("foregroud", GeneralUtils.isAppOnForeground(context)); String title = (String) extras.get("title"); String link = (String) extras.get("l"); // empty message with no data Intent notifyIntent; if (link != null) { // we want main app class to be launched notifyIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(link)); notifyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } else { notifyIntent = new Intent(context, PushHandlerActivity.class); notifyIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); // pass all bundle notifyIntent.putExtra("pushBundle", extras); } // first string will appear on the status bar once when message is added CharSequence appName = context.getPackageManager().getApplicationLabel(context.getApplicationInfo()); if (null == appName) { appName = ""; } NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationFactory notificationFactory; //is this banner notification? String bannerUrl = (String) extras.get("b"); //also check that notification layout has been placed in layout folder int layoutId = context.getResources().getIdentifier(BannerNotificationFactory.sNotificationLayout, "layout", context.getPackageName()); if (layoutId != 0 && bannerUrl != null) { notificationFactory = new BannerNotificationFactory(context, extras, appName.toString(), title, PushManager.sSoundType, PushManager.sVibrateType); } else { notificationFactory = new SimpleNotificationFactory(context, extras, appName.toString(), title, PushManager.sSoundType, PushManager.sVibrateType); } notificationFactory.generateNotification(); notificationFactory.addSoundAndVibrate(); notificationFactory.addCancel(); Notification notification = notificationFactory.getNotification(); notification.contentIntent = PendingIntent.getActivity(context, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); if (mSimpleNotification) { manager.notify(PushManager.MESSAGE_ID, notification); } else { manager.notify(PushManager.MESSAGE_ID++, notification); } generateBroadcast(context, extras); }
From source file:com.heliosapm.tsdblite.json.JSON.java
/** * Parses the passed stringy and returns the resulting JsonNode * @param cs the stringy to parse/* w w w . j a v a 2 s .com*/ * @return the JsonNode */ public static JsonNode parse(final CharSequence cs) { if (cs == null) throw new IllegalArgumentException("The passed CharSequence was null or empty"); try { return jsonMapper.readTree(cs.toString().trim()); } catch (Exception ex) { throw new JSONException(ex); } }
From source file:it.unimi.di.big.mg4j.index.DiskBasedIndex.java
/** Utility method to load a compressed size file into a list. * * @param ioFactory the factory that will be used to perform I/O. * @param filename the file containing the γ-coded sizes (see {@link BitStreamIndexWriter}). * @param n the number of documents./*from w w w .j a v a 2 s. com*/ * @return a list of integers backed by an array. */ public static IntBigArrayBigList readSizes(final IOFactory ioFactory, final CharSequence filename, final long n) throws IOException { final int[][] size = IntBigArrays.newBigArray(n); final InputBitStream in = new InputBitStream(ioFactory.getInputStream(filename.toString()), false); LOGGER.debug("Loading sizes..."); for (int segment = 0; segment < size.length; segment++) in.readGammas(size[segment], size[segment].length); LOGGER.debug("Completed."); in.close(); return IntBigArrayBigList.wrap(size); }
From source file:com.feilong.core.lang.StringUtil.java
/** * <code>replacement</code>??? <code>regex</code>?. * /*from w w w .ja v a 2s .c o m*/ * <p> * ?, {@link java.util.regex.Matcher#replaceAll(String)},same as * <code>Pattern.compile(regex).matcher(str).replaceAll(repl)</code> * </p> * * <h3>:</h3> * * <blockquote> * * <pre class="code"> * StringUtil.replaceAll("SH1265,SH5951,SH6766,SH7235,SH1265,SH5951,SH6766,SH7235", "([a-zA-Z]+[0-9]+)", "'$1'") * </pre> * * <b>:</b> * * <pre class="code"> * 'SH1265','SH5951','SH6766','SH7235','SH1265','SH5951','SH6766','SH7235' * </pre> * * </blockquote> * * <h3>?:</h3> * * <blockquote> * <p> * <code>replacement</code>, backslashes???(<tt>\</tt>) dollar signs? (<tt>$</tt>)????. * <br> * ? {@link java.util.regex.Matcher#replaceAll Matcher.replaceAll};?,? {@link java.util.regex.Matcher#quoteReplacement * Matcher.quoteReplacement}?? * <br> * Dollar signs may betreated as references to captured subsequences as described above,$,???, * $0?,$11?,$12? * <br> * andbackslashes are used to escape literal characters in the replacementstring. * </p> * </blockquote> * * <h3>?:</h3> * * <blockquote> * * <pre class="code"> * * //?. * public void splitAndAddYinHao(){ * String a = "12345,56789,1123456"; * String[] aStrings = a.split(","); * StringBuilder sb = new StringBuilder(); * int size = aStrings.length; * for (int i = 0; i {@code <} size; i++){ * sb.append("'" + aStrings[i] + "'"); * if (i != size - 1){ * sb.append(","); * } * } * LOGGER.debug(sb.toString()); * } * * </pre> * * ???: * * <pre class="code"> * StringUtil.replaceAll("12345,56789,1123456", "([0-9]+)", "'$1'") * </pre> * * : * * <pre class="code"> * '12345','56789','1123456' * </pre> * * </blockquote> * * @param content * ?? * @param regex * ??? * @param replacement * ???? * @return <code>content</code> null, {@link StringUtils#EMPTY}<br> * @see <a href="http://stamen.iteye.com/blog/2028256">String?</a> * @see java.lang.String#replaceAll(String, String) * @since jdk 1.4 */ public static String replaceAll(CharSequence content, String regex, String replacement) { return null == content ? EMPTY : content.toString().replaceAll(regex, replacement); }