public static String removeBranchAndPullRequestFromKey(String componentKey) { return substringBeforeLast(substringBeforeLast(componentKey, ComponentDto.BRANCH_KEY_SEPARATOR), ComponentDto.PULL_REQUEST_SEPARATOR); } }
ActionExtractor(String path) { this.path = path; String pathWithoutExtension = substringBeforeLast(path, POINT); this.controller = extractController(pathWithoutExtension); this.action = substringAfterLast(pathWithoutExtension, SLASH); checkArgument(!action.isEmpty(), "Url is incorrect : '%s'", path); this.extension = substringAfterLast(path, POINT); }
private static String extractController(String path) { String controller = substringBeforeLast(path, SLASH); if (controller.startsWith(SLASH)) { return substring(controller, 1); } return controller; }
private static Predicate<String> compile(String pattern) { int countStars = pattern.length() - pattern.replace(WILDCARD_CHAR, "").length(); if (countStars == 0) { checkArgument(pattern.startsWith("/"), "URL pattern must start with slash '/': %s", pattern); return url -> url.equals(pattern); } checkArgument(countStars == 1, "URL pattern accepts only zero or one wildcard character '*': %s", pattern); if (pattern.charAt(0) == '/') { checkArgument(pattern.endsWith(WILDCARD_CHAR), "URL pattern must end with wildcard character '*': %s", pattern); if (pattern.endsWith("/*")) { String path = pattern.substring(0, pattern.length() - "/*".length()); return url -> url.startsWith(path); } if (pattern.endsWith(".*")) { String path = pattern.substring(0, pattern.length() - ".*".length()); return url -> substringBeforeLast(url, ".").equals(path); } String path = pattern.substring(0, pattern.length() - "*".length()); return url -> url.startsWith(path); } checkArgument(pattern.startsWith(WILDCARD_CHAR), "URL pattern must start with wildcard character '*': %s", pattern); // remove the leading * String path = pattern.substring(1); return url -> url.endsWith(path); } }
rootDirectory = StringUtils.substringBeforeLast(rootPath, "/");
@Test(enabled = false) private String getJobConfigZipUri(File source) throws IOException { final File destination = new File(StringUtils.substringBeforeLast(source.toString(), File.separator) + File.separator + URI_ZIP_NAME); if (destination.exists()) { if (!destination.delete()) { throw new IOException("Cannot clean destination job conf zip file: " + destination); } } FileUtils.copyFile(source, destination); return destination.toURI().toString(); }
private void insertDailyPartition(Path dailyPartitionPath) throws Exception { String datasetPath = StringUtils.substringBeforeLast(dailyPartitionPath.toString(), Path.SEPARATOR + "daily"); DateTime partition = DateTimeFormat.forPattern(DAILY_PARTITION_PATTERN).parseDateTime( StringUtils.substringAfter(dailyPartitionPath.toString(), "daily" + Path.SEPARATOR)); PreparedStatement insert = connection.prepareStatement("INSERT INTO Daily_Partitions VALUES (?, ?, ?)"); insert.setString(1, datasetPath); insert.setString(2, dailyPartitionPath.toString()); insert.setTimestamp(3, new Timestamp(partition.getMillis())); insert.executeUpdate(); }
private void insertSnapshot(Path snapshotPath) throws Exception { String datasetPath = StringUtils.substringBeforeLast(snapshotPath.toString(), Path.SEPARATOR); String snapshotName = StringUtils.substringAfterLast(snapshotPath.toString(), Path.SEPARATOR); long ts = Long.parseLong(StringUtils.substringBefore(snapshotName, "-PT-")); long recordCount = Long.parseLong(StringUtils.substringAfter(snapshotName, "-PT-")); PreparedStatement insert = connection.prepareStatement("INSERT INTO Snapshots VALUES (?, ?, ?, ?, ?)"); insert.setString(1, datasetPath); insert.setString(2, snapshotName); insert.setString(3, snapshotPath.toString()); insert.setTimestamp(4, new Timestamp(ts)); insert.setLong(5, recordCount); insert.executeUpdate(); }
public static HostnameReposName resolveRepositoryName(String reposName) { if (reposName.contains("://")) { // It cannot contain a scheme! throw new InvalidRepositoryNameException(); } String[] nameParts = reposName.split("/", 2); if (nameParts.length == 1 || (!nameParts[0].contains(".") && !nameParts[0].contains(":") && !nameParts[0].equals("localhost"))) { return new HostnameReposName(AuthConfig.DEFAULT_SERVER_ADDRESS, reposName); } String hostname = nameParts[0]; reposName = nameParts[1]; if (hostname.contains("index.docker.io")) { throw new InvalidRepositoryNameException(String.format("Invalid repository name, try \"%s\" instead", reposName)); } if (StringUtils.containsIgnoreCase(reposName, SHA256_SEPARATOR)) { reposName = StringUtils.substringBeforeLast(reposName, SHA256_SEPARATOR); } validateRepoName(reposName); return new HostnameReposName(hostname, reposName); }
private static WebService newWs(String path, Consumer<WebService.NewAction> consumer) { return context -> { WebService.NewController controller = context.createController(substringBeforeLast(path, "/")); WebService.NewAction action = createNewDefaultAction(controller, substringAfterLast(path, "/")); action.setHandler((request, response) -> { }); consumer.accept(action); controller.done(); }; }
tableName = StringUtils.substringBeforeLast(columnLabel, ".");
private String determineS3TemplateNameFromKey(String key) { return StringUtils.substringAfterLast(StringUtils.substringBeforeLast(key, S3Utils.SEPARATOR), S3Utils.SEPARATOR); }
protected Long determineS3VolumeIdFromKey(String key) { return Long.parseLong(StringUtils.substringAfterLast(StringUtils.substringBeforeLast(key, S3Utils.SEPARATOR), S3Utils.SEPARATOR)); }
@Override public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException { final String referencePrefix = StringUtils.substringBeforeLast(originalRefValue, "/"); return super.handleElementRename(referencePrefix + SLASH + newElementName); } }
@Override public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException { final String referencePrefix = StringUtils.substringBeforeLast(originalRefValue, "/"); if (referencePrefix.equals(originalRefValue)) { return super.handleElementRename(newElementName); } return super.handleElementRename(referencePrefix + SLASH + newElementName); }
private Set<VirtualFile> getPartialOpenApiFiles(final Project project) { final Set<String> partialOpenApiFilesWithTypeInfo = getPartialOpenApiFilesWithTypeInfo(project); final Collection<VirtualFile> mainOpenApiFiles = FileBasedIndex.getInstance() .getContainingFiles( OpenApiFileIndex.OPEN_API_INDEX_ID, OpenApiFileIndex.MAIN_OPEN_API_FILE, GlobalSearchScope.allScope(project)); if (mainOpenApiFiles.isEmpty()) { return new HashSet<>(); } final VirtualFile mainOpenApiFileFolder = mainOpenApiFiles.iterator().next().getParent(); return partialOpenApiFilesWithTypeInfo .stream() .map(v -> substringBeforeLast(v, OpenApiDataIndexer.DELIMITER)) .map(mainOpenApiFileFolder::findFileByRelativePath) .filter(Objects::nonNull) .collect(Collectors.toSet()); }
private Set<VirtualFile> getPartialSwaggerFiles(final Project project) { final Set<String> partialSwaggerFilesWithTypeInfo = getPartialSwaggerFilesWithTypeInfo(project); final Collection<VirtualFile> mainSwaggerFiles = FileBasedIndex.getInstance() .getContainingFiles( SwaggerFileIndex.SWAGGER_INDEX_ID, SwaggerFileIndex.MAIN_SWAGGER_FILE, GlobalSearchScope.allScope(project)); if (mainSwaggerFiles.isEmpty()) { return new HashSet<>(); } final VirtualFile mainSwaggerFileFolder = mainSwaggerFiles.iterator().next().getParent(); return partialSwaggerFilesWithTypeInfo .stream() .map(v -> substringBeforeLast(v, SwaggerDataIndexer.DELIMITER)) .map(mainSwaggerFileFolder::findFileByRelativePath) .filter(Objects::nonNull) .collect(Collectors.toSet()); }
private OpenApiFileType getPartialOpenApiFileType( final VirtualFile virtualFile, final Project project) { final Set<String> partialOpenApiFilesWithTypeInfo = getPartialOpenApiFilesWithTypeInfo(project); final Collection<VirtualFile> mainOpenApiFiles = FileBasedIndex.getInstance() .getContainingFiles( OpenApiFileIndex.OPEN_API_INDEX_ID, OpenApiFileIndex.MAIN_OPEN_API_FILE, GlobalSearchScope.allScope(project)); if (mainOpenApiFiles.isEmpty()) { return OpenApiFileType.UNDEFINED; } final VirtualFile mainOpenApiFileFolder = mainOpenApiFiles.iterator().next().getParent(); return partialOpenApiFilesWithTypeInfo .stream() .filter( nameWithTypeInfo -> { final VirtualFile foundFile = mainOpenApiFileFolder.findFileByRelativePath( substringBeforeLast(nameWithTypeInfo, OpenApiDataIndexer.DELIMITER)); return virtualFile.equals(foundFile); }) .findFirst() .map(nameWithTypeInfo -> substringAfterLast(nameWithTypeInfo, OpenApiDataIndexer.DELIMITER)) .map(OpenApiFileType::valueOf) .orElse(OpenApiFileType.UNDEFINED); }
private SwaggerFileType getPartialSwaggerFileType( final VirtualFile virtualFile, final Project project) { final Set<String> partialSwaggerFilesWithTypeInfo = getPartialSwaggerFilesWithTypeInfo(project); final Collection<VirtualFile> mainSwaggerFiles = FileBasedIndex.getInstance() .getContainingFiles( SwaggerFileIndex.SWAGGER_INDEX_ID, SwaggerFileIndex.MAIN_SWAGGER_FILE, GlobalSearchScope.allScope(project)); if (mainSwaggerFiles.isEmpty()) { return SwaggerFileType.UNDEFINED; } final VirtualFile mainSwaggerFileFolder = mainSwaggerFiles.iterator().next().getParent(); return partialSwaggerFilesWithTypeInfo .stream() .filter( nameWithTypeInfo -> { final VirtualFile foundFile = mainSwaggerFileFolder.findFileByRelativePath( substringBeforeLast(nameWithTypeInfo, SwaggerDataIndexer.DELIMITER)); return virtualFile.equals(foundFile); }) .findFirst() .map(nameWithTypeInfo -> substringAfterLast(nameWithTypeInfo, SwaggerDataIndexer.DELIMITER)) .map(SwaggerFileType::valueOf) .orElse(SwaggerFileType.UNDEFINED); }
/** * Stubs a {@code createFolder} call. */ public static void stubCreateFolder( final IUnifiedRepository repo, final String path ) { final String parentPath = StringUtils.substringBeforeLast( path, RepositoryFile.SEPARATOR ); doReturn( makeFileObject( path, true ) ).when( repo ).createFolder( eq( makeIdObject( parentPath ) ), argThat( isLikeFile( makeFolderObject( path, false ) ) ), anyString() ); }