@SqlNullable @Description("extract query parameter from url") @ScalarFunction @LiteralParameters({"x", "y"}) @SqlType("varchar(x)") public static Slice urlExtractParameter( @SqlType("varchar(x)") Slice url, @SqlType("varchar(y)") Slice parameterName) { URI uri = parseUrl(url); if ((uri == null) || (uri.getQuery() == null)) { return null; } Slice query = slice(uri.getQuery()); String parameter = parameterName.toStringUtf8(); Iterable<String> queryArgs = QUERY_SPLITTER.split(query.toStringUtf8()); for (String queryArg : queryArgs) { Iterator<String> arg = ARG_SPLITTER.split(queryArg).iterator(); if (arg.next().equals(parameter)) { if (arg.hasNext()) { return utf8Slice(arg.next()); } // first matched key is empty return Slices.EMPTY_SLICE; } } // no key matched return null; }
@GET @Path("/{id}/xref") @ApiOperation(httpMethod = "GET", value = "Retrieves all the external references for the ID") public Response getByFeatureId( @PathParam("id") String query, @DefaultValue("") @QueryParam("dbname") String dbname) { try { checkParams(); XRefsDBAdaptor xRefDBAdaptor = dbAdaptorFactory.getXRefDBAdaptor(this.species, this.assembly); if (!dbname.equals("")) { queryOptions.put("dbname", Splitter.on(",").splitToList(dbname)); } return createOkResponse( xRefDBAdaptor.getAllByDBNameList(Splitter.on(",").splitToList(query), queryOptions)); // if (dbName.equals("")) { // return generateResponse(query, "XREF", // x.getAllByDBNameList(Splitter.on(",").splitToList(query), null)); // } // else { // return generateResponse(query, "XREF", // x.getAllByDBNameList(Splitter.on(",").splitToList(query), // Splitter.on(",").splitToList(dbName))); // } } catch (Exception e) { e.printStackTrace(); return createErrorResponse("getAllByAccessions", e.toString()); } }
public void loadGridNet(String mapGrid) throws IOException { Preconditions.checkArgument(!Strings.isNullOrEmpty(mapGrid)); logger.debug("loading {}...", mapGrid); CSVReader reader = new CSVReader(new FileReader(mapGrid), ',', '"', 1); String[] row; while ((row = reader.readNext()) != null) { String gridId = row[1].trim(); String dmRoads = row[2].trim(); String gjRoads = row[3].trim(); Set<String> x = Sets.newHashSet(Splitter.on('|').trimResults().omitEmptyStrings().split(dmRoads)); Set<String> y = Sets.newHashSet(Splitter.on('|').trimResults().omitEmptyStrings().split(gjRoads)); if (x.size() > 0 || y.size() > 0) { MapGrid grid = new MapGrid(); grid.dmRoads = x; grid.gjRoads = y; gridNet.put(gridId, grid); // logger.debug("{},{},{}", gridId, x, y); } } reader.close(); }
public void setupLoadOnly(String deobfFileName, boolean loadAll) { try { File mapData = new File(deobfFileName); LZMAInputSupplier zis = new LZMAInputSupplier(new FileInputStream(mapData)); InputSupplier<InputStreamReader> srgSupplier = CharStreams.newReaderSupplier(zis, Charsets.UTF_8); List<String> srgList = CharStreams.readLines(srgSupplier); rawMethodMaps = Maps.newHashMap(); rawFieldMaps = Maps.newHashMap(); Builder<String, String> builder = ImmutableBiMap.<String, String>builder(); Builder<String, String> mcpBuilder = ImmutableBiMap.<String, String>builder(); Splitter splitter = Splitter.on(CharMatcher.anyOf(": ")).omitEmptyStrings().trimResults(); for (String line : srgList) { String[] parts = Iterables.toArray(splitter.split(line), String.class); String typ = parts[0]; if ("CL".equals(typ)) { parseClass(builder, parts); parseMCPClass(mcpBuilder, parts); } else if ("MD".equals(typ) && loadAll) { parseMethod(parts); } else if ("FD".equals(typ) && loadAll) { parseField(parts); } } classNameBiMap = builder.build(); mcpNameBiMap = mcpBuilder.build(); } catch (IOException ioe) { FMLRelaunchLog.log(Level.ERROR, "An error occurred loading the deobfuscation map data", ioe); } methodNameMaps = Maps.newHashMapWithExpectedSize(rawMethodMaps.size()); fieldNameMaps = Maps.newHashMapWithExpectedSize(rawFieldMaps.size()); }
@Override public Collection<Either<JobSpec, URI>> parseJobSpec(byte[] message) throws IOException { try { String messageString = new String(message, Charsets.UTF_8); List<Either<JobSpec, URI>> jobSpecs = Lists.newArrayList(); for (String oneInstruction : SPLITTER_COMMA.split(messageString)) { List<String> tokens = SPLITTER_COLON.splitToList(oneInstruction); if (tokens.get(0).equals(REMOVE)) { URI uri = new URI(tokens.get(1)); jobSpecs.add(Either.<JobSpec, URI>right(uri)); } else { URI uri = new URI(tokens.get(0)); String version = tokens.get(1); JobSpec jobSpec = new JobSpec.Builder(uri) .withConfig(ConfigFactory.empty()) .withVersion(version) .build(); jobSpecs.add(Either.<JobSpec, URI>left(jobSpec)); } } return jobSpecs; } catch (URISyntaxException use) { throw new IOException(use); } }
public static Map<FormatBundle, Map<Integer, List<Path>>> getFormatNodeMap(JobContext job) { Map<FormatBundle, Map<Integer, List<Path>>> formatNodeMap = Maps.newHashMap(); Configuration conf = job.getConfiguration(); String crunchInputs = conf.get(CRUNCH_INPUTS); if (crunchInputs == null || crunchInputs.isEmpty()) { return ImmutableMap.of(); } for (String input : Splitter.on(RECORD_SEP).split(crunchInputs)) { List<String> fields = Lists.newArrayList(SPLITTER.split(input)); FormatBundle<InputFormat> inputBundle = FormatBundle.fromSerialized(fields.get(0), job.getConfiguration()); if (!formatNodeMap.containsKey(inputBundle)) { formatNodeMap.put(inputBundle, Maps.<Integer, List<Path>>newHashMap()); } Integer nodeIndex = Integer.valueOf(fields.get(1)); if (!formatNodeMap.get(inputBundle).containsKey(nodeIndex)) { formatNodeMap.get(inputBundle).put(nodeIndex, Lists.<Path>newLinkedList()); } List<Path> formatNodePaths = formatNodeMap.get(inputBundle).get(nodeIndex); String paths = fields.get(2); for (String path : Splitter.on(PATH_SEP).split(paths)) { formatNodePaths.add(new Path(path)); } } return formatNodeMap; }
@GET @Path("/{id}/contains") /* @ApiOperation(httpMethod = "GET", value = "Get the genes that contain the given string") */ public Response getByContainsQuery(@PathParam("id") String query) { try { checkParams(); XRefsDBAdaptor x = dbAdaptorFactory.getXRefDBAdaptor(this.species, this.assembly); List<List<Xref>> xrefs = x.getByContainsQueryList(Splitter.on(",").splitToList(query)); if (query.startsWith("rs") || query.startsWith("AFFY_") || query.startsWith("SNP_") || query.startsWith("VAR_") || query.startsWith("CRTAP_") || query.startsWith("FKBP10_") || query.startsWith("LEPRE1_") || query.startsWith("PPIB_")) { List<QueryResult> snpXrefs = x.getByStartsWithSnpQueryList(Splitter.on(",").splitToList(query), queryOptions); // for (List<Xref> xrefList : snpXrefs) { // xrefs.get(0).addAll(xrefList); // } } return generateResponse(query, xrefs); } catch (Exception e) { e.printStackTrace(); return createErrorResponse("getAllByAccessions", e.toString()); } }
@Test public void testFromSystem_containsListValues() throws Exception { AbstractConfiguration.setDefaultListDelimiter('|'); Map<String, String> properties = Maps.newHashMap(); properties.put("testProperty", "b,bee"); for (Entry<String, String> entry : properties.entrySet()) { System.setProperty(entry.getKey(), entry.getValue()); } Splitter splitter = Splitter.on(','); Configuration systemConfiguration = configurationHelper.fromSystem(); for (Entry<String, String> entry : properties.entrySet()) { String[] actualValues = systemConfiguration.getStringArray(entry.getKey()); String[] expectedValues; if ("line.separator".equals(entry.getKey())) { expectedValues = new String[] {SystemUtils.LINE_SEPARATOR}; } else { expectedValues = splitter.splitToList(entry.getValue()).toArray(new String[0]); } assertArrayEquals( String.format("Values for key %s do not match", entry.getKey()), expectedValues, actualValues); } }
@IMCCallback public void processIMCRequests(FMLInterModComms.IMCEvent event) { Splitter splitter = Splitter.on("@").trimResults(); for (IMCMessage m : event.getMessages()) { if ("add-facade".equals(m.key)) { String[] array = Iterables.toArray(splitter.split(m.getStringValue()), String.class); if (array.length != 2) { Logger.getLogger("Buildcraft") .log( Level.INFO, String.format( "Received an invalid add-facade request %s from mod %s", m.getStringValue(), m.getSender())); continue; } Integer blId = Ints.tryParse(array[0]); Integer metaId = Ints.tryParse(array[1]); if (blId == null || metaId == null) { Logger.getLogger("Buildcraft") .log( Level.INFO, String.format( "Received an invalid add-facade request %s from mod %s", m.getStringValue(), m.getSender())); continue; } ItemFacade.addFacade(new ItemStack(blId, 1, metaId)); } } }
@Singleton @Iso3166 @Override public Map<String, Set<String>> get() { Builder<String, Set<String>> codes = ImmutableMap.<String, Set<String>>builder(); for (String key : ImmutableSet.of(PROPERTY_REGION, PROPERTY_ZONE)) try { String regionString = injector.getInstance(Key.get(String.class, named(key + "s"))); for (String region : Splitter.on(',').split(regionString)) { try { codes.put( region, ImmutableSet.copyOf( Splitter.on(',') .split( injector.getInstance( Key.get( String.class, named(key + "." + region + "." + ISO3166_CODES)))))); } catch (ConfigurationException e) { // this happens if regions property isn't set // services not run by AWS may not have regions, so this is ok. } } } catch (ConfigurationException e) { // this happens if regions property isn't set // services not run by AWS may not have regions, so this is ok. } return codes.build(); }
private static ImmutableMap<String, String> getQueryMap(final String query) throws MalformedRequestException { if (StringUtils.isBlank(query)) { return ImmutableMap.of(); } else { final Iterable<String> params = Splitter.on('&').split(query); final ImmutableMap.Builder<String, String> map = ImmutableMap.builder(); for (final String param : params) { final ImmutableList<String> strings = ImmutableList.copyOf(Splitter.on('=').split(param)); final String name = strings.get(0); if (strings.size() > 2) { throw new MalformedRequestException("Multiple '=' for parameter " + name); } final String value; if (strings.size() > 1) { value = strings.get(1); } else { value = null; } if (map.build().keySet().contains(name)) { throw new MalformedRequestException("Duplicate value for parameter " + name); } map.put(name, value); } return map.build(); } }
public Map<String, Path> buildMultipleAndReturnOutputs(String... args) throws IOException { // Add in `--show-output` to the build, so we can parse the output paths after the fact. ImmutableList<String> buildArgs = ImmutableList.<String>builder().add("--show-output").add(args).build(); ProjectWorkspace.ProcessResult buildResult = runBuckBuild(buildArgs.toArray(new String[buildArgs.size()])); buildResult.assertSuccess(); // Grab the stdout lines, which have the build outputs. List<String> lines = Splitter.on(CharMatcher.anyOf(System.lineSeparator())) .trimResults() .omitEmptyStrings() .splitToList(buildResult.getStdout()); // Skip the first line, which is just "The outputs are:". assertThat(lines.get(0), Matchers.equalTo("The outputs are:")); lines = lines.subList(1, lines.size()); Splitter lineSplitter = Splitter.on(' ').trimResults(); ImmutableMap.Builder<String, Path> builder = ImmutableMap.builder(); for (String line : lines) { List<String> fields = lineSplitter.splitToList(line); assertThat(fields, Matchers.hasSize(2)); builder.put(fields.get(0), getPath(fields.get(1))); } return builder.build(); }
/** * Creates the list of comparables * * @since $version * @author hceylan */ private void createComparables() { // order on id if (this.mapping.getOrderBy().trim().length() == 0) { if (this.mapping.isAssociation()) { final EntityTypeImpl<E> type = ((PluralAssociationMapping<?, ?, E>) this.mapping).getType(); if (type.hasSingleIdAttribute()) { this.comparables.add(new ComparableMapping(true, (Mapping<?, ?, ?>) type.getIdMapping())); } else { for (final Pair<BasicMapping<? super E, ?>, BasicAttribute<?, ?>> pair : type.getIdMappings()) { this.comparables.add(new ComparableMapping(true, pair.getFirst())); } } } else if (this.mapping.getType().getPersistenceType() == PersistenceType.EMBEDDABLE) { throw new MappingException( "Embeddable element collections requires OrderBy value", this.mapping.getAttribute().getLocator()); } else { this.comparables.add(new ComparableMapping(true, null)); } } else { final Iterator<String> i = Splitter.on(",").trimResults().split(this.mapping.getOrderBy()).iterator(); while (i.hasNext()) { final Iterator<String> j = Splitter.on(" ").trimResults().split(i.next()).iterator(); int index = 0; String path = null; boolean order = true; while (j.hasNext()) { if (index == 0) { path = j.next(); } else if (index == 1) { order = "ASC".equals(j.next().toUpperCase()); } else { throw new MappingException( "Invalid order by statement: " + this.mapping.getOrderBy() + ".", this.mapping.getAttribute().getLocator()); } index++; } if (this.mapping.getType().getPersistenceType() == PersistenceType.BASIC) { throw new MappingException( "Basic element collection must not have OrderBy value", this.mapping.getAttribute().getLocator()); } final Mapping<?, ?, ?> mapping = this.mapping.getMapping(path); if (mapping == null) { throw new MappingException( "Sort property cannot be found: " + path, this.mapping.getAttribute().getLocator()); } this.comparables.add(new ComparableMapping(order, mapping)); } } }
@Test public void shouldTrimWhiteSpaceStrings() { Splitter splitter = Splitter.on(',').trimResults(); Iterable<String> result = splitter.split("foo, bar, baz"); assertEquals(newArrayList("foo", "bar", "baz"), newArrayList(result)); }
@Test public void shouldOmitEmptyStrings() { Splitter splitter = Splitter.on(',').omitEmptyStrings(); Iterable<String> result = splitter.split("foo,bar,,baz"); assertEquals(newArrayList("foo", "bar", "baz"), newArrayList(result)); }
/** * Get a {@link org.kitesdk.data.PartitionKey} corresponding to a partition's filesystem path * represented as a {@link URI}. If the path is not a valid partition, then {@link * IllegalArgumentException} is thrown. Note that the partition does not have to exist. * * @param dataset the filesystem dataset * @param partitionPath a directory path where the partition data is stored * @return a partition key representing the partition at the given path * @since 0.4.0 */ @SuppressWarnings("deprecation") public static PartitionKey partitionKeyForPath(Dataset dataset, URI partitionPath) { Preconditions.checkState( dataset.getDescriptor().isPartitioned(), "Attempt to get a partition on a non-partitioned dataset (name:%s)", dataset.getName()); Preconditions.checkArgument( dataset instanceof FileSystemDataset, "Dataset is not a FileSystemDataset"); FileSystemDataset fsDataset = (FileSystemDataset) dataset; FileSystem fs = fsDataset.getFileSystem(); URI partitionUri = fs.makeQualified(new Path(partitionPath)).toUri(); URI directoryUri = fsDataset.getDirectory().toUri(); URI relativizedUri = directoryUri.relativize(partitionUri); if (relativizedUri.equals(partitionUri)) { throw new IllegalArgumentException( String.format( "Partition URI %s has different " + "root directory to dataset (directory: %s).", partitionUri, directoryUri)); } Iterable<String> parts = Splitter.on('/').split(relativizedUri.getPath()); PartitionStrategy partitionStrategy = dataset.getDescriptor().getPartitionStrategy(); List<FieldPartitioner> fieldPartitioners = partitionStrategy.getFieldPartitioners(); if (Iterables.size(parts) > fieldPartitioners.size()) { throw new IllegalArgumentException( String.format( "Too many partition directories " + "for %s (%s), expecting %s.", partitionUri, Iterables.size(parts), fieldPartitioners.size())); } List<Object> values = Lists.newArrayList(); int i = 0; for (String part : parts) { Iterator<String> split = Splitter.on('=').split(part).iterator(); String fieldName = split.next(); FieldPartitioner fp = fieldPartitioners.get(i++); if (!fieldName.equals(fp.getName())) { throw new IllegalArgumentException( String.format( "Unrecognized partition name " + "'%s' in partition %s, expecting '%s'.", fieldName, partitionUri, fp.getName())); } if (!split.hasNext()) { throw new IllegalArgumentException( String.format( "Missing partition value for " + "'%s' in partition %s.", fieldName, partitionUri)); } String stringValue = split.next(); Object value = fp.valueFromString(stringValue); values.add(value); } return org.kitesdk.data.impl.Accessor.getDefault() .newPartitionKey(values.toArray(new Object[values.size()])); }
protected void setupCredentials() { identity = System.getProperty("test." + provider + ".identity", "administrator"); credential = System.getProperty("test." + provider + ".credential", "12345"); endpoint = URI.create(System.getProperty("test." + provider + ".endpoint", "http://localhost:18083/")); apiVersion = System.getProperty("test." + provider + ".apiversion", "4.1.2r73507"); majorVersion = Iterables.get(Splitter.on('r').split(apiVersion), 0); minorVersion = Iterables.get(Splitter.on('r').split(apiVersion), 1); }
public NameParts(final String dn) { final ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); for (final String chunk : Splitter.on(',').trimResults().split(dn)) { List<String> pairs = ImmutableList.copyOf(Splitter.on('=').trimResults().split(chunk)); if (pairs.size() == 2) { builder.put(pairs.get(0), pairs.get(1)); } } original = dn; parts = builder.build(); }
/** * Constructs a ApplicationBundler. * * @param excludePackages Class packages to exclude * @param includePackages Always includes classes/resources in these packages. Note that classes * in these packages will not get inspected for dependencies. */ public ApplicationBundler(Iterable<String> excludePackages, Iterable<String> includePackages) { this.excludePackages = ImmutableList.copyOf(excludePackages); this.includePackages = ImmutableList.copyOf(includePackages); this.acceptClassPath = Sets.difference( Sets.newHashSet( Splitter.on(File.pathSeparatorChar).split(System.getProperty("java.class.path"))), Sets.newHashSet( Splitter.on(File.pathSeparatorChar) .split(System.getProperty("sun.boot.class.path")))); }
private ImmutableSetMultimap<String, String> parsePermissions( @Nullable String database, Ini.Section rolesSection, Ini.Section groupsSection) { ImmutableSetMultimap.Builder<String, String> resultBuilder = ImmutableSetMultimap.builder(); Multimap<String, String> roleNameToPrivilegeMap = HashMultimap.create(); List<? extends RoleValidator> validators = Lists.newArrayList( new ServersAllIsInvalid(), new DatabaseMustMatch(), new DatabaseRequiredInRole(), new ServerNameMustMatch(serverName)); for (Map.Entry<String, String> entry : rolesSection.entrySet()) { String roleName = Strings.nullToEmpty(entry.getKey()).trim(); String roleValue = Strings.nullToEmpty(entry.getValue()).trim(); boolean invalidConfiguration = false; if (roleName.isEmpty()) { LOGGER.warn("Empty role name encountered in {}", resourcePath); invalidConfiguration = true; } if (roleValue.isEmpty()) { LOGGER.warn("Empty role value encountered in {}", resourcePath); invalidConfiguration = true; } if (roleNameToPrivilegeMap.containsKey(roleName)) { LOGGER.warn("Role {} defined twice in {}", roleName, resourcePath); } Set<String> roles = PermissionUtils.toPermissionStrings(roleValue); if (!invalidConfiguration && roles != null) { for (String role : roles) { for (RoleValidator validator : validators) { validator.validate(database, role.trim()); } } roleNameToPrivilegeMap.putAll(roleName, roles); } } Splitter roleSplitter = ROLE_SPLITTER.omitEmptyStrings().trimResults(); for (Map.Entry<String, String> entry : groupsSection.entrySet()) { String groupName = Strings.nullToEmpty(entry.getKey()).trim(); String groupPrivileges = Strings.nullToEmpty(entry.getValue()).trim(); Collection<String> resolvedGroupPrivileges = Sets.newHashSet(); for (String roleName : roleSplitter.split(groupPrivileges)) { if (roleNameToPrivilegeMap.containsKey(roleName)) { resolvedGroupPrivileges.addAll(roleNameToPrivilegeMap.get(roleName)); } else { LOGGER.warn( "Role {} for group {} does not exist in privileges section in {}", new Object[] {roleName, groupName, resourcePath}); } } resultBuilder.putAll(groupName, resolvedGroupPrivileges); } return resultBuilder.build(); }
public void testBuildImage() throws IOException, InterruptedException, URISyntaxException { BuildOptions options = BuildOptions.Builder.tag("testBuildImage").verbose(false).nocache(false); InputStream buildImageStream = api().build(new File(Resources.getResource("Dockerfile").toURI()), options); String buildStream = consumeStream(buildImageStream, false); Iterable<String> splitted = Splitter.on("\n").split(buildStream.replace("\r", "").trim()); String lastStreamedLine = Iterables.getLast(splitted).trim(); String rawImageId = Iterables.getLast(Splitter.on("Successfully built ").split(lastStreamedLine)); String imageId = rawImageId.substring(0, 11); Image image = api().inspectImage(imageId); api().deleteImage(image.getId(), DeleteImageOptions.Builder.force(true)); }
/** * Get HttpResourceModel which matches the HttpMethod of the request. * * @param routableDestinations List of ResourceModels. * @param targetHttpMethod HttpMethod. * @param requestUri request URI. * @return RoutableDestination that matches httpMethod that needs to be handled. null if there are * no matches. */ private List<PatternPathRouterWithGroups.RoutableDestination<HttpResourceModel>> getMatchedDestination( List<PatternPathRouterWithGroups.RoutableDestination<HttpResourceModel>> routableDestinations, HttpMethod targetHttpMethod, String requestUri) { Iterable<String> requestUriParts = Splitter.on('/').omitEmptyStrings().split(requestUri); List<PatternPathRouterWithGroups.RoutableDestination<HttpResourceModel>> matchedDestinations = Lists.newArrayListWithExpectedSize(routableDestinations.size()); int maxExactMatch = 0; int maxGroupMatch = 0; int maxPatternLength = 0; for (PatternPathRouterWithGroups.RoutableDestination<HttpResourceModel> destination : routableDestinations) { HttpResourceModel resourceModel = destination.getDestination(); int groupMatch = destination.getGroupNameValues().size(); for (HttpMethod httpMethod : resourceModel.getHttpMethod()) { if (targetHttpMethod.equals(httpMethod)) { int exactMatch = getExactPrefixMatchCount( requestUriParts, Splitter.on('/').omitEmptyStrings().split(resourceModel.getPath())); // When there are multiple matches present, the following precedence order is used - // 1. template path that has highest exact prefix match with the url is chosen. // 2. template path has the maximum groups is chosen. // 3. finally, template path that has the longest length is chosen. if (exactMatch > maxExactMatch) { maxExactMatch = exactMatch; maxGroupMatch = groupMatch; maxPatternLength = resourceModel.getPath().length(); matchedDestinations.clear(); matchedDestinations.add(destination); } else if (exactMatch == maxExactMatch && groupMatch >= maxGroupMatch) { if (groupMatch > maxGroupMatch || resourceModel.getPath().length() > maxPatternLength) { maxGroupMatch = groupMatch; maxPatternLength = resourceModel.getPath().length(); matchedDestinations.clear(); } matchedDestinations.add(destination); } } } } return matchedDestinations; }
private static String getPackageName(final String qualifiedName, final boolean strict) { Splitter _on = Splitter.on("."); Iterable<String> _split = _on.split(qualifiedName); final List<String> segments = IterableExtensions.<String>toList(_split); int _size = segments.size(); boolean _equals = (_size == 1); if (_equals) { return ""; } if (strict) { int _length = ((Object[]) Conversions.unwrapArray(segments, Object.class)).length; int _minus = (_length - 1); final List<String> packageSegments = segments.subList(0, _minus); final Function1<String, Boolean> _function = (String it) -> { char _charAt = it.charAt(0); return Boolean.valueOf(Character.isUpperCase(_charAt)); }; Iterable<String> _filter = IterableExtensions.<String>filter(packageSegments, _function); boolean _isEmpty = IterableExtensions.isEmpty(_filter); boolean _not = (!_isEmpty); if (_not) { throw new IllegalArgumentException( (("Cannot determine the package name of \'" + qualifiedName) + "\'. Please use the TypeReference(packageName, className) constructor")); } return IterableExtensions.join(packageSegments, "."); } else { int _length_1 = ((Object[]) Conversions.unwrapArray(segments, Object.class)).length; int _minus_1 = (_length_1 - 1); List<String> packageSegments_1 = segments.subList(0, _minus_1); while ((!packageSegments_1.isEmpty())) { String _last = IterableExtensions.<String>last(packageSegments_1); char _charAt = _last.charAt(0); boolean _isUpperCase = Character.isUpperCase(_charAt); if (_isUpperCase) { final List<String> _converted_packageSegments_1 = (List<String>) packageSegments_1; int _length_2 = ((Object[]) Conversions.unwrapArray(_converted_packageSegments_1, Object.class)) .length; int _minus_2 = (_length_2 - 1); List<String> _subList = packageSegments_1.subList(0, _minus_2); packageSegments_1 = _subList; } else { return IterableExtensions.join(packageSegments_1, "."); } } return ""; } }
private static LibraryDeps fromReaderEx(Reader reader) throws Exception { LibraryDeps deps = new LibraryDeps(); BufferedReader buf = new BufferedReader(reader); // Check version. { String line = buf.readLine(); if (!Objects.equal(line, VERSION)) { return deps; } } // Read units dependencies. String relPath; while (null != (relPath = buf.readLine())) { Source source = new Source(); // Read flags. source.shouldRecompileOnAnyTopLevelChange = Boolean.parseBoolean(buf.readLine()); // Read top symbols. { String line = buf.readLine(); Iterable<String> topSymbols = Splitter.on(' ').omitEmptyStrings().split(line); Iterables.addAll(source.topSymbols, topSymbols); } // Read all symbols. { String line = buf.readLine(); Iterable<String> allSymbols = Splitter.on(' ').omitEmptyStrings().split(line); Iterables.addAll(source.allSymbols, allSymbols); } // Read holes. { String line = buf.readLine(); Iterable<String> holes = Splitter.on(' ').omitEmptyStrings().split(line); Iterables.addAll(source.holes, holes); } // Read dependencies. while (true) { String line = buf.readLine(); // Blank line: next unit. if (line.length() == 0) { break; } // Parse line. String[] parts = line.split(" "); source.deps.add(new Dependency(new URI(parts[0]), parts[1], Long.parseLong(parts[2]))); } // Remember dependencies for current unit. deps.sources.put(relPath, source); } return deps; }
private static Splitter createSplitter(char separator, char... otherSeparators) { if (otherSeparators.length == 0) { return Splitter.on(separator).omitEmptyStrings(); } // TODO(cgdecker): When CharMatcher is out of @Beta, us Splitter.on(CharMatcher) StringBuilder patternBuilder = new StringBuilder(); patternBuilder.append("["); appendToRegex(separator, patternBuilder); for (char other : otherSeparators) { appendToRegex(other, patternBuilder); } patternBuilder.append("]"); return Splitter.onPattern(patternBuilder.toString()).omitEmptyStrings(); }
@BeforeClass public static void setUp() throws IOException { InputStream dataFileInputStream = NaraSoundexTest.class.getResourceAsStream("DaitchMokotoffSoundexTest.data"); List<String> lines = CharStreams.readLines(new InputStreamReader(dataFileInputStream)); for (String currentLine : lines) { if (!currentLine.startsWith(";")) { Iterable<String> components = Splitter.on("->").trimResults().split(currentLine); Iterable<String> expectedValues = Splitter.on(",").trimResults().split(Iterables.get(components, 1)); testCases.putAll(Iterables.get(components, 0), expectedValues); } } }
public void shouldSplitIntoList() { final String input = "first , second , third , fourth ,,, seventh"; assertEquals( Lists.newArrayList("first ", " second ", " third ", " fourth ", "", "", " seventh"), Lists.newArrayList(Splitter.on(",").split(input))); assertEquals( Lists.newArrayList("first ", " second ", " third ", " fourth ", " seventh"), Lists.newArrayList(Splitter.on(",").omitEmptyStrings().split(input))); assertEquals( Lists.newArrayList("first", "second", "third", "fourth", "", "", "seventh"), Lists.newArrayList(Splitter.on(",").trimResults().split(input))); }
private List<ServerAddress> mongoHosts() { Splitter splitter = Splitter.on(",").omitEmptyStrings().trimResults(); return ImmutableList.copyOf( Iterables.filter( Iterables.transform( splitter.split(mongoHost), new Function<String, ServerAddress>() { @Override public ServerAddress apply(String input) { return new ServerAddress(input, mongoDbPort); } }), Predicates.notNull())); }
/** * Setup blocked flag for all builtin UDFs as per udf whitelist and blacklist * * @param whiteListStr * @param blackListStr */ public void setupPermissionsForUDFs(String whiteListStr, String blackListStr) { Set<String> whiteList = Sets.newHashSet( Splitter.on(",").trimResults().omitEmptyStrings().split(whiteListStr.toLowerCase())); Set<String> blackList = Sets.newHashSet( Splitter.on(",").trimResults().omitEmptyStrings().split(blackListStr.toLowerCase())); blackList.removeAll(FunctionRegistry.HIVE_OPERATORS); for (Map.Entry<String, FunctionInfo> funcEntry : mFunctions.entrySet()) { funcEntry .getValue() .setBlockedFunction(isUdfBlocked(funcEntry.getKey(), whiteList, blackList)); } }
public void save() { try { if (file.getParentFile() != null) { file.getParentFile().mkdirs(); } if (!file.exists() && !file.createNewFile()) { return; } if (file.canWrite()) { FileOutputStream fos = new FileOutputStream(file); BufferedWriter buffer = new BufferedWriter(new OutputStreamWriter(fos, defaultEncoding)); buffer.write("# Configuration file\r\n"); buffer.write("# Generated on " + DateFormat.getInstance().format(new Date()) + "\r\n"); buffer.write("\r\n"); for (Map.Entry<String, Map<String, Property>> category : categories.entrySet()) { buffer.write("####################\r\n"); buffer.write("# " + category.getKey() + " \r\n"); if (customCategoryComments.containsKey(category.getKey())) { buffer.write("#===================\r\n"); String comment = customCategoryComments.get(category.getKey()); Splitter splitter = Splitter.onPattern("\r?\n"); for (String commentLine : splitter.split(comment)) { buffer.write("# "); buffer.write(commentLine + "\r\n"); } } buffer.write("####################\r\n\r\n"); String catKey = category.getKey(); if (!allowedProperties.matchesAllOf(catKey)) { catKey = '"' + catKey + '"'; } buffer.write(catKey + " {\r\n"); writeProperties(buffer, category.getValue().values()); buffer.write("}\r\n\r\n"); } buffer.close(); fos.close(); } } catch (IOException e) { e.printStackTrace(); } }