return prependIfMissing(str, prefix, false, prefixes);
return prependIfMissing(str, prefix, true, prefixes);
/** * A naive implementation of generating a jobSpec's URI within a multi-hop flow that follows the convention: * <JOB_CATALOG_SCHEME>/{@link ConfigurationKeys#JOB_GROUP_KEY}/{@link ConfigurationKeys#JOB_NAME_KEY}. */ private static URI jobSpecURIGenerator(String jobGroup, String jobName, FlowSpec flowSpec) throws URISyntaxException { return new URI(JobSpec.Builder.DEFAULT_JOB_CATALOG_SCHEME, flowSpec.getUri().getAuthority(), StringUtils.appendIfMissing(StringUtils.prependIfMissing(flowSpec.getUri().getPath(), "/"), "/") + jobGroup + "/" + jobName, null); } }
for (Extension extension : extensions) { final String name = extension.name(); final String key = name.length() > 0 ? StringUtils.prependIfMissing(name, "x-") : name; try { processedValue = Json.mapper().readTree(propertyValue); map.put(StringUtils.prependIfMissing(propertyName, "x-"), processedValue); } catch (Exception e) { map.put(StringUtils.prependIfMissing(propertyName, "x-"), propertyValue); map.put(StringUtils.prependIfMissing(propertyName, "x-"), propertyValue);
/** * Tests {@code prependIfMissing}. */ @Test public void testPrependIfMissing() { assertEquals("prependIfMissing(null,null)", null, StringUtils.prependIfMissing(null, null)); assertEquals("prependIfMissing(abc,null)", "abc", StringUtils.prependIfMissing("abc", null)); assertEquals("prependIfMissing(\"\",xyz)", "xyz", StringUtils.prependIfMissing("", "xyz")); assertEquals("prependIfMissing(abc,xyz)", "xyzabc", StringUtils.prependIfMissing("abc", "xyz")); assertEquals("prependIfMissing(xyzabc,xyz)", "xyzabc", StringUtils.prependIfMissing("xyzabc", "xyz")); assertEquals("prependIfMissing(XYZabc,xyz)", "xyzXYZabc", StringUtils.prependIfMissing("XYZabc", "xyz")); assertEquals("prependIfMissing(null,null null)", null, StringUtils.prependIfMissing(null, null, (CharSequence[]) null)); assertEquals("prependIfMissing(abc,null,null)", "abc", StringUtils.prependIfMissing("abc", null, (CharSequence[]) null)); assertEquals("prependIfMissing(\"\",xyz,null)", "xyz", StringUtils.prependIfMissing("", "xyz", (CharSequence[]) null)); assertEquals("prependIfMissing(abc,xyz,{null})", "xyzabc", StringUtils.prependIfMissing("abc", "xyz", new CharSequence[]{null})); assertEquals("prependIfMissing(abc,xyz,\"\")", "abc", StringUtils.prependIfMissing("abc", "xyz", "")); assertEquals("prependIfMissing(abc,xyz,mno)", "xyzabc", StringUtils.prependIfMissing("abc", "xyz", "mno")); assertEquals("prependIfMissing(xyzabc,xyz,mno)", "xyzabc", StringUtils.prependIfMissing("xyzabc", "xyz", "mno")); assertEquals("prependIfMissing(mnoabc,xyz,mno)", "mnoabc", StringUtils.prependIfMissing("mnoabc", "xyz", "mno")); assertEquals("prependIfMissing(XYZabc,xyz,mno)", "xyzXYZabc", StringUtils.prependIfMissing("XYZabc", "xyz", "mno")); assertEquals("prependIfMissing(MNOabc,xyz,mno)", "xyzMNOabc", StringUtils.prependIfMissing("MNOabc", "xyz", "mno")); }
/** * A naive implementation of generating a jobSpec's URI within a multi-hop logical Flow. */ @Override public URI jobSpecURIGenerator(Object... objects) { FlowSpec flowSpec = (FlowSpec) objects[0]; ServiceNode sourceNode = (ServiceNode) objects[1]; ServiceNode targetNode = (ServiceNode) objects[2]; try { return new URI(JobSpec.Builder.DEFAULT_JOB_CATALOG_SCHEME, flowSpec.getUri().getAuthority(), StringUtils.appendIfMissing(StringUtils.prependIfMissing(flowSpec.getUri().getPath(), "/"),"/") + sourceNode.getNodeName() + "-" + targetNode.getNodeName(), null); } catch (URISyntaxException e) { log.error( "URI construction failed when jobSpec from " + sourceNode.getNodeName() + " to " + targetNode.getNodeName()); throw new RuntimeException(); } } }
@Override public Object apply(List<Object> strings) { String prefixed; switch (strings.size()) { case 2: prefixed = StringUtils.prependIfMissing((String) strings.get(0), (String) strings.get(1)); break; case 3: prefixed = StringUtils.prependIfMissing((String) strings.get(0), (String) strings.get(1), (String) strings.get(2)); break; default: throw new IllegalArgumentException("[PREPEND_IF_MISSING] incorrect arguments: " + strings.toString() + "\nUsage: PREPEND_IF_MISSING <String> <prefix> [<prefix>...]"); } return prefixed; } }
/** * Returns the complete URL of the specified path for the running Fathom TEST instance. * * @param path * @return an url */ protected String urlFor(String path) { String url = StringUtils.removeEnd(RestAssured.baseURI, "/") + StringUtils.prependIfMissing(path, "/"); return url; }
public static String correctUri(String uri) { if (isBlank(uri)) { return EMPTY; } return removeEnd(prependIfMissing(uri, "/"), "/"); } }
public static String withSeparator(final String separator, final String... parts) { final StringBuilder result = new StringBuilder(); for (String s : parts) { if (!StringUtils.isEmpty(s)) { s = StringUtils.prependIfMissing(s, separator); s = StringUtils.removeEnd(s, separator); result.append(s); } } return result.toString(); }
@Override public List<RealmTO> list(final String fullPath) { return logic.list(StringUtils.prependIfMissing(fullPath, SyncopeConstants.ROOT_REALM)); }
@Override public PagedResult<GroupTO> searchAssignableGroups( final String realm, final String term, final int page, final int size) { Pair<Integer, List<GroupTO>> result = logic.searchAssignableGroups( StringUtils.prependIfMissing(realm, SyncopeConstants.ROOT_REALM), term, page, size); return buildPagedResult(result.getRight(), page, size, result.getLeft()); }
@Override public String getResourceModulePath(final Source source, final String resourcePath) { String resourceModulePath; if (resourcePath.startsWith("/")) { resourceModulePath = sourceBasePath + resourcePath; } else { resourceModulePath = sourceBasePath + StringUtils.prependIfMissing(source.getFolderPath() + "/" + resourcePath, "/"); } return StringUtils.stripStart(resourceModulePath, "/"); } }
public String getResourceModulePath(final Source source, final String resourcePath) { final String resourceModulePath; if (resourcePath.startsWith("/")) { resourceModulePath = sourceBasePath + resourcePath; } else { resourceModulePath = sourceBasePath + StringUtils.prependIfMissing(source.getFolderPath() + "/" + resourcePath, "/"); } return StringUtils.stripStart(resourceModulePath, "/"); } }
/** * A naive implementation of generating a jobSpec's URI within a multi-hop flow that follows the convention: * <JOB_CATALOG_SCHEME>/{@link ConfigurationKeys#JOB_GROUP_KEY}/{@link ConfigurationKeys#JOB_NAME_KEY}. */ private static URI jobSpecURIGenerator(String jobGroup, String jobName, FlowSpec flowSpec) throws URISyntaxException { return new URI(JobSpec.Builder.DEFAULT_JOB_CATALOG_SCHEME, flowSpec.getUri().getAuthority(), StringUtils.appendIfMissing(StringUtils.prependIfMissing(flowSpec.getUri().getPath(), "/"), "/") + jobGroup + "/" + jobName, null); } }
@Override public Response delete(final String fullPath) { ProvisioningResult<RealmTO> deleted = logic.delete(StringUtils.prependIfMissing(fullPath, SyncopeConstants.ROOT_REALM)); return modificationResponse(deleted); } }
@Override public Response create(final String parentPath, final RealmTO realmTO) { ProvisioningResult<RealmTO> created = logic.create(StringUtils.prependIfMissing(parentPath, SyncopeConstants.ROOT_REALM), realmTO); URI location = uriInfo.getAbsolutePathBuilder().path(created.getEntity().getName()).build(); Response.ResponseBuilder builder = Response.created(location). header(RESTHeaders.RESOURCE_KEY, created.getEntity().getFullPath()); return applyPreference(created, builder).build(); }
@Override protected SolrClient createSolrClient(String coreName) { return new HttpSolrClient.Builder(solrBaseUrl + StringUtils.prependIfMissing(createRemoteName(coreName), "/")) .build(); } }
public SyncopeClientFactoryBean newClientFactory() { return new SyncopeClientFactoryBean(). setAddress(scheme + "://" + host + ":" + port + StringUtils.prependIfMissing(rootPath, "/")). setUseCompression(BooleanUtils.toBoolean(useGZIPCompression)); }
@Override public Response update(final RealmTO realmTO) { realmTO.setFullPath(StringUtils.prependIfMissing(realmTO.getFullPath(), SyncopeConstants.ROOT_REALM)); ProvisioningResult<RealmTO> updated = logic.update(realmTO); return modificationResponse(updated); }