Example usage for com.google.common.base CharMatcher is

List of usage examples for com.google.common.base CharMatcher is

Introduction

In this page you can find the example usage for com.google.common.base CharMatcher is.

Prototype

public static CharMatcher is(final char match) 

Source Link

Document

Returns a char matcher that matches only one specified character.

Usage

From source file:dict.Dict.java

public static void main(String[] args) throws SQLException {

    //If a char is not in input, it should be in select...where...not like...
    String availableChars = args[0];
    List<String> letersToSelect = new ArrayList();
    for (String leter : ALPHABET) {
        if (!availableChars.contains(leter)) {
            letersToSelect.add(leter);/*  ww  w .  ja  va  2 s .  c  om*/
        }
    }

    //Indentify multiple occurance of the same character
    HashMap charMap = new HashMap();
    for (char oneChar : availableChars.toCharArray()) {
        int countIn = CharMatcher.is(oneChar).countIn(availableChars);
        charMap.put(String.valueOf(oneChar), countIn);
    }
    //Construct select statement
    String select = constructSelect(letersToSelect, charMap, availableChars.length());

    //URL of Oracle database server
    String url = "jdbc:oracle:thin:@192.168.56.101:1521:ORCL";

    //properties for creating connection to Oracle database
    Properties props = new Properties();
    props.setProperty("user", "dictionary");
    props.setProperty("password", "dictionary");

    //creating connection to Oracle database using JDBC
    Connection conn = DriverManager.getConnection(url, props);
    PreparedStatement preStatement = conn.prepareStatement(select);
    ResultSet result;

    result = preStatement.executeQuery();
    while (result.next()) {
        System.out.println("Scrabble word: " + result.getString("word"));
    }

    System.out.println("done");

}

From source file:com.google.cloud.genomics.dataflow.pipelines.DeleteVariants.java

public static void main(String[] args) throws IOException, GeneralSecurityException {
    // Register the options so that they show up via --help
    PipelineOptionsFactory.register(Options.class);
    Options options = PipelineOptionsFactory.fromArgs(args).withValidation().as(Options.class);
    // Option validation is not yet automatic, we make an explicit call here.
    Options.Methods.validateOptions(options);

    OfflineAuth auth = GenomicsOptions.Methods.getGenomicsAuth(options);

    GenomicsOptions.Methods.requestConfirmation("*** The pipeline will delete variants whose "
            + "ids are listed in: " + options.getInput() + ". ***");

    Pipeline p = Pipeline.create(options);

    p.apply(TextIO.Read.named("ReadLines").from(options.getInput()))
            .apply(ParDo.named("ParseVariantIds").of(new DoFn<String, String>() {
                @Override/*from  w ww.  j a  va2s.c om*/
                public void processElement(ProcessContext c) {
                    String record = c.element();

                    // The variant id will be retrieved from the first column.  Any other columns
                    // will be ignored.
                    Iterable<String> fields = Splitter
                            .on(CharMatcher.BREAKING_WHITESPACE.or(CharMatcher.is(','))).omitEmptyStrings()
                            .trimResults().split(record);
                    java.util.Iterator<String> iter = fields.iterator();
                    if (iter.hasNext()) {
                        c.output(iter.next());
                    }
                }
            })).apply(ParDo.of(new DeleteVariantFn(auth))).apply(Sum.integersGlobally())
            .apply(ParDo.named("FormatResults").of(new DoFn<Integer, String>() {
                @Override
                public void processElement(ProcessContext c) {
                    c.output("Deleted Variant Count: " + c.element());
                }
            })).apply(TextIO.Write.named("Write Count").to(options.getOutput()));

    p.run();
}

From source file:com.google.gerrit.httpd.LoginUrlToken.java

public static String getToken(final HttpServletRequest req) {
    String token = req.getPathInfo();
    if (Strings.isNullOrEmpty(token)) {
        return DEFAULT_TOKEN;
    }// w w w.  j  a  v  a2s . c om
    return CharMatcher.is('/').trimLeadingFrom(token);
}

From source file:com.squareup.wire.schema.Location.java

public static Location get(String base, String path) {
    base = CharMatcher.is('/').trimTrailingFrom(base);
    path = CharMatcher.is('/').trimLeadingFrom(path);
    return new AutoValue_Location(base, path, -1, -1);
}

From source file:com.google.api.server.spi.Strings.java

/**
 * Strips the lead slash from a string if it has a lead slash; otherwise return the
 * string unchanged./*from  ww w . ja va  2s . co  m*/
 */
public static String stripLeadingSlash(String s) {
    return s == null ? null : CharMatcher.is('/').trimLeadingFrom(s);
}

From source file:de.qaware.chronix.solr.compaction.TimeSeriesId.java

private static String escape(Object obj) {
    return CharMatcher.is('\\').replaceFrom(obj.toString(), "\\\\");
}

From source file:com.google.api.server.spi.Strings.java

/**
 * Strips the trailing slash from a string if it has a trailing slash; otherwise return the
 * string unchanged./* w w  w. j  ava2s . com*/
 */
public static String stripTrailingSlash(String s) {
    return s == null ? null : CharMatcher.is('/').trimTrailingFrom(s);
}

From source file:co.cask.cdap.app.verification.AbstractVerifier.java

protected boolean isId(final String name) {
    return !name.isEmpty()
            && CharMatcher.inRange('A', 'Z').or(CharMatcher.inRange('a', 'z')).or(CharMatcher.is('-'))
                    .or(CharMatcher.is('_')).or(CharMatcher.inRange('0', '9')).matchesAllOf(name);
}

From source file:com.google.api.server.spi.Strings.java

/**
 * Strips the leading and trailing slash from a string if it has a trailing slash; otherwise
 * return the string unchanged.//from w ww . jav  a  2 s .  co m
 */
public static String stripSlash(String s) {
    return s == null ? null : CharMatcher.is('/').trimFrom(s);
}

From source file:org.eclipse.mylyn.internal.wikitext.markdown.core.GfmIdGenerationStrategy.java

@Override
public String generateId(String headingText) {
    String id = headingText.toLowerCase(Locale.getDefault());
    id = id.replaceAll("[^a-z0-9_-]", "-"); //$NON-NLS-1$//$NON-NLS-2$
    CharMatcher hyphenMatcher = CharMatcher.is('-');
    id = hyphenMatcher.trimFrom(hyphenMatcher.collapseFrom(id, '-'));
    return id;/*w  w  w . j a v a  2s .c  o m*/
}