idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
152,500 | public void generate ( TypeElement directiveTypeElement ) { ClassName optionsClassName = GeneratorsNameUtil . directiveOptionsName ( directiveTypeElement ) ; Builder componentClassBuilder = TypeSpec . classBuilder ( optionsClassName ) . addModifiers ( Modifier . PUBLIC , Modifier . FINAL ) . superclass ( VueDirectiveOptions . class ) . addAnnotation ( JsType . class ) . addJavadoc ( "VueComponent Directive Options for directive {@link $S}" , directiveTypeElement . getQualifiedName ( ) . toString ( ) ) ; // Initialize constructor MethodSpec . Builder constructorBuilder = MethodSpec . constructorBuilder ( ) . addModifiers ( Modifier . PUBLIC ) ; // Add the Java Component Instance initialization constructorBuilder . addStatement ( "this.$L = new $T()" , "vuegwt$javaDirectiveInstance" , TypeName . get ( directiveTypeElement . asType ( ) ) ) ; // Call the method to copy hooks functions constructorBuilder . addStatement ( "this.copyHooks()" ) ; // Finish building the constructor componentClassBuilder . addMethod ( constructorBuilder . build ( ) ) ; // Build the DirectiveOptions class GeneratorsUtil . toJavaFile ( filer , componentClassBuilder , optionsClassName , directiveTypeElement ) ; } | Generate and save the Java file for the typeElement passed to the constructor | 282 | 15 |
152,501 | private void exposeExposedFieldsToJs ( ) { if ( fieldsWithNameExposed . isEmpty ( ) ) { return ; } MethodSpec . Builder exposeFieldMethod = MethodSpec . methodBuilder ( "vg$ef" ) . addAnnotation ( JsMethod . class ) ; fieldsWithNameExposed . forEach ( field -> exposeFieldMethod . addStatement ( "this.$L = $T.v()" , field . getName ( ) , FieldsExposer . class ) ) ; exposeFieldMethod . addStatement ( "$T.e($L)" , FieldsExposer . class , String . join ( "," , fieldsWithNameExposed . stream ( ) . map ( ExposedField :: getName ) . collect ( Collectors . toList ( ) ) ) ) ; componentExposedTypeBuilder . addMethod ( exposeFieldMethod . build ( ) ) ; } | Generate a method that use all the fields we want to determine the name of at runtime . This is to avoid GWT optimizing away assignation on those fields . | 188 | 33 |
152,502 | private void processComputed ( ) { getMethodsWithAnnotation ( component , Computed . class ) . forEach ( method -> { ComputedKind kind = ComputedKind . GETTER ; if ( "void" . equals ( method . getReturnType ( ) . toString ( ) ) ) { kind = ComputedKind . SETTER ; } String exposedMethodName = exposeExistingJavaMethodToJs ( method ) ; String fieldName = computedPropertyNameToFieldName ( getComputedPropertyName ( method ) ) ; TypeMirror propertyType = getComputedPropertyTypeFromMethod ( method ) ; fieldsWithNameExposed . add ( new ExposedField ( fieldName , propertyType ) ) ; optionsBuilder . addStatement ( "options.addJavaComputed(p.$L, $T.getFieldName(this, () -> this.$L = $L), $T.$L)" , exposedMethodName , VueGWTTools . class , fieldName , getFieldMarkingValueForType ( propertyType ) , ComputedKind . class , kind ) ; } ) ; addFieldsForComputedMethod ( component , new HashSet <> ( ) ) ; } | Process computed properties from the Component Class . | 249 | 8 |
152,503 | private void addFieldsForComputedMethod ( TypeElement component , Set < String > alreadyDone ) { getMethodsWithAnnotation ( component , Computed . class ) . forEach ( method -> { String propertyName = computedPropertyNameToFieldName ( getComputedPropertyName ( method ) ) ; if ( alreadyDone . contains ( propertyName ) ) { return ; } TypeMirror propertyType = getComputedPropertyTypeFromMethod ( method ) ; componentExposedTypeBuilder . addField ( FieldSpec . builder ( TypeName . get ( propertyType ) , propertyName , Modifier . PROTECTED ) . addAnnotation ( JsProperty . class ) . build ( ) ) ; alreadyDone . add ( propertyName ) ; } ) ; getSuperComponentType ( component ) . ifPresent ( superComponent -> addFieldsForComputedMethod ( superComponent , alreadyDone ) ) ; } | Add fields for computed methods so they are visible in the template | 188 | 12 |
152,504 | private void processWatchers ( MethodSpec . Builder createdMethodBuilder ) { createdMethodBuilder . addStatement ( "Proto p = __proto__" ) ; getMethodsWithAnnotation ( component , Watch . class ) . forEach ( method -> processWatcher ( createdMethodBuilder , method ) ) ; } | Process watchers from the Component Class . | 66 | 8 |
152,505 | private void processWatcher ( MethodSpec . Builder createdMethodBuilder , ExecutableElement method ) { Watch watch = method . getAnnotation ( Watch . class ) ; String exposedMethodName = exposeExistingJavaMethodToJs ( method ) ; String watcherTriggerMethodName = addNewMethodToProto ( ) ; MethodSpec . Builder watcherMethodBuilder = MethodSpec . methodBuilder ( watcherTriggerMethodName ) . addModifiers ( Modifier . PUBLIC ) . addAnnotation ( JsMethod . class ) . returns ( Object . class ) ; String [ ] valueSplit = watch . value ( ) . split ( "\\." ) ; String currentExpression = "" ; for ( int i = 0 ; i < valueSplit . length - 1 ; i ++ ) { currentExpression += valueSplit [ i ] ; watcherMethodBuilder . addStatement ( "if ($L == null) return null" , currentExpression ) ; currentExpression += "." ; } watcherMethodBuilder . addStatement ( "return $L" , watch . value ( ) ) ; componentExposedTypeBuilder . addMethod ( watcherMethodBuilder . build ( ) ) ; createdMethodBuilder . addStatement ( "vue().$L(p.$L, p.$L, $T.of($L, $L))" , "$watch" , watcherTriggerMethodName , exposedMethodName , WatchOptions . class , watch . isDeep ( ) , watch . isImmediate ( ) ) ; } | Process a watcher from the Component Class . | 314 | 9 |
152,506 | private void processPropValidators ( ) { getMethodsWithAnnotation ( component , PropValidator . class ) . forEach ( method -> { PropValidator propValidator = method . getAnnotation ( PropValidator . class ) ; if ( ! TypeName . get ( method . getReturnType ( ) ) . equals ( TypeName . BOOLEAN ) ) { printError ( "Method " + method . getSimpleName ( ) + " annotated with PropValidator must return a boolean." ) ; } String exposedMethodName = exposeExistingJavaMethodToJs ( method ) ; String propertyName = propValidator . value ( ) ; optionsBuilder . addStatement ( "options.addJavaPropValidator(p.$L, $S)" , exposedMethodName , propertyName ) ; } ) ; } | Process prop validators from the Component Class . | 172 | 9 |
152,507 | private void processPropDefaultValues ( ) { getMethodsWithAnnotation ( component , PropDefault . class ) . forEach ( method -> { PropDefault propValidator = method . getAnnotation ( PropDefault . class ) ; String exposedMethodName = exposeExistingJavaMethodToJs ( method ) ; String propertyName = propValidator . value ( ) ; optionsBuilder . addStatement ( "options.addJavaPropDefaultValue(p.$L, $S)" , exposedMethodName , propertyName ) ; } ) ; } | Process prop default values from the Component Class . | 110 | 9 |
152,508 | private void processHooks ( Set < ExecutableElement > hookMethodsFromInterfaces ) { ElementFilter . methodsIn ( component . getEnclosedElements ( ) ) . stream ( ) . filter ( method -> isHookMethod ( component , method , hookMethodsFromInterfaces ) ) // Created hook is already added by createCreatedHook . filter ( method -> ! "created" . equals ( method . getSimpleName ( ) . toString ( ) ) ) . forEach ( method -> { String exposedMethodName = exposeExistingJavaMethodToJs ( method ) ; String methodName = method . getSimpleName ( ) . toString ( ) ; optionsBuilder . addStatement ( "options.addHookMethod($S, p.$L)" , methodName , exposedMethodName ) ; } ) ; } | Process hook methods from the Component Class . | 170 | 8 |
152,509 | private Set < ExecutableElement > getHookMethodsFromInterfaces ( ) { return component . getInterfaces ( ) . stream ( ) . map ( DeclaredType . class :: cast ) . map ( DeclaredType :: asElement ) . map ( TypeElement . class :: cast ) . flatMap ( typeElement -> ElementFilter . methodsIn ( typeElement . getEnclosedElements ( ) ) . stream ( ) ) . filter ( method -> hasAnnotation ( method , HookMethod . class ) ) . peek ( this :: validateHookMethod ) . collect ( Collectors . toSet ( ) ) ; } | Return all hook methods from the implemented interfaces | 129 | 8 |
152,510 | private void processRenderFunction ( ) { if ( ! hasInterface ( processingEnv , component . asType ( ) , HasRender . class ) ) { return ; } componentExposedTypeBuilder . addMethod ( MethodSpec . methodBuilder ( "vg$render" ) . addModifiers ( Modifier . PUBLIC ) . addAnnotation ( JsMethod . class ) . returns ( VNode . class ) . addParameter ( CreateElementFunction . class , "createElementFunction" ) . addStatement ( "return super.render(new $T(createElementFunction))" , VNodeBuilder . class ) . build ( ) ) ; addMethodToProto ( "vg$render" ) ; // Register the render method optionsBuilder . addStatement ( "options.addHookMethod($S, p.$L)" , "render" , "vg$render" ) ; } | Process the render function from the Component Class if it has one . | 184 | 13 |
152,511 | private void createCreatedHook ( ComponentInjectedDependenciesBuilder dependenciesBuilder ) { String hasRunCreatedFlagName = "vg$hrc_" + getSuperComponentCount ( component ) ; componentExposedTypeBuilder . addField ( FieldSpec . builder ( boolean . class , hasRunCreatedFlagName , Modifier . PUBLIC ) . addAnnotation ( JsProperty . class ) . build ( ) ) ; MethodSpec . Builder createdMethodBuilder = MethodSpec . methodBuilder ( "vg$created" ) . addModifiers ( Modifier . PUBLIC ) . addAnnotation ( JsMethod . class ) ; // Avoid infinite recursion in case calling the Java constructor calls Vue.js constructor // This can happen when extending an existing JS component createdMethodBuilder . addStatement ( "if ($L) return" , hasRunCreatedFlagName ) . addStatement ( "$L = true" , hasRunCreatedFlagName ) ; createdMethodBuilder . addStatement ( "vue().$L().proxyFields(this)" , "$options" ) ; injectDependencies ( component , dependenciesBuilder , createdMethodBuilder ) ; initFieldsValues ( component , createdMethodBuilder ) ; processWatchers ( createdMethodBuilder ) ; if ( hasInterface ( processingEnv , component . asType ( ) , HasCreated . class ) ) { createdMethodBuilder . addStatement ( "super.created()" ) ; } componentExposedTypeBuilder . addMethod ( createdMethodBuilder . build ( ) ) ; // Register the hook addMethodToProto ( "vg$created" ) ; optionsBuilder . addStatement ( "options.addHookMethod($S, p.$L)" , "created" , "vg$created" ) ; } | Create the created hook method . This method will be called on each Component when it s created . It will inject dependencies if any . | 364 | 26 |
152,512 | private void initFieldsValues ( TypeElement component , MethodSpec . Builder createdMethodBuilder ) { // Do not init instance fields for abstract components if ( component . getModifiers ( ) . contains ( Modifier . ABSTRACT ) ) { return ; } createdMethodBuilder . addStatement ( "$T.initComponentInstanceFields(this, new $T())" , VueGWTTools . class , component ) ; } | Init fields at creation by using an instance of the Java class | 89 | 12 |
152,513 | private String getSuperMethodCallParameters ( ExecutableElement sourceMethod ) { return sourceMethod . getParameters ( ) . stream ( ) . map ( parameter -> parameter . getSimpleName ( ) . toString ( ) ) . collect ( Collectors . joining ( ", " ) ) ; } | Return the list of parameters name to pass to the super call on proxy methods . | 59 | 16 |
152,514 | private void addEmitEventCall ( ExecutableElement originalMethod , MethodSpec . Builder proxyMethodBuilder , String methodCallParameters ) { String methodName = "$emit" ; if ( methodCallParameters != null && ! "" . equals ( methodCallParameters ) ) { proxyMethodBuilder . addStatement ( "vue().$L($S, $L)" , methodName , methodToEventName ( originalMethod ) , methodCallParameters ) ; } else { proxyMethodBuilder . addStatement ( "vue().$L($S)" , methodName , methodToEventName ( originalMethod ) ) ; } } | Add a call to emit an event at the end of the function | 128 | 13 |
152,515 | private boolean isHookMethod ( TypeElement component , ExecutableElement method , Set < ExecutableElement > hookMethodsFromInterfaces ) { if ( hasAnnotation ( method , HookMethod . class ) ) { validateHookMethod ( method ) ; return true ; } for ( ExecutableElement hookMethodsFromInterface : hookMethodsFromInterfaces ) { if ( elements . overrides ( method , hookMethodsFromInterface , component ) ) { return true ; } } return false ; } | Return true of the given method is a proxy method | 100 | 10 |
152,516 | private String getNativeNameForJavaType ( TypeMirror typeMirror ) { TypeName typeName = TypeName . get ( typeMirror ) ; if ( typeName . equals ( TypeName . INT ) || typeName . equals ( TypeName . BYTE ) || typeName . equals ( TypeName . SHORT ) || typeName . equals ( TypeName . LONG ) || typeName . equals ( TypeName . FLOAT ) || typeName . equals ( TypeName . DOUBLE ) ) { return "Number" ; } else if ( typeName . equals ( TypeName . BOOLEAN ) ) { return "Boolean" ; } else if ( typeName . equals ( TypeName . get ( String . class ) ) || typeName . equals ( TypeName . CHAR ) ) { return "String" ; } else if ( typeMirror . toString ( ) . startsWith ( JsArray . class . getCanonicalName ( ) ) ) { return "Array" ; } else { return "Object" ; } } | Transform a Java type name into a JavaScript type name . Takes care of primitive types . | 221 | 17 |
152,517 | private void processInjectedFields ( TypeElement component ) { getInjectedFields ( component ) . stream ( ) . peek ( this :: validateField ) . forEach ( field -> { String fieldName = field . getSimpleName ( ) . toString ( ) ; addInjectedVariable ( field , fieldName ) ; injectedFieldsName . add ( fieldName ) ; } ) ; } | Process all the injected fields from our Component . | 83 | 9 |
152,518 | private void processInjectedMethods ( TypeElement component ) { getInjectedMethods ( component ) . stream ( ) . peek ( this :: validateMethod ) . forEach ( this :: processInjectedMethod ) ; } | Process all the injected methods from our Component . | 44 | 9 |
152,519 | private void addInjectedVariable ( VariableElement element , String fieldName ) { TypeName typeName = resolveVariableTypeName ( element , messager ) ; // Create field FieldSpec . Builder fieldBuilder = FieldSpec . builder ( typeName , fieldName , Modifier . PUBLIC ) ; // Copy field annotations element . getAnnotationMirrors ( ) . stream ( ) . map ( AnnotationSpec :: get ) . forEach ( fieldBuilder :: addAnnotation ) ; // If the variable element is a method parameter, it might not have the Inject annotation if ( ! hasInjectAnnotation ( element ) ) { fieldBuilder . addAnnotation ( Inject . class ) ; } // And add field builder . addField ( fieldBuilder . build ( ) ) ; } | Add an injected variable to our component | 160 | 7 |
152,520 | public LocalVariableInfo addLocalVariable ( String typeQualifiedName , String name ) { return contextLayers . getFirst ( ) . addLocalVariable ( typeQualifiedName , name ) ; } | Add a local variable in the current context . | 41 | 9 |
152,521 | public DestructuredPropertyInfo addDestructuredProperty ( String propertyType , String propertyName , LocalVariableInfo destructuredVariable ) { return contextLayers . getFirst ( ) . addDestructuredProperty ( propertyType , propertyName , destructuredVariable ) ; } | Add a local variable coming from a Variable destructuring to the current context . | 56 | 15 |
152,522 | public VariableInfo findVariable ( String name ) { for ( ContextLayer contextLayer : contextLayers ) { VariableInfo variableInfo = contextLayer . getVariableInfo ( name ) ; if ( variableInfo != null ) { return variableInfo ; } } return null ; } | Find a variable in the context stack . | 55 | 8 |
152,523 | public void addImport ( String fullyQualifiedName ) { String [ ] importSplit = fullyQualifiedName . split ( "\\." ) ; String className = importSplit [ importSplit . length - 1 ] ; classNameToFullyQualifiedName . put ( className , fullyQualifiedName ) ; } | Add a Java Import to the context . | 66 | 8 |
152,524 | public String getFullyQualifiedNameForClassName ( String className ) { if ( ! classNameToFullyQualifiedName . containsKey ( className ) ) { return className ; } return classNameToFullyQualifiedName . get ( className ) ; } | Return the fully qualified name for a given class . Only works if the class has been imported . | 59 | 19 |
152,525 | public void addStaticImport ( String fullyQualifiedName ) { String [ ] importSplit = fullyQualifiedName . split ( "\\." ) ; String symbolName = importSplit [ importSplit . length - 1 ] ; methodNameToFullyQualifiedName . put ( symbolName , fullyQualifiedName ) ; propertyNameToFullyQualifiedName . put ( symbolName , fullyQualifiedName ) ; } | Add a Java Static Import to the context . | 87 | 9 |
152,526 | public String getFullyQualifiedNameForMethodName ( String methodName ) { if ( ! methodNameToFullyQualifiedName . containsKey ( methodName ) ) { return methodName ; } return methodNameToFullyQualifiedName . get ( methodName ) ; } | Return the fully qualified name for a given method . Only works if the method has been statically imported . | 59 | 20 |
152,527 | public String getFullyQualifiedNameForPropertyName ( String propertyName ) { if ( ! propertyNameToFullyQualifiedName . containsKey ( propertyName ) ) { return propertyName ; } return propertyNameToFullyQualifiedName . get ( propertyName ) ; } | Return the fully qualified name for a given property . Only works if the property has been statically imported . | 59 | 20 |
152,528 | public Optional < Integer > getCurrentLine ( ) { if ( currentSegment == null ) { return Optional . empty ( ) ; } return Optional . of ( currentSegment . getSource ( ) . getRow ( currentSegment . getBegin ( ) ) ) ; } | Return the number of the line currently processed in the HTML | 57 | 11 |
152,529 | @ JsIgnore public static void initWithoutVueLib ( ) { if ( ! isVueLibInjected ( ) ) { throw new RuntimeException ( "Couldn't find Vue.js on init. Either include it Vue.js in your index.html or call VueGWT.init() instead of initWithoutVueLib." ) ; } // Register custom observers for Collection and Maps VueGWTObserverManager . get ( ) . registerVueGWTObserver ( new CollectionObserver ( ) ) ; VueGWTObserverManager . get ( ) . registerVueGWTObserver ( new MapObserver ( ) ) ; isReady = true ; // Call on ready callbacks for ( Runnable onReadyCbk : onReadyCallbacks ) { onReadyCbk . run ( ) ; } onReadyCallbacks . clear ( ) ; } | Inject scripts necessary for Vue GWT to work Requires Vue to be defined in Window . | 191 | 20 |
152,530 | @ JsIgnore public static void onReady ( Runnable callback ) { if ( isReady ) { callback . run ( ) ; return ; } onReadyCallbacks . push ( callback ) ; } | Ask to be warned when Vue GWT is ready . If Vue GWT is ready the callback is called immediately . | 43 | 25 |
152,531 | public static void resolveRichTextField ( ArrayResource array , CDAClient client ) { for ( CDAEntry entry : array . entries ( ) . values ( ) ) { ensureContentType ( entry , client ) ; for ( CDAField field : entry . contentType ( ) . fields ( ) ) { if ( "RichText" . equals ( field . type ( ) ) ) { resolveRichDocument ( entry , field ) ; resolveRichLink ( array , entry , field ) ; } } } } | Walk through the given array and resolve all rich text fields . | 106 | 12 |
152,532 | private static void resolveRichDocument ( CDAEntry entry , CDAField field ) { final Map < String , Object > rawValue = ( Map < String , Object > ) entry . rawFields ( ) . get ( field . id ( ) ) ; if ( rawValue == null ) { return ; } for ( final String locale : rawValue . keySet ( ) ) { final Object raw = rawValue . get ( locale ) ; if ( raw == null || raw instanceof CDARichNode ) { // ignore null and already parsed values continue ; } final Map < String , Object > map = ( Map < String , Object > ) rawValue . get ( locale ) ; entry . setField ( locale , field . id ( ) , RESOLVER_MAP . get ( "document" ) . resolve ( map ) ) ; } } | Resolve all children of the top most document block . | 175 | 11 |
152,533 | private static void resolveRichLink ( ArrayResource array , CDAEntry entry , CDAField field ) { final Map < String , Object > rawValue = ( Map < String , Object > ) entry . rawFields ( ) . get ( field . id ( ) ) ; if ( rawValue == null ) { return ; } for ( final String locale : rawValue . keySet ( ) ) { final CDARichDocument document = entry . getField ( locale , field . id ( ) ) ; for ( final CDARichNode node : document . getContent ( ) ) { resolveOneLink ( array , field , locale , node ) ; } } } | Resolve all links if possible . If linked to entry is not found null it s field . | 137 | 19 |
152,534 | private static void resolveOneLink ( ArrayResource array , CDAField field , String locale , CDARichNode node ) { if ( node instanceof CDARichHyperLink && ( ( CDARichHyperLink ) node ) . data instanceof Map ) { final CDARichHyperLink link = ( CDARichHyperLink ) node ; final Map < String , Object > data = ( Map < String , Object > ) link . data ; final Object target = data . get ( "target" ) ; if ( target instanceof Map ) { if ( isLink ( target ) ) { final Map < String , Object > map = ( Map < String , Object > ) target ; final Map < String , Object > sys = ( Map < String , Object > ) map . get ( "sys" ) ; final String linkType = ( String ) sys . get ( "linkType" ) ; final String id = ( String ) sys . get ( "id" ) ; if ( "Asset" . equals ( linkType ) ) { link . data = array . assets ( ) . get ( id ) ; } else if ( "Entry" . equals ( linkType ) ) { link . data = array . entries ( ) . get ( id ) ; } } else { throw new IllegalStateException ( "Could not parse content of data field '" + field . id ( ) + "' for locale '" + locale + "' at node '" + node + "'. Please check your content type model." ) ; } } else if ( target == null && data . containsKey ( "uri" ) ) { link . data = data . get ( "uri" ) ; } } else if ( node instanceof CDARichParagraph ) { for ( final CDARichNode child : ( ( CDARichParagraph ) node ) . getContent ( ) ) { resolveOneLink ( array , field , locale , child ) ; } } } | Link found resolve it . | 403 | 5 |
152,535 | private static boolean isLink ( Object data ) { try { final Map < String , Object > map = ( Map < String , Object > ) data ; final Map < String , Object > sys = ( Map < String , Object > ) map . get ( "sys" ) ; final String type = ( String ) sys . get ( "type" ) ; final String linkType = ( String ) sys . get ( "linkType" ) ; final String id = ( String ) sys . get ( "id" ) ; if ( "Link" . equals ( type ) && ( "Entry" . equals ( linkType ) || "Asset" . equals ( linkType ) && id != null ) ) { return true ; } } catch ( ClassCastException cast ) { return false ; } return false ; } | Is the give object a link of any kind? | 166 | 10 |
152,536 | public < T > T getField ( String locale , String key ) { return localize ( locale ) . getField ( key ) ; } | Extracts a field from the fields set of the active locale result type is inferred . | 29 | 18 |
152,537 | public Flowable < Transformed > one ( String id ) { try { return baseQuery ( ) . one ( id ) . filter ( new Predicate < CDAEntry > ( ) { @ Override public boolean test ( CDAEntry entry ) { return entry . contentType ( ) . id ( ) . equals ( contentTypeId ) ; } } ) . map ( new Function < CDAEntry , Transformed > ( ) { @ Override public Transformed apply ( CDAEntry entry ) throws Exception { return TransformQuery . this . transform ( entry ) ; } } ) ; } catch ( NullPointerException e ) { throw new CDAResourceNotFoundException ( CDAEntry . class , id ) ; } } | Retrieve the transformed entry from Contentful . | 152 | 9 |
152,538 | public CDACallback < Transformed > one ( String id , CDACallback < Transformed > callback ) { return Callbacks . subscribeAsync ( baseQuery ( ) . one ( id ) . filter ( new Predicate < CDAEntry > ( ) { @ Override public boolean test ( CDAEntry entry ) { return entry . contentType ( ) . id ( ) . equals ( contentTypeId ) ; } } ) . map ( this :: transform ) , callback , client ) ; } | Retrieve the transformed entry from Contentful by using the given callback . | 104 | 14 |
152,539 | public Flowable < Collection < Transformed > > all ( ) { return baseQuery ( ) . all ( ) . map ( new Function < CDAArray , Collection < Transformed > > ( ) { @ Override public Collection < Transformed > apply ( CDAArray array ) { final ArrayList < Transformed > result = new ArrayList <> ( array . total ( ) ) ; for ( final CDAResource resource : array . items ) { if ( resource instanceof CDAEntry && ( ( CDAEntry ) resource ) . contentType ( ) . id ( ) . equals ( contentTypeId ) ) { result . add ( TransformQuery . this . transform ( ( CDAEntry ) resource ) ) ; } } return result ; } } ) ; } | Retrieve all transformed entries from Contentful . | 160 | 9 |
152,540 | public CDACallback < Collection < Transformed > > all ( CDACallback < Collection < Transformed > > callback ) { return Callbacks . subscribeAsync ( baseQuery ( ) . all ( ) . map ( new Function < CDAArray , List < Transformed > > ( ) { @ Override public List < Transformed > apply ( CDAArray array ) { final ArrayList < Transformed > result = new ArrayList <> ( array . total ( ) ) ; for ( final CDAResource resource : array . items ) { if ( resource instanceof CDAEntry && ( ( CDAEntry ) resource ) . contentType ( ) . id ( ) . equals ( contentTypeId ) ) { result . add ( TransformQuery . this . transform ( ( CDAEntry ) resource ) ) ; } } return result ; } } ) , callback , client ) ; } | Retrieve all transformed entries from Contentful by the use of a callback . | 185 | 15 |
152,541 | @ SuppressWarnings ( "unchecked" ) public < T > T getAttribute ( String key ) { return ( T ) attrs . get ( key ) ; } | Retrieve a specific attribute of this resource . | 37 | 9 |
152,542 | public Flowable < CDAArray > all ( ) { return client . cacheAll ( false ) . flatMap ( new Function < Cache , Publisher < Response < CDAArray > > > ( ) { @ Override public Publisher < Response < CDAArray > > apply ( Cache cache ) { return client . service . array ( client . spaceId , client . environmentId , path ( ) , params ) ; } } ) . map ( new Function < Response < CDAArray > , CDAArray > ( ) { @ Override public CDAArray apply ( Response < CDAArray > response ) { return ResourceFactory . array ( response , client ) ; } } ) ; } | Observe an array of all resources matching the type of this query . | 142 | 14 |
152,543 | public static ImageOption jpegQualityOf ( int quality ) { if ( quality < 1 || quality > 100 ) { throw new IllegalArgumentException ( "Quality has to be in the range from 1 to 100." ) ; } return new ImageOption ( "q" , Integer . toString ( quality ) ) ; } | Define the quality of the jpg image to be returned . | 66 | 13 |
152,544 | public String apply ( String url ) { return format ( getDefault ( ) , "%s%s%s=%s" , url , concatenationOperator ( url ) , operation , argument ) ; } | Apply this image option to a url replacing and updating this url . | 44 | 13 |
152,545 | @ SuppressWarnings ( "unchecked" ) public < C extends CDACallback < CDASpace > > C fetchSpace ( C callback ) { return ( C ) Callbacks . subscribeAsync ( observeSpace ( ) , callback , this ) ; } | Asynchronously fetch the space . | 55 | 7 |
152,546 | public static void ensureContentType ( CDAEntry entry , CDAClient client ) { CDAContentType contentType = entry . contentType ( ) ; if ( contentType != null ) { return ; } String contentTypeId = extractNested ( entry . attrs ( ) , "contentType" , "sys" , "id" ) ; try { contentType = client . cacheTypeWithId ( contentTypeId ) . blockingFirst ( ) ; } catch ( CDAResourceNotFoundException e ) { throw new CDAContentTypeNotFoundException ( entry . id ( ) , CDAEntry . class , contentTypeId , e ) ; } entry . setContentType ( contentType ) ; } | Make sure that the given entry has a filled in content type . | 150 | 13 |
152,547 | @ SuppressWarnings ( "unchecked" ) public < C extends CDACallback < CDAArray > > C all ( C callback ) { return ( C ) Callbacks . subscribeAsync ( baseQuery ( ) . all ( ) , callback , client ) ; } | Async fetch all resources matching the type of this query . | 58 | 11 |
152,548 | public static CamundaBpmProducer createProducer ( final CamundaBpmEndpoint endpoint , final ParsedUri uri , final Map < String , Object > parameters ) throws IllegalArgumentException { switch ( uri . getType ( ) ) { case StartProcess : return new StartProcessProducer ( endpoint , parameters ) ; case SendSignal : case SendMessage : return new MessageProducer ( endpoint , parameters ) ; default : throw new IllegalArgumentException ( "Cannot create a producer for URI '" + uri + "' - new ProducerType '" + uri . getType ( ) + "' not yet supported?" ) ; } } | Prevent instantiation of helper class | 139 | 7 |
152,549 | protected void removeExcessiveInProgressTasks ( Queue < Exchange > exchanges , int limit ) { while ( exchanges . size ( ) > limit ) { // must remove last Exchange exchange = exchanges . poll ( ) ; releaseTask ( exchange ) ; } } | Drain any in progress files as we are done with this batch | 53 | 13 |
152,550 | @ SuppressWarnings ( "rawtypes" ) public static Map < String , Object > prepareVariables ( Exchange exchange , Map < String , Object > parameters ) { Map < String , Object > processVariables = new HashMap < String , Object > ( ) ; Object camelBody = exchange . getIn ( ) . getBody ( ) ; if ( camelBody instanceof String ) { // If the COPY_MESSAGE_BODY_AS_PROCESS_VARIABLE_PARAMETER was passed // the value of it // is taken as variable to store the (string) body in String processVariableName = "camelBody" ; if ( parameters . containsKey ( CamundaBpmConstants . COPY_MESSAGE_BODY_AS_PROCESS_VARIABLE_PARAMETER ) ) { processVariableName = ( String ) parameters . get ( CamundaBpmConstants . COPY_MESSAGE_BODY_AS_PROCESS_VARIABLE_PARAMETER ) ; } processVariables . put ( processVariableName , camelBody ) ; } else if ( camelBody instanceof Map < ? , ? > ) { Map < ? , ? > camelBodyMap = ( Map < ? , ? > ) camelBody ; for ( Map . Entry e : camelBodyMap . entrySet ( ) ) { if ( e . getKey ( ) instanceof String ) { processVariables . put ( ( String ) e . getKey ( ) , e . getValue ( ) ) ; } } } else if ( camelBody != null ) { log . log ( Level . WARNING , "unkown type of camel body - not handed over to process engine: " + camelBody . getClass ( ) ) ; } return processVariables ; } | Copies variables from Camel into the process engine . | 390 | 10 |
152,551 | @ Override public void close ( ) { if ( closed ) { return ; } if ( SHOULD_CHECK && ! txn . isReadOnly ( ) ) { txn . checkReady ( ) ; } LIB . mdb_cursor_close ( ptrCursor ) ; kv . close ( ) ; closed = true ; } | Close a cursor handle . | 70 | 5 |
152,552 | public long count ( ) { if ( SHOULD_CHECK ) { checkNotClosed ( ) ; txn . checkReady ( ) ; } final NativeLongByReference longByReference = new NativeLongByReference ( ) ; checkRc ( LIB . mdb_cursor_count ( ptrCursor , longByReference ) ) ; return longByReference . longValue ( ) ; } | Return count of duplicates for current key . | 81 | 9 |
152,553 | public boolean put ( final T key , final T val , final PutFlags ... op ) { if ( SHOULD_CHECK ) { requireNonNull ( key ) ; requireNonNull ( val ) ; checkNotClosed ( ) ; txn . checkReady ( ) ; txn . checkWritesAllowed ( ) ; } kv . keyIn ( key ) ; kv . valIn ( val ) ; final int mask = mask ( op ) ; final int rc = LIB . mdb_cursor_put ( ptrCursor , kv . pointerKey ( ) , kv . pointerVal ( ) , mask ) ; if ( rc == MDB_KEYEXIST ) { if ( isSet ( mask , MDB_NOOVERWRITE ) ) { kv . valOut ( ) ; // marked as in,out in LMDB C docs } else if ( ! isSet ( mask , MDB_NODUPDATA ) ) { checkRc ( rc ) ; } return false ; } checkRc ( rc ) ; return true ; } | Store by cursor . | 224 | 4 |
152,554 | public void renew ( final Txn < T > newTxn ) { if ( SHOULD_CHECK ) { requireNonNull ( newTxn ) ; checkNotClosed ( ) ; this . txn . checkReadOnly ( ) ; // existing newTxn . checkReadOnly ( ) ; newTxn . checkReady ( ) ; } checkRc ( LIB . mdb_cursor_renew ( newTxn . pointer ( ) , ptrCursor ) ) ; this . txn = newTxn ; } | Renew a cursor handle . | 111 | 6 |
152,555 | public long runFor ( final long duration , final TimeUnit unit ) { final long deadline = System . currentTimeMillis ( ) + unit . toMillis ( duration ) ; final ExecutorService es = Executors . newSingleThreadExecutor ( ) ; final Future < Long > future = es . submit ( this ) ; try { while ( System . currentTimeMillis ( ) < deadline && ! future . isDone ( ) ) { Thread . sleep ( unit . toMillis ( 1 ) ) ; } } catch ( final InterruptedException ignored ) { } finally { stop ( ) ; } final long result ; try { result = future . get ( ) ; } catch ( final InterruptedException | ExecutionException ex ) { throw new IllegalStateException ( ex ) ; } finally { es . shutdown ( ) ; } return result ; } | Execute the verifier for the given duration . | 176 | 10 |
152,556 | public static Version version ( ) { final IntByReference major = new IntByReference ( ) ; final IntByReference minor = new IntByReference ( ) ; final IntByReference patch = new IntByReference ( ) ; LIB . mdb_version ( major , minor , patch ) ; return new Version ( major . intValue ( ) , minor . intValue ( ) , patch . intValue ( ) ) ; } | Obtains the LMDB C library version information . | 87 | 10 |
152,557 | public void copy ( final File path , final CopyFlags ... flags ) { requireNonNull ( path ) ; if ( ! path . exists ( ) ) { throw new InvalidCopyDestination ( "Path must exist" ) ; } if ( ! path . isDirectory ( ) ) { throw new InvalidCopyDestination ( "Path must be a directory" ) ; } final String [ ] files = path . list ( ) ; if ( files != null && files . length > 0 ) { throw new InvalidCopyDestination ( "Path must contain no files" ) ; } final int flagsMask = mask ( flags ) ; checkRc ( LIB . mdb_env_copy2 ( ptr , path . getAbsolutePath ( ) , flagsMask ) ) ; } | Copies an LMDB environment to the specified destination path . | 158 | 12 |
152,558 | public List < byte [ ] > getDbiNames ( ) { final List < byte [ ] > result = new ArrayList <> ( ) ; final Dbi < T > names = openDbi ( ( byte [ ] ) null ) ; try ( Txn < T > txn = txnRead ( ) ; Cursor < T > cursor = names . openCursor ( txn ) ) { if ( ! cursor . first ( ) ) { return Collections . emptyList ( ) ; } do { final byte [ ] name = proxy . getBytes ( cursor . key ( ) ) ; result . add ( name ) ; } while ( cursor . next ( ) ) ; } return result ; } | Obtain the DBI names . | 147 | 7 |
152,559 | public EnvInfo info ( ) { if ( closed ) { throw new AlreadyClosedException ( ) ; } final MDB_envinfo info = new MDB_envinfo ( RUNTIME ) ; checkRc ( LIB . mdb_env_info ( ptr , info ) ) ; final long mapAddress ; if ( info . f0_me_mapaddr . get ( ) == null ) { mapAddress = 0 ; } else { mapAddress = info . f0_me_mapaddr . get ( ) . address ( ) ; } return new EnvInfo ( mapAddress , info . f1_me_mapsize . longValue ( ) , info . f2_me_last_pgno . longValue ( ) , info . f3_me_last_txnid . longValue ( ) , info . f4_me_maxreaders . intValue ( ) , info . f5_me_numreaders . intValue ( ) ) ; } | Return information about this environment . | 210 | 6 |
152,560 | public Stat stat ( ) { if ( closed ) { throw new AlreadyClosedException ( ) ; } final MDB_stat stat = new MDB_stat ( RUNTIME ) ; checkRc ( LIB . mdb_env_stat ( ptr , stat ) ) ; return new Stat ( stat . f0_ms_psize . intValue ( ) , stat . f1_ms_depth . intValue ( ) , stat . f2_ms_branch_pages . longValue ( ) , stat . f3_ms_leaf_pages . longValue ( ) , stat . f4_ms_overflow_pages . longValue ( ) , stat . f5_ms_entries . longValue ( ) ) ; } | Return statistics about this environment . | 157 | 6 |
152,561 | public void sync ( final boolean force ) { if ( closed ) { throw new AlreadyClosedException ( ) ; } final int f = force ? 1 : 0 ; checkRc ( LIB . mdb_env_sync ( ptr , f ) ) ; } | Flushes the data buffers to disk . | 54 | 8 |
152,562 | public Txn < T > txn ( final Txn < T > parent , final TxnFlags ... flags ) { if ( closed ) { throw new AlreadyClosedException ( ) ; } return new Txn <> ( this , parent , proxy , flags ) ; } | Obtain a transaction with the requested parent and flags . | 61 | 11 |
152,563 | @ SuppressWarnings ( "checkstyle:ReturnCount" ) public static int compareBuff ( final DirectBuffer o1 , final DirectBuffer o2 ) { requireNonNull ( o1 ) ; requireNonNull ( o2 ) ; if ( o1 . equals ( o2 ) ) { return 0 ; } final int minLength = Math . min ( o1 . capacity ( ) , o2 . capacity ( ) ) ; final int minWords = minLength / Long . BYTES ; for ( int i = 0 ; i < minWords * Long . BYTES ; i += Long . BYTES ) { final long lw = o1 . getLong ( i , BIG_ENDIAN ) ; final long rw = o2 . getLong ( i , BIG_ENDIAN ) ; final int diff = Long . compareUnsigned ( lw , rw ) ; if ( diff != 0 ) { return diff ; } } for ( int i = minWords * Long . BYTES ; i < minLength ; i ++ ) { final int lw = Byte . toUnsignedInt ( o1 . getByte ( i ) ) ; final int rw = Byte . toUnsignedInt ( o2 . getByte ( i ) ) ; final int result = Integer . compareUnsigned ( lw , rw ) ; if ( result != 0 ) { return result ; } } return o1 . capacity ( ) - o2 . capacity ( ) ; } | Lexicographically compare two buffers . | 310 | 7 |
152,564 | public boolean delete ( final T key ) { try ( Txn < T > txn = env . txnWrite ( ) ) { final boolean ret = delete ( txn , key ) ; txn . commit ( ) ; return ret ; } } | Starts a new read - write transaction and deletes the key . | 53 | 14 |
152,565 | public boolean delete ( final Txn < T > txn , final T key ) { return delete ( txn , key , null ) ; } | Deletes the key using the passed transaction . | 31 | 9 |
152,566 | public Cursor < T > openCursor ( final Txn < T > txn ) { if ( SHOULD_CHECK ) { requireNonNull ( txn ) ; txn . checkReady ( ) ; } final PointerByReference cursorPtr = new PointerByReference ( ) ; checkRc ( LIB . mdb_cursor_open ( txn . pointer ( ) , ptr , cursorPtr ) ) ; return new Cursor <> ( cursorPtr . getValue ( ) , txn ) ; } | Create a cursor handle . | 109 | 5 |
152,567 | public Stat stat ( final Txn < T > txn ) { if ( SHOULD_CHECK ) { requireNonNull ( txn ) ; txn . checkReady ( ) ; } final MDB_stat stat = new MDB_stat ( RUNTIME ) ; checkRc ( LIB . mdb_stat ( txn . pointer ( ) , ptr , stat ) ) ; return new Stat ( stat . f0_ms_psize . intValue ( ) , stat . f1_ms_depth . intValue ( ) , stat . f2_ms_branch_pages . longValue ( ) , stat . f3_ms_leaf_pages . longValue ( ) , stat . f4_ms_overflow_pages . longValue ( ) , stat . f5_ms_entries . longValue ( ) ) ; } | Return statistics about this database . | 180 | 6 |
152,568 | @ Override public void close ( ) { if ( state == RELEASED ) { return ; } if ( state == READY ) { LIB . mdb_txn_abort ( ptr ) ; } keyVal . close ( ) ; state = RELEASED ; } | Closes this transaction by aborting if not already committed . | 56 | 12 |
152,569 | protected String getNextLine ( int newlineCount ) throws IOException { if ( newlineCount == 0 ) { return "" ; } StringBuffer str = new StringBuffer ( ) ; int b ; while ( pis . available ( ) > 0 ) { b = pis . read ( ) ; if ( b == - 1 ) { return "" ; } if ( b == ' ' ) { newlineCount -- ; if ( newlineCount == 0 ) { log . debug ( "Read lines: " + str . toString ( ) ) ; String [ ] lines = str . toString ( ) . split ( "\n" ) ; // FIXME: this leads to queuing lines so we will have time lag! return lines [ lines . length - 1 ] ; } } str . append ( ( char ) b ) ; } return "" ; } | Method retrieves next line from received bytes sequence | 177 | 9 |
152,570 | public static Transport getTransport ( SocketAddress addr ) throws IOException { Transport trans ; try { log . debug ( "Connecting TCP" ) ; trans = TCPInstance ( addr ) ; if ( ! trans . test ( ) ) { throw new IOException ( "Agent is unreachable via TCP" ) ; } return trans ; } catch ( IOException e ) { log . info ( "Can't connect TCP transport for host: " + addr . toString ( ) , e ) ; try { log . debug ( "Connecting UDP" ) ; trans = UDPInstance ( addr ) ; if ( ! trans . test ( ) ) { throw new IOException ( "Agent is unreachable via UDP" ) ; } return trans ; } catch ( IOException ex ) { log . info ( "Can't connect UDP transport for host: " + addr . toString ( ) , ex ) ; throw ex ; } } } | Primary transport getting method . Tries to connect and test UDP Transport . If UDP failed tries TCP transport . If it fails too throws IOException | 190 | 28 |
152,571 | public static Transport TCPInstance ( SocketAddress addr ) throws IOException { Socket sock = new Socket ( ) ; sock . setSoTimeout ( getTimeout ( ) ) ; sock . connect ( addr ) ; StreamTransport trans = new StreamTransport ( ) ; trans . setStreams ( sock . getInputStream ( ) , sock . getOutputStream ( ) ) ; trans . setAddressLabel ( addr . toString ( ) ) ; return trans ; } | Returns TCP transport instance connected to specified address | 94 | 8 |
152,572 | public static Transport UDPInstance ( SocketAddress addr ) throws IOException { DatagramSocket sock = new DatagramSocket ( ) ; sock . setSoTimeout ( getTimeout ( ) ) ; sock . connect ( addr ) ; StreamTransport trans = new StreamTransport ( ) ; trans . setStreams ( new UDPInputStream ( sock ) , new UDPOutputStream ( sock ) ) ; trans . setAddressLabel ( addr . toString ( ) ) ; return trans ; } | Returns new UDP Transport instance connected to specified socket address | 98 | 10 |
152,573 | public ProgressBar maxHint ( long n ) { if ( n < 0 ) progress . setAsIndefinite ( ) ; else { progress . setAsDefinite ( ) ; progress . maxHint ( n ) ; } return this ; } | Gives a hint to the maximum value of the progress bar . | 52 | 13 |
152,574 | public static < R , S > Tuple2 < R , S > create ( R r , S s ) { return new Tuple2 < R , S > ( r , s ) ; } | Returns a new instance . | 41 | 5 |
152,575 | public static BigDecimal factorial ( int n ) { if ( n < 0 ) { throw new ArithmeticException ( "Illegal factorial(n) for n < 0: n = " + n ) ; } if ( n < factorialCache . length ) { return factorialCache [ n ] ; } BigDecimal result = factorialCache [ factorialCache . length - 1 ] ; return result . multiply ( factorialRecursion ( factorialCache . length , n ) ) ; } | Calculates the factorial of the specified integer argument . | 105 | 12 |
152,576 | public static BigDecimal pi ( MathContext mathContext ) { checkMathContext ( mathContext ) ; BigDecimal result = null ; synchronized ( piCacheLock ) { if ( piCache != null && mathContext . getPrecision ( ) <= piCache . precision ( ) ) { result = piCache ; } else { piCache = piChudnovski ( mathContext ) ; return piCache ; } } return round ( result , mathContext ) ; } | Returns the number pi . | 96 | 5 |
152,577 | public static BigDecimal e ( MathContext mathContext ) { checkMathContext ( mathContext ) ; BigDecimal result = null ; synchronized ( eCacheLock ) { if ( eCache != null && mathContext . getPrecision ( ) <= eCache . precision ( ) ) { result = eCache ; } else { eCache = exp ( ONE , mathContext ) ; return eCache ; } } return round ( result , mathContext ) ; } | Returns the number e . | 94 | 5 |
152,578 | private BigRational multiply ( BigDecimal value ) { BigDecimal n = numerator . multiply ( value ) ; BigDecimal d = denominator ; return of ( n , d ) ; } | private because we want to hide that we use BigDecimal internally | 42 | 13 |
152,579 | public static BigRational valueOf ( int integer , int fractionNumerator , int fractionDenominator ) { if ( fractionNumerator < 0 || fractionDenominator < 0 ) { throw new ArithmeticException ( "Negative value" ) ; } BigRational integerPart = valueOf ( integer ) ; BigRational fractionPart = valueOf ( fractionNumerator , fractionDenominator ) ; return integerPart . isPositive ( ) ? integerPart . add ( fractionPart ) : integerPart . subtract ( fractionPart ) ; } | Creates a rational number of the specified integer and fraction parts . | 116 | 13 |
152,580 | public static BigRational valueOf ( double value ) { if ( value == 0.0 ) { return ZERO ; } if ( value == 1.0 ) { return ONE ; } if ( Double . isInfinite ( value ) ) { throw new NumberFormatException ( "Infinite" ) ; } if ( Double . isNaN ( value ) ) { throw new NumberFormatException ( "NaN" ) ; } return valueOf ( new BigDecimal ( String . valueOf ( value ) ) ) ; } | Creates a rational number of the specified double value . | 109 | 11 |
152,581 | public static BigRational valueOf ( String string ) { String [ ] strings = string . split ( "/" ) ; BigRational result = valueOfSimple ( strings [ 0 ] ) ; for ( int i = 1 ; i < strings . length ; i ++ ) { result = result . divide ( valueOfSimple ( strings [ i ] ) ) ; } return result ; } | Creates a rational number of the specified string representation . | 79 | 11 |
152,582 | public static BigRational min ( BigRational ... values ) { if ( values . length == 0 ) { return BigRational . ZERO ; } BigRational result = values [ 0 ] ; for ( int i = 1 ; i < values . length ; i ++ ) { result = result . min ( values [ i ] ) ; } return result ; } | Returns the smallest of the specified rational numbers . | 76 | 9 |
152,583 | public static BigRational max ( BigRational ... values ) { if ( values . length == 0 ) { return BigRational . ZERO ; } BigRational result = values [ 0 ] ; for ( int i = 1 ; i < values . length ; i ++ ) { result = result . max ( values [ i ] ) ; } return result ; } | Returns the largest of the specified rational numbers . | 76 | 9 |
152,584 | public BigComplex add ( BigComplex value ) { return valueOf ( re . add ( value . re ) , im . add ( value . im ) ) ; } | Calculates the addition of the given complex value to this complex number . | 36 | 15 |
152,585 | public BigComplex subtract ( BigComplex value ) { return valueOf ( re . subtract ( value . re ) , im . subtract ( value . im ) ) ; } | Calculates the subtraction of the given complex value from this complex number . | 36 | 16 |
152,586 | public BigComplex multiply ( BigComplex value ) { return valueOf ( re . multiply ( value . re ) . subtract ( im . multiply ( value . im ) ) , re . multiply ( value . im ) . add ( im . multiply ( value . re ) ) ) ; } | Calculates the multiplication of the given complex value to this complex number . | 60 | 15 |
152,587 | public BigDecimal absSquare ( MathContext mathContext ) { return re . multiply ( re , mathContext ) . add ( im . multiply ( im , mathContext ) , mathContext ) ; } | Calculates the square of the absolute value of this complex number . | 41 | 14 |
152,588 | public BigComplex round ( MathContext mathContext ) { return valueOf ( re . round ( mathContext ) , im . round ( mathContext ) ) ; } | Returns this complex nuber rounded to the specified precision . | 34 | 11 |
152,589 | public boolean strictEquals ( Object obj ) { if ( this == obj ) return true ; if ( obj == null ) return false ; if ( getClass ( ) != obj . getClass ( ) ) return false ; BigComplex other = ( BigComplex ) obj ; return re . equals ( other . re ) && im . equals ( other . im ) ; } | Returns whether the real and imaginary parts of this complex number are strictly equal . | 77 | 15 |
152,590 | protected BigRational getFactor ( int index ) { while ( factors . size ( ) <= index ) { BigRational factor = getCurrentFactor ( ) ; factors . add ( factor ) ; calculateNextFactor ( ) ; } return factors . get ( index ) ; } | Returns the factor of the term with specified index . | 56 | 10 |
152,591 | protected static DBFField createField ( DataInput in , Charset charset , boolean useFieldFlags ) throws IOException { DBFField field = new DBFField ( ) ; byte t_byte = in . readByte ( ) ; /* 0 */ if ( t_byte == ( byte ) 0x0d ) { return null ; } byte [ ] fieldName = new byte [ 11 ] ; in . readFully ( fieldName , 1 , 10 ) ; /* 1-10 */ fieldName [ 0 ] = t_byte ; int nameNullIndex = fieldName . length - 1 ; for ( int i = 0 ; i < fieldName . length ; i ++ ) { if ( fieldName [ i ] == ( byte ) 0 ) { nameNullIndex = i ; break ; } } field . name = new String ( fieldName , 0 , nameNullIndex , charset ) ; try { field . type = DBFDataType . fromCode ( in . readByte ( ) ) ; /* 11 */ } catch ( Exception e ) { field . type = DBFDataType . UNKNOWN ; } field . reserv1 = DBFUtils . readLittleEndianInt ( in ) ; /* 12-15 */ field . length = in . readUnsignedByte ( ) ; /* 16 */ field . decimalCount = in . readByte ( ) ; /* 17 */ field . reserv2 = DBFUtils . readLittleEndianShort ( in ) ; /* 18-19 */ field . workAreaId = in . readByte ( ) ; /* 20 */ field . reserv3 = DBFUtils . readLittleEndianShort ( in ) ; /* 21-22 */ field . setFieldsFlag = in . readByte ( ) ; /* 23 */ in . readFully ( field . reserv4 ) ; /* 24-30 */ field . indexFieldFlag = in . readByte ( ) ; /* 31 */ adjustLengthForLongCharSupport ( field ) ; if ( ! useFieldFlags ) { field . reserv2 = 0 ; } return field ; } | Creates a DBFField object from the data read from the given DataInputStream . | 432 | 18 |
152,592 | protected void write ( DataOutput out , Charset charset ) throws IOException { // Field Name out . write ( this . name . getBytes ( charset ) ) ; /* 0-10 */ out . write ( new byte [ 11 - this . name . length ( ) ] ) ; // data type out . writeByte ( this . type . getCode ( ) ) ; /* 11 */ out . writeInt ( 0x00 ) ; /* 12-15 */ out . writeByte ( this . length ) ; /* 16 */ out . writeByte ( this . decimalCount ) ; /* 17 */ out . writeShort ( ( short ) 0x00 ) ; /* 18-19 */ out . writeByte ( ( byte ) 0x00 ) ; /* 20 */ out . writeShort ( ( short ) 0x00 ) ; /* 21-22 */ out . writeByte ( ( byte ) 0x00 ) ; /* 23 */ out . write ( new byte [ 7 ] ) ; /* 24-30 */ out . writeByte ( ( byte ) 0x00 ) ; /* 31 */ } | Writes the content of DBFField object into the stream as per DBF format specifications . | 225 | 19 |
152,593 | public void setName ( String name ) { if ( name == null ) { throw new IllegalArgumentException ( "Field name cannot be null" ) ; } if ( name . length ( ) == 0 || name . length ( ) > 10 ) { throw new IllegalArgumentException ( "Field name should be of length 0-10" ) ; } if ( ! DBFUtils . isPureAscii ( name ) ) { throw new IllegalArgumentException ( "Field name must be ASCII" ) ; } this . name = name ; } | Sets the name of the field . | 115 | 8 |
152,594 | public void setType ( DBFDataType type ) { if ( ! type . isWriteSupported ( ) ) { throw new IllegalArgumentException ( "No support for writting " + type ) ; } this . type = type ; if ( type . getDefaultSize ( ) > 0 ) { this . length = type . getDefaultSize ( ) ; } } | Set the type for this field | 76 | 6 |
152,595 | public static Charset getCharsetByByte ( int b ) { switch ( b ) { case 0x01 : // U.S. MS-DOS return forName ( "IBM437" ) ; case 0x02 : // International MS-DOS return forName ( "IBM850" ) ; case 0x03 : // Windows ANSI return forName ( "windows-1252" ) ; case 0x04 : // Standard Macintosh return forName ( "MacRoman" ) ; case 0x57 : // ESRI shape files use code 0x57 to indicate that // data is written in ANSI (whatever that means). // http://www.esricanada.com/english/support/faqs/arcview/avfaq21.asp return forName ( "windows-1252" ) ; case 0x59 : return forName ( "windows-1252" ) ; case 0x64 : // Eastern European MS-DOS return forName ( "IBM852" ) ; case 0x65 : // Russian MS-DOS return forName ( "IBM866" ) ; case 0x66 : // Nordic MS-DOS return forName ( "IBM865" ) ; case 0x67 : // Icelandic MS-DOS return forName ( "IBM861" ) ; // case 0x68: // Kamenicky (Czech) MS-DOS // return Charset.forName("895"); // case 0x69: // Mazovia (Polish) MS-DOS // return Charset.forName("620"); case 0x6A : // Greek MS-DOS (437G) return forName ( "x-IBM737" ) ; case 0x6B : // Turkish MS-DOS return forName ( "IBM857" ) ; case 0x78 : // Chinese (Hong Kong SAR, Taiwan) Windows return forName ( "windows-950" ) ; case 0x79 : // Korean Windows return Charset . forName ( "windows-949" ) ; case 0x7A : // Chinese (PRC, Singapore) Windows return forName ( "GBK" ) ; case 0x7B : // Japanese Windows return forName ( "windows-932" ) ; case 0x7C : // Thai Windows return forName ( "windows-874" ) ; case 0x7D : // Hebrew Windows return forName ( "windows-1255" ) ; case 0x7E : // Arabic Windows return forName ( "windows-1256" ) ; case 0x96 : // Russian Macintosh return forName ( "x-MacCyrillic" ) ; case 0x97 : // Macintosh EE return forName ( "x-MacCentralEurope" ) ; case 0x98 : // Greek Macintosh return forName ( "x-MacGreek" ) ; case 0xC8 : // Eastern European Windows return forName ( "windows-1250" ) ; case 0xC9 : // Russian Windows return forName ( "windows-1251" ) ; case 0xCA : // Turkish Windows return forName ( "windows-1254" ) ; case 0xCB : // Greek Windows return forName ( "windows-1253" ) ; } return null ; } | Gets Java charset from DBF code | 698 | 9 |
152,596 | public static int getDBFCodeForCharset ( Charset charset ) { if ( charset == null ) { return 0 ; } String charsetName = charset . toString ( ) ; if ( "ibm437" . equalsIgnoreCase ( charsetName ) ) { return 0x01 ; } if ( "ibm850" . equalsIgnoreCase ( charsetName ) ) { return 0x02 ; } if ( "windows-1252" . equalsIgnoreCase ( charsetName ) ) { return 0x03 ; } if ( "iso-8859-1" . equalsIgnoreCase ( charsetName ) ) { return 0x03 ; } if ( "MacRoman" . equalsIgnoreCase ( charsetName ) ) { return 0x04 ; } if ( "IBM852" . equalsIgnoreCase ( charsetName ) ) { return 0x64 ; } if ( "IBM865" . equalsIgnoreCase ( charsetName ) ) { return 0x66 ; } if ( "IBM866" . equalsIgnoreCase ( charsetName ) ) { return 0x65 ; } if ( "IBM861" . equalsIgnoreCase ( charsetName ) ) { return 0x67 ; } // 0x68 // 0x69 if ( "IBM737" . equalsIgnoreCase ( charsetName ) ) { return 0x6a ; } if ( "IBM857" . equalsIgnoreCase ( charsetName ) ) { return 0x6b ; } if ( "windows-950" . equalsIgnoreCase ( charsetName ) ) { return 0x78 ; } if ( "windows-949" . equalsIgnoreCase ( charsetName ) ) { return 0x79 ; } if ( "gbk" . equalsIgnoreCase ( charsetName ) ) { return 0x7a ; } if ( "windows-932" . equalsIgnoreCase ( charsetName ) ) { return 0x7b ; } if ( "windows-874" . equalsIgnoreCase ( charsetName ) ) { return 0x7c ; } if ( "windows-1255" . equalsIgnoreCase ( charsetName ) ) { return 0x7d ; } if ( "windows-1256" . equalsIgnoreCase ( charsetName ) ) { return 0x7e ; } if ( "x-MacCyrillic" . equalsIgnoreCase ( charsetName ) ) { return 0x96 ; } if ( "x-MacCentralEurope" . equalsIgnoreCase ( charsetName ) ) { return 0x97 ; } if ( "x-MacGreek" . equalsIgnoreCase ( charsetName ) ) { return 0x98 ; } if ( "windows-1250" . equalsIgnoreCase ( charsetName ) ) { return 0xc8 ; } if ( "windows-1251" . equalsIgnoreCase ( charsetName ) ) { return 0xc9 ; } if ( "windows-1254" . equalsIgnoreCase ( charsetName ) ) { return 0xca ; } if ( "windows-1253" . equalsIgnoreCase ( charsetName ) ) { return 0xcb ; } // Unsupported charsets returns 0 return 0 ; } | gets the DBF code for a given Java charset | 717 | 11 |
152,597 | public Date getLastModificationDate ( ) { if ( this . year == 0 || this . month == 0 || this . day == 0 ) { return null ; } try { Calendar calendar = Calendar . getInstance ( ) ; calendar . set ( this . year , this . month , this . day , 0 , 0 , 0 ) ; calendar . set ( Calendar . MILLISECOND , 0 ) ; return calendar . getTime ( ) ; } catch ( Exception e ) { return null ; } } | Gets the date the file was modified | 104 | 8 |
152,598 | public static Number readNumericStoredAsText ( DataInputStream dataInput , int length ) throws IOException { try { byte t_float [ ] = new byte [ length ] ; int readed = dataInput . read ( t_float ) ; if ( readed != length ) { throw new EOFException ( "failed to read:" + length + " bytes" ) ; } t_float = DBFUtils . removeSpaces ( t_float ) ; t_float = DBFUtils . removeNullBytes ( t_float ) ; if ( t_float . length > 0 && DBFUtils . isPureAscii ( t_float ) && ! DBFUtils . contains ( t_float , ( byte ) ' ' ) && ! DBFUtils . contains ( t_float , ( byte ) ' ' ) ) { String aux = new String ( t_float , StandardCharsets . US_ASCII ) . replace ( ' ' , ' ' ) ; if ( "." . equals ( aux ) ) { return BigDecimal . ZERO ; } return new BigDecimal ( aux ) ; } else { return null ; } } catch ( NumberFormatException e ) { throw new DBFException ( "Failed to parse Float: " + e . getMessage ( ) , e ) ; } } | Reads a number from a stream | 284 | 7 |
152,599 | public static int littleEndian ( int value ) { int num1 = value ; int mask = 0xff ; int num2 = 0x00 ; num2 |= num1 & mask ; for ( int i = 1 ; i < 4 ; i ++ ) { num2 <<= 8 ; mask <<= 8 ; num2 |= ( num1 & mask ) >> ( 8 * i ) ; } return num2 ; } | Convert an int value to littleEndian | 89 | 9 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.