Created
June 21, 2024 17:02
-
-
Save dlabey/e0eea7f3f78d1a59447f5225761426f7 to your computer and use it in GitHub Desktop.
Get Path Parameter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sony.sie.payments.paas.apigateway; | |
import java.util.regex.Pattern; | |
import org.apache.commons.lang3.StringUtils; | |
public final class Utils { | |
private static final String PATH_SEPARATOR = "/"; | |
private Utils() { | |
throw new IllegalStateException("Utility class"); | |
} | |
public static String getPathParameter(String pathTemplate, String path, String paramTemplate) { | |
String pathTemplateDelimiter = Pattern.quote(paramTemplate); | |
String[] pathTemplatePieces = pathTemplate.split(pathTemplateDelimiter); | |
int pathTemplateSeparatorPosition = StringUtils.countMatches(pathTemplatePieces[0], PATH_SEPARATOR); | |
String[] pathPieces = path.split(PATH_SEPARATOR); | |
String param = null; | |
if (pathTemplateSeparatorPosition <= pathPieces.length) { | |
param = pathPieces[pathTemplateSeparatorPosition]; | |
} | |
return param; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment