idx
int64
0
41.2k
question
stringlengths
73
5.81k
target
stringlengths
5
918
38,900
public static boolean createFolder ( String path ) { File direct = new File ( Environment . getExternalStorageDirectory ( ) + "/" + path ) ; if ( ! direct . exists ( ) ) { if ( direct . mkdir ( ) ) { return true ; } } return false ; }
Create folder in the SDCard
38,901
private static void writeToFile ( String text , String logFilePath , boolean isDetailed ) { if ( isSDCardAvailable ( ) && isSDCardWritable ( ) && text != null ) { try { File file = new File ( logFilePath ) ; OutputStream os = new FileOutputStream ( file , true ) ; if ( isDetailed ) { os . write ( ( "---" + new SimpleDateFormat ( "yyyy/MM/dd HH:mm:ss.SSS" ) . format ( Calendar . getInstance ( ) . getTime ( ) ) + "---\n" ) . getBytes ( ) ) ; } os . write ( ( text + "\n" ) . getBytes ( ) ) ; os . close ( ) ; } catch ( Exception e ) { QuickUtils . log . e ( "Exception" , e ) ; } } else { return ; } }
private write to file method
38,902
public static byte [ ] readAsBytes ( InputStream inputStream ) throws IOException { int cnt = 0 ; byte [ ] buffer = new byte [ BUFFER_SIZE ] ; InputStream is = new BufferedInputStream ( inputStream ) ; try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream ( ) ; cnt = is . read ( buffer ) ; while ( cnt != - 1 ) { outputStream . write ( buffer , 0 , cnt ) ; cnt = is . read ( buffer ) ; } return outputStream . toByteArray ( ) ; } finally { safeClose ( is ) ; } }
Reads the inputStream and returns a byte array with all the information
38,903
@ SuppressWarnings ( "InfiniteLoopStatement" ) public void run ( ) { try { while ( true ) { try { cleanUp ( queue . remove ( ) ) ; } catch ( InterruptedException e ) { } } } catch ( ShutDown shutDown ) { } }
Loops continuously pulling references off the queue and cleaning them up .
38,904
protected boolean setFrame ( int l , int t , int r , int b ) { if ( getDrawable ( ) == null ) { return super . setFrame ( l , t , r , b ) ; } Matrix matrix = getImageMatrix ( ) ; float scaleFactor = getWidth ( ) / ( float ) getDrawable ( ) . getIntrinsicWidth ( ) ; matrix . setScale ( scaleFactor , scaleFactor , 0 , 0 ) ; setImageMatrix ( matrix ) ; return super . setFrame ( l , t , r , b ) ; }
Top crop scale type
38,905
public View newDropDownView ( LayoutInflater inflater , int position , ViewGroup container ) { return newView ( inflater , position , container ) ; }
Create a new instance of a drop - down view for the specified position .
38,906
public Map < ModelField , Set < Command > > process ( ModelFactory modelFactory , Erector erector , Object model ) throws PolicyException { Map < ModelField , Set < Command > > modelFieldCommands = new HashMap < ModelField , Set < Command > > ( ) ; for ( ModelField modelField : erector . getModelFields ( ) ) { logger . debug ( " {} {}" , getTarget ( ) , modelField ) ; if ( modelField . getName ( ) . equals ( field ) ) { Set < Command > commands = modelFieldCommands . get ( modelField ) ; if ( commands == null ) { commands = new HashSet < Command > ( ) ; } commands . add ( Command . SKIP_REFERENCE_INJECTION ) ; modelFieldCommands . put ( modelField , commands ) ; } } return modelFieldCommands ; }
Prevents Model from being set by the Reference Model
38,907
protected Object createNewInstance ( Erector erector ) throws BlueprintTemplateException { SpringBlueprint springBlueprint = erector . getBlueprint ( ) . getClass ( ) . getAnnotation ( SpringBlueprint . class ) ; if ( springBlueprint != null && springBlueprint . bean ( ) ) { Class beanClass = springBlueprint . beanClass ( ) ; if ( beanClass . equals ( NotSet . class ) ) { beanClass = erector . getTarget ( ) ; } try { if ( StringUtils . isNotBlank ( springBlueprint . beanName ( ) ) ) { logger . debug ( "Retrieving model from Spring [{},{}]" , springBlueprint . beanName ( ) , beanClass ) ; return applicationContext . getBean ( springBlueprint . beanName ( ) , beanClass ) ; } else { logger . debug ( "Retrieving model from Spring [{}]" , beanClass ) ; return applicationContext . getBean ( beanClass ) ; } } catch ( NoSuchBeanDefinitionException e ) { Object instance = super . createNewInstance ( erector ) ; beanFactory . autowireBean ( instance ) ; return instance ; } } else { return super . createNewInstance ( erector ) ; } }
Create new instance of model before blueprint values are set . Autowire them from Spring Context if they have the SpringBlueprint annotation
38,908
public void registerBlueprint ( Object blueprint ) throws RegisterBlueprintException { SpringBlueprint springBlueprint = blueprint . getClass ( ) . getAnnotation ( SpringBlueprint . class ) ; if ( springBlueprint != null && springBlueprint . autowire ( ) ) { logger . debug ( "Autowiring blueprint {}" , blueprint ) ; beanFactory . autowireBean ( blueprint ) ; } super . registerBlueprint ( blueprint ) ; }
Register Blueprints autowire them from Spring Context if they have the SpringBlueprint annotation
38,909
public void addPolicy ( Policy policy ) throws PolicyException { if ( policy instanceof BlueprintPolicy ) { if ( erectors . get ( policy . getTarget ( ) ) == null ) { throw new PolicyException ( "Blueprint does not exist for BlueprintPolicy target: " + policy . getTarget ( ) ) ; } List < BlueprintPolicy > policies = blueprintPolicies . get ( policy . getTarget ( ) ) ; if ( policies == null ) { policies = new ArrayList < BlueprintPolicy > ( ) ; } policies . add ( ( BlueprintPolicy ) policy ) ; logger . info ( "Setting BlueprintPolicy {} for {}" , policy , policy . getTarget ( ) ) ; blueprintPolicies . put ( policy . getTarget ( ) , policies ) ; } else if ( policy instanceof FieldPolicy ) { if ( erectors . get ( policy . getTarget ( ) ) == null ) { throw new PolicyException ( "Blueprint does not exist for FieldPolicy target: " + policy . getTarget ( ) ) ; } List < FieldPolicy > policies = fieldPolicies . get ( policy . getTarget ( ) ) ; if ( policies == null ) { policies = new ArrayList < FieldPolicy > ( ) ; } policies . add ( ( FieldPolicy ) policy ) ; logger . info ( "Setting FieldPolicy {} for {}" , policy , policy . getTarget ( ) ) ; fieldPolicies . put ( policy . getTarget ( ) , policies ) ; } }
Add Policy to ModelFactory
38,910
public void setRegisterBlueprintsByPackage ( String _package ) throws RegisterBlueprintException { Set < Class < ? > > annotated = null ; try { annotated = new ClassesInPackageScanner ( ) . findAnnotatedClasses ( _package , Blueprint . class ) ; } catch ( IOException e ) { throw new RegisterBlueprintException ( e ) ; } logger . info ( "Scanned {} and found {}" , _package , annotated ) ; this . setRegisterBlueprints ( annotated ) ; }
Register all Blueprint in package .
38,911
public void setRegisterBlueprints ( Collection blueprints ) throws RegisterBlueprintException { for ( Object blueprint : blueprints ) { if ( blueprint instanceof Class ) { registerBlueprint ( ( Class ) blueprint ) ; } else if ( blueprint instanceof String ) { registerBlueprint ( ( String ) blueprint ) ; } else if ( blueprint instanceof String ) { registerBlueprint ( blueprint ) ; } else { throw new RegisterBlueprintException ( "Only supports List comprised of Class<Blueprint>, Blueprint, or String className" ) ; } } }
Register a List of Blueprint Class or String class names of Blueprint
38,912
public void registerBlueprint ( String className ) throws RegisterBlueprintException { try { registerBlueprint ( Class . forName ( className ) ) ; } catch ( ClassNotFoundException e ) { throw new RegisterBlueprintException ( e ) ; } }
Register a Blueprint from a String Class name
38,913
public void registerBlueprint ( Class clazz ) throws RegisterBlueprintException { Object blueprint = null ; try { blueprint = clazz . newInstance ( ) ; } catch ( InstantiationException e ) { throw new RegisterBlueprintException ( e ) ; } catch ( IllegalAccessException e ) { throw new RegisterBlueprintException ( e ) ; } registerBlueprint ( blueprint ) ; }
Register a Blueprint from Class
38,914
@ SuppressWarnings ( { "rawtypes" , "unchecked" } ) public < T > T createModel ( T referenceModel , boolean withPolicies ) throws CreateModelException { Erector erector = erectors . get ( referenceModel . getClass ( ) ) ; if ( erector == null ) { throw new CreateModelException ( "Unregistered class: " + referenceModel . getClass ( ) ) ; } return createModel ( erector , referenceModel , withPolicies ) ; }
Create a Model for a registered Blueprint . Values set in the model will not be overridden by defaults in the Blueprint .
38,915
public static GsonBuilder registerAll ( GsonBuilder gsonBuilder ) { registerInstant ( gsonBuilder ) ; registerLocalDate ( gsonBuilder ) ; registerLocalDateTime ( gsonBuilder ) ; registerLocalTime ( gsonBuilder ) ; registerLocalDate ( gsonBuilder ) ; registerOffsetDateTime ( gsonBuilder ) ; registerOffsetTime ( gsonBuilder ) ; registerZonedDateTime ( gsonBuilder ) ; return gsonBuilder ; }
A convenient method to register all supported ThreeTen BP types .
38,916
private Set < Class < ? extends Annotation > > getSupportedAnnotations ( ) { Set < Class < ? extends Annotation > > annotations = new LinkedHashSet < > ( ) ; annotations . add ( Remoter . class ) ; return annotations ; }
Only one annotation is supported at class level -
38,917
public void generateProxy ( Element element ) { try { getClassBuilder ( element ) . buildProxyClass ( ) . build ( ) . writeTo ( filer ) ; } catch ( Exception ex ) { messager . printMessage ( Diagnostic . Kind . WARNING , "Error while generating Proxy " + ex . getMessage ( ) ) ; } }
Generates the Proxy for the given
38,918
public void generateStub ( Element element ) { try { getClassBuilder ( element ) . buildStubClass ( ) . build ( ) . writeTo ( filer ) ; } catch ( Exception ex ) { messager . printMessage ( Diagnostic . Kind . WARNING , "Error while generating Stub " + ex . getMessage ( ) ) ; } }
Generates the Stub for the given
38,919
public TypeElement getGenericType ( TypeMirror typeMirror ) { return typeMirror . accept ( new SimpleTypeVisitor6 < TypeElement , Void > ( ) { public TypeElement visitDeclared ( DeclaredType declaredType , Void v ) { TypeElement genericTypeElement = null ; TypeElement typeElement = ( TypeElement ) declaredType . asElement ( ) ; if ( parcelClass != null && typeUtils . isAssignable ( typeElement . asType ( ) , listTypeMirror ) ) { List < ? extends TypeMirror > typeArguments = declaredType . getTypeArguments ( ) ; if ( ! typeArguments . isEmpty ( ) ) { for ( TypeMirror genericType : typeArguments ) { if ( genericType instanceof WildcardType ) { WildcardType wildcardType = ( WildcardType ) genericType ; TypeMirror extendsType = wildcardType . getExtendsBound ( ) ; if ( extendsType != null ) { typeElement = elementUtils . getTypeElement ( extendsType . toString ( ) ) ; if ( typeElement . getAnnotation ( parcelClass ) != null ) { genericTypeElement = typeElement ; break ; } } } else { typeElement = elementUtils . getTypeElement ( genericType . toString ( ) ) ; if ( typeElement . getAnnotation ( parcelClass ) != null ) { genericTypeElement = typeElement ; break ; } } } } } return genericTypeElement ; } } , null ) ; }
Return the generic type if any
38,920
public void writeParamsToStub ( VariableElement param , ParamType paramType , String paramName , MethodSpec . Builder methodBuilder ) { methodBuilder . addStatement ( "$T " + paramName , param . asType ( ) ) ; }
Called to generate code to write params for stub
38,921
public void writeOutParamsToStub ( VariableElement param , ParamType paramType , String paramName , MethodSpec . Builder methodBuilder ) { if ( paramType != ParamType . IN ) { methodBuilder . addStatement ( "int " + paramName + "_length = data.readInt()" ) ; methodBuilder . beginControlFlow ( "if (" + paramName + "_length < 0 )" ) ; methodBuilder . addStatement ( paramName + " = null" ) ; methodBuilder . endControlFlow ( ) ; methodBuilder . beginControlFlow ( "else" ) ; methodBuilder . addStatement ( paramName + " = new " + ( ( ( ArrayType ) param . asType ( ) ) . getComponentType ( ) . toString ( ) ) + "[" + paramName + "_length]" ) ; methodBuilder . endControlFlow ( ) ; } }
Called to generate code to write
38,922
protected void writeArrayOutParamsToProxy ( VariableElement param , MethodSpec . Builder methodBuilder ) { methodBuilder . beginControlFlow ( "if (" + param . getSimpleName ( ) + " == null)" ) ; methodBuilder . addStatement ( "data.writeInt(-1)" ) ; methodBuilder . endControlFlow ( ) ; methodBuilder . beginControlFlow ( "else" ) ; methodBuilder . addStatement ( "data.writeInt(" + param . getSimpleName ( ) + ".length)" ) ; methodBuilder . endControlFlow ( ) ; }
Called to generate code that writes the out params for array type
38,923
public void addStubMethods ( TypeSpec . Builder classBuilder ) { MethodSpec . Builder methodBuilder = MethodSpec . methodBuilder ( "onTransact" ) . addModifiers ( Modifier . PUBLIC ) . addAnnotation ( Override . class ) . returns ( boolean . class ) . addException ( ClassName . get ( "android.os" , "RemoteException" ) ) . addParameter ( int . class , "code" ) . addParameter ( ClassName . get ( "android.os" , "Parcel" ) , "data" ) . addParameter ( ClassName . get ( "android.os" , "Parcel" ) , "reply" ) . addParameter ( int . class , "flags" ) ; methodBuilder . beginControlFlow ( "try" ) ; methodBuilder . beginControlFlow ( "switch (code)" ) ; methodBuilder . beginControlFlow ( "case INTERFACE_TRANSACTION:" ) ; methodBuilder . addStatement ( "reply.writeString(DESCRIPTOR)" ) ; methodBuilder . addStatement ( "return true" ) ; methodBuilder . endControlFlow ( ) ; processRemoterElements ( classBuilder , new ElementVisitor ( ) { public void visitElement ( TypeSpec . Builder classBuilder , Element member , int methodIndex , MethodSpec . Builder methodBuilder ) { addStubMethods ( classBuilder , member , methodIndex , methodBuilder ) ; } } , methodBuilder ) ; methodBuilder . beginControlFlow ( "case TRANSACTION__getStubID:" ) ; methodBuilder . addStatement ( "data.enforceInterface(DESCRIPTOR)" ) ; methodBuilder . addStatement ( "reply.writeNoException()" ) ; methodBuilder . addStatement ( "reply.writeInt(serviceImpl.hashCode())" ) ; methodBuilder . addStatement ( "return true" ) ; methodBuilder . endControlFlow ( ) ; methodBuilder . endControlFlow ( ) ; methodBuilder . endControlFlow ( ) ; methodBuilder . beginControlFlow ( "catch ($T re)" , Throwable . class ) ; methodBuilder . beginControlFlow ( "if ((flags & FLAG_ONEWAY) == 0)" ) ; methodBuilder . addStatement ( "reply.setDataPosition(0)" ) ; methodBuilder . addStatement ( "reply.writeInt(REMOTER_EXCEPTION_CODE)" ) ; methodBuilder . addStatement ( "reply.writeString(re.getMessage())" ) ; methodBuilder . addStatement ( "reply.writeSerializable(re)" ) ; methodBuilder . endControlFlow ( ) ; methodBuilder . beginControlFlow ( "else" ) ; methodBuilder . addStatement ( "$T.w(serviceImpl.getClass().getName(), \"Binder call failed.\", re)" , ClassName . get ( "android.util" , "Log" ) ) ; methodBuilder . endControlFlow ( ) ; methodBuilder . addStatement ( "return true" ) ; methodBuilder . endControlFlow ( ) ; methodBuilder . addStatement ( "return super.onTransact(code, data, reply, flags)" ) ; classBuilder . addMethod ( methodBuilder . build ( ) ) ; addCommonExtras ( classBuilder ) ; addStubExtras ( classBuilder ) ; }
Build the stub methods
38,924
private void addProxyExtras ( TypeSpec . Builder classBuilder ) { addRemoterProxyMethods ( classBuilder ) ; addProxyDeathMethod ( classBuilder , "linkToDeath" , "Register a {@link android.os.IBinder.DeathRecipient} to know of binder connection lose\n" ) ; addProxyDeathMethod ( classBuilder , "unlinkToDeath" , "UnRegisters a {@link android.os.IBinder.DeathRecipient}\n" ) ; addProxyRemoteAlive ( classBuilder ) ; addProxyCheckException ( classBuilder ) ; addGetId ( classBuilder ) ; addHashCode ( classBuilder ) ; addEquals ( classBuilder ) ; addProxyDestroyMethods ( classBuilder ) ; }
Add other extra methods
38,925
private void addProxyDestroyMethods ( TypeSpec . Builder classBuilder ) { MethodSpec . Builder methodBuilder = MethodSpec . methodBuilder ( "destroyStub" ) . addModifiers ( Modifier . PUBLIC ) . addAnnotation ( Override . class ) . addParameter ( Object . class , "object" ) . returns ( TypeName . VOID ) . beginControlFlow ( "if(object != null)" ) . beginControlFlow ( "synchronized (stubMap)" ) . addStatement ( "IBinder binder = stubMap.get(object)" ) . beginControlFlow ( "if (binder != null)" ) . addStatement ( "(($T)binder).destroyStub()" , RemoterStub . class ) . addStatement ( "stubMap.remove(object)" ) . endControlFlow ( ) . endControlFlow ( ) . endControlFlow ( ) ; classBuilder . addMethod ( methodBuilder . build ( ) ) ; methodBuilder = MethodSpec . methodBuilder ( "__checkProxy" ) . addModifiers ( Modifier . PRIVATE ) . returns ( TypeName . VOID ) . addStatement ( "if(mRemote == null) throw new RuntimeException(\"Trying to use a destroyed Proxy\")" ) ; classBuilder . addMethod ( methodBuilder . build ( ) ) ; methodBuilder = MethodSpec . methodBuilder ( "destroyProxy" ) . addModifiers ( Modifier . PUBLIC ) . addAnnotation ( Override . class ) . returns ( TypeName . VOID ) . addStatement ( "this.mRemote = null" ) . addStatement ( "unRegisterProxyListener(null)" ) . beginControlFlow ( "synchronized (stubMap)" ) . beginControlFlow ( "for(IBinder binder:stubMap.values())" ) . addStatement ( "((RemoterStub)binder).destroyStub()" ) . endControlFlow ( ) . addStatement ( "stubMap.clear()" ) . endControlFlow ( ) ; classBuilder . addMethod ( methodBuilder . build ( ) ) ; }
Add proxy method for destroystub
38,926
private void addProxyDeathMethod ( TypeSpec . Builder classBuilder , String deathMethod , String doc ) { MethodSpec . Builder methodBuilder = MethodSpec . methodBuilder ( deathMethod ) . addModifiers ( Modifier . PUBLIC ) . returns ( TypeName . VOID ) . addParameter ( ClassName . get ( "android.os" , "IBinder.DeathRecipient" ) , "deathRecipient" ) . beginControlFlow ( "try" ) . addStatement ( "mRemote." + deathMethod + "(deathRecipient, 0)" ) . endControlFlow ( ) . beginControlFlow ( "catch ($T ignored)" , Exception . class ) . endControlFlow ( ) . addJavadoc ( doc ) ; classBuilder . addMethod ( methodBuilder . build ( ) ) ; }
Add proxy method that exposes the linkToDeath
38,927
private void addProxyRemoteAlive ( TypeSpec . Builder classBuilder ) { MethodSpec . Builder methodBuilder = MethodSpec . methodBuilder ( "isRemoteAlive" ) . addModifiers ( Modifier . PUBLIC ) . returns ( boolean . class ) . addStatement ( "boolean alive = false" ) . beginControlFlow ( "try" ) . addStatement ( "alive = mRemote.isBinderAlive()" ) . endControlFlow ( ) . beginControlFlow ( "catch ($T ignored)" , Exception . class ) . endControlFlow ( ) . addStatement ( "return alive" ) . addJavadoc ( "Checks whether the remote process is alive\n" ) ; classBuilder . addMethod ( methodBuilder . build ( ) ) ; }
Add proxy method that exposes whether remote is alive
38,928
private void addProxyCheckException ( TypeSpec . Builder classBuilder ) { MethodSpec . Builder methodBuilder = MethodSpec . methodBuilder ( "checkException" ) . addModifiers ( Modifier . PRIVATE ) . returns ( Throwable . class ) . addParameter ( ClassName . get ( "android.os" , "Parcel" ) , "reply" ) . addStatement ( "int code = reply.readInt()" ) . addStatement ( "Throwable exception = null" ) . beginControlFlow ( "if (code != 0)" ) . addStatement ( "String msg = reply.readString()" ) . beginControlFlow ( "if (code == REMOTER_EXCEPTION_CODE)" ) . addStatement ( "exception = (Throwable) reply.readSerializable()" ) . endControlFlow ( ) . beginControlFlow ( "else" ) . addStatement ( "exception = new RuntimeException(msg)" ) . endControlFlow ( ) . endControlFlow ( ) . addStatement ( "return exception" ) ; classBuilder . addMethod ( methodBuilder . build ( ) ) ; }
Add proxy method to check for exception
38,929
private void addHashCode ( TypeSpec . Builder classBuilder ) { MethodSpec . Builder methodBuilder = MethodSpec . methodBuilder ( "hashCode" ) . addModifiers ( Modifier . PUBLIC ) . returns ( int . class ) . addAnnotation ( Override . class ) . addStatement ( "return _binderID" ) ; classBuilder . addMethod ( methodBuilder . build ( ) ) ; }
Add proxy method to set hashcode to uniqueu id of binder
38,930
private void addEquals ( TypeSpec . Builder classBuilder ) { MethodSpec . Builder methodBuilder = MethodSpec . methodBuilder ( "equals" ) . addModifiers ( Modifier . PUBLIC ) . addParameter ( ClassName . get ( Object . class ) , "obj" ) . returns ( boolean . class ) . addAnnotation ( Override . class ) . addStatement ( "return (obj instanceof " + getRemoterInterfaceClassName ( ) + ClassBuilder . PROXY_SUFFIX + ") && obj.hashCode() == hashCode()" ) ; classBuilder . addMethod ( methodBuilder . build ( ) ) ; }
Add proxy method for equals
38,931
private void addGetId ( TypeSpec . Builder classBuilder ) { MethodSpec . Builder methodBuilder = MethodSpec . methodBuilder ( "__getStubID" ) . addModifiers ( Modifier . PRIVATE ) . returns ( int . class ) . addStatement ( "android.os.Parcel data = android.os.Parcel.obtain()" ) . addStatement ( "android.os.Parcel reply = android.os.Parcel.obtain()" ) . addStatement ( "int result" ) ; methodBuilder . beginControlFlow ( "try" ) ; methodBuilder . addStatement ( "data.writeInterfaceToken(DESCRIPTOR)" ) ; methodBuilder . addStatement ( "mRemote.transact(TRANSACTION__getStubID, data, reply, 0)" ) ; methodBuilder . addStatement ( "Throwable exception = checkException(reply)" ) ; methodBuilder . beginControlFlow ( "if(exception != null)" ) ; methodBuilder . addStatement ( "throw ($T)exception" , RuntimeException . class ) ; methodBuilder . endControlFlow ( ) ; methodBuilder . addStatement ( "result = reply.readInt()" ) ; methodBuilder . endControlFlow ( ) ; methodBuilder . beginControlFlow ( "catch ($T re)" , ClassName . get ( "android.os" , "RemoteException" ) ) ; methodBuilder . addStatement ( "throw new $T(re)" , RuntimeException . class ) ; methodBuilder . endControlFlow ( ) ; methodBuilder . beginControlFlow ( "finally" ) ; methodBuilder . addStatement ( "reply.recycle()" ) ; methodBuilder . addStatement ( "data.recycle()" ) ; methodBuilder . endControlFlow ( ) ; methodBuilder . addStatement ( "return result" ) ; classBuilder . addMethod ( methodBuilder . build ( ) ) ; }
Add proxy method to get unique id
38,932
private TypeSpec getBinderWrapper ( ) { TypeSpec . Builder staticBinderWrapperClassBuilder = TypeSpec . classBuilder ( "BinderWrapper" ) . addModifiers ( Modifier . PRIVATE ) . addModifiers ( Modifier . STATIC ) . addField ( ClassName . get ( "android.os" , "IBinder" ) , "binder" , Modifier . PRIVATE ) . addMethod ( MethodSpec . constructorBuilder ( ) . addParameter ( ClassName . get ( "android.os" , "IBinder" ) , "binder" ) . addStatement ( "this.binder = binder" ) . build ( ) ) . addMethod ( MethodSpec . methodBuilder ( "asBinder" ) . addModifiers ( Modifier . PUBLIC ) . addAnnotation ( Override . class ) . returns ( ClassName . get ( "android.os" , "IBinder" ) ) . addStatement ( "return binder" ) . build ( ) ) . addSuperinterface ( ClassName . get ( "android.os" , "IInterface" ) ) ; return staticBinderWrapperClassBuilder . build ( ) ; }
Add the static inner Binder wrapper
38,933
private TypeSpec getDeathRecipientWrapper ( ) { TypeSpec . Builder staticBinderWrapperClassBuilder = TypeSpec . classBuilder ( "DeathRecipient" ) . addModifiers ( Modifier . PRIVATE ) . addModifiers ( Modifier . STATIC ) . addField ( RemoterProxyListener . class , "proxyListener" , Modifier . PRIVATE ) . addMethod ( MethodSpec . constructorBuilder ( ) . addParameter ( RemoterProxyListener . class , "proxyListener" ) . addStatement ( "this.proxyListener = proxyListener" ) . build ( ) ) . addMethod ( MethodSpec . methodBuilder ( "binderDied" ) . addModifiers ( Modifier . PUBLIC ) . addAnnotation ( Override . class ) . beginControlFlow ( "if (proxyListener != null)" ) . addStatement ( "proxyListener.onProxyDead()" ) . endControlFlow ( ) . build ( ) ) . addSuperinterface ( ClassName . get ( "android.os" , "IBinder.DeathRecipient" ) ) ; return staticBinderWrapperClassBuilder . build ( ) ; }
Add the static inner DeathRecipient wrapper
38,934
protected void processRemoterElements ( TypeSpec . Builder classBuilder , ElementVisitor elementVisitor , MethodSpec . Builder methodBuilder ) { processRemoterElements ( classBuilder , getRemoterInterfaceElement ( ) , 0 , elementVisitor , methodBuilder ) ; }
Finds that elements that needs to be processed
38,935
private int processRemoterElements ( TypeSpec . Builder classBuilder , Element element , int methodIndex , ElementVisitor elementVisitor , MethodSpec . Builder methodBuilder ) { if ( element instanceof TypeElement ) { for ( TypeMirror typeMirror : ( ( TypeElement ) element ) . getInterfaces ( ) ) { if ( typeMirror instanceof DeclaredType ) { Element superElement = ( ( DeclaredType ) typeMirror ) . asElement ( ) ; methodIndex = processRemoterElements ( classBuilder , superElement , methodIndex , elementVisitor , methodBuilder ) ; } } for ( Element member : element . getEnclosedElements ( ) ) { if ( member . getKind ( ) == ElementKind . METHOD ) { elementVisitor . visitElement ( classBuilder , member , methodIndex , methodBuilder ) ; methodIndex ++ ; } } } return methodIndex ; }
Recursevely Visit extended elements
38,936
public < V extends View > V get ( int id ) { Object result = mViews . get ( id ) ; if ( result == NULL ) { return null ; } if ( result != null ) { return cast ( result ) ; } result = mView . findViewById ( id ) ; if ( result == null ) { mViews . put ( id , NULL ) ; } else { mViews . put ( id , result ) ; } return cast ( result ) ; }
Gets the child view by id .
38,937
@ SuppressWarnings ( "unchecked" ) protected final U fromObject ( Object value ) { return value == NULL ? null : ( U ) value ; }
Cast the object back to a typed value .
38,938
public final < R > R as ( IxFunction < ? super Ix < T > , R > transformer ) { return transformer . apply ( this ) ; }
Calls the given transformers with this and returns its value allowing fluent conversions to non - Ix types .
38,939
@ SuppressWarnings ( "unchecked" ) public final T first ( T defaultValue ) { if ( this instanceof Callable ) { return checkedCall ( ( Callable < T > ) this ) ; } Iterator < T > it = iterator ( ) ; if ( it . hasNext ( ) ) { return it . next ( ) ; } return defaultValue ; }
Returns the first element of this sequence or the defaultValue if this sequence is empty .
38,940
public final < U extends Collection < ? super T > > U into ( U collection ) { for ( T v : this ) { collection . add ( v ) ; } return collection ; }
Consumes the entire sequence and adds each element into the given collection that is also returned .
38,941
@ SuppressWarnings ( "unchecked" ) public final T last ( ) { if ( this instanceof Callable ) { return checkedCall ( ( Callable < T > ) this ) ; } Iterator < T > it = iterator ( ) ; if ( ! it . hasNext ( ) ) { throw new NoSuchElementException ( ) ; } for ( ; ; ) { T t = it . next ( ) ; if ( ! it . hasNext ( ) ) { return t ; } } }
Returns the last element of this sequence .
38,942
public final void print ( CharSequence separator , int charsPerLine ) { boolean first = true ; int len = 0 ; for ( T v : this ) { String s = String . valueOf ( v ) ; if ( first ) { System . out . print ( s ) ; len += s . length ( ) ; first = false ; } else { System . out . print ( separator ) ; len += separator . length ( ) ; if ( len > charsPerLine ) { System . out . println ( ) ; System . out . print ( s ) ; len = s . length ( ) ; } else { System . out . print ( s ) ; len += s . length ( ) ; } } } }
Prints the elements of this sequence to the console separated by the given separator and with a line break after roughly the given charsPerLine amount .
38,943
public final void println ( CharSequence prefix ) { for ( T v : this ) { System . out . print ( prefix ) ; System . out . println ( v ) ; } }
Prints each element of this sequence into a new line on the console prefixed by the given character sequence .
38,944
public final void removeAll ( IxPredicate < ? super T > predicate ) { Iterator < T > it = iterator ( ) ; while ( it . hasNext ( ) ) { T v = it . next ( ) ; if ( predicate . test ( v ) ) { it . remove ( ) ; } } }
Consumes this Iterable and removes all elements for which the predicate returns true ; in other words remove those elements of a mutable source that match the predicate .
38,945
public final T single ( ) { Iterator < T > it = iterator ( ) ; if ( it . hasNext ( ) ) { T v = it . next ( ) ; if ( it . hasNext ( ) ) { throw new IndexOutOfBoundsException ( "The source has more than one element." ) ; } return v ; } throw new NoSuchElementException ( "The source is empty." ) ; }
Returns the single element of this sequence or throws a NoSuchElementException if this sequence is empty or IndexOutOfBoundsException if this sequence has more than on element
38,946
public final void subscribe ( IxConsumer < ? super T > onNext , IxConsumer < Throwable > onError ) { try { for ( T v : this ) { onNext . accept ( v ) ; } } catch ( Throwable ex ) { onError . accept ( ex ) ; } }
Iterates over this sequence and calls the given onNext action with each element and calls the onError with any exception thrown by the iteration or the onNext action .
38,947
public final void subscribe ( IxConsumer < ? super T > onNext , IxConsumer < Throwable > onError , Runnable onCompleted ) { try { for ( T v : this ) { onNext . accept ( v ) ; } } catch ( Throwable ex ) { onError . accept ( ex ) ; return ; } onCompleted . run ( ) ; }
Iterates over this sequence and calls the given onNext action with each element and calls the onError with any exception thrown by the iteration or the onNext action ; otherwise calls the onCompleted action when the sequence completes without exception .
38,948
protected static < U > U nullCheck ( U value , String message ) { if ( value == null ) { throw new NullPointerException ( message ) ; } return value ; }
Checks if the value is null and if so throws a NullPointerException with the given message .
38,949
public static Stream < Statement > encode ( final Stream < ? extends Outcome > stream ) { Preconditions . checkNotNull ( stream ) ; return Record . encode ( stream . transform ( new Function < Outcome , Record > ( ) { public Record apply ( final Outcome outcome ) { return outcome . toRecord ( ) ; } } , 0 ) , ImmutableSet . of ( KSR . INVOCATION ) ) ; }
Performs outcome - to - RDF encoding by converting a stream of outcomes in a stream of RDF statements .
38,950
public void createConfiguration ( final Properties properties ) { setHbcfg ( HBaseConfiguration . create ( ) ) ; getHbcfg ( ) . set ( HBASE_ZOOKEEPER_QUORUM , properties . getProperty ( HBASE_ZOOKEEPER_QUORUM , "hlt-services4" ) ) ; getHbcfg ( ) . set ( HBASE_ZOOKEEPER_CLIENT_PORT , properties . getProperty ( HBASE_ZOOKEEPER_CLIENT_PORT , "2181" ) ) ; getHbcfg ( ) . set ( HADOOP_FS_DEFAULT_NAME , properties . getProperty ( HADOOP_FS_DEFAULT_NAME , "hdfs://hlt-services4:9000" ) ) ; }
Creates an HBase configuration object .
38,951
public FilterList getFilter ( XPath condition , boolean passAll , String [ ] famNames , String [ ] qualNames , String [ ] params ) { FilterList list = new FilterList ( ( passAll ) ? FilterList . Operator . MUST_PASS_ALL : FilterList . Operator . MUST_PASS_ONE ) ; for ( int iCont = 0 ; iCont < famNames . length ; iCont ++ ) { SingleColumnValueFilter filterTmp = new SingleColumnValueFilter ( Bytes . toBytes ( famNames [ iCont ] ) , Bytes . toBytes ( qualNames [ iCont ] ) , CompareOp . EQUAL , Bytes . toBytes ( params [ iCont ] ) ) ; list . addFilter ( filterTmp ) ; } return list ; }
Gets filter based on the condition to be performed
38,952
public Scan getResultScan ( String tableName , String famName , ByteBuffer startKey , ByteBuffer endKey ) throws IOException { logger . debug ( "AbstractHBaseUtils Begin of getResultScan(" + tableName + ", " + famName + ")" ) ; Scan scan = new Scan ( ) ; scan . addFamily ( Bytes . toBytes ( famName ) ) ; if ( startKey != null ) scan . setStartRow ( Bytes . toBytes ( startKey ) ) ; if ( endKey != null ) scan . setStopRow ( Bytes . toBytes ( endKey ) ) ; return scan ; }
Creates a scan
38,953
public Scan getScan ( String tableName , String famName ) throws IOException { return getResultScan ( tableName , famName , null , null ) ; }
Creates a result scanner
38,954
public static String decompress ( final byte [ ] strBytes ) { if ( strBytes [ 0 ] == UNCOMPRESSED_FLAG ) { return new String ( strBytes , 1 , strBytes . length , Charsets . UTF_8 ) ; } final StringBuilder out = new StringBuilder ( ) ; for ( int i = 0 ; i < strBytes . length ; i ++ ) { final char b = ( char ) ( 0xFF & strBytes [ i ] ) ; if ( b == 254 ) { out . append ( ( char ) strBytes [ ++ i ] ) ; } else if ( b == 255 ) { final int length = 0xFF & strBytes [ ++ i ] ; for ( int j = 1 ; j <= length ; j ++ ) { out . append ( ( char ) strBytes [ i + j ] ) ; } i += length ; } else { final int loc = 0xFF & b ; out . append ( REVERSE_CODEBOOK [ loc ] ) ; } } return out . toString ( ) ; }
Decompress byte array from compress back into String
38,955
private static void outputVerb ( final ByteArrayOutputStream baos , final String str ) { if ( str . length ( ) == 1 ) { baos . write ( 254 ) ; baos . write ( str . toCharArray ( ) [ 0 ] ) ; } else { final byte [ ] bytes = str . getBytes ( Charsets . UTF_8 ) ; baos . write ( 255 ) ; baos . write ( str . length ( ) ) ; baos . write ( bytes , 0 , bytes . length ) ; } }
Outputs the verbatim string to the output stream
38,956
public static < T > Stream < T > create ( final Iterator < ? extends T > iterator ) { if ( iterator . hasNext ( ) ) { return new IteratorStream < T > ( iterator ) ; } else { return new EmptyStream < T > ( ) ; } }
Creates a new Stream over the elements returned by the supplied Iterator .
38,957
public static < T > Stream < T > create ( final Iteration < ? extends T , ? > iteration ) { return new IterationStream < T > ( iteration ) ; }
Creates a new Stream over the elements returned by the supplied Sesame Iteration .
38,958
public static < T > Stream < T > create ( final Enumeration < ? extends T > enumeration ) { if ( enumeration . hasMoreElements ( ) ) { return new IteratorStream < T > ( Iterators . forEnumeration ( enumeration ) ) ; } else { return new EmptyStream < T > ( ) ; } }
Creates a new Stream over the elements returned by the supplied Enumeration .
38,959
public static < T > Stream < T > concat ( final Iterable < ? extends Iterable < ? extends T > > iterables ) { return new ConcatStream < Iterable < ? extends T > , T > ( create ( iterables ) ) ; }
Returns a Stream concatenating zero or more Iterables . If an input Iterable is a Stream it is closed as soon as exhausted or as iteration completes .
38,960
public final long count ( ) { final AtomicLong result = new AtomicLong ( ) ; toHandler ( new Handler < T > ( ) { private long count ; public void handle ( final T element ) { if ( element != null ) { ++ this . count ; } else { result . set ( this . count ) ; } } } ) ; return result . get ( ) ; }
Terminal operation returning the number of elements in this Stream . Note that only few elements are materialized at any time so it is safe to use this method with arbitrarily large Streams .
38,961
public final T [ ] toArray ( final Class < T > elementClass ) { return Iterables . toArray ( toCollection ( Lists . < T > newArrayListWithCapacity ( 256 ) ) , elementClass ) ; }
Terminal operation returning an array of the specified type with all the elements of this Stream . Call this method only if there is enough memory to hold the resulting array .
38,962
public final < C extends Collection < ? super T > > C toCollection ( final C collection ) { Preconditions . checkNotNull ( collection ) ; toHandler ( new Handler < T > ( ) { public void handle ( final T element ) { if ( element != null ) { collection . add ( element ) ; } } } ) ; return collection ; }
Terminal operation storing all the elements of this Stream in the supplied Collection . Call this method only if the target Collection can hold all the remaining elements .
38,963
public final T getUnique ( final T defaultValue ) { try { final T result = getUnique ( ) ; if ( result != null ) { return result ; } } catch ( final Throwable ex ) { } return defaultValue ; }
Terminal operation returning the only element in this Stream or the default value specified if there are no elements multiple elements or an Exception occurs .
38,964
public static boolean regexMatch ( String input , String regex ) { return Pattern . compile ( regex ) . matcher ( input ) . matches ( ) ; }
If input matched regex
38,965
public synchronized Operation timeout ( final Long timeout ) { this . timeout = timeout == null || timeout > 0 ? timeout : null ; return this ; }
Sets the optional timeout for this operation in milliseconds . Passing null or a non - positive value will remove any timeout previously set .
38,966
private void checkAndCreateTable ( final String tabName , final String colFamName ) throws IOException { hbaseUtils . checkAndCreateTable ( tabName , colFamName ) ; }
Verifies the existence of tables .
38,967
public final void merge ( final Record oldRecord , final Record newRecord ) { Preconditions . checkNotNull ( oldRecord ) ; for ( final URI property : newRecord . getProperties ( ) ) { if ( appliesTo ( property ) ) { oldRecord . set ( property , merge ( property , oldRecord . get ( property ) , newRecord . get ( property ) ) ) ; } } }
Merges all supported properties in common to the old and new record specified storing the results in the old record .
38,968
public static void main ( final String ... args ) { final Options options = new Options ( ) ; options . addOption ( "c" , "config" , true , "use service configuration file / classpath " + "resource (default '" + DEFAULT_CONFIG + "')" ) ; options . addOption ( "v" , "version" , false , "display version and copyright information, then exit" ) ; options . addOption ( "h" , "help" , false , "display usage information, then exit" ) ; int status = EX_OK ; try { final CommandLine cmd = new GnuParser ( ) . parse ( options , args ) ; if ( cmd . hasOption ( "v" ) ) { System . out . println ( String . format ( "%s (FBK KnowledgeStore) %s\njava %s bit (%s) %s\n%s" , PROGRAM_EXECUTABLE , PROGRAM_VERSION , System . getProperty ( "sun.arch.data.model" ) , System . getProperty ( "java.vendor" ) , System . getProperty ( "java.version" ) , PROGRAM_DISCLAIMER ) ) ; } else if ( cmd . hasOption ( "h" ) ) { status = EX_USAGE ; } else { final String configLocation = cmd . getOptionValue ( 'c' , DEFAULT_CONFIG ) ; if ( cmd . getArgList ( ) . contains ( "__start" ) ) { start ( configLocation ) ; } else if ( cmd . getArgList ( ) . contains ( "__stop" ) ) { stop ( ) ; } else { run ( configLocation ) ; } } } catch ( final ParseException ex ) { System . err . println ( "SYNTAX ERROR: " + ex . getMessage ( ) ) ; status = EX_USAGE ; } catch ( final ServiceConfigurationError ex ) { System . err . println ( "INVALID CONFIGURATION: " + ex . getMessage ( ) ) ; Throwables . getRootCause ( ex ) . printStackTrace ( ) ; status = EX_CONFIG ; } catch ( final Throwable ex ) { System . err . print ( "EXECUTION FAILED: " ) ; ex . printStackTrace ( ) ; status = ex instanceof IOException ? EX_IOERR : EX_UNAVAILABLE ; } if ( status == EX_USAGE ) { final PrintWriter out = new PrintWriter ( System . out ) ; final HelpFormatter formatter = new HelpFormatter ( ) ; formatter . printUsage ( out , WIDTH , PROGRAM_EXECUTABLE , options ) ; if ( PROGRAM_DESCRIPTION != null ) { formatter . printWrapped ( out , WIDTH , "\n" + PROGRAM_DESCRIPTION . trim ( ) ) ; } out . println ( "\nOptions" ) ; formatter . printOptions ( out , WIDTH , options , 2 , 2 ) ; out . flush ( ) ; } if ( status != EX_OK ) { System . err . println ( "[exit status: " + status + "]" ) ; } else { System . out . println ( "[exit status: " + status + "]" ) ; } System . out . flush ( ) ; System . err . flush ( ) ; System . exit ( status ) ; }
Program entry point . See class documentation for the supported features .
38,969
public void add ( final Statement statement ) throws DataCorruptedException , IOException { Preconditions . checkNotNull ( statement ) ; checkWritable ( ) ; try { this . connection . add ( statement ) ; } catch ( final RepositoryException ex ) { throw new IOException ( "Failed to add statement: " + statement , ex ) ; } }
Adds the specified RDF statement to the triple store . Virtuoso may buffer the operation performing it when more opportune and in any case ensuring that the same effects are produced as obtainable by directly executing the operation .
38,970
public void remove ( final Statement statement ) throws DataCorruptedException , IOException { Preconditions . checkState ( ! this . readOnly ) ; checkWritable ( ) ; try { this . connection . remove ( statement ) ; } catch ( final RepositoryException ex ) { throw new IOException ( "Failed to remove statement: " + statement , ex ) ; } }
Removes the specified RDF statement from the triple store . Virtuoso may buffer the operation performing it when more opportune and in any case ensuring that the same effects are produced as obtainable by directly executing the operation .
38,971
public void removeBulk ( final Iterable < ? extends Statement > statements , final boolean transaction ) throws DataCorruptedException , IOException { Preconditions . checkNotNull ( statements ) ; checkWritable ( ) ; try { if ( ! transaction && ! this . store . existsTransactionMarker ( ) ) { this . store . addTransactionMarker ( ) ; this . connection . getQuadStoreConnection ( ) . prepareCall ( "log_enable(2)" ) . execute ( ) ; } this . connection . remove ( statements ) ; this . connection . commit ( ) ; } catch ( final SQLException sqle ) { throw new IllegalStateException ( "Invalid internal operation." , sqle ) ; } catch ( final RepositoryException e ) { throw new DataCorruptedException ( "Error while adding bulk data." , e ) ; } }
Removes the specified RDF statements from the triple store . Implementations are designed to perform high throughput insertion .
38,972
public < T > T getUnique ( final URI property , final Class < T > valueClass , final T defaultValue ) { try { final T value = getUnique ( property , valueClass ) ; return value == null ? defaultValue : value ; } catch ( final IllegalStateException ex ) { return defaultValue ; } catch ( final IllegalArgumentException ex ) { return defaultValue ; } }
Returns the unique value of the property converted to an instance of a certain class or the default value supplied in case of failure .
38,973
public < T > List < T > get ( final URI property , final Class < T > valueClass , final List < T > defaultValue ) { try { final List < T > values = get ( property , valueClass ) ; return values . isEmpty ( ) ? defaultValue : values ; } catch ( final IllegalArgumentException ex ) { return defaultValue ; } }
Returns the values of the property converted to instances of a certain class or the default value supplied in case of failure or if the property has no values .
38,974
public synchronized Record retain ( final URI ... properties ) { for ( final URI property : doGetProperties ( ) ) { boolean retain = false ; for ( int i = 0 ; i < properties . length ; ++ i ) { if ( property . equals ( properties [ i ] ) ) { retain = true ; break ; } } if ( ! retain ) { doSet ( property , ImmutableSet . < Object > of ( ) ) ; } } return this ; }
Retains only the properties specified clearing the remaining ones . Note that the ID is not affected .
38,975
public synchronized Record clear ( final URI ... properties ) { final List < URI > propertiesToClear ; if ( properties == null || properties . length == 0 ) { propertiesToClear = doGetProperties ( ) ; } else { propertiesToClear = Arrays . asList ( properties ) ; } for ( final URI property : propertiesToClear ) { doSet ( property , ImmutableSet . < Object > of ( ) ) ; } return this ; }
Clears the properties specified or all the stored properties if no property is specified . Note that the ID is not affected .
38,976
public Record get ( final String tableName , final URI id ) throws IOException { logger . debug ( "TEPHRA Begin of get(" + tableName + ", " + id + ")" ) ; final TransactionAwareHTable txTable = ( TransactionAwareHTable ) getTable ( tableName ) ; Record resGotten = null ; if ( txTable != null ) { final Get get = new Get ( Bytes . toBytes ( id . toString ( ) ) ) . setMaxVersions ( 1 ) ; final Result rs = txTable . get ( get ) ; logger . debug ( "Value obtained: " + new String ( rs . value ( ) ) ) ; final AvroSerializer serializer = getSerializer ( ) ; resGotten = ( Record ) serializer . fromBytes ( rs . value ( ) ) ; } return resGotten ; }
Gets a Record based on information passed .
38,977
private Record getRecord ( final URI layer , final URI id ) throws Throwable { final Record record = id == null ? null : getSession ( ) . retrieve ( layer ) . ids ( id ) . exec ( ) . getUnique ( ) ; if ( record != null && layer . equals ( KS . MENTION ) ) { final String template = "SELECT ?e WHERE { ?e $$ $$ " + ( getUIConfig ( ) . isDenotedByAllowsGraphs ( ) ? "" : "FILTER NOT EXISTS { GRAPH ?e { ?s ?p ?o } } " ) + "}" ; for ( final URI entityID : getSession ( ) . sparql ( template , getUIConfig ( ) . getDenotedByProperty ( ) , id ) . execTuples ( ) . transform ( URI . class , true , "e" ) ) { record . add ( KS . REFERS_TO , entityID ) ; } } return record ; }
DATA ACCESS METHODS
38,978
public static Iterable < String > renderSolutionTable ( final List < String > variables , final Iterable < ? extends BindingSet > solutions ) { final List < String > actualVariables ; if ( variables != null ) { actualVariables = ImmutableList . copyOf ( variables ) ; } else { final Set < String > variableSet = Sets . newHashSet ( ) ; for ( final BindingSet solution : solutions ) { variableSet . addAll ( solution . getBindingNames ( ) ) ; } actualVariables = Ordering . natural ( ) . sortedCopy ( variableSet ) ; } final int width = 75 / actualVariables . size ( ) ; final StringBuilder builder = new StringBuilder ( ) ; builder . append ( "<table class=\"sparql table table-condensed tablesorter\"><thead>\n<tr>" ) ; for ( final String variable : actualVariables ) { builder . append ( "<th style=\"width: " ) . append ( width ) . append ( "%\">" ) . append ( escapeHtml ( variable ) ) . append ( "</th>" ) ; } final Iterable < String > header = ImmutableList . of ( builder . toString ( ) ) ; final Iterable < String > footer = ImmutableList . of ( "</tbody></table>" ) ; final Function < BindingSet , String > renderer = new Function < BindingSet , String > ( ) { public String apply ( final BindingSet bindings ) { if ( Thread . interrupted ( ) ) { throw new IllegalStateException ( "Interrupted" ) ; } final StringBuilder builder = new StringBuilder ( ) ; builder . append ( "<tr>" ) ; for ( final String variable : actualVariables ) { builder . append ( "<td>" ) ; try { render ( bindings . getValue ( variable ) , builder ) ; } catch ( final IOException ex ) { throw new Error ( ex ) ; } builder . append ( "</td>" ) ; } builder . append ( "</tr>\n" ) ; return builder . toString ( ) ; } } ; return Iterables . concat ( header , Iterables . transform ( solutions , renderer ) , footer ) ; }
Render in a streaming - way the solutions of a SPARQL SELECT query to an HTML table emitting an iterable with of HTML fragments .
38,979
public static String escapeHtml ( final Object object ) { return object == null ? null : HtmlEscapers . htmlEscaper ( ) . escape ( object . toString ( ) ) ; }
Transforms the supplied object to an escaped HTML string .
38,980
public void processPut ( Record record , String tabName , String famName , String quaName ) { logger . debug ( "NATIVE Begin processPut(" + record + ", " + tabName + ")" ) ; HTable hTable = getTable ( tabName ) ; try { Put op = createPut ( record , tabName , famName , quaName ) ; hTable . put ( op ) ; } catch ( IOException e ) { logger . error ( "Error while attempting to perform operations at HBaseDataTransactions." ) ; logger . error ( e . getMessage ( ) ) ; } }
Process put operations on an HBase table .
38,981
public void processDelete ( URI id , String tabName , String famName , String quaName ) { logger . debug ( "NATIVE Begin processDelete(" + id + ", " + tabName + ")" ) ; HTable hTable = getTable ( tabName ) ; try { Delete op = createDelete ( id , tabName ) ; hTable . delete ( op ) ; } catch ( IOException e ) { logger . error ( "Error while attempting to perform operations at HBaseDataTransactions." ) ; logger . error ( e . getMessage ( ) ) ; } }
Process delete operations on an HBase table .
38,982
public Put createPut ( Record record , String tableName , String famName , String quaName ) throws IOException { HTable hTable = getTable ( tableName ) ; Put put = null ; if ( hTable != null ) { AvroSerializer serializer = getSerializer ( ) ; final byte [ ] bytes = serializer . toBytes ( record ) ; put = new Put ( Bytes . toBytes ( record . getID ( ) . toString ( ) ) ) ; put . add ( Bytes . toBytes ( famName ) , Bytes . toBytes ( quaName ) , bytes ) ; } return put ; }
Creates puts for HBase
38,983
public List < Object > checkForErrors ( Object [ ] objs ) { List < Object > errors = new ArrayList < Object > ( ) ; if ( objs != null ) { for ( int cont = 0 ; cont < objs . length ; cont ++ ) { if ( objs [ cont ] == null ) { logger . debug ( "A operation could not be performed." ) ; errors . add ( objs [ cont ] ) ; } } } return errors ; }
Checking for errors after operations have been processed .
38,984
protected IEncoder getAppliedEncoder ( DataUrlEncoding encoding ) { switch ( encoding ) { case BASE64 : return base64Encoder ; case URL : return urlEncodedEncoder ; } throw new IllegalArgumentException ( ) ; }
Get the matching encoder for the given encoding
38,985
private static byte [ ] pad ( byte [ ] in ) { final byte [ ] result = Arrays . copyOf ( in , 16 ) ; new ISO7816d4Padding ( ) . addPadding ( result , in . length ) ; return result ; }
First bit 1 following bits 0 .
38,986
public static void shallowCopyFieldState ( final Object src , final Object dest ) { if ( src == null ) { throw new IllegalArgumentException ( "Source for field copy cannot be null" ) ; } if ( dest == null ) { throw new IllegalArgumentException ( "Destination for field copy cannot be null" ) ; } if ( ! src . getClass ( ) . isAssignableFrom ( dest . getClass ( ) ) ) { throw new IllegalArgumentException ( "Destination class [" + dest . getClass ( ) . getName ( ) + "] must be same or subclass as source class [" + src . getClass ( ) . getName ( ) + "]" ) ; } doWithFields ( src . getClass ( ) , new FieldCallback ( ) { public void doWith ( Field field ) throws IllegalArgumentException , IllegalAccessException { makeAccessible ( field ) ; Object srcValue = field . get ( src ) ; field . set ( dest , srcValue ) ; } } , COPYABLE_FIELDS ) ; }
Given the source object and the destination which must be the same class or a subclass copy all fields including inherited fields . Designed to work on objects with public no - arg constructors .
38,987
public static Object [ ] insertArray ( Object obj , Object [ ] arr ) { Object [ ] newArr = new Object [ arr . length + 1 ] ; System . arraycopy ( arr , 0 , newArr , 1 , arr . length ) ; newArr [ 0 ] = obj ; return newArr ; }
Insert an Object at front of array
38,988
public static Object [ ] appendArray ( Object [ ] arr , Object obj ) { Object [ ] newArr = new Object [ arr . length + 1 ] ; System . arraycopy ( arr , 0 , newArr , 0 , arr . length ) ; newArr [ arr . length ] = obj ; return newArr ; }
Append an Object at end of array
38,989
public static String [ ] appendStrArray ( String [ ] arr , String str ) { String [ ] newArr = new String [ arr . length + 1 ] ; System . arraycopy ( arr , 0 , newArr , 0 , arr . length ) ; newArr [ arr . length ] = str ; return newArr ; }
Append a String at end of String array
38,990
public static List < String > strArrayToList ( String [ ] arr ) { List < String > result = new ArrayList < String > ( ) ; if ( arr == null || arr . length == 0 ) return result ; for ( String str : arr ) result . add ( str ) ; return result ; }
Transfer a String array to String List
38,991
public static String [ ] strListToArray ( List < String > list ) { if ( list == null ) return new String [ 0 ] ; return list . toArray ( new String [ list . size ( ) ] ) ; }
Transfer a String List to String array
38,992
public static boolean isReservedWord ( Dialect dialect , String word ) { if ( ! isReservedWord ( word ) ) return false ; String fitDatabases = RESERVED_WORDS . get ( word . toUpperCase ( ) ) . toUpperCase ( ) ; if ( fitDatabases . contains ( "ANSI" ) ) return true ; String dia = dialect . toString ( ) . replace ( "Dialect" , "" ) . toUpperCase ( ) ; if ( dia . length ( ) >= 4 ) dia = dia . substring ( 0 , 4 ) ; return ( fitDatabases . contains ( dia ) ) ; }
Check if is a dialect reserved word of ANSI - SQL reserved word
38,993
public static boolean isReservedWord ( String word ) { return ! StrUtils . isEmpty ( word ) && RESERVED_WORDS . containsKey ( word . toUpperCase ( ) ) ; }
Check if is a reserved word of any database
38,994
public static Dialect guessDialect ( DataSource dataSource ) { Dialect result = dataSourceDialectCache . get ( dataSource ) ; if ( result != null ) return result ; Connection con = null ; try { con = dataSource . getConnection ( ) ; result = guessDialect ( con ) ; if ( result == null ) return ( Dialect ) DialectException . throwEX ( "Can not get dialect from DataSource, please submit this bug." ) ; dataSourceDialectCache . put ( dataSource , result ) ; return result ; } catch ( SQLException e ) { return ( Dialect ) DialectException . throwEX ( e ) ; } finally { try { if ( con != null && ! con . isClosed ( ) ) { try { con . close ( ) ; } catch ( SQLException e ) { DialectException . throwEX ( e ) ; } } } catch ( SQLException e ) { DialectException . throwEX ( e ) ; } } }
Guess dialect based on given dataSource
38,995
public static int indexOfIgnoreCase ( final String str , final String searchStr ) { if ( searchStr . isEmpty ( ) || str . isEmpty ( ) ) { return str . indexOf ( searchStr ) ; } for ( int i = 0 ; i < str . length ( ) ; ++ i ) { if ( i + searchStr . length ( ) > str . length ( ) ) { return - 1 ; } int j = 0 ; int ii = i ; while ( ii < str . length ( ) && j < searchStr . length ( ) ) { char c = Character . toLowerCase ( str . charAt ( ii ) ) ; char c2 = Character . toLowerCase ( searchStr . charAt ( j ) ) ; if ( c != c2 ) { break ; } j ++ ; ii ++ ; } if ( j == searchStr . length ( ) ) { return i ; } } return - 1 ; }
Return first postion ignore case return - 1 if not found
38,996
public static int lastIndexOfIgnoreCase ( String str , String searchStr ) { if ( searchStr . isEmpty ( ) || str . isEmpty ( ) ) return - 1 ; return str . toLowerCase ( ) . lastIndexOf ( searchStr . toLowerCase ( ) ) ; }
Return last sub - String position ignore case return - 1 if not found
38,997
public static boolean arraysEqual ( Object [ ] array1 , Object [ ] array2 ) { if ( array1 == null || array1 . length == 0 || array2 == null || array2 . length == 0 ) DialectException . throwEX ( "StrUtils arraysEqual() method can not compare empty arrays" ) ; for ( int i = 0 ; array1 != null && array2 != null && i < array1 . length ; i ++ ) if ( ! array1 [ i ] . equals ( array2 [ i ] ) ) return false ; return true ; }
Compare 2 array
38,998
public static String toLowerCaseFirstOne ( String s ) { if ( Character . isLowerCase ( s . charAt ( 0 ) ) ) return s ; else return ( new StringBuilder ( ) ) . append ( Character . toLowerCase ( s . charAt ( 0 ) ) ) . append ( s . substring ( 1 ) ) . toString ( ) ; }
First letter change to lower
38,999
public static String toUpperCaseFirstOne ( String s ) { if ( Character . isUpperCase ( s . charAt ( 0 ) ) ) return s ; else return ( new StringBuilder ( ) ) . append ( Character . toUpperCase ( s . charAt ( 0 ) ) ) . append ( s . substring ( 1 ) ) . toString ( ) ; }
First letter change to capitalised