idx
int64
0
41.2k
question
stringlengths
83
4.15k
target
stringlengths
5
715
29,100
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
29,101
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 .
29,102
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 .
29,103
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 .
29,104
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 .
29,105
private void processHooks ( Set < ExecutableElement > hookMethodsFromInterfaces ) { ElementFilter . methodsIn ( component . getEnclosedElements ( ) ) . stream ( ) . filter ( method -> isHookMethod ( component , method , hookMethodsFromInterfaces ) ) . 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 .
29,106
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
29,107
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" ) ; optionsBuilder . addStatement ( "options.addHookMethod($S, p.$L)" , "render" , "vg$render" ) ; }
Process the render function from the Component Class if it has one .
29,108
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 ) ; 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 ( ) ) ; 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 .
29,109
private void initFieldsValues ( TypeElement component , MethodSpec . Builder createdMethodBuilder ) { 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
29,110
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 .
29,111
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
29,112
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
29,113
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 .
29,114
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 .
29,115
private void processInjectedMethods ( TypeElement component ) { getInjectedMethods ( component ) . stream ( ) . peek ( this :: validateMethod ) . forEach ( this :: processInjectedMethod ) ; }
Process all the injected methods from our Component .
29,116
private void addInjectedVariable ( VariableElement element , String fieldName ) { TypeName typeName = resolveVariableTypeName ( element , messager ) ; FieldSpec . Builder fieldBuilder = FieldSpec . builder ( typeName , fieldName , Modifier . PUBLIC ) ; element . getAnnotationMirrors ( ) . stream ( ) . map ( AnnotationSpec :: get ) . forEach ( fieldBuilder :: addAnnotation ) ; if ( ! hasInjectAnnotation ( element ) ) { fieldBuilder . addAnnotation ( Inject . class ) ; } builder . addField ( fieldBuilder . build ( ) ) ; }
Add an injected variable to our component
29,117
public LocalVariableInfo addLocalVariable ( String typeQualifiedName , String name ) { return contextLayers . getFirst ( ) . addLocalVariable ( typeQualifiedName , name ) ; }
Add a local variable in the current context .
29,118
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 .
29,119
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 .
29,120
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 .
29,121
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 .
29,122
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 .
29,123
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 .
29,124
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 .
29,125
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
29,126
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." ) ; } VueGWTObserverManager . get ( ) . registerVueGWTObserver ( new CollectionObserver ( ) ) ; VueGWTObserverManager . get ( ) . registerVueGWTObserver ( new MapObserver ( ) ) ; isReady = true ; for ( Runnable onReadyCbk : onReadyCallbacks ) { onReadyCbk . run ( ) ; } onReadyCallbacks . clear ( ) ; }
Inject scripts necessary for Vue GWT to work Requires Vue to be defined in Window .
29,127
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 .
29,128
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 .
29,129
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 ) { 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 .
29,130
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 .
29,131
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 .
29,132
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?
29,133
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,134
public Flowable < Transformed > one ( String id ) { try { return baseQuery ( ) . one ( id ) . filter ( new Predicate < CDAEntry > ( ) { public boolean test ( CDAEntry entry ) { return entry . contentType ( ) . id ( ) . equals ( contentTypeId ) ; } } ) . map ( new Function < CDAEntry , Transformed > ( ) { 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 .
29,135
public CDACallback < Transformed > one ( String id , CDACallback < Transformed > callback ) { return Callbacks . subscribeAsync ( baseQuery ( ) . one ( id ) . filter ( new Predicate < CDAEntry > ( ) { 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 .
29,136
public Flowable < Collection < Transformed > > all ( ) { return baseQuery ( ) . all ( ) . map ( new Function < CDAArray , Collection < Transformed > > ( ) { 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 .
29,137
public CDACallback < Collection < Transformed > > all ( CDACallback < Collection < Transformed > > callback ) { return Callbacks . subscribeAsync ( baseQuery ( ) . all ( ) . map ( new Function < CDAArray , List < Transformed > > ( ) { 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 .
29,138
@ SuppressWarnings ( "unchecked" ) public < T > T getAttribute ( String key ) { return ( T ) attrs . get ( key ) ; }
Retrieve a specific attribute of this resource .
29,139
public Flowable < CDAArray > all ( ) { return client . cacheAll ( false ) . flatMap ( new Function < Cache , Publisher < Response < CDAArray > > > ( ) { public Publisher < Response < CDAArray > > apply ( Cache cache ) { return client . service . array ( client . spaceId , client . environmentId , path ( ) , params ) ; } } ) . map ( new Function < Response < CDAArray > , CDAArray > ( ) { public CDAArray apply ( Response < CDAArray > response ) { return ResourceFactory . array ( response , client ) ; } } ) ; }
Observe an array of all resources matching the type of this query .
29,140
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 .
29,141
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 .
29,142
@ SuppressWarnings ( "unchecked" ) public < C extends CDACallback < CDASpace > > C fetchSpace ( C callback ) { return ( C ) Callbacks . subscribeAsync ( observeSpace ( ) , callback , this ) ; }
Asynchronously fetch the space .
29,143
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 .
29,144
@ 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 .
29,145
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
29,146
protected void removeExcessiveInProgressTasks ( Queue < Exchange > exchanges , int limit ) { while ( exchanges . size ( ) > limit ) { Exchange exchange = exchanges . poll ( ) ; releaseTask ( exchange ) ; } }
Drain any in progress files as we are done with this batch
29,147
@ 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 ) { 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 .
29,148
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 .
29,149
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 .
29,150
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 ( ) ; } else if ( ! isSet ( mask , MDB_NODUPDATA ) ) { checkRc ( rc ) ; } return false ; } checkRc ( rc ) ; return true ; }
Store by cursor .
29,151
public void renew ( final Txn < T > newTxn ) { if ( SHOULD_CHECK ) { requireNonNull ( newTxn ) ; checkNotClosed ( ) ; this . txn . checkReadOnly ( ) ; newTxn . checkReadOnly ( ) ; newTxn . checkReady ( ) ; } checkRc ( LIB . mdb_cursor_renew ( newTxn . pointer ( ) , ptrCursor ) ) ; this . txn = newTxn ; }
Renew a cursor handle .
29,152
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 .
29,153
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 .
29,154
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 .
29,155
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 .
29,156
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 .
29,157
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 .
29,158
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 .
29,159
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 .
29,160
@ 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 .
29,161
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 .
29,162
public boolean delete ( final Txn < T > txn , final T key ) { return delete ( txn , key , null ) ; }
Deletes the key using the passed transaction .
29,163
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 .
29,164
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 .
29,165
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 .
29,166
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 == '\n' ) { newlineCount -- ; if ( newlineCount == 0 ) { log . debug ( "Read lines: " + str . toString ( ) ) ; String [ ] lines = str . toString ( ) . split ( "\n" ) ; return lines [ lines . length - 1 ] ; } } str . append ( ( char ) b ) ; } return "" ; }
Method retrieves next line from received bytes sequence
29,167
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
29,168
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
29,169
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
29,170
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 .
29,171
public static < R , S > Tuple2 < R , S > create ( R r , S s ) { return new Tuple2 < R , S > ( r , s ) ; }
Returns a new instance .
29,172
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 .
29,173
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 .
29,174
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 .
29,175
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
29,176
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 .
29,177
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 .
29,178
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 .
29,179
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 .
29,180
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 .
29,181
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 .
29,182
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 .
29,183
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 .
29,184
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 .
29,185
public BigComplex round ( MathContext mathContext ) { return valueOf ( re . round ( mathContext ) , im . round ( mathContext ) ) ; }
Returns this complex nuber rounded to the specified precision .
29,186
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 .
29,187
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 .
29,188
protected static DBFField createField ( DataInput in , Charset charset , boolean useFieldFlags ) throws IOException { DBFField field = new DBFField ( ) ; byte t_byte = in . readByte ( ) ; if ( t_byte == ( byte ) 0x0d ) { return null ; } byte [ ] fieldName = new byte [ 11 ] ; in . readFully ( fieldName , 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 ( ) ) ; } catch ( Exception e ) { field . type = DBFDataType . UNKNOWN ; } field . reserv1 = DBFUtils . readLittleEndianInt ( in ) ; field . length = in . readUnsignedByte ( ) ; field . decimalCount = in . readByte ( ) ; field . reserv2 = DBFUtils . readLittleEndianShort ( in ) ; field . workAreaId = in . readByte ( ) ; field . reserv3 = DBFUtils . readLittleEndianShort ( in ) ; field . setFieldsFlag = in . readByte ( ) ; in . readFully ( field . reserv4 ) ; field . indexFieldFlag = in . readByte ( ) ; adjustLengthForLongCharSupport ( field ) ; if ( ! useFieldFlags ) { field . reserv2 = 0 ; } return field ; }
Creates a DBFField object from the data read from the given DataInputStream .
29,189
protected void write ( DataOutput out , Charset charset ) throws IOException { out . write ( this . name . getBytes ( charset ) ) ; out . write ( new byte [ 11 - this . name . length ( ) ] ) ; out . writeByte ( this . type . getCode ( ) ) ; out . writeInt ( 0x00 ) ; out . writeByte ( this . length ) ; out . writeByte ( this . decimalCount ) ; out . writeShort ( ( short ) 0x00 ) ; out . writeByte ( ( byte ) 0x00 ) ; out . writeShort ( ( short ) 0x00 ) ; out . writeByte ( ( byte ) 0x00 ) ; out . write ( new byte [ 7 ] ) ; out . writeByte ( ( byte ) 0x00 ) ; }
Writes the content of DBFField object into the stream as per DBF format specifications .
29,190
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 .
29,191
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
29,192
public static Charset getCharsetByByte ( int b ) { switch ( b ) { case 0x01 : return forName ( "IBM437" ) ; case 0x02 : return forName ( "IBM850" ) ; case 0x03 : return forName ( "windows-1252" ) ; case 0x04 : return forName ( "MacRoman" ) ; case 0x57 : return forName ( "windows-1252" ) ; case 0x59 : return forName ( "windows-1252" ) ; case 0x64 : return forName ( "IBM852" ) ; case 0x65 : return forName ( "IBM866" ) ; case 0x66 : return forName ( "IBM865" ) ; case 0x67 : return forName ( "IBM861" ) ; case 0x6A : return forName ( "x-IBM737" ) ; case 0x6B : return forName ( "IBM857" ) ; case 0x78 : return forName ( "windows-950" ) ; case 0x79 : return Charset . forName ( "windows-949" ) ; case 0x7A : return forName ( "GBK" ) ; case 0x7B : return forName ( "windows-932" ) ; case 0x7C : return forName ( "windows-874" ) ; case 0x7D : return forName ( "windows-1255" ) ; case 0x7E : return forName ( "windows-1256" ) ; case 0x96 : return forName ( "x-MacCyrillic" ) ; case 0x97 : return forName ( "x-MacCentralEurope" ) ; case 0x98 : return forName ( "x-MacGreek" ) ; case 0xC8 : return forName ( "windows-1250" ) ; case 0xC9 : return forName ( "windows-1251" ) ; case 0xCA : return forName ( "windows-1254" ) ; case 0xCB : return forName ( "windows-1253" ) ; } return null ; }
Gets Java charset from DBF code
29,193
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 ; } 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 ; } return 0 ; }
gets the DBF code for a given Java charset
29,194
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
29,195
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
29,196
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
29,197
public static byte [ ] doubleFormating ( Number num , Charset charset , int fieldLength , int sizeDecimalPart ) { int sizeWholePart = fieldLength - ( sizeDecimalPart > 0 ? ( sizeDecimalPart + 1 ) : 0 ) ; StringBuilder format = new StringBuilder ( fieldLength ) ; for ( int i = 0 ; i < sizeWholePart - 1 ; i ++ ) { format . append ( "#" ) ; } if ( format . length ( ) < sizeWholePart ) { format . append ( "0" ) ; } if ( sizeDecimalPart > 0 ) { format . append ( "." ) ; for ( int i = 0 ; i < sizeDecimalPart ; i ++ ) { format . append ( "0" ) ; } } DecimalFormat df = ( DecimalFormat ) NumberFormat . getInstance ( Locale . ENGLISH ) ; df . applyPattern ( format . toString ( ) ) ; return textPadding ( df . format ( num ) . toString ( ) , charset , fieldLength , DBFAlignment . RIGHT , ( byte ) ' ' ) ; }
Format a double number to write to a dbf file
29,198
public static boolean contains ( byte [ ] array , byte value ) { if ( array != null ) { for ( byte data : array ) { if ( data == value ) { return true ; } } } return false ; }
Checks that a byte array contains some specific byte
29,199
public static boolean isPureAscii ( String stringToCheck ) { if ( stringToCheck == null || stringToCheck . length ( ) == 0 ) { return true ; } synchronized ( ASCII_ENCODER ) { return ASCII_ENCODER . canEncode ( stringToCheck ) ; } }
Checks if a string is pure Ascii