List of usage examples for com.google.common.collect Lists charactersOf
@Beta public static List<Character> charactersOf(CharSequence sequence)
From source file:Dictconvert_with_elements.java
public static void main(String args[]) throws Exception { String targetNameSpace = args[1]; String targetNameSpaceVar = args[2]; Map<String, String> namespaces = ImmutableMap.<String, String>of(targetNameSpace, targetNameSpaceVar); HashMap<String, String> keys = new HashMap<String, String>(); DocumentBuilderFactory builderF = DocumentBuilderFactory.newInstance(); builderF.setNamespaceAware(true);/*w w w. jav a2 s . com*/ DocumentBuilder builder = builderF.newDocumentBuilder(); Document xmlDictionary = builder.parse(args[0]); for (Map.Entry<String, String> e : namespaces.entrySet()) { System.out.println("XMLCh " + e.getValue() + "[] = {" + Joiner.on(",") .join(Iterables.transform(Lists.charactersOf(e.getKey()), new Function<Character, String>() { public String apply(Character o) { return "\'" + o + "\'"; } })) + ",\'\\0\'};"); } Map<String, String> localKeys = new HashMap<String, String>(); for (Element e : Iterables.filter(getElements(xmlDictionary.getDocumentElement()), new Predicate<Element>() { public boolean apply(Element element) { return element.getAttribute("type").equals("localSet"); } })) { String name = e.getLocalName(); String keyName = "key_" + Joiner.on("").join(e.getAttribute("key").split("\\s")); localKeys.put(keyName, keyName + "_name"); System.out.println("mxfKey " + keyName + " = {" + Joiner.on(",").join(Iterables .transform(Arrays.asList(e.getAttribute("key").split("\\s")), new Function<String, String>() { public String apply(String o) { return "0x" + o; } })) + "};"); System.out.println("XMLCh " + keyName + "_name[] = {" + Joiner.on(",") .join(Iterables.transform(Lists.charactersOf(name), new Function<Character, String>() { public String apply(Character o) { return "\'" + o + "\'"; } })) + ",\'\\0\'};"); //System.out.println("st434dict.insert(std::pair<mxfKey, st434info*>("); //System.out.println('\t' + keyName + ','); //System.out.println("\tnew st434info(/* " + name + " */ " + keyName + "_name, /* " + targetNameSpace + " */ " + namespaces.get(targetNameSpace) + ")"); //System.out.println("));"); for (Element ee : getElements(e)) { String elemKeyName = "key_" + Joiner.on("").join(ee.getAttribute("globalKey").split("\\s")); localKeys.put(elemKeyName, elemKeyName + "_name"); System.out.println("mxfKey " + elemKeyName + " = {" + Joiner.on(",").join(Iterables.transform( Arrays.asList(ee.getAttribute("globalKey").split("\\s")), new Function<String, String>() { public String apply(String o) { return "0x" + o; } })) + "};"); System.out.println("XMLCh " + elemKeyName + "_name[] = {" + Joiner.on(",").join(Iterables .transform(Lists.charactersOf(ee.getLocalName()), new Function<Character, String>() { public String apply(Character o) { return "\'" + o + "\'"; } })) + ",\'\\0\'};"); //System.out.println("st434dict.insert(std::pair<mxfKey, st434info*>("); //System.out.println('\t' + elemKeyName + ','); //System.out.println("\tnew st434info(/* " + ee.getLocalName() + " */ " + elemKeyName + "_name, /* " + targetNameSpace + " */ " + namespaces.get(targetNameSpace) + ")"); //System.out.println("));"); } } if (localKeys.size() > 0) { String arrayName = "arr_" + targetNameSpaceVar; System.out.println("const void* " + arrayName + "[][2] = {"); System.out.println(Joiner.on(", \n").join( Iterables.transform(localKeys.entrySet(), new Function<Map.Entry<String, String>, String>() { @Override public String apply(java.util.Map.Entry<String, String> e) { return "{ &" + e.getKey() + ", " + e.getValue() + " }"; } }))); System.out.println("};"); System.out.println("for (int i=0; i<" + localKeys.size() + ";i++) {"); System.out.println("\tst434dict.insert(std::pair<const mxfKey, st434info*>("); System.out.println("\t*(const mxfKey*)" + arrayName + "[i][0], "); System.out .println("\tnew st434info((const XMLCh*)" + arrayName + "[i][1], " + targetNameSpaceVar + ")"); System.out.println("));"); System.out.println("}"); } }
From source file:Dictconvert.java
public static void main(String args[]) throws Exception { final ImmutableMap<String, String> nameMap = new ImmutableMap.Builder<String, String>() .put("ebucoreMainFramework", "ebucoreMainFramework") .put("ebucorePartFramework", "ebucorePartFramework") .put("ebucoreMetadataSchemeInformation", "ebucoreMetadataSchemeInformation") /* List mainly generated using AWK: awk '{t=$2; gsub(/ebucore/, "", t); print "\x27"$2"\x27:\x27" tolower(substr(t, 1, 1))substr(t, 2)"\x27," }' < tmp.txt > tmpout.txt *///from w w w. j a va 2 s.co m .put("ebucoreEntity", "entity").put("ebucoreContact", "contact") .put("ebucoreContactDetails", "details").put("ebucoreAddress", "address") .put("ebucoreRegion", "region").put("ebucoreCompoundName", "compoundName") .put("ebucoreRole", "role").put("ebucoreCountry", "country") .put("ebucoreTextualAnnotation", "textualAnnotation").put("ebucoreBasicLink", "basicLink") .put("ebucoreTypeGroup", "typeGroup").put("ebucoreOrganisation", "organisation") .put("ebucoreOrganisationDepartment", "organisationDepartment") .put("ebucoreCoreMetadata", "coreMetadata").put("ebucoreIdentifier", "identifier") .put("ebucoreTitle", "title").put("ebucoreAlternativeTitle", "alternativeTitle") .put("ebucoreFormatGroup", "formatGroup").put("ebucoreStatusGroup", "statusGroup") .put("ebucoreSubject", "subject").put("ebucoreDescription", "description") .put("ebucoreDate", "date").put("ebucoreDateType", "dateType").put("ebucoreType", "type") .put("ebucoreObjectType", "objectType").put("ebucoreGenre", "genre") .put("ebucoreTargetAudience", "targetAudience").put("ebucoreLanguage", "language") .put("ebucoreCoverage", "coverage").put("ebucoreSpatial", "spatial") .put("ebucoreLocation", "location").put("ebucoreCoordinates", "coordinates") .put("ebucoreTemporal", "temporal").put("ebucorePeriodOfTime", "periodOfTime") .put("ebucoreRights", "rights").put("ebucoreVersion", "version").put("ebucoreRating", "rating") .put("ebucorePublicationHistoryEvent", "publicationHistoryEvent") .put("ebucorePublicationHistory", "publicationHistory") .put("ebucorePublicationChannel", "publicationChannel") .put("ebucorePublicationMedium", "publicationMedium") .put("ebucorePublicationService", "publicationService") .put("ebucoreCustomRelation", "customRelation").put("ebucoreBasicRelation", "basicRelation") .put("ebucorePartMetadata", "partMetadata").put("ebucoreFormat", "format") .put("ebucoreVideoFormat", "videoFormat").put("ebucoreImageFormat", "imageFormat") .put("ebucoreAudioFormat", "audioFormat").put("ebucoreTrack", "track") .put("ebucoreDataFormat", "dataFormat").put("ebucoreCaptioning", "captioning") .put("ebucoreSubtitling", "subtitling").put("ebucoreAncillaryData", "ancillaryData") .put("ebucoreSigningFormat", "signingFormat") .put("ebucoreTechnicalAttributeString", "technicalAttributeString") .put("ebucoreTechnicalAttributeInt8", "technicalAttributeInt8") .put("ebucoreTechnicalAttributeInt16", "technicalAttributeInt16") .put("ebucoreTechnicalAttributeInt32", "technicalAttributeInt32") .put("ebucoreTechnicalAttributeInt64", "technicalAttributeInt64") .put("ebucoreTechnicalAttributeUInt8", "technicalAttributeUInt8") .put("ebucoreTechnicalAttributeUInt16", "technicalAttributeUInt16") .put("ebucoreTechnicalAttributeUInt32", "technicalAttributeUInt32") .put("ebucoreTechnicalAttributeUInt64", "technicalAttributeUInt64") .put("ebucoreTechnicalAttributeFloat", "technicalAttributeFloat") .put("ebucoreTechnicalAttributeRational", "technicalAttributeRational") .put("ebucoreTechnicalAttributeAnyURI", "technicalAttributeAnyURI") .put("ebucoreTechnicalAttributeBoolean", "technicalAttributeBoolean") .put("ebucoreDimension", "dimension").put("ebucoreWidth", "width").put("ebucoreHeight", "height") .put("ebucorePackageInfo", "packageInfo").put("ebucoreMedium", "medium") .put("ebucoreCodec", "codec").put("ebucoreRational", "rational") .put("ebucoreAspectRatio", "aspectRatio").build(); String key_ns_ebucore_1 = "urn:ebu:metadata-schema:smpteclass13/groups/ebucore_2013"; Map<String, String> namespaces = ImmutableMap.<String, String>of(key_ns_ebucore_1, "key_ns_ebucore_1"); HashMap<String, String> keys = new HashMap<String, String>(); DocumentBuilderFactory builderF = DocumentBuilderFactory.newInstance(); builderF.setNamespaceAware(true); DocumentBuilder builder = builderF.newDocumentBuilder(); Document xmlDictionary = builder.parse(args[0]); Map<String, String> localKeys = new HashMap<String, String>(); for (Map.Entry<String, String> e : namespaces.entrySet()) { System.out.println("XMLCh " + e.getValue() + "[] = {" + Joiner.on(",") .join(Iterables.transform(Lists.charactersOf(e.getKey()), new Function<Character, String>() { public String apply(Character o) { return "\'" + o + "\'"; } })) + ",\'\\0\'};"); } for (Element e : Iterables.filter(getElements(xmlDictionary.getDocumentElement()), new Predicate<Element>() { public boolean apply(Element element) { return element.getAttribute("type").equals("localSet"); } })) { String name = nameMap.get(e.getLocalName()); String keyName = "key_" + Joiner.on("").join(e.getAttribute("key").split("\\s")); localKeys.put(keyName, keyName + "_name"); System.out.println("const mxfKey " + keyName + " = {" + Joiner.on(",").join(Iterables .transform(Arrays.asList(e.getAttribute("key").split("\\s")), new Function<String, String>() { public String apply(String o) { return "0x" + o; } })) + "};"); System.out.println("const XMLCh " + keyName + "_name[] = {" + Joiner.on(",") .join(Iterables.transform(Lists.charactersOf(name), new Function<Character, String>() { public String apply(Character o) { return "\'" + o + "\'"; } })) + ",\'\\0\'};"); //System.out.println("st434dict.insert(std::pair<const mxfKey, st434info*>("); //System.out.println('\t' + keyName + ','); //System.out.println("\tnew st434info(/* " + e.getLocalName() + " */ " + keyName + "_name, /* " + key_ns_ebucore_1 + " */ " + namespaces.get(key_ns_ebucore_1) + ")"); //System.out.println("));"); } if (localKeys.size() > 0) { String arrayName = "arr_ebucore_elems"; System.out.println("const void* " + arrayName + "[][2] = {"); System.out.println(Joiner.on(", \n").join( Iterables.transform(localKeys.entrySet(), new Function<Map.Entry<String, String>, String>() { @Override public String apply(java.util.Map.Entry<String, String> e) { return "{ &" + e.getKey() + ", " + e.getValue() + " }"; } }))); System.out.println("};"); System.out.println("for (int i=0; i<" + localKeys.size() + ";i++) {"); System.out.println("\tst434dict.insert(std::pair<const mxfKey, st434info*>("); System.out.println("\t*(const mxfKey*)" + arrayName + "[i][0], "); System.out.println("\tnew st434info((const XMLCh*)" + arrayName + "[i][1], key_ns_ebucore_1)"); System.out.println("));"); System.out.println("}"); } }
From source file:edu.udo.scaffoldhunter.util.StringEscapeUtils.java
/** * Escapes a string so that it can be used within HTML markup. * /*from w w w .ja v a2s. c om*/ * @param str * the string to be escaped * * @return the escaped string */ public static final String escapeHTML(String str) { if (str == null) { return null; } StringBuilder sb = new StringBuilder(); for (char c : Lists.charactersOf(str)) { switch (c) { case '<': sb.append("<"); break; case '>': sb.append(">"); break; case '&': sb.append("&"); break; case '"': sb.append("""); break; default: sb.append(c); break; } } return sb.toString(); }
From source file:org.jclouds.http.UriTemplates.java
/** * /*from w w w .j a v a 2 s . c o m*/ * @param template * URI template that can be in level 1 <a href="http://tools.ietf.org/html/rfc6570">RFC6570</a> form. * * @param variables * to the URI template * @return expanded template, leaving any unresolved parameters literal */ public static String expand(String template, Map<String, ?> variables) { if (checkNotNull(template, "template").length() < 3) return template.toString(); // skip expansion if there's no valid variables set. ex. {a} is the first valid checkNotNull(variables, "variables for %s", template); boolean inVar = false; StringBuilder var = new StringBuilder(); StringBuilder builder = new StringBuilder(); for (char c : Lists.charactersOf(template)) { switch (c) { case '{': inVar = true; break; case '}': inVar = false; String key = var.toString(); Object value = variables.get(var.toString()); if (value != null) builder.append(value); else builder.append('{').append(key).append('}'); var = new StringBuilder(); break; default: if (inVar) var.append(c); else builder.append(c); } } return builder.toString(); }
From source file:org.obm.push.minig.imap.impl.IMAPParsingTools.java
public static String getNextNumber(String content) { if (content == null) { return null; }/*from ww w. jav a 2 s. c om*/ ImmutableList<Character> chars = Lists.charactersOf(content); StringBuilder longAsString = new StringBuilder(); for (Character c : chars) { if (Character.isDigit(c)) { longAsString.append(c); } else { break; } } return longAsString.toString(); }
From source file:org.asoem.greyfish.utils.collect.BitSets.java
/** * Parses a string of '0' and '1' characters interpreted in big-endian format and transforms it into a BitSet. * <p>Whitespaces are ignored.</p> * * @param s the input string/* ww w . j av a 2s . c o m*/ * @return A {@code BitSet} whose bits at indices are set to {@code true}, when the reversed input string has a '1' * character at the same index. */ public static BitSet parse(final String s) { checkNotNull(s); checkArgument(s.matches("^[01]*$"), "Invalid characters (other than '0' or '1') in string: %s", s); final ImmutableList<Character> characters = Lists.charactersOf(s); final BitSet bitSet = new BitSet(characters.size()); for (int i = 0, j = characters.size() - 1; i < characters.size() && j >= 0; i++, j--) { final Character character = characters.get(j); switch (character) { case '1': bitSet.set(i); break; case '0': break; default: if (!Character.isWhitespace(character)) { throw new IllegalArgumentException("Invalid character at position " + j); } } } return bitSet; }
From source file:ratpack.sse.internal.ServerSentEventEncoder.java
public ByteBuf encode(Event<?> event, ByteBufAllocator bufferAllocator) throws Exception { ByteBuf buffer = bufferAllocator.buffer(); OutputStream outputStream = new ByteBufOutputStream(buffer); Writer writer = new OutputStreamWriter(outputStream, UTF_8); String eventType = event.getEvent(); if (eventType != null) { outputStream.write(EVENT_TYPE_PREFIX); writer.append(eventType).flush(); outputStream.write(NEWLINE);//from w w w. j av a 2 s .c om } String eventData = event.getData(); if (eventData != null) { outputStream.write(EVENT_DATA_PREFIX); for (Character character : Lists.charactersOf(eventData)) { if (character == '\n') { outputStream.write(NEWLINE); outputStream.write(EVENT_DATA_PREFIX); } else { writer.append(character).flush(); } } outputStream.write(NEWLINE); } String eventId = event.getId(); if (eventId != null) { outputStream.write(EVENT_ID_PREFIX); writer.append(eventId).flush(); outputStream.write(NEWLINE); } outputStream.write(NEWLINE); writer.flush(); writer.close(); return buffer; }
From source file:org.testfx.robot.impl.WriteRobotImpl.java
@Override public void write(String text) { Scene scene = fetchTargetWindow().getScene(); for (char character : Lists.charactersOf(text)) { typeCharacterInScene(character, scene); sleepRobot.sleep(SLEEP_AFTER_CHARACTER_IN_MILLIS); }/*from w ww . java 2s .c om*/ }
From source file:org.apache.metron.stellar.dsl.functions.FunctionalFunctions.java
private static Iterable<? extends Object> getIterable(Object o) { if (o == null) { return null; }/*from w ww . j av a 2 s.c o m*/ if (o instanceof String) { return Lists.charactersOf((String) o); } else if (o instanceof Iterable) { return (Iterable<Object>) o; } else { throw new IllegalArgumentException(o.getClass() + " is not an iterable, and therefore cannot be used."); } }
From source file:org.splevo.vpm.analyzer.semantic.lucene.CodeTokenizer.java
/** * Fix featured terms in a string when it occurs with not more than one separating character * between its defined characters./* w ww.j a va 2 s . c om*/ * * For example, a fixed term "myterm" representing as "my-term" in the input string * "helloworldmy-termtest" will be returned as "helloworld myterm test". It is assumed that the * output will later on be split at whitespaces and thus, the featured term will be treated * explicitly. * * @param string * The string to fix. * @param terms * The terms to test. * @return The resulting string with fixed featured terms. */ public static String fixFeaturedTerms(String string, Set<String> terms) { if (terms == null) { return string; } for (String term : terms) { String pattern = String.format("(?i)%s", Joiner.on(".?").join(Lists.charactersOf(term))); // perform this logging in debug only as it might require // a lot of processing resources if (logger.isDebugEnabled()) { logFixedFeaturedString(string, term, pattern); } string = string.replaceAll(pattern, " " + term + " "); } return string.trim(); }