Package discord4j.rest.request
Class RouteMatcher
- java.lang.Object
-
- discord4j.rest.request.RouteMatcher
-
@Experimental public class RouteMatcher extends Object
A predicate that can match a givenDiscordWebRequest. You can create instances of this class using theroute(Route)factory, or throughany()to provide a catch-all matcher.
-
-
Constructor Summary
Constructors Constructor Description RouteMatcher(DiscordWebRequest request, Predicate<Map<String,String>> requestVariableMatcher)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static RouteMatcherany()Create a newRouteMatcherthat returns true for every request.booleanmatches(DiscordWebRequest otherRequest)Tests this matcher against the givenDiscordWebRequest.static RouteMatcherroute(Route route)Create a newRouteMatcherthat matches any request made for the givenRoute.static RouteMatcherroute(Route route, Predicate<Map<String,String>> requestVariableMatcher)Create a newRouteMatcherthat matches every request made for the givenRoutethat also match a givenPredicateof URI variables.
-
-
-
Method Detail
-
any
public static RouteMatcher any()
Create a newRouteMatcherthat returns true for every request.- Returns:
- a new
RouteMatcher
-
route
public static RouteMatcher route(Route route)
Create a newRouteMatcherthat matches any request made for the givenRoute. A list ofRouteobjects exist in theRoutesclass.- Parameters:
route- theRouteto be matched by this instance- Returns:
- a new
RouteMatcher
-
route
public static RouteMatcher route(Route route, Predicate<Map<String,String>> requestVariableMatcher)
Create a newRouteMatcherthat matches every request made for the givenRoutethat also match a givenPredicateof URI variables.The given predicate will receive a
MapofStringURI template parameters as keys andStringvalues used to compile the URI for aDiscordWebRequest. This means you would expect keys asguild.id,channel.id,message.id,user.id, among others. Refer to the actualRouteinstances declared in theRoutesclass for the exact template keys used in the requests you want to match.- Parameters:
route- theRouteto be matched by this instancerequestVariableMatcher- aMapofStringkeys and values representing the URI template and the completed value for a givenDiscordWebRequest, respectively- Returns:
- a new
RouteMatcher
-
matches
public boolean matches(DiscordWebRequest otherRequest)
Tests this matcher against the givenDiscordWebRequest.- Parameters:
otherRequest- theDiscordWebRequestargument- Returns:
trueif the input argument matches the predicate, otherwisefalse
-
-