idx
int64
0
41.2k
question
stringlengths
74
4.21k
target
stringlengths
5
888
3,800
public static Object buildGenericType ( final Class < ? > mainClass , final Class < ? > assignableClass , final Object ... parameters ) throws CoreException { return buildGenericType ( mainClass , new Class < ? > [ ] { assignableClass } , parameters ) ; }
Build the nth generic type of a class .
3,801
public static Object buildGenericType ( final Class < ? > mainClass , final Class < ? > [ ] assignableClasses , final Object ... constructorParameters ) throws CoreException { Class < ? > genericClass = null ; final Class < ? > [ ] constructorParameterTypes = new Class < ? > [ constructorParameters . length ] ; try { int i = 0 ; for ( final Object obj : constructorParameters ) { constructorParameterTypes [ i ] = obj . getClass ( ) ; i ++ ; } genericClass = findGenericClass ( mainClass , assignableClasses ) ; final Constructor < ? > constructor = getConstructor ( genericClass , constructorParameterTypes ) ; return constructor . newInstance ( constructorParameters ) ; } catch ( InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | SecurityException e ) { final StringBuilder sb = new StringBuilder ( "[" ) ; for ( final Class < ? > assignableClass : assignableClasses ) { sb . append ( assignableClass . getName ( ) ) . append ( ", " ) ; } sb . append ( "]" ) ; if ( genericClass == null ) { LOGGER . log ( GENERIC_TYPE_ERROR_1 , e , sb . toString ( ) , mainClass . getName ( ) ) ; } else { LOGGER . log ( GENERIC_TYPE_ERROR_2 , e , genericClass . getName ( ) , mainClass . getName ( ) ) ; } if ( e instanceof IllegalArgumentException ) { LOGGER . log ( ARGUMENT_LIST ) ; for ( int i = 0 ; i < constructorParameterTypes . length ; i ++ ) { LOGGER . log ( ARGUMENT_DETAIL , constructorParameterTypes [ i ] . toString ( ) , constructorParameters [ i ] . toString ( ) ) ; } } if ( genericClass == null ) { throw new CoreException ( GENERIC_TYPE_ERROR_1 . getText ( sb . toString ( ) , mainClass . getName ( ) ) , e ) ; } else { throw new CoreException ( GENERIC_TYPE_ERROR_2 . getText ( genericClass . getName ( ) , mainClass . getName ( ) ) , e ) ; } } }
Build the generic type according to assignable class .
3,802
public static Object findAndBuildGenericType ( final Class < ? > mainClass , final Class < ? > assignableClass , final Class < ? > excludedClass , final Object ... parameters ) throws CoreException { Object object = null ; final Class < ? > objectClass = ClassUtility . findGenericClass ( mainClass , assignableClass ) ; if ( objectClass != null && ( excludedClass == null || ! excludedClass . equals ( objectClass ) ) ) { object = buildGenericType ( mainClass , new Class < ? > [ ] { assignableClass } , parameters ) ; } return object ; }
Find and Build the generic type according to assignable and excluded classes .
3,803
private static Constructor < ? > getConstructor ( final Class < ? > genericClass , final Class < ? > [ ] constructorParameterTypes ) { Constructor < ? > constructor = null ; try { constructor = genericClass . getConstructor ( constructorParameterTypes ) ; } catch ( final NoSuchMethodException e ) { constructor = genericClass . getConstructors ( ) [ 0 ] ; } catch ( final SecurityException e ) { LOGGER . log ( NO_CONSTRUCTOR , e ) ; throw e ; } return constructor ; }
Retrieve the constructor of a Type .
3,804
public static String underscoreToCamelCase ( final String undescoredString ) { final String [ ] parts = undescoredString . split ( CASE_SEPARATOR ) ; final StringBuilder camelCaseString = new StringBuilder ( undescoredString . length ( ) ) ; camelCaseString . append ( parts [ 0 ] . toLowerCase ( Locale . getDefault ( ) ) ) ; for ( int i = 1 ; i < parts . length ; i ++ ) { camelCaseString . append ( parts [ i ] . substring ( 0 , 1 ) . toUpperCase ( Locale . getDefault ( ) ) ) ; camelCaseString . append ( parts [ i ] . substring ( 1 ) . toLowerCase ( Locale . getDefault ( ) ) ) ; } return camelCaseString . toString ( ) ; }
Convert A_STRING_UNDESCORED into aStringUnderscored .
3,805
public static String camelCaseToUnderscore ( final String camelCaseString ) { final StringBuilder sb = new StringBuilder ( ) ; for ( final String camelPart : camelCaseString . split ( "(?<!(^|[A-Z]))(?=[A-Z])|(?<!^)(?=[A-Z][a-z])" ) ) { if ( sb . length ( ) > 0 ) { sb . append ( CASE_SEPARATOR ) ; } sb . append ( camelPart . toUpperCase ( Locale . getDefault ( ) ) ) ; } return sb . toString ( ) ; }
Convert aStringUnderscored into A_STRING_UNDESCORED .
3,806
public static Method getMethodByName ( final Class < ? > cls , final String action ) throws NoSuchMethodException { for ( final Method m : cls . getMethods ( ) ) { if ( m . getName ( ) . equals ( action ) ) { return m ; } } throw new NoSuchMethodException ( action ) ; }
Return the method that exactly match the action name . The name must be unique into the class .
3,807
public static List < Field > retrievePropertyList ( final Class < ? > cls ) { final List < Field > propertyList = new ArrayList < > ( ) ; for ( final Field f : cls . getFields ( ) ) { propertyList . add ( f ) ; } return propertyList ; }
List all properties for the given class .
3,808
public static Field findProperty ( final Class < ? > sourceClass , final String itemName , final Class < ? > searchedClass ) { Field found = null ; if ( itemName != null && ! itemName . trim ( ) . isEmpty ( ) ) { try { found = sourceClass . getField ( ClassUtility . underscoreToCamelCase ( itemName ) ) ; } catch ( NoSuchFieldException | SecurityException e ) { found = null ; } } if ( found == null ) { Field f = null ; for ( int i = 0 ; found == null && i < sourceClass . getFields ( ) . length ; i ++ ) { f = sourceClass . getFields ( ) [ i ] ; if ( f . getClass ( ) . equals ( searchedClass ) ) { found = f ; } } } return found ; }
Retrieve a field according to the item name first then according to searched class .
3,809
public static List < Method > retrieveMethodList ( final Class < ? > cls , final String methodName ) { final List < Method > methodList = new ArrayList < > ( ) ; final String camelCasedMethodName = underscoreToCamelCase ( methodName ) ; for ( final Method m : cls . getMethods ( ) ) { if ( m . getName ( ) . equals ( camelCasedMethodName ) || m . getName ( ) . equals ( methodName ) ) { methodList . add ( m ) ; } } return methodList ; }
Check if the given method exists in the given class .
3,810
public static Class < ? > getClassFromType ( final Type type ) { Class < ? > returnClass = null ; if ( type instanceof Class < ? > ) { returnClass = ( Class < ? > ) type ; } else if ( type instanceof ParameterizedType ) { returnClass = getClassFromType ( ( ( ParameterizedType ) type ) . getRawType ( ) ) ; } return returnClass ; }
Return the Class object for the given type .
3,811
public static Object getAnnotationAttribute ( final Annotation annotation , final String attributeName ) { Object object = null ; try { final Method attributeMethod = annotation . annotationType ( ) . getDeclaredMethod ( attributeName ) ; object = attributeMethod . invoke ( annotation ) ; } catch ( NoSuchMethodException | SecurityException e ) { LOGGER . log ( NO_ANNOTATION_PROPERTY , e , attributeName ) ; } catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) { LOGGER . log ( NO_ANNOTATION_PROPERTY_VALUE , e , attributeName ) ; } return object ; }
Retrieve an annotation property dynamically by reflection .
3,812
@ SuppressWarnings ( "unchecked" ) public static Class < ? extends Application > getClassFromStaticMethod ( final int classDeepLevel ) { Class < ? extends Application > clazz = null ; try { clazz = ( Class < ? extends Application > ) Class . forName ( Thread . currentThread ( ) . getStackTrace ( ) [ classDeepLevel ] . getClassName ( ) ) ; } catch ( final ClassNotFoundException e ) { clazz = null ; } return clazz ; }
Return the class used by the Nth level of the current call stack .
3,813
public static Object callMethod ( final Method method , final Object instance , final Object ... parameters ) throws CoreException { Object res = null ; try { final boolean accessible = method . isAccessible ( ) ; method . setAccessible ( true ) ; res = method . invoke ( instance , parameters ) ; method . setAccessible ( accessible ) ; } catch ( IllegalAccessException | InvocationTargetException | IllegalArgumentException e ) { final String methodName = instance . getClass ( ) . getSimpleName ( ) + "." + method . getName ( ) ; throw new CoreException ( "Impossible to call method " + methodName , e ) ; } return res ; }
Call the given method for the instance object even if its visibility is private or protected .
3,814
public static void setFieldValue ( final Field field , final Object instance , final Object value ) throws CoreException { try { final boolean accessible = field . isAccessible ( ) ; field . setAccessible ( true ) ; field . set ( instance , value ) ; field . setAccessible ( accessible ) ; } catch ( IllegalAccessException | IllegalArgumentException e ) { throw new CoreException ( e ) ; } }
Update an object field even if it has a private or protected visibility .
3,815
public static Object getFieldValue ( final Field field , final Object instance ) throws CoreRuntimeException { Object value = null ; try { final boolean accessible = field . isAccessible ( ) ; field . setAccessible ( true ) ; value = field . get ( instance ) ; field . setAccessible ( accessible ) ; } catch ( IllegalAccessException | IllegalArgumentException e ) { throw new CoreRuntimeException ( e ) ; } return value ; }
Retrieve an object field even if it has a private or protected visibility .
3,816
public static Class < ? > getGenericClassAssigned ( final Class < ? > fromClass , final Class < ? > typeSearched ) { Class < ? > realType = null ; final Type superType = fromClass . getGenericSuperclass ( ) ; realType = searchIntoParameterzedType ( superType , typeSearched ) ; if ( realType == null ) { for ( final Type api : fromClass . getGenericInterfaces ( ) ) { realType = searchIntoParameterzedType ( api , typeSearched ) ; } } if ( realType == null && superType instanceof Class < ? > ) { realType = getGenericClassAssigned ( ( Class < ? > ) superType , typeSearched ) ; } if ( realType == null ) { for ( final Type api : fromClass . getGenericInterfaces ( ) ) { if ( api instanceof Class < ? > ) { realType = getGenericClassAssigned ( ( Class < ? > ) api , typeSearched ) ; } } } return realType ; }
Return the first generic type of the hierarchy that can be assigned to the type searched .
3,817
private static Class < ? > searchIntoParameterzedType ( final Type superType , final Class < ? > typeSearched ) { if ( superType instanceof ParameterizedType ) { for ( final Type genericType : ( ( ParameterizedType ) superType ) . getActualTypeArguments ( ) ) { if ( genericType instanceof Class < ? > && typeSearched . isAssignableFrom ( ( Class < ? > ) genericType ) ) { return ( Class < ? > ) genericType ; } else if ( genericType instanceof ParameterizedType && typeSearched . isAssignableFrom ( ( Class < ? > ) ( ( ParameterizedType ) genericType ) . getRawType ( ) ) ) { return ( Class < ? > ) ( ( ParameterizedType ) genericType ) . getRawType ( ) ; } } } return null ; }
Extract the searched type from a ParamterizedType .
3,818
public Middleware init ( final Yoke yoke , final String mount ) { if ( initialized ) { throw new RuntimeException ( "Already Initialized!" ) ; } this . yoke = yoke ; this . mount = mount ; this . initialized = true ; return this ; }
Initializes the middleware . This methos is called from Yoke once a middleware is added to the chain .
3,819
public String getUrl ( ) { final StringBuilder sb = new StringBuilder ( ) ; sb . append ( secured ( ) ? "https://" : "http://" ) . append ( website ( ) ) . append ( path ( ) ) . append ( name ( ) ) . append ( extension ( ) ) ; return sb . toString ( ) ; }
Build the image url .
3,820
private Region getRootPane ( final StageWaveBean swb ) { return swb . rootPane ( ) == null ? new StackPane ( ) : swb . rootPane ( ) ; }
Gets the root pane .
3,821
private Scene getScene ( final StageWaveBean swb , final Region region ) { Scene scene = swb . scene ( ) ; if ( scene == null ) { scene = new Scene ( region ) ; } else { scene . setRoot ( region ) ; } return scene ; }
Gets the scene .
3,822
private Stage getStage ( final StageWaveBean swb , final Scene scene ) { Stage stage = swb . stage ( ) ; if ( stage == null ) { stage = new Stage ( ) ; } stage . setScene ( scene ) ; return stage ; }
Gets the stage .
3,823
public static boolean canProcessAnnotation ( final Class < ? extends Component < ? > > componentClass ) { final SkipAnnotation skip = ClassUtility . getLastClassAnnotation ( componentClass , SkipAnnotation . class ) ; return ! ( skip == null || skip . value ( ) ) ; }
Check if annotation can be processed for the given class .
3,824
private static void injectComponent ( final Component < ? > component , final boolean inner ) { for ( final Field field : ClassUtility . getAnnotatedFields ( component . getClass ( ) , Link . class ) ) { final String keyPart = field . getAnnotation ( Link . class ) . value ( ) ; if ( inner ) { if ( InnerComponent . class . isAssignableFrom ( field . getType ( ) ) ) { if ( keyPart . isEmpty ( ) ) { injectInnerComponent ( component , field ) ; } else { injectInnerComponent ( component , field , keyPart ) ; } } } else { if ( Component . class . isAssignableFrom ( field . getType ( ) ) ) { if ( keyPart . isEmpty ( ) ) { injectComponent ( component , field ) ; } else { injectComponent ( component , field , keyPart ) ; } } } } }
Inject component .
3,825
@ SuppressWarnings ( "unchecked" ) private static void injectComponent ( final FacadeReady < ? > component , final Field field , final Object ... keyParts ) { try { if ( Command . class . isAssignableFrom ( field . getType ( ) ) ) { ClassUtility . setFieldValue ( field , component , component . localFacade ( ) . globalFacade ( ) . commandFacade ( ) . retrieve ( ( Class < Command > ) field . getType ( ) , keyParts ) ) ; } else if ( Service . class . isAssignableFrom ( field . getType ( ) ) ) { ClassUtility . setFieldValue ( field , component , component . localFacade ( ) . globalFacade ( ) . serviceFacade ( ) . retrieve ( ( Class < Service > ) field . getType ( ) , keyParts ) ) ; } else if ( Model . class . isAssignableFrom ( field . getType ( ) ) ) { ClassUtility . setFieldValue ( field , component , component . localFacade ( ) . globalFacade ( ) . uiFacade ( ) . retrieve ( ( Class < Model > ) field . getType ( ) , keyParts ) ) ; } } catch ( IllegalArgumentException | CoreException e ) { LOGGER . error ( COMPONENT_INJECTION_FAILURE , component . getClass ( ) , e ) ; } }
Inject a component into the property of an other .
3,826
@ SuppressWarnings ( "unchecked" ) private static void injectInnerComponent ( final Component < ? > component , final Field field , final Object ... keyParts ) { final ParameterizedType innerComponentType = ( ParameterizedType ) field . getGenericType ( ) ; final Class < ? > componentType = ( Class < ? > ) innerComponentType . getActualTypeArguments ( ) [ 0 ] ; try { ClassUtility . setFieldValue ( field , component , CBuilder . innerComponent ( ( Class < Command > ) componentType , keyParts ) . host ( component ) ) ; } catch ( IllegalArgumentException | CoreException e ) { LOGGER . error ( COMPONENT_INJECTION_FAILURE , component . getClass ( ) , e ) ; } }
Inject Inner component .
3,827
public static MultiMap < String , Method > defineLifecycleMethod ( final Component < ? > component ) { final MultiMap < String , Method > lifecycleMethod = new MultiMap < > ( ) ; manageLifecycleAnnotation ( component , lifecycleMethod , BeforeInit . class ) ; manageLifecycleAnnotation ( component , lifecycleMethod , AfterInit . class ) ; manageLifecycleAnnotation ( component , lifecycleMethod , OnRelease . class ) ; return lifecycleMethod ; }
Parse all methods to search annotated methods that are attached to a lifecycle phase .
3,828
private static void manageLifecycleAnnotation ( final Component < ? > component , final MultiMap < String , Method > lifecycleMethod , final Class < ? extends Annotation > annotationClass ) { for ( final Method method : ClassUtility . getAnnotatedMethods ( component . getClass ( ) , annotationClass ) ) { lifecycleMethod . add ( annotationClass . getName ( ) , method ) ; } }
Store annotated method related to a lifecycle phase .
3,829
protected static void preloadAndLaunch ( final Class < ? extends Preloader > preloaderClass , final String ... args ) { preloadAndLaunch ( ClassUtility . getClassFromStaticMethod ( 3 ) , preloaderClass , args ) ; }
Launch the Current JavaFX Application with given preloader .
3,830
protected static void preloadAndLaunch ( final Class < ? extends Application > appClass , final Class < ? extends Preloader > preloaderClass , final String ... args ) { LauncherImpl . launchApplication ( appClass , preloaderClass , args ) ; }
Launch the given JavaFX Application with given preloader .
3,831
private void loadConfigurationFiles ( ) { final Configuration conf = ClassUtility . getLastClassAnnotation ( this . getClass ( ) , Configuration . class ) ; ResourceBuilders . PARAMETER_BUILDER . searchConfigurationFiles ( conf . value ( ) , conf . extension ( ) ) ; }
Load all configuration files before showing anything .
3,832
private void loadMessagesFiles ( ) { final Localized local = ClassUtility . getLastClassAnnotation ( this . getClass ( ) , Localized . class ) ; ResourceBuilders . MESSAGE_BUILDER . searchMessagesFiles ( local . value ( ) ) ; }
Load all Messages files before showing anything .
3,833
private void initializeStage ( ) { this . stage . setTitle ( applicationTitle ( ) ) ; final List < Image > stageIcons = stageIcons ( ) ; if ( stageIcons != null && ! stageIcons . isEmpty ( ) ) { this . stage . getIcons ( ) . addAll ( stageIcons ) ; } customizeStage ( this . stage ) ; }
Customize the primary Stage .
3,834
private void initializeScene ( ) { final Stage currentStage = this . stage ; final KeyCode fullKeyCode = fullScreenKeyCode ( ) ; final KeyCode iconKeyCode = iconifiedKeyCode ( ) ; if ( fullKeyCode != null && iconKeyCode != null ) { this . scene . addEventFilter ( KeyEvent . KEY_PRESSED , keyEvent -> { if ( fullKeyCode != null && fullKeyCode == keyEvent . getCode ( ) ) { currentStage . setFullScreen ( ! currentStage . isFullScreen ( ) ) ; keyEvent . consume ( ) ; } else if ( iconKeyCode != null && iconKeyCode == keyEvent . getCode ( ) ) { currentStage . setIconified ( ! currentStage . isIconified ( ) ) ; keyEvent . consume ( ) ; } } ) ; } customizeScene ( this . scene ) ; manageDefaultStyleSheet ( this . scene ) ; }
Initialize the default scene .
3,835
protected void preloadModules ( ) { JRebirthThread . getThread ( ) . getFacade ( ) . componentFactory ( ) . define ( RegistrationPointItemBase . create ( ) . interfaceClass ( ModuleModel . class ) . exclusive ( false ) . reverse ( false ) ) ; final ServiceLoader < ModuleStarter > loader = ServiceLoader . load ( ModuleStarter . class ) ; final List < ModuleStarter > modules = new ArrayList < > ( ) ; loader . iterator ( ) . forEachRemaining ( modules :: add ) ; modules . stream ( ) . sorted ( ( m1 , m2 ) -> - 1 * Integer . compare ( m1 . priority ( ) , m2 . priority ( ) ) ) . forEach ( ModuleStarter :: start ) ; }
Preload Module . xml files .
3,836
protected void addCSS ( final Scene scene , final StyleSheetItem styleSheetItem ) { final URL styleSheetURL = styleSheetItem . get ( ) ; if ( styleSheetURL == null ) { LOGGER . error ( CSS_LOADING_ERROR , styleSheetItem . toString ( ) , ResourceParameters . STYLE_FOLDER . get ( ) ) ; } else { scene . getStylesheets ( ) . add ( styleSheetURL . toExternalForm ( ) ) ; } }
Attach a new CSS file to the scene using the default classloader .
3,837
protected String applicationTitle ( ) { String name = StageParameters . APPLICATION_NAME . get ( ) ; if ( name . contains ( PARAM ) ) { name = name . replace ( PARAM , computeShortClassName ( ) ) ; } final String version = StageParameters . APPLICATION_VERSION . get ( ) ; final StringBuilder sb = new StringBuilder ( name ) ; if ( ! "0.0.0" . equals ( version ) ) { sb . append ( ' ' ) . append ( version ) ; } return sb . toString ( ) ; }
Return the application title .
3,838
protected List < Image > stageIcons ( ) { return StageParameters . APPLICATION_ICONS . get ( ) . stream ( ) . map ( p -> Resources . create ( p ) . get ( ) ) . collect ( Collectors . toList ( ) ) ; }
Return the application stage icon .
3,839
private String computeShortClassName ( ) { String name = this . getClass ( ) . getSimpleName ( ) ; if ( name . endsWith ( APP_SUFFIX_CLASSNAME ) ) { name = name . substring ( 0 , name . indexOf ( APP_SUFFIX_CLASSNAME ) ) ; } return name ; }
Return the application class name without the Application suffix .
3,840
private void manageDefaultStyleSheet ( final Scene scene ) { if ( scene . getStylesheets ( ) . isEmpty ( ) ) { LOGGER . log ( NO_CSS_DEFINED ) ; addCSS ( scene , JRebirthStyles . DEFAULT ) ; } }
Attach default CSS file if none have been previously attached .
3,841
protected final Scene buildScene ( ) throws CoreException { final Scene scene = new Scene ( buildRootPane ( ) , StageParameters . APPLICATION_SCENE_WIDTH . get ( ) , StageParameters . APPLICATION_SCENE_HEIGHT . get ( ) , JRebirthColors . SCENE_BG_COLOR . get ( ) ) ; return scene ; }
Initialize the properties of the scene .
3,842
@ SuppressWarnings ( "unchecked" ) protected P buildRootPane ( ) throws CoreException { this . rootNode = ( P ) ClassUtility . buildGenericType ( this . getClass ( ) , Pane . class ) ; return this . rootNode ; }
Build dynamically the root pane .
3,843
protected void initializeExceptionHandler ( ) { Thread . setDefaultUncaughtExceptionHandler ( getDefaultUncaughtExceptionHandler ( ) ) ; JRebirth . runIntoJAT ( ATTACH_JAT_UEH . getText ( ) , ( ) -> Thread . currentThread ( ) . setUncaughtExceptionHandler ( getJatUncaughtExceptionHandler ( ) ) ) ; JRebirth . runIntoJIT ( ATTACH_JIT_UEH . getText ( ) , ( ) -> Thread . currentThread ( ) . setUncaughtExceptionHandler ( getJitUncaughtExceptionHandler ( ) ) ) ; }
Initialize all Uncaught Exception Handler .
3,844
public static Collection < String > getClasspathResources ( final Pattern searchPattern ) { final List < String > resources = new ArrayList < > ( ) ; final ClassLoader cl = Thread . currentThread ( ) . getContextClassLoader ( ) ; if ( hasJavaWebstartLibrary ( ) && cl instanceof JNLPClassLoaderIf ) { LOGGER . log ( USE_JNLP_CLASSLOADER ) ; final JNLPClassLoaderIf wsLoader = ( JNLPClassLoaderIf ) cl ; for ( final JARDesc jd : wsLoader . getLaunchDesc ( ) . getResources ( ) . getLocalJarDescs ( ) ) { try { final JarFile jarFile = wsLoader . getJarFile ( jd . getLocation ( ) ) ; LOGGER . log ( PARSE_CACHED_JAR_FILE , jarFile . getName ( ) , jd . getLocationString ( ) ) ; resources . addAll ( getResources ( jarFile . getName ( ) , searchPattern , true ) ) ; } catch ( final IOException e ) { LOGGER . log ( CANT_READ_CACHED_JAR_FILE , jd . getLocation ( ) ) ; } } } else { LOGGER . log ( USE_DEFAULT_CLASSLOADER ) ; final String [ ] classpathEntries = CLASSPATH . split ( CLASSPATH_SEPARATOR ) ; for ( final String urlEntry : classpathEntries ) { resources . addAll ( getResources ( urlEntry , searchPattern , false ) ) ; } } Collections . sort ( resources ) ; return resources ; }
Retrieve all resources that match the search pattern from the java . class . path .
3,845
private static boolean hasJavaWebstartLibrary ( ) { boolean hasWebStartLibrary = true ; try { Class . forName ( "com.sun.jnlp.JNLPClassLoaderIf" ) ; } catch ( final ClassNotFoundException e ) { hasWebStartLibrary = false ; } return hasWebStartLibrary ; }
Check that javaws . jar is accessible .
3,846
private static List < String > getResources ( final String classpathEntryPath , final Pattern searchPattern , final boolean cachedJar ) { final List < String > resources = new ArrayList < > ( ) ; final File classpathEntryFile = new File ( classpathEntryPath ) ; if ( classpathEntryFile . isDirectory ( ) ) { resources . addAll ( getResourcesFromDirectory ( classpathEntryFile , searchPattern ) ) ; } else if ( classpathEntryFile . getName ( ) . endsWith ( ".jar" ) || classpathEntryFile . getName ( ) . endsWith ( ".zip" ) || cachedJar ) { resources . addAll ( getResourcesFromJarOrZipFile ( classpathEntryFile , searchPattern ) ) ; } else { LOGGER . log ( RESOURCE_IGNORED , classpathEntryFile . getAbsolutePath ( ) ) ; } return resources ; }
Search all files that match the given Regex pattern .
3,847
private static List < String > getResourcesFromDirectory ( final File directory , final Pattern searchPattern ) { final List < String > resources = new ArrayList < > ( ) ; final File [ ] fileList = directory . listFiles ( ) ; if ( fileList != null && fileList . length > 0 ) { for ( final File file : fileList ) { if ( file . isDirectory ( ) ) { resources . addAll ( getResourcesFromDirectory ( file , searchPattern ) ) ; } else { try { checkResource ( resources , searchPattern , file . getCanonicalPath ( ) ) ; } catch ( final IOException e ) { LOGGER . log ( BAD_CANONICAL_PATH , e ) ; } } } } return resources ; }
Browse a directory to search resources that match the pattern .
3,848
@ SuppressWarnings ( "unchecked" ) private static List < String > getResourcesFromJarOrZipFile ( final File jarOrZipFile , final Pattern searchPattern ) { final List < String > resources = new ArrayList < > ( ) ; try ( ZipFile zf = new ZipFile ( jarOrZipFile ) ; ) { final Enumeration < ZipEntry > e = ( Enumeration < ZipEntry > ) zf . entries ( ) ; while ( e . hasMoreElements ( ) ) { final ZipEntry ze = e . nextElement ( ) ; checkResource ( resources , searchPattern , ze . getName ( ) ) ; } } catch ( final IOException e ) { LOGGER . log ( FILE_UNREADABLE , e ) ; } return resources ; }
Browse the jar content to search resources that match the pattern .
3,849
private static void checkResource ( final List < String > resources , final Pattern searchPattern , final String resourceName ) { if ( searchPattern . matcher ( resourceName ) . matches ( ) ) { resources . add ( resourceName ) ; } }
Check if the resource match the regex .
3,850
public static InputStream loadInputStream ( final String custConfFileName ) { InputStream is = null ; final File resourceFile = new File ( custConfFileName ) ; if ( resourceFile . exists ( ) ) { try { is = new FileInputStream ( resourceFile ) ; } catch ( final FileNotFoundException e ) { } } else { is = Thread . currentThread ( ) . getContextClassLoader ( ) . getResourceAsStream ( custConfFileName ) ; } return is ; }
TRy to load a custom resource file .
3,851
@ SuppressWarnings ( "unchecked" ) private Class < PageEnum > getPageEnumClass ( ) { Class < PageEnum > res = null ; if ( object ( ) != null && object ( ) . pageEnumClass ( ) != null ) { res = ( Class < PageEnum > ) object ( ) . pageEnumClass ( ) ; } else if ( getFirstKeyPart ( ) instanceof Class && PageEnum . class . isAssignableFrom ( ( Class < ? > ) getFirstKeyPart ( ) ) ) { res = ( Class < PageEnum > ) getFirstKeyPart ( ) ; } return res ; }
Returns the page enum class associated to this model .
3,852
private String getStackName ( ) { String res = null ; if ( object ( ) != null && object ( ) . stackName ( ) != null ) { res = object ( ) . stackName ( ) ; } else if ( getFirstKeyPart ( ) instanceof String ) { res = ( String ) getFirstKeyPart ( ) ; } return res ; }
Returns the current stack name associated to this model .
3,853
private void showPage ( final UniqueKey < ? extends Model > pageModelKey , final Wave wave ) { if ( pageModelKey != null && ! pageModelKey . equals ( this . currentModelKey ) ) { LOGGER . info ( "Show Page Model: " + pageModelKey . toString ( ) ) ; final DisplayModelWaveBean waveBean = DisplayModelWaveBean . create ( ) . childrenPlaceHolder ( view ( ) . node ( ) . getChildren ( ) ) . appendChild ( false ) . showModelKey ( pageModelKey ) . hideModelKey ( this . currentModelKey ) ; this . currentModelKey = waveBean . showModelKey ( ) ; if ( wave != null ) { sendWave ( WBuilder . callCommand ( ShowFadingModelCommand . class ) . waveBean ( waveBean ) . relatedWave ( wave ) . addWaveListener ( new RelatedWaveListener ( ) ) ) ; } else { final Wave showWave = WBuilder . callCommand ( ShowFadingModelCommand . class ) . waveBean ( waveBean ) . addDatas ( JRebirthWaves . FORCE_SYNC ) ; getCommand ( ShowFadingModelCommand . class , showWave . wUID ( ) ) . run ( showWave ) ; } } else { LOGGER . debug ( "Page Model currently displayed: " + pageModelKey . toString ( ) ) ; } }
Private method used to show another page .
3,854
final void parseRange ( String range ) { if ( range == null ) { throw new IllegalArgumentException ( "Invalid IP range" ) ; } int index = range . indexOf ( '/' ) ; String subnetStr = null ; if ( index == - 1 ) { ipAddress = new IPAddress ( range ) ; } else { ipAddress = new IPAddress ( range . substring ( 0 , index ) ) ; subnetStr = range . substring ( index + 1 ) ; } try { if ( subnetStr != null ) { extendedNetworkPrefix = Integer . parseInt ( subnetStr ) ; if ( ( extendedNetworkPrefix < 0 ) || ( extendedNetworkPrefix > 32 ) ) { throw new IllegalArgumentException ( "Invalid IP range [" + range + "]" ) ; } ipSubnetMask = computeMaskFromNetworkPrefix ( extendedNetworkPrefix ) ; } } catch ( NumberFormatException ex ) { ipSubnetMask = new IPAddress ( subnetStr ) ; extendedNetworkPrefix = computeNetworkPrefixFromMask ( ipSubnetMask ) ; if ( extendedNetworkPrefix == - 1 ) { throw new IllegalArgumentException ( "Invalid IP range [" + range + "]" , ex ) ; } } }
Parse the IP range string representation .
3,855
private int computeNetworkPrefixFromMask ( IPAddress mask ) { int result = 0 ; int tmp = mask . getIPAddress ( ) ; while ( ( tmp & 0x00000001 ) == 0x00000001 ) { result ++ ; tmp = tmp >>> 1 ; } if ( tmp != 0 ) { return - 1 ; } return result ; }
Compute the extended network prefix from the IP subnet mask .
3,856
private IPAddress computeMaskFromNetworkPrefix ( int prefix ) { StringBuilder str = new StringBuilder ( ) ; for ( int i = 0 ; i < 32 ; i ++ ) { if ( i < prefix ) { str . append ( "1" ) ; } else { str . append ( "0" ) ; } } String decimalString = toDecimalString ( str . toString ( ) ) ; return new IPAddress ( decimalString ) ; }
Convert a extended network prefix integer into an IP number .
3,857
public boolean isIPAddressInRange ( IPAddress address ) { if ( ipSubnetMask == null ) { return this . ipAddress . equals ( address ) ; } int result1 = address . getIPAddress ( ) & ipSubnetMask . getIPAddress ( ) ; int result2 = ipAddress . getIPAddress ( ) & ipSubnetMask . getIPAddress ( ) ; return result1 == result2 ; }
Check if the specified IP address is in the encapsulated range .
3,858
final int parseIPAddress ( String ipAddressStr ) { int result = 0 ; if ( ipAddressStr == null ) { throw new IllegalArgumentException ( ) ; } try { String tmp = ipAddressStr ; int offset = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { int index = tmp . indexOf ( '.' ) ; if ( index != - 1 ) { String numberStr = tmp . substring ( 0 , index ) ; int number = Integer . parseInt ( numberStr ) ; if ( ( number < 0 ) || ( number > 255 ) ) { throw new IllegalArgumentException ( "Invalid IP Address [" + ipAddressStr + "]" ) ; } result += number << offset ; offset += 8 ; tmp = tmp . substring ( index + 1 ) ; } else { throw new IllegalArgumentException ( "Invalid IP Address [" + ipAddressStr + "]" ) ; } } if ( tmp . length ( ) > 0 ) { int number = Integer . parseInt ( tmp ) ; if ( ( number < 0 ) || ( number > 255 ) ) { throw new IllegalArgumentException ( "Invalid IP Address [" + ipAddressStr + "]" ) ; } result += number << offset ; ipAddress = result ; } else { throw new IllegalArgumentException ( "Invalid IP Address [" + ipAddressStr + "]" ) ; } } catch ( NoSuchElementException ex ) { throw new IllegalArgumentException ( "Invalid IP Address [" + ipAddressStr + "]" , ex ) ; } catch ( NumberFormatException ex ) { throw new IllegalArgumentException ( "Invalid IP Address [" + ipAddressStr + "]" , ex ) ; } return result ; }
Convert a decimal - dotted notation representation of an IP address into an 32 bits interger value .
3,859
public static void on ( String op , OnListener listener ) { getInstance ( ) . mEvents . add ( new Event ( op , listener ) ) ; }
Connect && Disconnect events
3,860
private void enableDisableView ( View view , boolean enabled ) { view . setEnabled ( enabled ) ; view . setFocusable ( enabled ) ; if ( view instanceof ViewGroup ) { ViewGroup group = ( ViewGroup ) view ; for ( int idx = 0 ; idx < group . getChildCount ( ) ; idx ++ ) { enableDisableView ( group . getChildAt ( idx ) , enabled ) ; } } }
helper method to disable a view and all its subviews
3,861
public Crossfader withStructure ( View first , int firstWidth , View second , int secondWidth ) { withFirst ( first , firstWidth ) ; withSecond ( second , secondWidth ) ; return this ; }
define the default view and the slided view of the crossfader
3,862
public Crossfader withCanSlide ( boolean canSlide ) { this . mCanSlide = canSlide ; if ( mCrossFadeSlidingPaneLayout != null ) { mCrossFadeSlidingPaneLayout . setCanSlide ( mCanSlide ) ; } return this ; }
Allow the panel to slide
3,863
public Crossfader withPanelSlideListener ( SlidingPaneLayout . PanelSlideListener panelSlideListener ) { this . mPanelSlideListener = panelSlideListener ; if ( mCrossFadeSlidingPaneLayout != null ) { mCrossFadeSlidingPaneLayout . setPanelSlideListener ( mPanelSlideListener ) ; } return this ; }
set a PanelSlideListener used with the CrossFadeSlidingPaneLayout
3,864
public Crossfader build ( ) { if ( mFirstWidth < mSecondWidth ) { throw new RuntimeException ( "the first layout has to be the layout with the greater width" ) ; } ViewGroup container = ( ( ViewGroup ) mContent . getParent ( ) ) ; container . removeView ( mContent ) ; mCrossFadeSlidingPaneLayout = ( T ) LayoutInflater . from ( mContent . getContext ( ) ) . inflate ( mBaseLayout , container , false ) ; container . addView ( mCrossFadeSlidingPaneLayout ) ; FrameLayout mCrossFadePanel = ( FrameLayout ) mCrossFadeSlidingPaneLayout . findViewById ( R . id . panel ) ; LinearLayout mCrossFadeFirst = ( LinearLayout ) mCrossFadeSlidingPaneLayout . findViewById ( R . id . first ) ; LinearLayout mCrossFadeSecond = ( LinearLayout ) mCrossFadeSlidingPaneLayout . findViewById ( R . id . second ) ; LinearLayout mCrossFadeContainer = ( LinearLayout ) mCrossFadeSlidingPaneLayout . findViewById ( R . id . content ) ; setWidth ( mCrossFadePanel , mFirstWidth ) ; setWidth ( mCrossFadeFirst , mFirstWidth ) ; setWidth ( mCrossFadeSecond , mSecondWidth ) ; setLeftMargin ( mCrossFadeContainer , mSecondWidth ) ; mCrossFadeFirst . addView ( mFirst , mFirstWidth , ViewGroup . LayoutParams . MATCH_PARENT ) ; mCrossFadeSecond . addView ( mSecond , mSecondWidth , ViewGroup . LayoutParams . MATCH_PARENT ) ; mCrossFadeContainer . addView ( mContent , ViewGroup . LayoutParams . MATCH_PARENT , ViewGroup . LayoutParams . MATCH_PARENT ) ; boolean cross_faded = false ; if ( mSavedInstance != null ) { cross_faded = mSavedInstance . getBoolean ( BUNDLE_CROSS_FADED , false ) ; } if ( cross_faded ) { mCrossFadeSlidingPaneLayout . setOffset ( 1 ) ; } else { mCrossFadeSlidingPaneLayout . setOffset ( 0 ) ; } mCrossFadeSlidingPaneLayout . setPanelSlideListener ( mPanelSlideListener ) ; mCrossFadeSlidingPaneLayout . setCanSlide ( mCanSlide ) ; mCrossFadeSlidingPaneLayout . setSliderFadeColor ( Color . TRANSPARENT ) ; enableResizeContentPanel ( mResizeContentPanel ) ; return this ; }
builds the crossfader and it s content views will define all properties and define and add the layouts
3,865
protected void setWidth ( View view , int width ) { ViewGroup . LayoutParams lp = view . getLayoutParams ( ) ; lp . width = width ; view . setLayoutParams ( lp ) ; }
define the width of the given view
3,866
protected void setLeftMargin ( View view , int leftMargin ) { SlidingPaneLayout . LayoutParams lp = ( SlidingPaneLayout . LayoutParams ) view . getLayoutParams ( ) ; lp . leftMargin = leftMargin ; lp . rightMargin = 0 ; if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . JELLY_BEAN_MR1 ) { lp . setMarginStart ( leftMargin ) ; lp . setMarginEnd ( 0 ) ; } view . setLayoutParams ( lp ) ; }
define the left margin of the given view
3,867
public static boolean isPointInsideView ( float x , float y , View view ) { int location [ ] = new int [ 2 ] ; view . getLocationOnScreen ( location ) ; int viewX = location [ 0 ] ; int viewY = location [ 1 ] ; if ( ( viewX < x && x < ( viewX + view . getWidth ( ) ) ) && ( viewY < y && y < ( viewY + view . getHeight ( ) ) ) ) { return true ; } else { return false ; } }
Determines if given points are inside view
3,868
protected void ensureParentage ( AbstractNode child ) throws IllegalStateException { if ( child . parent == this ) return ; throw new IllegalStateException ( String . format ( "Can't disown child of type %s - it isn't my child (I'm a %s)" , child . getClass ( ) . getName ( ) , this . getClass ( ) . getName ( ) ) ) ; }
Checks if the provided node is a direct child of this node .
3,869
public Mat4 add ( final Mat4 other ) { return new Mat4 ( m00 + other . m00 , m01 + other . m01 , m02 + other . m02 , m03 + other . m03 , m10 + other . m10 , m11 + other . m11 , m12 + other . m12 , m13 + other . m13 , m20 + other . m20 , m21 + other . m21 , m22 + other . m22 , m23 + other . m23 , m30 + other . m30 , m31 + other . m31 , m32 + other . m32 , m33 + other . m33 ) ; }
Add two matrices together and return the result
3,870
public String getOverviewReport ( ) { TreeSet < ReportEntry < V > > topLevelFailed = new TreeSet < ReportEntry < V > > ( ) ; fillReport ( topLevelFailed , rootReport ) ; StringBuilder out = new StringBuilder ( ) ; for ( ReportEntry < V > entry : topLevelFailed ) { if ( entry . getSubSteps ( ) < 100 ) break ; out . append ( formatReport ( entry , false ) ) ; } return out . toString ( ) ; }
Returns a string describing in order of expensiveness the top - level failed rule chains in the parse run .
3,871
public List < String > getExtendedReport ( int topEntries ) { TreeSet < ReportEntry < V > > topLevelFailed = new TreeSet < ReportEntry < V > > ( ) ; fillReport ( topLevelFailed , rootReport ) ; int count = topEntries ; List < String > result = Lists . newArrayList ( ) ; StringBuilder out = new StringBuilder ( ) ; for ( ReportEntry < V > entry : topLevelFailed ) { if ( count -- == 0 ) return result ; out . setLength ( 0 ) ; fillExtendedReport ( out , 0 , entry ) ; result . add ( out . toString ( ) ) ; } return result ; }
Lists the work done by the most expensive failed rules .
3,872
private static double doubleHighPart ( double d ) { if ( d > - Precision . SAFE_MIN && d < Precision . SAFE_MIN ) { return d ; } long xl = Double . doubleToLongBits ( d ) ; xl = xl & MASK_30BITS ; return Double . longBitsToDouble ( xl ) ; }
Get the high order bits from the mantissa . Equivalent to adding and subtracting HEX_40000 but also works for very large numbers
3,873
public static double cosh ( double x ) { if ( x != x ) { return x ; } if ( x > 20 ) { if ( x >= LOG_MAX_VALUE ) { final double t = exp ( 0.5 * x ) ; return ( 0.5 * t ) * t ; } else { return 0.5 * exp ( x ) ; } } else if ( x < - 20 ) { if ( x <= - LOG_MAX_VALUE ) { final double t = exp ( - 0.5 * x ) ; return ( 0.5 * t ) * t ; } else { return 0.5 * exp ( - x ) ; } } final double hiPrec [ ] = new double [ 2 ] ; if ( x < 0.0 ) { x = - x ; } exp ( x , 0.0 , hiPrec ) ; double ya = hiPrec [ 0 ] + hiPrec [ 1 ] ; double yb = - ( ya - hiPrec [ 0 ] - hiPrec [ 1 ] ) ; double temp = ya * HEX_40000000 ; double yaa = ya + temp - temp ; double yab = ya - yaa ; double recip = 1.0 / ya ; temp = recip * HEX_40000000 ; double recipa = recip + temp - temp ; double recipb = recip - recipa ; recipb += ( 1.0 - yaa * recipa - yaa * recipb - yab * recipa - yab * recipb ) * recip ; recipb += - yb * recip * recip ; temp = ya + recipa ; yb += - ( temp - ya - recipa ) ; ya = temp ; temp = ya + recipb ; yb += - ( temp - ya - recipb ) ; ya = temp ; double result = ya + yb ; result *= 0.5 ; return result ; }
Compute the hyperbolic cosine of a number .
3,874
private static double exp ( double x , double extra , double [ ] hiPrec ) { double intPartA ; double intPartB ; int intVal ; if ( x < 0.0 ) { intVal = ( int ) - x ; if ( intVal > 746 ) { if ( hiPrec != null ) { hiPrec [ 0 ] = 0.0 ; hiPrec [ 1 ] = 0.0 ; } return 0.0 ; } if ( intVal > 709 ) { final double result = exp ( x + 40.19140625 , extra , hiPrec ) / 285040095144011776.0 ; if ( hiPrec != null ) { hiPrec [ 0 ] /= 285040095144011776.0 ; hiPrec [ 1 ] /= 285040095144011776.0 ; } return result ; } if ( intVal == 709 ) { final double result = exp ( x + 1.494140625 , extra , hiPrec ) / 4.455505956692756620 ; if ( hiPrec != null ) { hiPrec [ 0 ] /= 4.455505956692756620 ; hiPrec [ 1 ] /= 4.455505956692756620 ; } return result ; } intVal ++ ; intPartA = ExpIntTable . EXP_INT_TABLE_A [ EXP_INT_TABLE_MAX_INDEX - intVal ] ; intPartB = ExpIntTable . EXP_INT_TABLE_B [ EXP_INT_TABLE_MAX_INDEX - intVal ] ; intVal = - intVal ; } else { intVal = ( int ) x ; if ( intVal > 709 ) { if ( hiPrec != null ) { hiPrec [ 0 ] = Double . POSITIVE_INFINITY ; hiPrec [ 1 ] = 0.0 ; } return Double . POSITIVE_INFINITY ; } intPartA = ExpIntTable . EXP_INT_TABLE_A [ EXP_INT_TABLE_MAX_INDEX + intVal ] ; intPartB = ExpIntTable . EXP_INT_TABLE_B [ EXP_INT_TABLE_MAX_INDEX + intVal ] ; } final int intFrac = ( int ) ( ( x - intVal ) * 1024.0 ) ; final double fracPartA = ExpFracTable . EXP_FRAC_TABLE_A [ intFrac ] ; final double fracPartB = ExpFracTable . EXP_FRAC_TABLE_B [ intFrac ] ; final double epsilon = x - ( intVal + intFrac / 1024.0 ) ; double z = 0.04168701738764507 ; z = z * epsilon + 0.1666666505023083 ; z = z * epsilon + 0.5000000000042687 ; z = z * epsilon + 1.0 ; z = z * epsilon + - 3.940510424527919E-20 ; double tempA = intPartA * fracPartA ; double tempB = intPartA * fracPartB + intPartB * fracPartA + intPartB * fracPartB ; final double tempC = tempB + tempA ; final double result ; if ( extra != 0.0 ) { result = tempC * extra * z + tempC * extra + tempC * z + tempB + tempA ; } else { result = tempC * z + tempB + tempA ; } if ( hiPrec != null ) { hiPrec [ 0 ] = tempA ; hiPrec [ 1 ] = tempC * extra * z + tempC * extra + tempC * z + tempB ; } return result ; }
Internal helper method for exponential function .
3,875
public static double log10 ( final double x ) { final double hiPrec [ ] = new double [ 2 ] ; final double lores = log ( x , hiPrec ) ; if ( Double . isInfinite ( lores ) ) { return lores ; } final double tmp = hiPrec [ 0 ] * HEX_40000000 ; final double lna = hiPrec [ 0 ] + tmp - tmp ; final double lnb = hiPrec [ 0 ] - lna + hiPrec [ 1 ] ; final double rln10a = 0.4342944622039795 ; final double rln10b = 1.9699272335463627E-8 ; return rln10b * lnb + rln10b * lna + rln10a * lnb + rln10a * lna ; }
Compute the base 10 logarithm .
3,876
public static double pow ( double d , int e ) { if ( e == 0 ) { return 1.0 ; } else if ( e < 0 ) { e = - e ; d = 1.0 / d ; } final int splitFactor = 0x8000001 ; final double cd = splitFactor * d ; final double d1High = cd - ( cd - d ) ; final double d1Low = d - d1High ; double resultHigh = 1 ; double resultLow = 0 ; double d2p = d ; double d2pHigh = d1High ; double d2pLow = d1Low ; while ( e != 0 ) { if ( ( e & 0x1 ) != 0 ) { final double tmpHigh = resultHigh * d2p ; final double cRH = splitFactor * resultHigh ; final double rHH = cRH - ( cRH - resultHigh ) ; final double rHL = resultHigh - rHH ; final double tmpLow = rHL * d2pLow - ( ( ( tmpHigh - rHH * d2pHigh ) - rHL * d2pHigh ) - rHH * d2pLow ) ; resultHigh = tmpHigh ; resultLow = resultLow * d2p + tmpLow ; } final double tmpHigh = d2pHigh * d2p ; final double cD2pH = splitFactor * d2pHigh ; final double d2pHH = cD2pH - ( cD2pH - d2pHigh ) ; final double d2pHL = d2pHigh - d2pHH ; final double tmpLow = d2pHL * d2pLow - ( ( ( tmpHigh - d2pHH * d2pHigh ) - d2pHL * d2pHigh ) - d2pHH * d2pLow ) ; final double cTmpH = splitFactor * tmpHigh ; d2pHigh = cTmpH - ( cTmpH - tmpHigh ) ; d2pLow = d2pLow * d2p + tmpLow + ( tmpHigh - d2pHigh ) ; d2p = d2pHigh + d2pLow ; e = e >> 1 ; } return resultHigh + resultLow ; }
Raise a double to an int power .
3,877
public static double sin ( double x ) { boolean negative = false ; int quadrant = 0 ; double xa ; double xb = 0.0 ; xa = x ; if ( x < 0 ) { negative = true ; xa = - xa ; } if ( xa == 0.0 ) { long bits = Double . doubleToLongBits ( x ) ; if ( bits < 0 ) { return - 0.0 ; } return 0.0 ; } if ( xa != xa || xa == Double . POSITIVE_INFINITY ) { return Double . NaN ; } if ( xa > 3294198.0 ) { double reduceResults [ ] = new double [ 3 ] ; reducePayneHanek ( xa , reduceResults ) ; quadrant = ( ( int ) reduceResults [ 0 ] ) & 3 ; xa = reduceResults [ 1 ] ; xb = reduceResults [ 2 ] ; } else if ( xa > 1.5707963267948966 ) { final CodyWaite cw = new CodyWaite ( xa ) ; quadrant = cw . getK ( ) & 3 ; xa = cw . getRemA ( ) ; xb = cw . getRemB ( ) ; } if ( negative ) { quadrant ^= 2 ; } switch ( quadrant ) { case 0 : return sinQ ( xa , xb ) ; case 1 : return cosQ ( xa , xb ) ; case 2 : return - sinQ ( xa , xb ) ; case 3 : return - cosQ ( xa , xb ) ; default : return Double . NaN ; } }
Sine function .
3,878
public static double cos ( double x ) { int quadrant = 0 ; double xa = x ; if ( x < 0 ) { xa = - xa ; } if ( xa != xa || xa == Double . POSITIVE_INFINITY ) { return Double . NaN ; } double xb = 0 ; if ( xa > 3294198.0 ) { double reduceResults [ ] = new double [ 3 ] ; reducePayneHanek ( xa , reduceResults ) ; quadrant = ( ( int ) reduceResults [ 0 ] ) & 3 ; xa = reduceResults [ 1 ] ; xb = reduceResults [ 2 ] ; } else if ( xa > 1.5707963267948966 ) { final CodyWaite cw = new CodyWaite ( xa ) ; quadrant = cw . getK ( ) & 3 ; xa = cw . getRemA ( ) ; xb = cw . getRemB ( ) ; } switch ( quadrant ) { case 0 : return cosQ ( xa , xb ) ; case 1 : return - sinQ ( xa , xb ) ; case 2 : return - cosQ ( xa , xb ) ; case 3 : return sinQ ( xa , xb ) ; default : return Double . NaN ; } }
Cosine function .
3,879
public static double tan ( double x ) { boolean negative = false ; int quadrant = 0 ; double xa = x ; if ( x < 0 ) { negative = true ; xa = - xa ; } if ( xa == 0.0 ) { long bits = Double . doubleToLongBits ( x ) ; if ( bits < 0 ) { return - 0.0 ; } return 0.0 ; } if ( xa != xa || xa == Double . POSITIVE_INFINITY ) { return Double . NaN ; } double xb = 0 ; if ( xa > 3294198.0 ) { double reduceResults [ ] = new double [ 3 ] ; reducePayneHanek ( xa , reduceResults ) ; quadrant = ( ( int ) reduceResults [ 0 ] ) & 3 ; xa = reduceResults [ 1 ] ; xb = reduceResults [ 2 ] ; } else if ( xa > 1.5707963267948966 ) { final CodyWaite cw = new CodyWaite ( xa ) ; quadrant = cw . getK ( ) & 3 ; xa = cw . getRemA ( ) ; xb = cw . getRemB ( ) ; } if ( xa > 1.5 ) { final double pi2a = 1.5707963267948966 ; final double pi2b = 6.123233995736766E-17 ; final double a = pi2a - xa ; double b = - ( a - pi2a + xa ) ; b += pi2b - xb ; xa = a + b ; xb = - ( xa - a - b ) ; quadrant ^= 1 ; negative ^= true ; } double result ; if ( ( quadrant & 1 ) == 0 ) { result = tanQ ( xa , xb , false ) ; } else { result = - tanQ ( xa , xb , true ) ; } if ( negative ) { result = - result ; } return result ; }
Tangent function .
3,880
public static double asin ( double x ) { if ( x != x ) { return Double . NaN ; } if ( x > 1.0 || x < - 1.0 ) { return Double . NaN ; } if ( x == 1.0 ) { return Math . PI / 2.0 ; } if ( x == - 1.0 ) { return - Math . PI / 2.0 ; } if ( x == 0.0 ) { return x ; } double temp = x * HEX_40000000 ; final double xa = x + temp - temp ; final double xb = x - xa ; double ya = xa * xa ; double yb = xa * xb * 2.0 + xb * xb ; ya = - ya ; yb = - yb ; double za = 1.0 + ya ; double zb = - ( za - 1.0 - ya ) ; temp = za + yb ; zb += - ( temp - za - yb ) ; za = temp ; double y ; y = sqrt ( za ) ; temp = y * HEX_40000000 ; ya = y + temp - temp ; yb = y - ya ; yb += ( za - ya * ya - 2 * ya * yb - yb * yb ) / ( 2.0 * y ) ; double dx = zb / ( 2.0 * y ) ; double r = x / y ; temp = r * HEX_40000000 ; double ra = r + temp - temp ; double rb = r - ra ; rb += ( x - ra * ya - ra * yb - rb * ya - rb * yb ) / y ; rb += - x * dx / y / y ; temp = ra + rb ; rb = - ( temp - ra - rb ) ; ra = temp ; return atan ( ra , rb , false ) ; }
Compute the arc sine of a number .
3,881
public static double acos ( double x ) { if ( x != x ) { return Double . NaN ; } if ( x > 1.0 || x < - 1.0 ) { return Double . NaN ; } if ( x == - 1.0 ) { return Math . PI ; } if ( x == 1.0 ) { return 0.0 ; } if ( x == 0 ) { return Math . PI / 2.0 ; } double temp = x * HEX_40000000 ; final double xa = x + temp - temp ; final double xb = x - xa ; double ya = xa * xa ; double yb = xa * xb * 2.0 + xb * xb ; ya = - ya ; yb = - yb ; double za = 1.0 + ya ; double zb = - ( za - 1.0 - ya ) ; temp = za + yb ; zb += - ( temp - za - yb ) ; za = temp ; double y = sqrt ( za ) ; temp = y * HEX_40000000 ; ya = y + temp - temp ; yb = y - ya ; yb += ( za - ya * ya - 2 * ya * yb - yb * yb ) / ( 2.0 * y ) ; yb += zb / ( 2.0 * y ) ; y = ya + yb ; yb = - ( y - ya - yb ) ; double r = y / x ; if ( Double . isInfinite ( r ) ) { return Math . PI / 2 ; } double ra = doubleHighPart ( r ) ; double rb = r - ra ; rb += ( y - ra * xa - ra * xb - rb * xa - rb * xb ) / x ; rb += yb / x ; temp = ra + rb ; rb = - ( temp - ra - rb ) ; ra = temp ; return atan ( ra , rb , x < 0 ) ; }
Compute the arc cosine of a number .
3,882
public static double cbrt ( double x ) { long inbits = Double . doubleToLongBits ( x ) ; int exponent = ( int ) ( ( inbits >> 52 ) & 0x7ff ) - 1023 ; boolean subnormal = false ; if ( exponent == - 1023 ) { if ( x == 0 ) { return x ; } subnormal = true ; x *= 1.8014398509481984E16 ; inbits = Double . doubleToLongBits ( x ) ; exponent = ( int ) ( ( inbits >> 52 ) & 0x7ff ) - 1023 ; } if ( exponent == 1024 ) { return x ; } int exp3 = exponent / 3 ; double p2 = Double . longBitsToDouble ( ( inbits & 0x8000000000000000L ) | ( long ) ( ( ( exp3 + 1023 ) & 0x7ff ) ) << 52 ) ; final double mant = Double . longBitsToDouble ( ( inbits & 0x000fffffffffffffL ) | 0x3ff0000000000000L ) ; double est = - 0.010714690733195933 ; est = est * mant + 0.0875862700108075 ; est = est * mant + - 0.3058015757857271 ; est = est * mant + 0.7249995199969751 ; est = est * mant + 0.5039018405998233 ; est *= CBRTTWO [ exponent % 3 + 2 ] ; final double xs = x / ( p2 * p2 * p2 ) ; est += ( xs - est * est * est ) / ( 3 * est * est ) ; est += ( xs - est * est * est ) / ( 3 * est * est ) ; double temp = est * HEX_40000000 ; double ya = est + temp - temp ; double yb = est - ya ; double za = ya * ya ; double zb = ya * yb * 2.0 + yb * yb ; temp = za * HEX_40000000 ; double temp2 = za + temp - temp ; zb += za - temp2 ; za = temp2 ; zb = za * yb + ya * zb + zb * yb ; za = za * ya ; double na = xs - za ; double nb = - ( na - xs + za ) ; nb -= zb ; est += ( na + nb ) / ( 3 * est * est ) ; est *= p2 ; if ( subnormal ) { est *= 3.814697265625E-6 ; } return est ; }
Compute the cubic root of a number .
3,883
public static double toRadians ( double x ) { if ( Double . isInfinite ( x ) || x == 0.0 ) { return x ; } final double facta = 0.01745329052209854 ; final double factb = 1.997844754509471E-9 ; double xa = doubleHighPart ( x ) ; double xb = x - xa ; double result = xb * factb + xb * facta + xa * factb + xa * facta ; if ( result == 0 ) { result = result * x ; } return result ; }
Convert degrees to radians with error of less than 0 . 5 ULP
3,884
public static double toDegrees ( double x ) { if ( Double . isInfinite ( x ) || x == 0.0 ) { return x ; } final double facta = 57.2957763671875 ; final double factb = 3.145894820876798E-6 ; double xa = doubleHighPart ( x ) ; double xb = x - xa ; return xb * factb + xb * facta + xa * factb + xa * facta ; }
Convert radians to degrees with error of less than 0 . 5 ULP
3,885
public static double scalb ( final double d , final int n ) { if ( ( n > - 1023 ) && ( n < 1024 ) ) { return d * Double . longBitsToDouble ( ( ( long ) ( n + 1023 ) ) << 52 ) ; } if ( Double . isNaN ( d ) || Double . isInfinite ( d ) || ( d == 0 ) ) { return d ; } if ( n < - 2098 ) { return ( d > 0 ) ? 0.0 : - 0.0 ; } if ( n > 2097 ) { return ( d > 0 ) ? Double . POSITIVE_INFINITY : Double . NEGATIVE_INFINITY ; } final long bits = Double . doubleToLongBits ( d ) ; final long sign = bits & 0x8000000000000000L ; int exponent = ( ( int ) ( bits >>> 52 ) ) & 0x7ff ; long mantissa = bits & 0x000fffffffffffffL ; int scaledExponent = exponent + n ; if ( n < 0 ) { if ( scaledExponent > 0 ) { return Double . longBitsToDouble ( sign | ( ( ( long ) scaledExponent ) << 52 ) | mantissa ) ; } else if ( scaledExponent > - 53 ) { mantissa = mantissa | ( 1L << 52 ) ; final long mostSignificantLostBit = mantissa & ( 1L << ( - scaledExponent ) ) ; mantissa = mantissa >>> ( 1 - scaledExponent ) ; if ( mostSignificantLostBit != 0 ) { mantissa ++ ; } return Double . longBitsToDouble ( sign | mantissa ) ; } else { return ( sign == 0L ) ? 0.0 : - 0.0 ; } } else { if ( exponent == 0 ) { while ( ( mantissa >>> 52 ) != 1 ) { mantissa = mantissa << 1 ; -- scaledExponent ; } ++ scaledExponent ; mantissa = mantissa & 0x000fffffffffffffL ; if ( scaledExponent < 2047 ) { return Double . longBitsToDouble ( sign | ( ( ( long ) scaledExponent ) << 52 ) | mantissa ) ; } else { return ( sign == 0L ) ? Double . POSITIVE_INFINITY : Double . NEGATIVE_INFINITY ; } } else if ( scaledExponent < 2047 ) { return Double . longBitsToDouble ( sign | ( ( ( long ) scaledExponent ) << 52 ) | mantissa ) ; } else { return ( sign == 0L ) ? Double . POSITIVE_INFINITY : Double . NEGATIVE_INFINITY ; } } }
Multiply a double number by a power of 2 .
3,886
public static float scalb ( final float f , final int n ) { if ( ( n > - 127 ) && ( n < 128 ) ) { return f * Float . intBitsToFloat ( ( n + 127 ) << 23 ) ; } if ( Float . isNaN ( f ) || Float . isInfinite ( f ) || ( f == 0f ) ) { return f ; } if ( n < - 277 ) { return ( f > 0 ) ? 0.0f : - 0.0f ; } if ( n > 276 ) { return ( f > 0 ) ? Float . POSITIVE_INFINITY : Float . NEGATIVE_INFINITY ; } final int bits = Float . floatToIntBits ( f ) ; final int sign = bits & 0x80000000 ; int exponent = ( bits >>> 23 ) & 0xff ; int mantissa = bits & 0x007fffff ; int scaledExponent = exponent + n ; if ( n < 0 ) { if ( scaledExponent > 0 ) { return Float . intBitsToFloat ( sign | ( scaledExponent << 23 ) | mantissa ) ; } else if ( scaledExponent > - 24 ) { mantissa = mantissa | ( 1 << 23 ) ; final int mostSignificantLostBit = mantissa & ( 1 << ( - scaledExponent ) ) ; mantissa = mantissa >>> ( 1 - scaledExponent ) ; if ( mostSignificantLostBit != 0 ) { mantissa ++ ; } return Float . intBitsToFloat ( sign | mantissa ) ; } else { return ( sign == 0 ) ? 0.0f : - 0.0f ; } } else { if ( exponent == 0 ) { while ( ( mantissa >>> 23 ) != 1 ) { mantissa = mantissa << 1 ; -- scaledExponent ; } ++ scaledExponent ; mantissa = mantissa & 0x007fffff ; if ( scaledExponent < 255 ) { return Float . intBitsToFloat ( sign | ( scaledExponent << 23 ) | mantissa ) ; } else { return ( sign == 0 ) ? Float . POSITIVE_INFINITY : Float . NEGATIVE_INFINITY ; } } else if ( scaledExponent < 255 ) { return Float . intBitsToFloat ( sign | ( scaledExponent << 23 ) | mantissa ) ; } else { return ( sign == 0 ) ? Float . POSITIVE_INFINITY : Float . NEGATIVE_INFINITY ; } } }
Multiply a float number by a power of 2 .
3,887
public static double floor ( double x ) { long y ; if ( x != x ) { return x ; } if ( x >= TWO_POWER_52 || x <= - TWO_POWER_52 ) { return x ; } y = ( long ) x ; if ( x < 0 && y != x ) { y -- ; } if ( y == 0 ) { return x * y ; } return y ; }
Get the largest whole number smaller than x .
3,888
public static double ceil ( double x ) { double y ; if ( x != x ) { return x ; } y = floor ( x ) ; if ( y == x ) { return y ; } y += 1.0 ; if ( y == 0 ) { return x * y ; } return y ; }
Get the smallest whole number larger than x .
3,889
public static double rint ( double x ) { double y = floor ( x ) ; double d = x - y ; if ( d > 0.5 ) { if ( y == - 1.0 ) { return - 0.0 ; } return y + 1.0 ; } if ( d < 0.5 ) { return y ; } long z = ( long ) y ; return ( z & 1 ) == 0 ? y : y + 1.0 ; }
Get the whole number that is the nearest to x or the even one if x is exactly half way between two integers .
3,890
private static void resplit ( final double a [ ] ) { final double c = a [ 0 ] + a [ 1 ] ; final double d = - ( c - a [ 0 ] - a [ 1 ] ) ; if ( c < 8e298 && c > - 8e298 ) { double z = c * HEX_40000000 ; a [ 0 ] = ( c + z ) - z ; a [ 1 ] = c - a [ 0 ] + d ; } else { double z = c * 9.31322574615478515625E-10 ; a [ 0 ] = ( c + z - c ) * HEX_40000000 ; a [ 1 ] = c - a [ 0 ] + d ; } }
Recompute a split .
3,891
private static void splitMult ( double a [ ] , double b [ ] , double ans [ ] ) { ans [ 0 ] = a [ 0 ] * b [ 0 ] ; ans [ 1 ] = a [ 0 ] * b [ 1 ] + a [ 1 ] * b [ 0 ] + a [ 1 ] * b [ 1 ] ; resplit ( ans ) ; }
Multiply two numbers in split form .
3,892
private static void splitAdd ( final double a [ ] , final double b [ ] , final double ans [ ] ) { ans [ 0 ] = a [ 0 ] + b [ 0 ] ; ans [ 1 ] = a [ 1 ] + b [ 1 ] ; resplit ( ans ) ; }
Add two numbers in split form .
3,893
static void printarray ( PrintStream out , String name , int expectedLen , double [ ] [ ] array2d ) { out . println ( name ) ; checkLen ( expectedLen , array2d . length ) ; out . println ( TABLE_START_DECL + " " ) ; int i = 0 ; for ( double [ ] array : array2d ) { out . print ( " {" ) ; for ( double d : array ) { out . printf ( "%-25.25s" , format ( d ) ) ; } out . println ( "}, // " + i ++ ) ; } out . println ( TABLE_END_DECL ) ; }
Print an array .
3,894
Rule variableDefinition ( ) { return Sequence ( group . types . type ( ) . label ( "type" ) , variableDefinitionPart ( ) . label ( "head" ) , ZeroOrMore ( Sequence ( Ch ( ',' ) , group . basics . optWS ( ) , variableDefinitionPart ( ) ) . label ( "tail" ) ) , set ( actions . createVariableDefinition ( value ( "type" ) , value ( "head" ) , values ( "ZeroOrMore/tail" ) ) ) ) ; }
Add your own modifiers!
3,895
Rule postfixIncrementExpressionChaining ( ) { return Sequence ( dotNewExpressionChaining ( ) , set ( ) , ZeroOrMore ( Sequence ( FirstOf ( String ( "++" ) , String ( "--" ) ) . label ( "operator" ) , group . basics . optWS ( ) ) . label ( "operatorCt" ) ) , set ( actions . createUnaryPostfixExpression ( value ( ) , nodes ( "ZeroOrMore/operatorCt/operator" ) , texts ( "ZeroOrMore/operatorCt/operator" ) ) ) ) ; }
P2 Technically postfix increment operations are in P2 along with all the unary operators like ~ and ! as well as typecasts . However because ALL of the P2 expression are right - associative the postfix operators can be considered as a higher level of precedence .
3,896
public static int compareTo ( double x , double y , double eps ) { if ( equals ( x , y , eps ) ) { return 0 ; } else if ( x < y ) { return - 1 ; } return 1 ; }
Compares two numbers given some amount of allowed error .
3,897
private void associateJavadoc ( List < Comment > comments , List < Node > nodes ) { final TreeMap < Integer , Node > startPosMap = Maps . newTreeMap ( ) ; for ( Node node : nodes ) node . accept ( new ForwardingAstVisitor ( ) { public boolean visitNode ( Node node ) { if ( node . isGenerated ( ) ) return false ; int startPos = node . getPosition ( ) . getStart ( ) ; Node current = startPosMap . get ( startPos ) ; if ( current == null || ! ( current instanceof JavadocContainer ) ) { startPosMap . put ( startPos , node ) ; } return false ; } } ) ; for ( Comment comment : comments ) { if ( ! comment . isJavadoc ( ) ) continue ; Map < Integer , Node > tailMap = startPosMap . tailMap ( comment . getPosition ( ) . getEnd ( ) ) ; if ( tailMap . isEmpty ( ) ) continue ; Node assoc = tailMap . values ( ) . iterator ( ) . next ( ) ; if ( ! ( assoc instanceof JavadocContainer ) ) continue ; JavadocContainer jc = ( JavadocContainer ) assoc ; if ( jc . rawJavadoc ( ) != null ) { if ( jc . rawJavadoc ( ) . getPosition ( ) . getEnd ( ) >= comment . getPosition ( ) . getEnd ( ) ) continue ; } jc . rawJavadoc ( comment ) ; } }
Associates comments that are javadocs to the node they belong to by checking if the node that immediately follows a javadoc node is a JavadocContainer .
3,898
private boolean gatherComments ( org . parboiled . Node < Node > parsed ) { boolean foundComments = false ; for ( org . parboiled . Node < Node > child : parsed . getChildren ( ) ) { foundComments |= gatherComments ( child ) ; } List < Comment > cmts = registeredComments . get ( parsed ) ; if ( cmts != null ) for ( Comment c : cmts ) { comments . add ( c ) ; return true ; } return foundComments ; }
Delves through the parboiled node tree to find comments .
3,899
public void startTiming ( String label ) { if ( mPerfWriter != null ) mPerfWriter . writeStartTiming ( label ) ; mPerfMeasurement = new Bundle ( ) ; mPerfMeasurement . putParcelableArrayList ( METRIC_KEY_ITERATIONS , new ArrayList < Parcelable > ( ) ) ; mExecTime = SystemClock . uptimeMillis ( ) ; mCpuTime = Process . getElapsedCpuTime ( ) ; }
Start measurement of user and cpu time .