idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
40,200 | @ Override public void runFinallyRoutes ( ) { while ( iterator . hasNext ( ) ) { Route route = iterator . next ( ) . getRoute ( ) ; if ( route . isRunAsFinally ( ) ) { try { handleRoute ( route ) ; } catch ( Exception e ) { log . error ( "Unexpected error in Finally Route" , e ) ; } } else if ( log . isDebugEnabled ( )... | Execute all routes that are flagged to run as finally . | 209 | 12 |
40,201 | public boolean hasContentTypeEngine ( String contentTypeOrSuffix ) { String sanitizedTypes = sanitizeContentTypes ( contentTypeOrSuffix ) ; String [ ] types = sanitizedTypes . split ( "," ) ; for ( String type : types ) { if ( engines . containsKey ( type ) ) { return true ; } } return suffixes . containsKey ( contentT... | Returns true if there is an engine registered for the content type or content type suffix . | 96 | 17 |
40,202 | public ContentTypeEngine registerContentTypeEngine ( Class < ? extends ContentTypeEngine > engineClass ) { ContentTypeEngine engine ; try { engine = engineClass . newInstance ( ) ; } catch ( Exception e ) { throw new PippoRuntimeException ( e , "Failed to instantiate '{}'" , engineClass . getName ( ) ) ; } if ( ! engin... | Registers a content type engine if no other engine has been registered for the content type . | 149 | 18 |
40,203 | public void setContentTypeEngine ( ContentTypeEngine engine ) { String contentType = engine . getContentType ( ) ; String suffix = StringUtils . removeStart ( contentType . substring ( contentType . lastIndexOf ( ' ' ) + 1 ) , "x-" ) ; engines . put ( engine . getContentType ( ) , engine ) ; suffixes . put ( suffix . t... | Sets the engine for it s specified content type . An suffix for the engine is also registered based on the specific type ; extension types are supported and the leading x - is trimmed out . | 129 | 38 |
40,204 | public static < T > Collection < Class < ? extends T > > getSubTypesOf ( Class < T > type , String ... packageNames ) { List < Class < ? extends T > > classes = getClasses ( packageNames ) . stream ( ) . filter ( aClass -> type . isAssignableFrom ( aClass ) ) . map ( aClass -> ( Class < ? extends T > ) aClass ) . colle... | Gets all sub types in hierarchy of a given type . | 127 | 12 |
40,205 | public static < T extends Annotation > T getAnnotation ( Method method , Class < T > annotationClass ) { T annotation = method . getAnnotation ( annotationClass ) ; if ( annotation == null ) { annotation = getAnnotation ( method . getDeclaringClass ( ) , annotationClass ) ; } return annotation ; } | Extract the annotation from the controllerMethod or the declaring class . | 68 | 13 |
40,206 | public static long copy ( InputStream input , OutputStream output ) throws IOException { byte [ ] buffer = new byte [ 2 * 1024 ] ; long total = 0 ; int count ; while ( ( count = input . read ( buffer ) ) != - 1 ) { output . write ( buffer , 0 , count ) ; total += count ; } return total ; } | Copies all data from an InputStream to an OutputStream . | 75 | 13 |
40,207 | public ParameterValue getParameter ( String name ) { if ( ! getParameters ( ) . containsKey ( name ) ) { return buildParameterValue ( ) ; } return getParameters ( ) . get ( name ) ; } | Returns one parameter value . | 46 | 5 |
40,208 | public ParameterValue getQueryParameter ( String name ) { if ( ! getQueryParameters ( ) . containsKey ( name ) ) { return buildParameterValue ( ) ; } return getQueryParameters ( ) . get ( name ) ; } | Returns one query parameter value . | 49 | 6 |
40,209 | public ParameterValue getPathParameter ( String name ) { if ( ! getPathParameters ( ) . containsKey ( name ) ) { return buildParameterValue ( ) ; } return getPathParameters ( ) . get ( name ) ; } | Returns one path parameter . | 49 | 5 |
40,210 | public String getApplicationUriWithQuery ( ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( getApplicationUri ( ) ) ; if ( getQuery ( ) != null ) { sb . append ( ' ' ) . append ( getQuery ( ) ) ; } return sb . toString ( ) ; } | Returns the uri with the query string relative to the application root path . | 73 | 15 |
40,211 | private Properties loadProperties ( File baseDir , Properties currentProperties , String key , boolean override ) throws IOException { Properties loadedProperties = new Properties ( ) ; String include = ( String ) currentProperties . remove ( key ) ; if ( ! StringUtils . isNullOrEmpty ( include ) ) { // allow for multi... | Recursively read referenced properties files . | 373 | 8 |
40,212 | protected void addInterpolationValue ( String name , String value ) { interpolationValues . put ( String . format ( "${%s}" , name ) , value ) ; interpolationValues . put ( String . format ( "@{%s}" , name ) , value ) ; } | Add a value that may be interpolated . | 60 | 9 |
40,213 | protected String interpolateString ( String value ) { String interpolatedValue = value ; for ( Map . Entry < String , String > entry : interpolationValues . entrySet ( ) ) { interpolatedValue = interpolatedValue . replace ( entry . getKey ( ) , entry . getValue ( ) ) ; } return interpolatedValue ; } | Interpolates a string value using System properties and Environment variables . | 71 | 13 |
40,214 | public List < String > getSettingNames ( String startingWith ) { List < String > names = new ArrayList <> ( ) ; Properties props = getProperties ( ) ; if ( StringUtils . isNullOrEmpty ( startingWith ) ) { names . addAll ( props . stringPropertyNames ( ) ) ; } else { startingWith = startingWith . toLowerCase ( ) ; for (... | Returns the list of settings whose name starts with the specified prefix . If the prefix is null or empty all settings names are returned . | 137 | 26 |
40,215 | public String getString ( String name , String defaultValue ) { String value = getProperties ( ) . getProperty ( name , defaultValue ) ; value = overrides . getProperty ( name , value ) ; return value ; } | Returns the string value for the specified name . If the name does not exist or the value for the name can not be interpreted as a string the defaultValue is returned . | 48 | 34 |
40,216 | public boolean getBoolean ( String name , boolean defaultValue ) { String value = getString ( name , null ) ; if ( ! StringUtils . isNullOrEmpty ( value ) ) { return Boolean . parseBoolean ( value . trim ( ) ) ; } return defaultValue ; } | Returns the boolean value for the specified name . If the name does not exist or the value for the name can not be interpreted as a boolean the defaultValue is returned . | 61 | 34 |
40,217 | public int getInteger ( String name , int defaultValue ) { try { String value = getString ( name , null ) ; if ( ! StringUtils . isNullOrEmpty ( value ) ) { return Integer . parseInt ( value . trim ( ) ) ; } } catch ( NumberFormatException e ) { log . warn ( "Failed to parse integer for " + name + USING_DEFAULT_OF + de... | Returns the integer value for the specified name . If the name does not exist or the value for the name can not be interpreted as an integer the defaultValue is returned . | 98 | 34 |
40,218 | public long getLong ( String name , long defaultValue ) { try { String value = getString ( name , null ) ; if ( ! StringUtils . isNullOrEmpty ( value ) ) { return Long . parseLong ( value . trim ( ) ) ; } } catch ( NumberFormatException e ) { log . warn ( "Failed to parse long for " + name + USING_DEFAULT_OF + defaultV... | Returns the long value for the specified name . If the name does not exist or the value for the name can not be interpreted as an long the defaultValue is returned . | 98 | 34 |
40,219 | public float getFloat ( String name , float defaultValue ) { try { String value = getString ( name , null ) ; if ( ! StringUtils . isNullOrEmpty ( value ) ) { return Float . parseFloat ( value . trim ( ) ) ; } } catch ( NumberFormatException e ) { log . warn ( "Failed to parse float for " + name + USING_DEFAULT_OF + de... | Returns the float value for the specified name . If the name does not exist or the value for the name can not be interpreted as a float the defaultValue is returned . | 98 | 34 |
40,220 | public double getDouble ( String name , double defaultValue ) { try { String value = getString ( name , null ) ; if ( ! StringUtils . isNullOrEmpty ( value ) ) { return Double . parseDouble ( value . trim ( ) ) ; } } catch ( NumberFormatException e ) { log . warn ( "Failed to parse double for " + name + USING_DEFAULT_O... | Returns the double value for the specified name . If the name does not exist or the value for the name can not be interpreted as a double the defaultValue is returned . | 98 | 34 |
40,221 | public char getChar ( String name , char defaultValue ) { String value = getString ( name , null ) ; if ( ! StringUtils . isNullOrEmpty ( value ) ) { return value . trim ( ) . charAt ( 0 ) ; } return defaultValue ; } | Returns the char value for the specified name . If the name does not exist or the value for the name can not be interpreted as a char the defaultValue is returned . | 59 | 34 |
40,222 | public String getRequiredString ( String name ) { String value = getString ( name , null ) ; if ( value != null ) { return value . trim ( ) ; } throw new PippoRuntimeException ( "Setting '{}' has not been configured!" , name ) ; } | Returns the string value for the specified name . If the name does not exist an exception is thrown . | 60 | 20 |
40,223 | public List < String > getStrings ( String name , String delimiter ) { String value = getString ( name , null ) ; if ( StringUtils . isNullOrEmpty ( value ) ) { return Collections . emptyList ( ) ; } value = value . trim ( ) ; // to handles cases where value is specified like [a,b, c] if ( value . startsWith ( "[" ) &&... | Returns a list of strings from the specified name using the specified delimiter . | 131 | 15 |
40,224 | public List < Integer > getIntegers ( String name , String delimiter ) { List < String > strings = getStrings ( name , delimiter ) ; List < Integer > ints = new ArrayList <> ( strings . size ( ) ) ; for ( String value : strings ) { try { int i = Integer . parseInt ( value ) ; ints . add ( i ) ; } catch ( NumberFormatEx... | Returns a list of integers from the specified name using the specified delimiter . | 106 | 15 |
40,225 | public List < Long > getLongs ( String name , String delimiter ) { List < String > strings = getStrings ( name , delimiter ) ; List < Long > longs = new ArrayList <> ( strings . size ( ) ) ; for ( String value : strings ) { try { long i = Long . parseLong ( value ) ; longs . add ( i ) ; } catch ( NumberFormatException ... | Returns a list of longs from the specified name using the specified delimiter . | 106 | 16 |
40,226 | public List < Float > getFloats ( String name , String delimiter ) { List < String > strings = getStrings ( name , delimiter ) ; List < Float > floats = new ArrayList <> ( strings . size ( ) ) ; for ( String value : strings ) { try { float i = Float . parseFloat ( value ) ; floats . add ( i ) ; } catch ( NumberFormatEx... | Returns a list of floats from the specified name using the specified delimiter . | 103 | 15 |
40,227 | public List < Double > getDoubles ( String name , String delimiter ) { List < String > strings = getStrings ( name , delimiter ) ; List < Double > doubles = new ArrayList <> ( strings . size ( ) ) ; for ( String value : strings ) { try { double i = Double . parseDouble ( value ) ; doubles . add ( i ) ; } catch ( Number... | Returns a list of doubles from the specified name using the specified delimiter . | 103 | 15 |
40,228 | private TimeUnit extractTimeUnit ( String name , String defaultValue ) { String value = getString ( name , defaultValue ) ; try { final String [ ] s = value . split ( " " , 2 ) ; return TimeUnit . valueOf ( s [ 1 ] . trim ( ) . toUpperCase ( ) ) ; } catch ( Exception e ) { throw new PippoRuntimeException ( "{} must hav... | Extracts the TimeUnit from the name . | 138 | 10 |
40,229 | public static URL locateOnClasspath ( String resourceName ) { URL url = null ; // attempt to load from the context classpath ClassLoader loader = Thread . currentThread ( ) . getContextClassLoader ( ) ; if ( loader != null ) { url = loader . getResource ( resourceName ) ; if ( url != null ) { log . debug ( "Located '{}... | Tries to find a resource with the given name in the classpath . | 156 | 15 |
40,230 | public static List < URL > getResources ( String name ) { List < URL > list = new ArrayList <> ( ) ; try { ClassLoader loader = Thread . currentThread ( ) . getContextClassLoader ( ) ; Enumeration < URL > resources = loader . getResources ( name ) ; while ( resources . hasMoreElements ( ) ) { URL url = resources . next... | Return a list of resource URLs that match the given name . | 117 | 12 |
40,231 | private void registerDirectory ( Path dir ) throws IOException { Files . walkFileTree ( dir , new SimpleFileVisitor < Path > ( ) { @ Override public FileVisitResult preVisitDirectory ( Path dir , BasicFileAttributes attrs ) throws IOException { WatchKey key = dir . register ( watchService , ENTRY_CREATE , ENTRY_DELETE ... | Register the given directory and all its sub - directories . | 112 | 11 |
40,232 | public void registerTemplateEngine ( Class < ? extends TemplateEngine > engineClass ) { if ( templateEngine != null ) { log . debug ( "Template engine already registered, ignoring '{}'" , engineClass . getName ( ) ) ; return ; } try { TemplateEngine engine = engineClass . newInstance ( ) ; setTemplateEngine ( engine ) ... | Registers a template engine if no other engine has been registered . | 113 | 13 |
40,233 | public static String getPippoVersion ( ) { // and the key inside the properties file. String pippoVersionPropertyKey = "pippo.version" ; String pippoVersion ; try { Properties prop = new Properties ( ) ; URL url = ClasspathUtils . locateOnClasspath ( PippoConstants . LOCATION_OF_PIPPO_BUILTIN_PROPERTIES ) ; InputStream... | Simply reads a property resource file that contains the version of this Pippo build . Helps to identify the Pippo version currently running . | 198 | 29 |
40,234 | @ Override public Object layout ( Map model , String templateName , boolean inheritModel ) throws IOException , ClassNotFoundException { Map submodel = inheritModel ? forkModel ( model ) : model ; URL resource = engine . resolveTemplate ( templateName ) ; PippoGroovyTemplate template = ( PippoGroovyTemplate ) engine . ... | Imports a template and renders it using the specified model allowing fine grained composition of templates and layouting . This works similarily to a template include but allows a distinct model to be used . If the layout inherits from the parent model a new model is created with the values from the parent model eventu... | 117 | 72 |
40,235 | public static EmbeddedCacheManager create ( long idleTime ) { Configuration configuration = new ConfigurationBuilder ( ) . expiration ( ) . maxIdle ( idleTime , TimeUnit . SECONDS ) . build ( ) ; return new DefaultCacheManager ( configuration ) ; } | Create cache manager with custom idle time . | 55 | 8 |
40,236 | public static EmbeddedCacheManager create ( String file ) { try { return new DefaultCacheManager ( file ) ; } catch ( IOException ex ) { log . error ( "" , ex ) ; throw new PippoRuntimeException ( ex ) ; } } | Create cache manager with custom config file . | 53 | 8 |
40,237 | public Response bind ( String name , Object model ) { getLocals ( ) . put ( name , model ) ; return this ; } | Binds an object to the response . | 28 | 8 |
40,238 | public Response removeCookie ( String name ) { Cookie cookie = new Cookie ( name , "" ) ; cookie . setSecure ( true ) ; cookie . setMaxAge ( 0 ) ; addCookie ( cookie ) ; return this ; } | Removes the specified cookie by name . | 49 | 8 |
40,239 | public Response noCache ( ) { checkCommitted ( ) ; // no-cache headers for HTTP/1.1 header ( HttpConstants . Header . CACHE_CONTROL , "no-store, no-cache, must-revalidate" ) ; // no-cache headers for HTTP/1.1 (IE) header ( HttpConstants . Header . CACHE_CONTROL , "post-check=0, pre-check=0" ) ; // no-cache headers for ... | Sets this response as not cacheable . | 162 | 9 |
40,240 | public String getContentType ( ) { String contentType = getHeader ( HttpConstants . Header . CONTENT_TYPE ) ; if ( contentType == null ) { contentType = httpServletResponse . getContentType ( ) ; } return contentType ; } | Returns the content type of the response . | 56 | 8 |
40,241 | public Response contentType ( String contentType ) { checkCommitted ( ) ; header ( HttpConstants . Header . CONTENT_TYPE , contentType ) ; httpServletResponse . setContentType ( contentType ) ; return this ; } | Sets the content type of the response . | 51 | 9 |
40,242 | public static String getHashSHA256 ( String text ) { byte [ ] bytes = text . getBytes ( StandardCharsets . ISO_8859_1 ) ; return getHashSHA256 ( bytes ) ; } | Calculates the SHA256 hash of the string . | 45 | 11 |
40,243 | public static String getHashSHA1 ( String text ) { byte [ ] bytes = text . getBytes ( StandardCharsets . ISO_8859_1 ) ; return getHashSHA1 ( bytes ) ; } | Calculates the SHA1 hash of the string . | 45 | 11 |
40,244 | public static String getHashMD5 ( String text ) { byte [ ] bytes = text . getBytes ( StandardCharsets . ISO_8859_1 ) ; return getHashMD5 ( bytes ) ; } | Calculates the MD5 hash of the string . | 45 | 11 |
40,245 | public static String getHashMD5 ( byte [ ] bytes ) { try { MessageDigest md = MessageDigest . getInstance ( "MD5" ) ; md . update ( bytes , 0 , bytes . length ) ; byte [ ] digest = md . digest ( ) ; return toHex ( digest ) ; } catch ( NoSuchAlgorithmException t ) { throw new RuntimeException ( t ) ; } } | Calculates the MD5 hash of the byte array . | 87 | 12 |
40,246 | public static String generateSecretKey ( ) { return hmacDigest ( UUID . randomUUID ( ) . toString ( ) , UUID . randomUUID ( ) . toString ( ) , HMAC_SHA256 ) ; } | Generates a random secret key . | 51 | 7 |
40,247 | public static MongoClient create ( final PippoSettings settings ) { String host = settings . getString ( HOST , "mongodb://localhost:27017" ) ; return create ( host ) ; } | Create a MongoDB client with pippo settings . | 44 | 11 |
40,248 | public static MongoClient create ( String hosts ) { MongoClientURI connectionString = new MongoClientURI ( hosts ) ; return new MongoClient ( connectionString ) ; } | Create a MongoDB client with params . | 34 | 8 |
40,249 | protected void onPreDispatch ( Request request , Response response ) { application . getRoutePreDispatchListeners ( ) . onPreDispatch ( request , response ) ; } | Executes onPreDispatch of registered route pre - dispatch listeners . | 34 | 13 |
40,250 | protected void onRouteDispatch ( Request request , Response response ) { final String requestPath = request . getPath ( ) ; final String requestMethod = request . getMethod ( ) ; if ( shouldIgnorePath ( requestPath ) ) { // NOT FOUND (404) RouteContext routeContext = routeContextFactory . createRouteContext ( applicati... | onRouteDispatch is the front - line for Route processing . | 562 | 12 |
40,251 | protected void onPostDispatch ( Request request , Response response ) { application . getRoutePostDispatchListeners ( ) . onPostDispatch ( request , response ) ; } | Executes onPostDispatch of registered route post - dispatch listeners . | 34 | 13 |
40,252 | private void processFlash ( RouteContext routeContext ) { Flash flash = null ; if ( routeContext . hasSession ( ) ) { // get flash from session flash = routeContext . removeSession ( "flash" ) ; // put an empty flash (outgoing flash) in session; defense against session.get("flash") routeContext . setSession ( "flash" ,... | Removes a Flash instance from the session binds it to the RouteContext and creates a new Flash instance . | 119 | 21 |
40,253 | protected Map < String , Object > prepareTemplateBindings ( int statusCode , RouteContext routeContext ) { Map < String , Object > locals = new LinkedHashMap <> ( ) ; locals . put ( "applicationName" , application . getApplicationName ( ) ) ; locals . put ( "applicationVersion" , application . getApplicationVersion ( )... | Get the template bindings for the error response . | 156 | 9 |
40,254 | protected Error prepareError ( int statusCode , RouteContext routeContext ) { String messageKey = "pippo.statusCode" + statusCode ; Error error = new Error ( ) ; error . setStatusCode ( statusCode ) ; error . setStatusMessage ( application . getMessages ( ) . get ( messageKey , routeContext ) ) ; error . setRequestMeth... | Prepares an Error instance for the error response . | 148 | 10 |
40,255 | public String getParameterName ( ) { if ( parameterName == null ) { Parameter parameter = getParameter ( ) ; if ( parameter . isNamePresent ( ) ) { parameterName = parameter . getName ( ) ; } } return parameterName ; } | Try looking for the parameter name in the compiled . class file . | 53 | 13 |
40,256 | private Map < String , Properties > loadRegisteredMessageResources ( ) { Map < String , Properties > internalMessages = loadRegisteredMessageResources ( "pippo/pippo-messages%s.properties" ) ; Map < String , Properties > applicationMessages = loadRegisteredMessageResources ( "conf/messages%s.properties" ) ; Map < Strin... | Loads Pippo internal messages & application messages and returns the merger . | 289 | 15 |
40,257 | private Map < String , Properties > loadRegisteredMessageResources ( String name ) { Map < String , Properties > messageResources = new TreeMap <> ( ) ; // Load default messages Properties defaultMessages = loadMessages ( String . format ( name , "" ) ) ; if ( defaultMessages == null ) { log . error ( "Could not locate... | Loads all registered message resources . | 575 | 7 |
40,258 | private Properties loadMessages ( String fileOrUrl ) { URL url = ClasspathUtils . locateOnClasspath ( fileOrUrl ) ; if ( url != null ) { try ( InputStreamReader reader = new InputStreamReader ( url . openStream ( ) , StandardCharsets . UTF_8 ) ) { Properties messages = new Properties ( ) ; messages . load ( reader ) ; ... | Attempts to load a message resource . | 118 | 7 |
40,259 | public String getSubmittedFileName ( ) { // TODO this method also introduced in servlet 3.1 specification (delegate to part when I adopt servlet 3.1) if ( submittedFileName == null ) { String header = part . getHeader ( HttpConstants . Header . CONTENT_DISPOSITION ) ; if ( header == null ) { return null ; } for ( Strin... | Retrieves the filename specified by the client . | 161 | 10 |
40,260 | public void write ( File file ) throws IOException { try ( InputStream inputStream = getInputStream ( ) ) { IoUtils . copy ( inputStream , file ) ; } } | Saves this file item to a given file on the server side . | 39 | 14 |
40,261 | protected Cache < String , SessionData > create ( String name , long idleTime ) { return Caching . getCachingProvider ( ) . getCacheManager ( ) . createCache ( name , new MutableConfiguration < String , SessionData > ( ) . setTypes ( String . class , SessionData . class ) . setExpiryPolicyFactory ( TouchedExpiryPolicy ... | Create a cache with name and expiry policy with idle time . | 101 | 13 |
40,262 | public static String getPrettyPath ( List < Puzzle > path , int size ) { // Print each row of all states StringBuffer output = new StringBuffer ( ) ; for ( int y = 0 ; y < size ; y ++ ) { String row = "" ; for ( Puzzle state : path ) { int [ ] [ ] board = state . getMatrixBoard ( ) ; row += "| " ; for ( int x = 0 ; x <... | Prints a search path in a readable form . | 142 | 10 |
40,263 | public static Maze2D read ( File file ) throws IOException { ArrayList < String > array = new ArrayList < String > ( ) ; BufferedReader br = new BufferedReader ( new FileReader ( file ) ) ; String line ; while ( ( line = br . readLine ( ) ) != null ) { array . add ( line ) ; } br . close ( ) ; return new Maze2D ( ( Str... | Read a maze from a file in plain text . | 101 | 10 |
40,264 | public void updateLocation ( Point p , Symbol symbol ) { int row = p . y ; int column = p . x ; this . maze [ row ] [ column ] = symbol . value ( ) ; } | Replace a tile in the maze | 43 | 7 |
40,265 | public void updateRectangle ( Point a , Point b , Symbol symbol ) { int xfrom = ( a . x < b . x ) ? a . x : b . x ; int xto = ( a . x > b . x ) ? a . x : b . x ; int yfrom = ( a . y < b . y ) ? a . y : b . y ; int yto = ( a . y > b . y ) ? a . y : b . y ; for ( int x = xfrom ; x <= xto ; x ++ ) { for ( int y = yfrom ; ... | Replace all tiles inside the rectangle with the provided symbol . | 157 | 12 |
40,266 | public void putObstacleRectangle ( Point a , Point b ) { updateRectangle ( a , b , Symbol . OCCUPIED ) ; } | Fill a rectangle defined by points a and b with occupied tiles . | 33 | 13 |
40,267 | public void removeObstacleRectangle ( Point a , Point b ) { updateRectangle ( a , b , Symbol . EMPTY ) ; } | Fill a rectangle defined by points a and b with empty tiles . | 31 | 13 |
40,268 | public String getReplacedMazeString ( List < Map < Point , Character > > replacements ) { String [ ] stringMaze = toStringArray ( ) ; for ( Map < Point , Character > replacement : replacements ) { for ( Point p : replacement . keySet ( ) ) { int row = p . y ; int column = p . x ; char c = stringMaze [ row ] . charAt ( ... | Generates a string representation of this maze but replacing all the indicated points with the characters provided . | 179 | 19 |
40,269 | public String getStringMazeFilled ( Collection < Point > points , char symbol ) { Map < Point , Character > replacements = new HashMap < Point , Character > ( ) ; for ( Point p : points ) { replacements . put ( p , symbol ) ; } return getReplacedMazeString ( Collections . singletonList ( replacements ) ) ; } | Generates a string representation of this maze with the indicated points replaced with the symbol provided . | 75 | 18 |
40,270 | public boolean pointInBounds ( Point loc ) { return loc . x >= 0 && loc . x < this . columns && loc . y >= 0 && loc . y < this . rows ; } | Check if the provided point is in the maze bounds or outside . | 41 | 13 |
40,271 | public Collection < Point > validLocationsFrom ( Point loc ) { Collection < Point > validMoves = new HashSet < Point > ( ) ; // Check for all valid movements for ( int row = - 1 ; row <= 1 ; row ++ ) { for ( int column = - 1 ; column <= 1 ; column ++ ) { try { if ( isFree ( new Point ( loc . x + column , loc . y + row ... | Return all neighbor empty points from a specific location point . | 153 | 11 |
40,272 | public Set < Point > diff ( Maze2D to ) { char [ ] [ ] maze1 = this . getMazeCharArray ( ) ; char [ ] [ ] maze2 = to . getMazeCharArray ( ) ; Set < Point > differentLocations = new HashSet < Point > ( ) ; for ( int row = 0 ; row < this . rows ; row ++ ) { for ( int column = 0 ; column < this . columns ; column ++ ) { i... | Returns a set of points that are different with respect this maze . Both mazes must have same size . | 145 | 21 |
40,273 | public static Maze2D empty ( int size ) { char [ ] [ ] maze = new char [ size ] [ size ] ; for ( int i = 0 ; i < size ; i ++ ) { Arrays . fill ( maze [ i ] , Symbol . EMPTY . value ( ) ) ; } maze [ 0 ] [ 0 ] = Symbol . START . value ( ) ; maze [ size ] [ size ] = Symbol . GOAL . value ( ) ; return new Maze2D ( maze ) ;... | Generate an empty squared maze of the indicated size . | 106 | 11 |
40,274 | public Entry < T > enqueue ( T value , double priority ) { checkPriority ( priority ) ; /* Create the entry object, which is a circularly-linked list of length * one. */ Entry < T > result = new Entry < T > ( value , priority ) ; /* Merge this singleton list with the tree list. */ mMin = mergeLists ( mMin , result ) ; ... | Inserts the specified element into the Fibonacci heap with the specified priority . Its priority must be a valid double so you cannot set the priority to NaN . | 116 | 33 |
40,275 | public static < T > FibonacciHeap < T > merge ( FibonacciHeap < T > one , FibonacciHeap < T > two ) { /* Create a new FibonacciHeap to hold the result. */ FibonacciHeap < T > result = new FibonacciHeap < T > ( ) ; /* Merge the two Fibonacci heap root lists together. This helper function * also computes the min of the t... | Given two Fibonacci heaps returns a new Fibonacci heap that contains all of the elements of the two heaps . Each of the input heaps is destructively modified by having all its elements removed . You can continue to use those heaps but be aware that they will be empty after this call completes . | 220 | 64 |
40,276 | private void decreaseKeyUnchecked ( Entry < T > entry , double priority ) { /* First, change the node's priority. */ entry . mPriority = priority ; /* If the node no longer has a higher priority than its parent, cut it. * Note that this also means that if we try to run a delete operation * that decreases the key to -in... | Decreases the key of a node in the tree without doing any checking to ensure that the new priority is valid . | 185 | 23 |
40,277 | private void cutNode ( Entry < T > entry ) { /* Begin by clearing the node's mark, since we just cut it. */ entry . mIsMarked = false ; /* Base case: If the node has no parent, we're done. */ if ( entry . mParent == null ) return ; /* Rewire the node's siblings around it, if it has any siblings. */ if ( entry . mNext !... | Cuts a node from its parent . If the parent was already marked recursively cuts that node from its parent as well . | 398 | 26 |
40,278 | public static ScalarOperation < Double > doubleMultiplicationOp ( ) { return new ScalarOperation < Double > ( new ScalarFunction < Double > ( ) { @ Override public Double scale ( Double a , double b ) { return a * b ; } } , 1d ) ; } | Builds the scaling operation for Doubles that is the multiplying operation for the factor . | 62 | 17 |
40,279 | public Iterable < N > expandTransitionsChanged ( N begin , Iterable < Transition < A , S > > transitions ) { Collection < N > nodes = new ArrayList < N > ( ) ; for ( Transition < A , S > transition : transitions ) { S state = transition . getState ( ) ; //if v != start if ( ! state . equals ( begin . state ( ) ) ) { //... | Generates an iterable list of nodes updated as inconsistent after applying the cost changes in the list of transitions passed as parameter . | 238 | 25 |
40,280 | private Map < Transition < A , S > , N > predecessorsMap ( S current ) { //Map<Transition, Node> containing predecessors relations Map < Transition < A , S > , N > mapPredecessors = new HashMap < Transition < A , S > , N > ( ) ; //Fill with non-null pairs of <Transition, Node> for ( Transition < A , S > predecessor : p... | Retrieves a map with the predecessors states and the node associated to each predecessor state . | 142 | 18 |
40,281 | public N makeNode ( N from , Transition < A , S > transition ) { return nodeFactory . makeNode ( from , transition ) ; } | Creates a new node from the parent and a transition calling the node factory . | 30 | 16 |
40,282 | public void updateKey ( N node ) { node . getKey ( ) . update ( node . getG ( ) , node . getV ( ) , heuristicFunction . estimate ( node . state ( ) ) , epsilon , add , scale ) ; } | Updating the priority of a node is required when changing the value of Epsilon . | 55 | 17 |
40,283 | private static Graph buildGraph ( ) { Graph g = new TinkerGraph ( ) ; //add vertices Vertex v1 = g . addVertex ( "v1" ) ; Vertex v2 = g . addVertex ( "v2" ) ; Vertex v3 = g . addVertex ( "v3" ) ; Vertex v4 = g . addVertex ( "v4" ) ; Vertex v5 = g . addVertex ( "v5" ) ; Vertex v6 = g . addVertex ( "v6" ) ; //add edges l... | Build an example graph to execute in this example . | 628 | 10 |
40,284 | public static < A , S > Transition < A , S > create ( S fromState , A action , S toState ) { return new Transition < A , S > ( fromState , action , toState ) ; } | Instantiates a transition specifying an action the origin and destination states . | 46 | 14 |
40,285 | public static < S > Transition < Void , S > create ( S fromState , S toState ) { return new Transition < Void , S > ( fromState , null , toState ) ; } | Offers a way to instantiate a transition without specifying an action but only the origin and destination states . | 41 | 21 |
40,286 | public static void printSearch ( Iterator < ? extends Node < ? , Point , ? > > it , Maze2D maze ) throws InterruptedException { Collection < Point > explored = new HashSet < Point > ( ) ; while ( it . hasNext ( ) ) { Node < ? , Point , ? > currentNode = it . next ( ) ; if ( currentNode . previousNode ( ) != null ) { ex... | Prints the maze and the result of the current iteration until the solution is found . | 214 | 17 |
40,287 | public static String getMazeStringSolution ( Maze2D maze , Collection < Point > explored , Collection < Point > path ) { List < Map < Point , Character > > replacements = new ArrayList < Map < Point , Character > > ( ) ; Map < Point , Character > replacement = new HashMap < Point , Character > ( ) ; for ( Point p : exp... | Returns the maze passed as parameter but replacing some characters to print the path found in the current iteration . | 150 | 20 |
40,288 | public static void main ( String [ ] args ) { /* SearchProblem is the structure used by Hipster to store all the information about the search query, like: start, goals, transition function, cost function, etc. Once created it is used to instantiate the search iterators which provide the results. */ SearchProblem p = Pr... | Possible actions of our problem | 734 | 6 |
40,289 | @ Override public Iterable < GraphEdge < V , E > > edges ( ) { return F . map ( vedges ( ) , new Function < Map . Entry < V , GraphEdge < V , E > > , GraphEdge < V , E > > ( ) { @ Override public GraphEdge < V , E > apply ( Map . Entry < V , GraphEdge < V , E > > entry ) { return entry . getValue ( ) ; } } ) ; } | Returns a list of the edges in the graph . | 102 | 10 |
40,290 | public SearchResult search ( final S goalState ) { return search ( new Predicate < N > ( ) { @ Override public boolean apply ( N n ) { if ( goalState != null ) { return n . state ( ) . equals ( goalState ) ; } return false ; } } ) ; } | Run the algorithm until the goal is found or no more states are available . | 64 | 15 |
40,291 | public SearchResult search ( Predicate < N > condition ) { int iteration = 0 ; Iterator < N > it = iterator ( ) ; long begin = System . currentTimeMillis ( ) ; N currentNode = null ; while ( it . hasNext ( ) ) { iteration ++ ; currentNode = it . next ( ) ; if ( condition . apply ( currentNode ) ) { break ; } } long end... | Executes the search algorithm until the predicate condition is satisfied or there are no more nodes to explore . | 112 | 20 |
40,292 | public static < S , N extends Node < ? , S , N > > List < S > recoverStatePath ( N node ) { List < S > states = new LinkedList < S > ( ) ; for ( N n : node . path ( ) ) { states . add ( n . state ( ) ) ; } return states ; } | Returns a path with all the states of the path . | 72 | 11 |
40,293 | public static < A , S , C extends Comparable < C > , N extends CostNode < A , S , C , N > > BellmanFord < A , S , C , N > createBellmanFord ( SearchProblem < A , S , N > components ) { return new BellmanFord < A , S , C , N > ( components . getInitialNode ( ) , components . getExpander ( ) ) ; } | Instantiates a Bellman Ford algorithm for a problem definition . | 91 | 13 |
40,294 | public static < A , S , N extends Node < A , S , N > > BreadthFirstSearch < A , S , N > createBreadthFirstSearch ( SearchProblem < A , S , N > components ) { return new BreadthFirstSearch < A , S , N > ( components . getInitialNode ( ) , components . getExpander ( ) ) ; } | Instantiates Breadth First Search algorithm for a problem definition . | 80 | 13 |
40,295 | public static < A , S , N extends Node < A , S , N > > DepthFirstSearch < A , S , N > createDepthFirstSearch ( SearchProblem < A , S , N > components ) { return new DepthFirstSearch < A , S , N > ( components . getInitialNode ( ) , components . getExpander ( ) ) ; } | Instantiates Depth First Search algorithm for a problem definition . | 76 | 12 |
40,296 | public static < A , S , N extends Node < A , S , N > > DepthLimitedSearch < A , S , N > createDepthLimitedSearch ( SearchProblem < A , S , N > components , int depth ) { return new DepthLimitedSearch < A , S , N > ( components . getInitialNode ( ) , components . getFinalNode ( ) , components . getExpander ( ) , depth )... | Instantiates Depth Limited Search algorithm for a problem definition . | 89 | 12 |
40,297 | public static < A , S , C extends Comparable < C > , N extends HeuristicNode < A , S , C , N > > HillClimbing < A , S , C , N > createHillClimbing ( SearchProblem < A , S , N > components , boolean enforced ) { return new HillClimbing < A , S , C , N > ( components . getInitialNode ( ) , components . getExpander ( ) , ... | Instantiates a Hill Climbing algorithm given a problem definition . | 100 | 13 |
40,298 | public static < A , S , N extends HeuristicNode < A , S , Double , N > > AnnealingSearch < A , S , N > createAnnealingSearch ( SearchProblem < A , S , N > components , Double alpha , Double minTemp , AcceptanceProbability acceptanceProbability , SuccessorFinder < A , S , N > successorFinder ) { return new AnnealingSear... | Instantiates an AnnealingSearch algorithm given a problem definition . | 126 | 13 |
40,299 | public static < A , S , C extends Comparable < C > , N extends HeuristicNode < A , S , C , N > > MultiobjectiveLS < A , S , C , N > createMultiobjectiveLS ( SearchProblem < A , S , N > components ) { return new MultiobjectiveLS < A , S , C , N > ( components . getInitialNode ( ) , components . getExpander ( ) ) ; } | Instantiates a Multi - objective Label Setting algorithm given a problem definition . | 95 | 15 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.