idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
38,400 | private BufferedImage convertImage ( BufferedImage image ) { if ( image . getType ( ) == BufferedImage . TYPE_INT_RGB ) { return image ; } else { BufferedImage newImage = new BufferedImage ( image . getWidth ( ) , image . getHeight ( ) , BufferedImage . TYPE_INT_RGB ) ; newImage . getGraphics ( ) . drawImage ( image , ... | Make sure that the image is in the most efficient format for reading from . This avoids having to convert pixels every time we access them . | 101 | 27 |
38,401 | public double getFitness ( List < ColouredPolygon > candidate , List < ? extends List < ColouredPolygon > > population ) { // Use one renderer per thread because they are not thread safe. Renderer < List < ColouredPolygon > , BufferedImage > renderer = threadLocalRenderer . get ( ) ; if ( renderer == null ) { renderer ... | Render the polygons as an image and then do a pixel - by - pixel comparison against the target image . The fitness score is the total error . A lower score means a closer match . | 257 | 38 |
38,402 | public List < T > apply ( List < T > selectedCandidates , Random rng ) { double ratio = weightVariable . nextValue ( ) ; int size = ( int ) Math . round ( ratio * selectedCandidates . size ( ) ) ; // Shuffle the collection before applying each operation so that the // split is not influenced by any ordering artifacts f... | Applies one evolutionary operator to part of the population and another to the remainder . Returns a list combining the output of both . Which candidates are submitted to which stream is determined randomly . | 216 | 36 |
38,403 | public static void main ( String [ ] args ) throws IOException { MonaLisaApplet gui = new MonaLisaApplet ( ) ; // If a URL is specified as an argument, use that image. Otherwise use the default Mona Lisa picture. URL imageURL = args . length > 0 ? new URL ( args [ 0 ] ) : MonaLisaApplet . class . getClassLoader ( ) . g... | Entry point for running this example as an application rather than an applet . | 128 | 15 |
38,404 | public List < T > apply ( List < T > selectedCandidates , Random rng ) { return new ArrayList < T > ( selectedCandidates ) ; } | Returns the selected candidates unaltered . | 34 | 8 |
38,405 | @ Override protected List < Node > mate ( Node parent1 , Node parent2 , int numberOfCrossoverPoints , Random rng ) { List < Node > offspring = new ArrayList < Node > ( 2 ) ; Node offspring1 = parent1 ; Node offspring2 = parent2 ; for ( int i = 0 ; i < numberOfCrossoverPoints ; i ++ ) { int crossoverPoint1 = rng . nextI... | Swaps randomly selected sub - trees between the two parents . | 210 | 12 |
38,406 | public String generateRandomCandidate ( Random rng ) { char [ ] chars = new char [ stringLength ] ; for ( int i = 0 ; i < stringLength ; i ++ ) { chars [ i ] = alphabet [ rng . nextInt ( alphabet . length ) ] ; } return new String ( chars ) ; } | Generates a random string of a pre - configured length . Each character is randomly selected from the pre - configured alphabet . The same character may appear multiple times and some characters may not appear at all . | 68 | 40 |
38,407 | public static Method findKnownMethod ( Class < ? > aClass , String name , Class < ? > ... paramTypes ) { try { return aClass . getMethod ( name , paramTypes ) ; } catch ( NoSuchMethodException ex ) { // This cannot happen if the method is correctly identified. throw new IllegalArgumentException ( "Method " + name + " d... | Looks up a method that is explicitly identified . This method should only be used for methods that definitely exist . It does not throw the checked NoSuchMethodException . If the method does not exist it will instead fail with an unchecked IllegalArgumentException . | 96 | 50 |
38,408 | public static < T > Constructor < T > findKnownConstructor ( Class < T > aClass , Class < ? > ... paramTypes ) { try { return aClass . getConstructor ( paramTypes ) ; } catch ( NoSuchMethodException ex ) { // This cannot happen if the method is correctly identified. throw new IllegalArgumentException ( "Specified const... | Looks up a constructor that is explicitly identified . This method should only be used for constructors that definitely exist . It does not throw the checked NoSuchMethodException . If the constructor does not exist it will instead fail with an unchecked IllegalArgumentException . | 97 | 51 |
38,409 | private List < Callable < List < EvaluatedCandidate < T > > > > createEpochTasks ( int populationSize , int eliteCount , int epochLength , List < List < T > > islandPopulations ) { List < Callable < List < EvaluatedCandidate < T > > > > islandEpochs = new ArrayList < Callable < List < EvaluatedCandidate < T > > > > ( i... | Create the concurrently - executed tasks that perform evolution on each island . | 189 | 13 |
38,410 | public List < T > apply ( List < T > selectedCandidates , Random rng ) { // Shuffle the collection before applying each operation so that the // evolution is not influenced by any ordering artifacts from previous // operations. List < T > selectionClone = new ArrayList < T > ( selectedCandidates ) ; Collections . shuff... | Applies the cross - over operation to the selected candidates . Pairs of candidates are chosen randomly and subjected to cross - over to produce a pair of offspring candidates . | 330 | 33 |
38,411 | private Border getBorder ( int row , int column ) { if ( row % 3 == 2 ) { switch ( column % 3 ) { case 2 : return BOTTOM_RIGHT_BORDER ; case 0 : return BOTTOM_LEFT_BORDER ; default : return BOTTOM_BORDER ; } } else if ( row % 3 == 0 ) { switch ( column % 3 ) { case 2 : return TOP_RIGHT_BORDER ; case 0 : return TOP_LEFT... | Get appropriate border for cell based on its position in the grid . | 160 | 13 |
38,412 | public static < T > List < TerminationCondition > shouldContinue ( PopulationData < T > data , TerminationCondition ... conditions ) { // If the thread has been interrupted, we should abort and return whatever // result we currently have. if ( Thread . currentThread ( ) . isInterrupted ( ) ) { return Collections . empt... | Given data about the current population and a set of termination conditions determines whether or not the evolution should continue . | 155 | 21 |
38,413 | public static < T > PopulationData < T > getPopulationData ( List < EvaluatedCandidate < T > > evaluatedPopulation , boolean naturalFitness , int eliteCount , int iterationNumber , long startTime ) { DataSet stats = new DataSet ( evaluatedPopulation . size ( ) ) ; for ( EvaluatedCandidate < T > candidate : evaluatedPop... | Gets data about the current population including the fittest candidate and statistics about the population as a whole . | 177 | 21 |
38,414 | public BufferedImage render ( List < ColouredPolygon > entity ) { // Need to set the background before applying the transform. graphics . setTransform ( IDENTITY_TRANSFORM ) ; graphics . setColor ( Color . GRAY ) ; graphics . fillRect ( 0 , 0 , targetSize . width , targetSize . height ) ; if ( transform != null ) { gra... | Renders the specified polygons as an image . | 136 | 10 |
38,415 | public < S extends Object > void migrate ( List < List < EvaluatedCandidate < S > > > islandPopulations , int migrantCount , Random rng ) { // The first batch of immigrants is from the last island to the first. List < EvaluatedCandidate < S >> lastIsland = islandPopulations . get ( islandPopulations . size ( ) - 1 ) ; ... | Migrates a fixed number of individuals from each island to the adjacent island . Operates as if the islands are arranged in a ring with migration occurring in a clockwise direction . The individuals to be migrated are chosen completely at random . | 348 | 47 |
38,416 | public Collection < String > getSelectedCities ( ) { Set < String > cities = new TreeSet < String > ( ) ; for ( JCheckBox checkBox : checkBoxes ) { if ( checkBox . isSelected ( ) ) { cities . add ( checkBox . getText ( ) ) ; } } return cities ; } | Returns the cities that have been selected as part of the itinerary . | 72 | 14 |
38,417 | @ Override protected List < Point > mutateVertices ( List < Point > vertices , Random rng ) { // A single point is added with the configured probability, unless // we already have the maximum permitted number of points. if ( vertices . size ( ) < MAX_VERTEX_COUNT && getMutationProbability ( ) . nextValue ( ) . nextEven... | Mutates the list of vertices for a given polygon by adding a new random point . Whether or not a point is actually added is determined by the configured mutation probability . | 182 | 35 |
38,418 | public int [ ] [ ] getPatternPhenotype ( ) { if ( phenotype == null ) { // Decode the genes as per Dawkins' rules. int [ ] dx = new int [ GENE_COUNT - 1 ] ; dx [ 3 ] = genes [ 0 ] ; dx [ 4 ] = genes [ 1 ] ; dx [ 5 ] = genes [ 2 ] ; dx [ 1 ] = - dx [ 3 ] ; dx [ 0 ] = - dx [ 4 ] ; dx [ 7 ] = - dx [ 5 ] ; dx [ 2 ] = 0 ; d... | Returns an array of integers that represent the graphical pattern determined by the biomorph s genes . | 242 | 18 |
38,419 | private boolean isIntroducingFixedConflict ( Sudoku sudoku , int row , int fromIndex , int toIndex ) { return columnFixedValues [ fromIndex ] [ sudoku . getValue ( row , toIndex ) - 1 ] || columnFixedValues [ toIndex ] [ sudoku . getValue ( row , fromIndex ) - 1 ] || subGridFixedValues [ convertToSubGrid ( row , fromIn... | Checks whether the proposed mutation would introduce a duplicate of a fixed value into a column or sub - grid . | 143 | 22 |
38,420 | public List < T > apply ( List < T > selectedCandidates , Random rng ) { List < T > population = selectedCandidates ; for ( EvolutionaryOperator < T > operator : pipeline ) { population = operator . apply ( population , rng ) ; } return population ; } | Applies each operation in the pipeline in turn to the selection . | 61 | 13 |
38,421 | public double getFitness ( List < String > candidate , List < ? extends List < String > > population ) { int totalDistance = 0 ; int cityCount = candidate . size ( ) ; for ( int i = 0 ; i < cityCount ; i ++ ) { int nextIndex = i < cityCount - 1 ? i + 1 : 0 ; totalDistance += distances . getDistance ( candidate . get ( ... | Calculates the length of an evolved route . | 103 | 10 |
38,422 | public static void main ( String [ ] args ) { Class < ? > exampleClass = args . length > 0 ? EXAMPLES . get ( args [ 0 ] ) : null ; if ( exampleClass == null ) { System . err . println ( "First argument must be the name of an example, i.e. one of " + Arrays . toString ( EXAMPLES . keySet ( ) . toArray ( ) ) ) ; System ... | Launch the specified example application from the command - line . | 217 | 11 |
38,423 | private String mutateString ( String s , Random rng ) { StringBuilder buffer = new StringBuilder ( s ) ; for ( int i = 0 ; i < buffer . length ( ) ; i ++ ) { if ( mutationProbability . nextValue ( ) . nextEvent ( rng ) ) { buffer . setCharAt ( i , alphabet [ rng . nextInt ( alphabet . length ) ] ) ; } } return buffer .... | Mutate a single string . Zero or more characters may be modified . The probability of any given character being modified is governed by the probability generator configured for this mutation operator . | 98 | 34 |
38,424 | public static Node evolveProgram ( Map < double [ ] , Double > data ) { TreeFactory factory = new TreeFactory ( 2 , // Number of parameters passed into each program. 4 , // Maximum depth of generated trees. Probability . EVENS , // Probability that a node is a function node. new Probability ( 0.6d ) ) ; // Probability ... | Evolve a function to fit the specified data . | 282 | 10 |
38,425 | private void showWindow ( Window newWindow ) { if ( window != null ) { window . remove ( getGUIComponent ( ) ) ; window . setVisible ( false ) ; window . dispose ( ) ; window = null ; } newWindow . add ( getGUIComponent ( ) , BorderLayout . CENTER ) ; newWindow . pack ( ) ; newWindow . setVisible ( true ) ; this . wind... | Helper method for showing the evolution monitor in a frame or dialog . | 95 | 13 |
38,426 | private void checkUnmappedElements ( List < T > offspring , Map < T , T > mapping , int mappingStart , int mappingEnd ) { for ( int i = 0 ; i < offspring . size ( ) ; i ++ ) { if ( ! isInsideMappedRegion ( i , mappingStart , mappingEnd ) ) { T mapped = offspring . get ( i ) ; while ( mapping . containsKey ( mapped ) ) ... | Checks elements that are outside of the partially mapped section to see if there are any duplicate items in the list . If there are they are mapped appropriately . | 113 | 31 |
38,427 | private boolean isInsideMappedRegion ( int position , int startPoint , int endPoint ) { boolean enclosed = ( position < endPoint && position >= startPoint ) ; boolean wrapAround = ( startPoint > endPoint && ( position >= startPoint || position < endPoint ) ) ; return enclosed || wrapAround ; } | Checks whether a given list position is within the partially mapped region used for cross - over . | 66 | 19 |
38,428 | private void configure ( final Container container ) { try { // Use invokeAndWait so that we can be sure that initialisation is complete // before continuing. SwingUtilities . invokeAndWait ( new Runnable ( ) { public void run ( ) { try { UIManager . setLookAndFeel ( UIManager . getSystemLookAndFeelClassName ( ) ) ; } ... | Configure the program to display its GUI in the specified container . | 223 | 13 |
38,429 | private BitString mutateBitString ( BitString bitString , Random rng ) { if ( mutationProbability . nextValue ( ) . nextEvent ( rng ) ) { BitString mutatedBitString = bitString . clone ( ) ; int mutations = mutationCount . nextValue ( ) ; for ( int i = 0 ; i < mutations ; i ++ ) { mutatedBitString . flipBit ( rng . nex... | Mutate a single bit string . Zero or more bits may be flipped . The probability of any given bit being flipped is governed by the probability generator configured for this mutation operator . | 113 | 35 |
38,430 | public static < T > T run ( HTablePool pool , byte [ ] tableName , HTableRunnable < T > runnable ) throws IOException { HTableInterface hTable = null ; try { hTable = pool . getTable ( tableName ) ; return runnable . runWith ( hTable ) ; } catch ( Exception e ) { if ( e instanceof IOException ) { throw ( IOException ) ... | Take an htable from the pool use it with the given HTableRunnable and return it to the pool . This is the loan pattern where the htable resource is used temporarily by the runnable . | 127 | 43 |
38,431 | public static void put ( HTablePool pool , byte [ ] tableName , final Put put ) throws IOException { run ( pool , tableName , new HTableRunnable < Object > ( ) { @ Override public Object runWith ( HTableInterface hTable ) throws IOException { hTable . put ( put ) ; return null ; } } ) ; } | Do an HBase put and return null . | 77 | 9 |
38,432 | public static < T > void gauge ( MetricNameDetails nameDetails , final Callable < T > impl ) { gauge ( nameDetails , new Gauge < T > ( ) { @ Override public T getValue ( ) { try { return impl . call ( ) ; } catch ( Exception ex ) { throw new RuntimeException ( ex ) ; } } } ) ; } | This doesn t make a ton of sense given the above but it will likely be cleaner in Java8 . Also avoids having to catch an exception in a Gauge implementation . | 78 | 34 |
38,433 | public static byte [ ] [ ] getSplitKeys ( Pair < byte [ ] [ ] , byte [ ] [ ] > regionStartsEnds ) { byte [ ] [ ] starts = regionStartsEnds . getFirst ( ) ; List < byte [ ] > splitKeys = new ArrayList < byte [ ] > ( ) ; for ( int i = 1 ; i < starts . length ; i ++ ) { splitKeys . add ( starts [ i ] ) ; } return splitKey... | Get the non - null non - null non - zero - length row keys that divide the regions | 117 | 19 |
38,434 | private Map < BoxedByteArray , byte [ ] > processBatchCallresults ( List < Map . Entry < BoxedByteArray , T > > entries , Object [ ] objects ) { Map < BoxedByteArray , byte [ ] > successes = new HashMap <> ( ) ; for ( int i = 0 ; i < objects . length ; ++ i ) { if ( objects [ i ] != null && objects [ i ] instanceof Res... | Converts the datacube request objects and an array of objects returned from an hbase batch call into the map we use to track success . | 158 | 29 |
38,435 | private Future < ? > runBatch ( Batch < T > batch ) throws InterruptedException { while ( true ) { try { runBatchMeter . mark ( ) ; if ( perRollupMetrics ) { batch . getMap ( ) . forEach ( ( addr , op ) -> { if ( addr . getSourceRollup ( ) . isPresent ( ) ) { updateRollupHistogram ( rollupWriteSize , addr . getSourceRo... | Hand off a batch to the DbHarness layer retrying on FullQueueException . | 196 | 18 |
38,436 | @ Override public Future < ? > runBatchAsync ( Batch < T > batch , AfterExecute < T > afterExecute ) throws FullQueueException { /* * Since ThreadPoolExecutor throws RejectedExecutionException when its queue is full, * we have to backoff and retry if execute() throws RejectedExecutionHandler. * * This will cause all ot... | Hands off the given batch to the flush executor to be sent to the database soon . Doesn t throw IOException since batches are just asynchronously submitted for execution but will throw AsyncException if some previous batch had a RuntimeException . | 187 | 49 |
38,437 | public Batch < T > getWrites ( WriteBuilder writeBuilder , T op ) { Map < Address , T > outputMap = Maps . newHashMap ( ) ; for ( Rollup rollup : rollups ) { List < Set < byte [ ] > > coordSets = new ArrayList < Set < byte [ ] > > ( rollup . getComponents ( ) . size ( ) ) ; boolean dimensionHadNoBucket = false ; for ( ... | Get a batch of writes that when applied to the database will make the change given by op . | 554 | 19 |
38,438 | public static List < Scan > scansThisCubeOnly ( byte [ ] keyPrefix , byte [ ] [ ] splitKeys ) throws IOException { Scan copyScan = new Scan ( ) ; copyScan . setCaching ( 5000 ) ; copyScan . setCacheBlocks ( false ) ; // Hack: generate a key that probably comes after all this cube's keys but doesn't include any // keys ... | Get a collection of Scans one per region that cover the range of the table having the given key prefix . Thes will be used as the map task input splits . | 294 | 34 |
38,439 | private static final Scan truncateScan ( Scan scan , byte [ ] rangeStart , byte [ ] rangeEnd ) { byte [ ] scanStart = scan . getStartRow ( ) ; byte [ ] scanEnd = scan . getStopRow ( ) ; if ( scanEnd . length > 0 && bytesCompare ( scanEnd , rangeStart ) <= 0 ) { // The entire scan range is before the entire cube key ran... | Given a scan and a key range return a new Scan whose range is truncated to only include keys in that range . Returns null if the Scan does not overlap the given range . | 336 | 36 |
38,440 | @ SuppressWarnings ( "unchecked" ) @ Override public Future < ? > runBatchAsync ( Batch < T > batch , AfterExecute < T > afterExecute ) { for ( Map . Entry < Address , T > entry : batch . getMap ( ) . entrySet ( ) ) { Address address = entry . getKey ( ) ; T opFromBatch = entry . getValue ( ) ; BoxedByteArray mapKey ; ... | Actually synchronous and not asyncronous which is allowed . | 731 | 12 |
38,441 | @ Override public ListMultimap < Iterator < T > , T > next ( ) { ListMultimap < Iterator < T > , T > results = ArrayListMultimap . create ( ) ; while ( true ) { HeapEntry heapEntry = heap . poll ( ) ; if ( heapEntry == null ) { break ; // heap is empty } results . put ( iterators . get ( heapEntry . fromIterator ) , he... | Get the next group of results that compare equal . | 347 | 10 |
38,442 | private T nextWrapper ( Iterator < T > it ) { try { if ( trace != null ) { trace . add ( new TraceEntry ( System . nanoTime ( ) , System . currentTimeMillis ( ) , NextOrHasNext . NEXT , debugLabels . get ( it ) ) ) ; } return it . next ( ) ; } catch ( RuntimeException e ) { logTrace ( ) ; throw e ; } } | Get and return the next value from an iterator and add a tracing record if enabled . Logs tracing info if a RuntimeException occurs . | 92 | 27 |
38,443 | private ObjectName createMetrics3Name ( String domain , String name ) throws MalformedObjectNameException { try { return new ObjectName ( domain , "name" , name ) ; } catch ( MalformedObjectNameException e ) { return new ObjectName ( domain , "name" , ObjectName . quote ( name ) ) ; } } | Default behavior of Metrics 3 library for fallback | 71 | 10 |
38,444 | @ SuppressWarnings ( "unchecked" ) private static Deserializer < ? > getDeserializer ( Configuration conf ) { String deserializerClassName = conf . get ( HBaseBackfillMerger . CONFKEY_DESERIALIZER ) ; if ( deserializerClassName == null ) { throw new RuntimeException ( "Configuration didn't set " + deserializerClassName... | Get the deserializer class name from the job config instantiate it and return the instance . | 257 | 19 |
38,445 | public static byte [ ] intToBytesWithLen ( int x , int len ) { if ( len <= 4 ) { return trailingBytes ( intToBytes ( x ) , len ) ; } else { ByteBuffer bb = ByteBuffer . allocate ( len ) ; bb . position ( len - 4 ) ; bb . putInt ( x ) ; assert bb . remaining ( ) == 0 ; return bb . array ( ) ; } } | Write a big - endian integer into the least significant bytes of a byte array . | 94 | 17 |
38,446 | public static byte hashByteArray ( byte [ ] array , int startInclusive , int endExclusive ) { if ( array == null ) { return 0 ; } int range = endExclusive - startInclusive ; if ( range < 0 ) { throw new IllegalArgumentException ( startInclusive + " > " + endExclusive ) ; } int result = 1 ; for ( int i = startInclusive ... | A utility to allow hashing of a portion of an array without having to copy it . | 116 | 17 |
38,447 | public void close ( ) { if ( nativeProxy != 0 ) { new Task < Void > ( ) { public Void call ( ) { Native . unadvise ( nativeProxy ) ; return null ; } } . execute ( ) ; nativeProxy = 0 ; } } | Terminates the event subscription . | 55 | 6 |
38,448 | private static < T > EventInterfaceDescriptor < T > getDescriptor ( Class < T > t ) { EventInterfaceDescriptor < T > r = descriptors . get ( t ) ; if ( r == null ) { r = new EventInterfaceDescriptor < T > ( t ) ; descriptors . put ( t , r ) ; } return r ; } | Gets the descriptor for the given type . | 80 | 9 |
38,449 | private void collectGarbage ( ) { // dispose unused objects if any NativePointerPhantomReference toCollect ; while ( ( toCollect = ( NativePointerPhantomReference ) collectableObjects . poll ( ) ) != null ) { liveComObjects . remove ( toCollect ) ; toCollect . clear ( ) ; toCollect . releaseNative ( ) ; } } | Cleans up any left over references | 78 | 7 |
38,450 | private static String getTypeString ( IType t ) { if ( t == null ) return "null" ; IPtrType pt = t . queryInterface ( IPtrType . class ) ; if ( pt != null ) return getTypeString ( pt . getPointedAtType ( ) ) + "*" ; IPrimitiveType prim = t . queryInterface ( IPrimitiveType . class ) ; if ( prim != null ) return prim . ... | Returns a human - readable identifier of the type but it s not necessarily a correct Java id . | 189 | 19 |
38,451 | public void commit ( ) throws IOException { if ( ! marked ) throw new IllegalStateException ( ) ; marked = false ; super . append ( buffer ) ; buffer . setLength ( 0 ) ; } | Write the pending data . | 42 | 5 |
38,452 | public void generate ( IWTypeLib lib ) throws BindingException , IOException { LibBinder tli = getTypeLibInfo ( lib ) ; if ( referenceResolver . suppress ( lib ) ) return ; // skip code generation if ( generatedTypeLibs . add ( tli ) ) tli . generate ( ) ; } | Call this method repeatedly to generate classes from each type library . | 69 | 12 |
38,453 | public void finish ( ) throws IOException { //Map<String,Set<TypeLibInfo>> byPackage = new HashMap<String,Set<TypeLibInfo>>(); //for( TypeLibInfo tli : generatedTypeLibs ) { // Set<TypeLibInfo> s = byPackage.get(tli.packageName); // if(s==null) // byPackage.put(tli.packageName,s=new HashSet<TypeLibInfo>()); // s.add(tl... | Finally call this method to wrap things up . | 413 | 9 |
38,454 | ITypeDecl getDefaultInterface ( ICoClassDecl t ) { final int count = t . countImplementedInterfaces ( ) ; // look for the default interface first. for ( int i = 0 ; i < count ; i ++ ) { IImplementedInterfaceDecl impl = t . getImplementedInterface ( i ) ; if ( impl . isSource ( ) ) continue ; if ( impl . isDefault ( ) )... | Returns the primary interface for the given co - class . | 388 | 11 |
38,455 | @ SuppressWarnings ( "unchecked" ) protected void messageParameters ( Object [ ] args ) { for ( int i = 0 ; i < args . length ; i ++ ) { if ( args [ i ] instanceof Holder && params [ i ] . getNoByRef ( ) != null ) { // massage the value of Holder, not the Holder itself Holder h = ( Holder ) args [ i ] ; h . value = par... | Converts the parameters to be more native friendly . | 136 | 10 |
38,456 | static NativeType getDefaultConversion ( Type t ) { if ( t instanceof Class ) { Class < ? > c = ( Class < ? > ) t ; NativeType r = defaultConversions . get ( c ) ; if ( r != null ) return r ; if ( Com4jObject . class . isAssignableFrom ( c ) ) return NativeType . ComObject ; if ( Enum . class . isAssignableFrom ( c ) )... | Computes the default conversion for the given type . | 517 | 10 |
38,457 | public static < T extends Enum < T > > EnumDictionary < T > get ( Class < T > clazz ) { EnumDictionary < T > dic = registry . get ( clazz ) ; if ( dic == null ) { boolean sparse = ComEnum . class . isAssignableFrom ( clazz ) ; if ( sparse ) dic = new Sparse < T > ( clazz ) ; else dic = new Continuous < T > ( clazz ) ; ... | Looks up a dictionary from an enum class . | 122 | 9 |
38,458 | static < T extends Enum < T > > T get ( Class < T > clazz , int v ) { return get ( clazz ) . constant ( v ) ; } | Convenience method to be invoked by JNI . | 37 | 11 |
38,459 | public static < T extends Com4jObject > T wrap ( final Class < T > primaryInterface , final long ptr ) throws ComException { return new Task < T > ( ) { @ Override public T call ( ) { return Wrapper . create ( primaryInterface , ptr ) ; } } . execute ( ) ; } | Wraps an externally obtained interface pointer into a COM wrapper object . | 67 | 13 |
38,460 | public static < T extends Com4jObject > T getActiveObject ( Class < T > primaryInterface , GUID clsid ) { return new GetActiveObjectTask < T > ( clsid , primaryInterface ) . execute ( ) ; } | Gets an already running object from the running object table . | 50 | 12 |
38,461 | public static < T extends Com4jObject > T getActiveObject ( Class < T > primaryInterface , String clsid ) { return getActiveObject ( primaryInterface , new GUID ( clsid ) ) ; } | Gets an already object from the running object table . | 45 | 11 |
38,462 | public static < T extends Com4jObject > T getObject ( Class < T > primaryInterface , String fileName , String progId ) { return new GetObjectTask < T > ( fileName , progId , primaryInterface ) . execute ( ) ; } | Returns a reference to a COM object primarily by loading a file . | 54 | 13 |
38,463 | public static GUID getIID ( Class < ? > _interface ) { IID iid = _interface . getAnnotation ( IID . class ) ; if ( iid == null ) throw new IllegalArgumentException ( _interface . getName ( ) + " doesn't have @IID annotation" ) ; return new GUID ( iid . value ( ) ) ; } | Gets the interface GUID associated with the given interface . | 81 | 12 |
38,464 | public Type getType ( ) { int varType = image . getInt ( 0 ) & 0xFFFF ; return EnumDictionary . get ( Type . class ) . constant ( varType ) ; } | Gets the type of the variant . | 43 | 8 |
38,465 | public String getParseableString ( ) { // TODO expand this switch ( this . getType ( ) ) { case VT_I1 : case VT_I2 : case VT_I4 : case VT_INT : return Integer . toString ( this . intValue ( ) ) ; case VT_I8 : return Long . toString ( this . longValue ( ) ) ; case VT_R4 : return Float . toString ( this . floatValue ( ) ... | Generates an String representation of this Variant that can be parsed . | 226 | 13 |
38,466 | public < T extends Com4jObject > T object ( final Class < T > type ) { // native method invocation changeType needs to happen in the COM thread, that is responsible for this variant // @see ComCollection#fetch ComThread t = thread != null ? thread : ComThread . get ( ) ; return t . execute ( new Task < T > ( ) { public... | Reads this VARIANT as a COM interface pointer . | 137 | 12 |
38,467 | static Date toDate ( double d ) { GregorianCalendar ret = new GregorianCalendar ( 1899 , 11 , 30 ) ; int days = ( int ) d ; d -= days ; ret . add ( Calendar . DATE , days ) ; d *= 24 ; int hours = ( int ) d ; ret . add ( Calendar . HOUR , hours ) ; d -= hours ; d *= 60 ; // d += 0.5; // round int min = ( int ) d ; ret ... | Called from the native code to assist VT_DATE - > Date conversion . | 155 | 17 |
38,468 | private static String cutEOL ( String s ) { if ( s == null ) return "(Unknown error)" ; if ( s . endsWith ( "\r\n" ) ) return s . substring ( 0 , s . length ( ) - 2 ) ; else return s ; } | Cuts off the end of line characters . | 59 | 9 |
38,469 | private void fetch ( ) { next . clear ( ) ; // We need to remember for what thread the IEnumVARIANT was marshaled. Because if we want to interpret this // VARIANT as an interface pointer later on, we need to do this in the same thread! next . thread = e . getComThread ( ) ; int r = e . next ( 1 , next ) ; if ( r == 0 )... | Fetches the next element . | 102 | 7 |
38,470 | private int getReturnParam ( ) { // look for [retval] attribute for ( int i = 0 ; i < params . length ; i ++ ) { if ( params [ i ] . isRetval ( ) ) { return i ; } } // sometimes a COM method has only one [out] param. // treat that as the return value. // this is seen frequently in MSHTML (see IHTMLChangeLog, for exampl... | Returns the index of the return value parameter or - 1 if none . | 181 | 14 |
38,471 | private void declare ( IndentingWriter o , IParam p ) throws BindingException { TypeBinding vb = TypeBinding . bind ( g , p . getType ( ) , p . getName ( ) ) ; String javaType = vb . javaType ; if ( method . isVarArg ( ) && p == params [ params . length - 1 ] ) { // use varargs if applicable if ( javaType . endsWith ( ... | Declares a parameter . | 312 | 5 |
38,472 | protected final void declareReturnType ( IndentingWriter o , List < IType > intermediates , boolean usesDefaltValues ) throws BindingException { generateAccessModifier ( o ) ; if ( returnType == null && intermediates == null ) { o . print ( "void " ) ; } else { // we assume that the [retval] param to be passed by refer... | Declares the return type . | 463 | 6 |
38,473 | protected final IType getDispInterfaceReturnType ( ) { IType r = method . getReturnType ( ) ; // if the return type is HRESULT, bind it to 'void'. // dispinterfaces defined by C++ often uses HRESULT // as the return value IPrimitiveType pt = r . queryInterface ( IPrimitiveType . class ) ; if ( pt != null && pt . getVar... | Computes the return type for disp - only interface . | 124 | 11 |
38,474 | private void checkEnv ( ) throws MojoExecutionException { // check OS String osName = System . getProperty ( "os.name" ) ; if ( ! osName . startsWith ( "Windows" ) ) { getLog ( ) . warn ( "Wrong OS: " + osName ) ; throw new MojoExecutionException ( "Com4j can only be run on a Windows operating system, and you're runnin... | Check the runtime environment . | 174 | 5 |
38,475 | private void validate ( ) throws MojoExecutionException { if ( ( file == null && libId == null ) || ( file != null && libId != null ) ) { getLog ( ) . warn ( "You specified <file> and <libId>. The <libId> always wins." ) ; } // check that COM target exists if ( file != null && ! file . exists ( ) ) { getLog ( ) . warn ... | Check the configuration from the pom . xml | 130 | 9 |
38,476 | static Version parseValidSemVer ( String version ) { VersionParser parser = new VersionParser ( version ) ; return parser . parseValidSemVer ( ) ; } | Parses the whole version including pre - release version and build metadata . | 33 | 15 |
38,477 | static NormalVersion parseVersionCore ( String versionCore ) { VersionParser parser = new VersionParser ( versionCore ) ; return parser . parseVersionCore ( ) ; } | Parses the version core . | 34 | 7 |
38,478 | static MetadataVersion parsePreRelease ( String preRelease ) { VersionParser parser = new VersionParser ( preRelease ) ; return parser . parsePreRelease ( ) ; } | Parses the pre - release version . | 35 | 9 |
38,479 | static MetadataVersion parseBuild ( String build ) { VersionParser parser = new VersionParser ( build ) ; return parser . parseBuild ( ) ; } | Parses the build metadata . | 31 | 7 |
38,480 | private Character consumeNextCharacter ( CharType ... expected ) { try { return chars . consume ( expected ) ; } catch ( UnexpectedElementException e ) { throw new UnexpectedCharacterException ( e ) ; } } | Tries to consume the next character in the stream . | 44 | 11 |
38,481 | private void ensureValidLookahead ( CharType ... expected ) { if ( ! chars . positiveLookahead ( expected ) ) { throw new UnexpectedCharacterException ( chars . lookahead ( 1 ) , chars . currentOffset ( ) , expected ) ; } } | Checks if the next character in the stream is valid . | 53 | 12 |
38,482 | @ Override public Expression parse ( String input ) { tokens = lexer . tokenize ( input ) ; Expression expr = parseSemVerExpression ( ) ; consumeNextToken ( EOI ) ; return expr ; } | Parses the SemVer Expressions . | 46 | 9 |
38,483 | private boolean isVersionFollowedBy ( ElementType < Token > type ) { EnumSet < Token . Type > expected = EnumSet . of ( NUMERIC , DOT ) ; Iterator < Token > it = tokens . iterator ( ) ; Token lookahead = null ; while ( it . hasNext ( ) ) { lookahead = it . next ( ) ; if ( ! expected . contains ( lookahead . type ) ) { ... | Determines if the version terminals are followed by the specified token type . | 108 | 15 |
38,484 | private Token consumeNextToken ( Token . Type ... expected ) { try { return tokens . consume ( expected ) ; } catch ( UnexpectedElementException e ) { throw new UnexpectedTokenException ( e ) ; } } | Tries to consume the next token in the stream . | 45 | 11 |
38,485 | Stream < Token > tokenize ( String input ) { List < Token > tokens = new ArrayList < Token > ( ) ; int tokenPos = 0 ; while ( ! input . isEmpty ( ) ) { boolean matched = false ; for ( Token . Type tokenType : Token . Type . values ( ) ) { Matcher matcher = tokenType . pattern . matcher ( input ) ; if ( matcher . find (... | Tokenizes the specified input string . | 223 | 7 |
38,486 | public Version incrementMajorVersion ( String preRelease ) { return new Version ( normal . incrementMajor ( ) , VersionParser . parsePreRelease ( preRelease ) ) ; } | Increments the major version and appends the pre - release version . | 35 | 14 |
38,487 | public Version incrementMinorVersion ( String preRelease ) { return new Version ( normal . incrementMinor ( ) , VersionParser . parsePreRelease ( preRelease ) ) ; } | Increments the minor version and appends the pre - release version . | 35 | 14 |
38,488 | public Version incrementPatchVersion ( String preRelease ) { return new Version ( normal . incrementPatch ( ) , VersionParser . parsePreRelease ( preRelease ) ) ; } | Increments the patch version and appends the pre - release version . | 35 | 14 |
38,489 | public Version setBuildMetadata ( String build ) { return new Version ( normal , preRelease , VersionParser . parseBuild ( build ) ) ; } | Sets the build metadata . | 31 | 6 |
38,490 | @ Override public int compareTo ( Version other ) { int result = normal . compareTo ( other . normal ) ; if ( result == 0 ) { result = preRelease . compareTo ( other . preRelease ) ; } return result ; } | Compares this version to the other version . | 51 | 9 |
38,491 | MetadataVersion increment ( ) { String [ ] ids = idents ; String lastId = ids [ ids . length - 1 ] ; if ( isInt ( lastId ) ) { int intId = Integer . parseInt ( lastId ) ; ids [ ids . length - 1 ] = String . valueOf ( ++ intId ) ; } else { ids = Arrays . copyOf ( ids , ids . length + 1 ) ; ids [ ids . length - 1 ] = Str... | Increments the metadata version . | 129 | 6 |
38,492 | private int compareIdentifierArrays ( String [ ] otherIdents ) { int result = 0 ; int length = getLeastCommonArrayLength ( idents , otherIdents ) ; for ( int i = 0 ; i < length ; i ++ ) { result = compareIdentifiers ( idents [ i ] , otherIdents [ i ] ) ; if ( result != 0 ) { break ; } } return result ; } | Compares two arrays of identifiers . | 89 | 7 |
38,493 | private int getLeastCommonArrayLength ( String [ ] arr1 , String [ ] arr2 ) { return arr1 . length <= arr2 . length ? arr1 . length : arr2 . length ; } | Returns the size of the smallest array . | 44 | 8 |
38,494 | private int compareIdentifiers ( String ident1 , String ident2 ) { if ( isInt ( ident1 ) && isInt ( ident2 ) ) { return Integer . parseInt ( ident1 ) - Integer . parseInt ( ident2 ) ; } else { return ident1 . compareTo ( ident2 ) ; } } | Compares two identifiers . | 67 | 5 |
38,495 | private boolean isInt ( String str ) { try { Integer . parseInt ( str ) ; } catch ( NumberFormatException e ) { return false ; } return true ; } | Checks if the specified string is an integer . | 36 | 10 |
38,496 | public < T extends ElementType < E > > boolean positiveLookahead ( T ... expected ) { for ( ElementType < E > type : expected ) { if ( type . isMatchedBy ( lookahead ( 1 ) ) ) { return true ; } } return false ; } | Checks if the next element in this stream is of the expected types . | 58 | 15 |
38,497 | public < T extends ElementType < E > > boolean positiveLookaheadUntil ( int until , T ... expected ) { for ( int i = 1 ; i <= until ; i ++ ) { for ( ElementType < E > type : expected ) { if ( type . isMatchedBy ( lookahead ( i ) ) ) { return true ; } } } return false ; } | Checks if there is an element in this stream of the expected types until the specified position . | 78 | 19 |
38,498 | @ Override public Iterator < E > iterator ( ) { return new Iterator < E > ( ) { /** * The index to indicate the current position * of this iterator. * * The starting point is set to the current * value of this stream's offset, so that it * doesn't iterate over consumed elements. */ private int index = offset ; /** * {@... | Returns an iterator over elements that are left in this stream . | 180 | 12 |
38,499 | public void start ( int restartableId ) { stop ( restartableId ) ; requested . add ( restartableId ) ; restartableSubscriptions . put ( restartableId , restartables . get ( restartableId ) . call ( ) ) ; } | Starts the given restartable . | 54 | 7 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.