id
int32
0
165k
repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
list
docstring
stringlengths
3
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
105
339
8,500
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClassUtility.java
ClassUtility.camelCaseToUnderscore
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(); }
java
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(); }
[ "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. @param camelCaseString the string to convert @return the underscored string
[ "Convert", "aStringUnderscored", "into", "A_STRING_UNDESCORED", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClassUtility.java#L276-L286
8,501
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClassUtility.java
ClassUtility.getMethodByName
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); }
java
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); }
[ "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. @param cls the class which contain the searched method @param action the name of the method to find @return the method @throws NoSuchMethodException if no method was method
[ "Return", "the", "method", "that", "exactly", "match", "the", "action", "name", ".", "The", "name", "must", "be", "unique", "into", "the", "class", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClassUtility.java#L296-L303
8,502
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClassUtility.java
ClassUtility.retrievePropertyList
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; }
java
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; }
[ "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. @param cls the class to inspect by reflection @return the field list
[ "List", "all", "properties", "for", "the", "given", "class", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClassUtility.java#L312-L318
8,503
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClassUtility.java
ClassUtility.findProperty
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; }
java
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; }
[ "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. @param sourceClass the class to inspect @param itemName the item name to find (LIKE_THIS) @param searchedClass the property class to find if item name query has failed @return the source class field that match provided criterion
[ "Retrieve", "a", "field", "according", "to", "the", "item", "name", "first", "then", "according", "to", "searched", "class", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClassUtility.java#L329-L350
8,504
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClassUtility.java
ClassUtility.retrieveMethodList
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; }
java
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; }
[ "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. @param cls the class to search into @param methodName the name of the method to check (camelCased or in upper case with underscore separator) @return true if the method exists
[ "Check", "if", "the", "given", "method", "exists", "in", "the", "given", "class", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClassUtility.java#L360-L369
8,505
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClassUtility.java
ClassUtility.getClassFromType
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; }
java
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; }
[ "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. @param type the given type to cast into Class @return the Class casted object
[ "Return", "the", "Class", "object", "for", "the", "given", "type", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClassUtility.java#L378-L386
8,506
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClassUtility.java
ClassUtility.getAnnotationAttribute
public static Object getAnnotationAttribute(final Annotation annotation, final String attributeName) { Object object = null; try { // Get the annotation method for the given name final Method attributeMethod = annotation.annotationType().getDeclaredMethod(attributeName); // Call the method to gets the value 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; }
java
public static Object getAnnotationAttribute(final Annotation annotation, final String attributeName) { Object object = null; try { // Get the annotation method for the given name final Method attributeMethod = annotation.annotationType().getDeclaredMethod(attributeName); // Call the method to gets the value 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; }
[ "public", "static", "Object", "getAnnotationAttribute", "(", "final", "Annotation", "annotation", ",", "final", "String", "attributeName", ")", "{", "Object", "object", "=", "null", ";", "try", "{", "// Get the annotation method for the given name", "final", "Method", "attributeMethod", "=", "annotation", ".", "annotationType", "(", ")", ".", "getDeclaredMethod", "(", "attributeName", ")", ";", "// Call the method to gets the value", "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. @param annotation the annotation to explore @param attributeName the name of the method to call @return the property value
[ "Retrieve", "an", "annotation", "property", "dynamically", "by", "reflection", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClassUtility.java#L417-L432
8,507
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClassUtility.java
ClassUtility.getClassFromStaticMethod
@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; }
java
@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; }
[ "@", "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. @param classDeepLevel the deep level to use to find the right class @return the Nth level ancestor class
[ "Return", "the", "class", "used", "by", "the", "Nth", "level", "of", "the", "current", "call", "stack", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClassUtility.java#L441-L450
8,508
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClassUtility.java
ClassUtility.callMethod
public static Object callMethod(final Method method, final Object instance, final Object... parameters) throws CoreException { Object res = null; try { // store current visibility final boolean accessible = method.isAccessible(); // let it accessible anyway method.setAccessible(true); // Call this method with right parameters res = method.invoke(instance, parameters); // Reset default visibility 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; }
java
public static Object callMethod(final Method method, final Object instance, final Object... parameters) throws CoreException { Object res = null; try { // store current visibility final boolean accessible = method.isAccessible(); // let it accessible anyway method.setAccessible(true); // Call this method with right parameters res = method.invoke(instance, parameters); // Reset default visibility 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; }
[ "public", "static", "Object", "callMethod", "(", "final", "Method", "method", ",", "final", "Object", "instance", ",", "final", "Object", "...", "parameters", ")", "throws", "CoreException", "{", "Object", "res", "=", "null", ";", "try", "{", "// store current visibility", "final", "boolean", "accessible", "=", "method", ".", "isAccessible", "(", ")", ";", "// let it accessible anyway", "method", ".", "setAccessible", "(", "true", ")", ";", "// Call this method with right parameters", "res", "=", "method", ".", "invoke", "(", "instance", ",", "parameters", ")", ";", "// Reset default visibility", "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. @param method the method to call @param instance the object instance to use @param parameters the list of method parameters to use @return the method return @throws CoreException if the method call has failed
[ "Call", "the", "given", "method", "for", "the", "instance", "object", "even", "if", "its", "visibility", "is", "private", "or", "protected", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClassUtility.java#L519-L541
8,509
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClassUtility.java
ClassUtility.setFieldValue
public static void setFieldValue(final Field field, final Object instance, final Object value) throws CoreException { try { // store current visibility final boolean accessible = field.isAccessible(); // let it accessible anyway field.setAccessible(true); // Call this method with right parameters field.set(instance, value); // Reset default visibility field.setAccessible(accessible); } catch (IllegalAccessException | IllegalArgumentException e) { throw new CoreException(e); } }
java
public static void setFieldValue(final Field field, final Object instance, final Object value) throws CoreException { try { // store current visibility final boolean accessible = field.isAccessible(); // let it accessible anyway field.setAccessible(true); // Call this method with right parameters field.set(instance, value); // Reset default visibility field.setAccessible(accessible); } catch (IllegalAccessException | IllegalArgumentException e) { throw new CoreException(e); } }
[ "public", "static", "void", "setFieldValue", "(", "final", "Field", "field", ",", "final", "Object", "instance", ",", "final", "Object", "value", ")", "throws", "CoreException", "{", "try", "{", "// store current visibility", "final", "boolean", "accessible", "=", "field", ".", "isAccessible", "(", ")", ";", "// let it accessible anyway", "field", ".", "setAccessible", "(", "true", ")", ";", "// Call this method with right parameters", "field", ".", "set", "(", "instance", ",", "value", ")", ";", "// Reset default visibility", "field", ".", "setAccessible", "(", "accessible", ")", ";", "}", "catch", "(", "IllegalAccessException", "|", "IllegalArgumentException", "e", ")", "{", "throw", "new", "CoreException", "(", "e", ")", ";", "}", "}" ]
Update an object field even if it has a private or protected visibility. @param field the field to update @param instance the object instance that hold this field @param value the value to set into this field @throws CoreException if the new value cannot be set
[ "Update", "an", "object", "field", "even", "if", "it", "has", "a", "private", "or", "protected", "visibility", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClassUtility.java#L552-L570
8,510
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClassUtility.java
ClassUtility.getFieldValue
public static Object getFieldValue(final Field field, final Object instance) throws CoreRuntimeException { Object value = null; try { // store current visibility final boolean accessible = field.isAccessible(); // let it accessible anyway field.setAccessible(true); // Call this method with right parameters value = field.get(instance); // Reset default visibility field.setAccessible(accessible); } catch (IllegalAccessException | IllegalArgumentException e) { throw new CoreRuntimeException(e); } return value; }
java
public static Object getFieldValue(final Field field, final Object instance) throws CoreRuntimeException { Object value = null; try { // store current visibility final boolean accessible = field.isAccessible(); // let it accessible anyway field.setAccessible(true); // Call this method with right parameters value = field.get(instance); // Reset default visibility field.setAccessible(accessible); } catch (IllegalAccessException | IllegalArgumentException e) { throw new CoreRuntimeException(e); } return value; }
[ "public", "static", "Object", "getFieldValue", "(", "final", "Field", "field", ",", "final", "Object", "instance", ")", "throws", "CoreRuntimeException", "{", "Object", "value", "=", "null", ";", "try", "{", "// store current visibility", "final", "boolean", "accessible", "=", "field", ".", "isAccessible", "(", ")", ";", "// let it accessible anyway", "field", ".", "setAccessible", "(", "true", ")", ";", "// Call this method with right parameters", "value", "=", "field", ".", "get", "(", "instance", ")", ";", "// Reset default visibility", "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. @param field the field to update @param instance the object instance that hold this field @return value the value stored into this field @throws CoreException if the new value cannot be set
[ "Retrieve", "an", "object", "field", "even", "if", "it", "has", "a", "private", "or", "protected", "visibility", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClassUtility.java#L582-L601
8,511
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClassUtility.java
ClassUtility.getGenericClassAssigned
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; }
java
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; }
[ "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. @param fromClass the base class hosting the generic type @param typeSearched the searched type, the returned class shall be a subclass of it @return a class that is a subclass of typeSearched or null
[ "Return", "the", "first", "generic", "type", "of", "the", "hierarchy", "that", "can", "be", "assigned", "to", "the", "type", "searched", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClassUtility.java#L611-L638
8,512
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClassUtility.java
ClassUtility.searchIntoParameterzedType
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; }
java
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; }
[ "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. @param superType the base class hosting the generic type @param typeSearched the searched type, the returned class shall be a subclass of it @return the searched type or null
[ "Extract", "the", "searched", "type", "from", "a", "ParamterizedType", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClassUtility.java#L648-L659
8,513
pmlopes/yoke
framework/src/main/java/com/jetdrone/vertx/yoke/Middleware.java
Middleware.init
public Middleware init(@NotNull final Yoke yoke, @NotNull final String mount) { if (initialized) { throw new RuntimeException("Already Initialized!"); } this.yoke = yoke; this.mount = mount; this.initialized = true; return this; }
java
public Middleware init(@NotNull final Yoke yoke, @NotNull final String mount) { if (initialized) { throw new RuntimeException("Already Initialized!"); } this.yoke = yoke; this.mount = mount; this.initialized = true; return this; }
[ "public", "Middleware", "init", "(", "@", "NotNull", "final", "Yoke", "yoke", ",", "@", "NotNull", "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. @param yoke the local Yoke instance. @param mount the configured mount path. @return self
[ "Initializes", "the", "middleware", ".", "This", "methos", "is", "called", "from", "Yoke", "once", "a", "middleware", "is", "added", "to", "the", "chain", "." ]
fe8a64036f09fb745f0644faddd46162d64faf3c
https://github.com/pmlopes/yoke/blob/fe8a64036f09fb745f0644faddd46162d64faf3c/framework/src/main/java/com/jetdrone/vertx/yoke/Middleware.java#L69-L80
8,514
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/resource/image/WebImage.java
WebImage.getUrl
public String getUrl() { final StringBuilder sb = new StringBuilder(); sb.append(secured() ? "https://" : "http://") .append(website()) .append(path()) .append(name()) .append(extension()); return sb.toString(); }
java
public String getUrl() { final StringBuilder sb = new StringBuilder(); sb.append(secured() ? "https://" : "http://") .append(website()) .append(path()) .append(name()) .append(extension()); return sb.toString(); }
[ "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. @return the full image url string
[ "Build", "the", "image", "url", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/resource/image/WebImage.java#L112-L122
8,515
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/service/basic/impl/StageServiceImpl.java
StageServiceImpl.getRootPane
private Region getRootPane(final StageWaveBean swb) { return swb.rootPane() == null ? new StackPane() : swb.rootPane(); }
java
private Region getRootPane(final StageWaveBean swb) { return swb.rootPane() == null ? new StackPane() : swb.rootPane(); }
[ "private", "Region", "getRootPane", "(", "final", "StageWaveBean", "swb", ")", "{", "return", "swb", ".", "rootPane", "(", ")", "==", "null", "?", "new", "StackPane", "(", ")", ":", "swb", ".", "rootPane", "(", ")", ";", "}" ]
Gets the root pane. @param swb the swb the waveBean holding defau!t values @return the root pane
[ "Gets", "the", "root", "pane", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/service/basic/impl/StageServiceImpl.java#L97-L102
8,516
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/service/basic/impl/StageServiceImpl.java
StageServiceImpl.getScene
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; }
java
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; }
[ "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. @param swb the waveBean holding defaut values @param region the region @return the scene
[ "Gets", "the", "scene", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/service/basic/impl/StageServiceImpl.java#L112-L122
8,517
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/service/basic/impl/StageServiceImpl.java
StageServiceImpl.getStage
private Stage getStage(final StageWaveBean swb, final Scene scene) { Stage stage = swb.stage(); if (stage == null) { stage = new Stage(); } stage.setScene(scene); return stage; }
java
private Stage getStage(final StageWaveBean swb, final Scene scene) { Stage stage = swb.stage(); if (stage == null) { stage = new Stage(); } stage.setScene(scene); return stage; }
[ "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. @param swb the waveBean holding default values @param scene the scene @return the stage
[ "Gets", "the", "stage", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/service/basic/impl/StageServiceImpl.java#L132-L141
8,518
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/link/ComponentEnhancer.java
ComponentEnhancer.canProcessAnnotation
public static boolean canProcessAnnotation(final Class<? extends Component<?>> componentClass) { final SkipAnnotation skip = ClassUtility.getLastClassAnnotation(componentClass, SkipAnnotation.class); // No annotation or annotation deactivated ==> skip annotation processing return !(skip == null || skip.value()); }
java
public static boolean canProcessAnnotation(final Class<? extends Component<?>> componentClass) { final SkipAnnotation skip = ClassUtility.getLastClassAnnotation(componentClass, SkipAnnotation.class); // No annotation or annotation deactivated ==> skip annotation processing return !(skip == null || skip.value()); }
[ "public", "static", "boolean", "canProcessAnnotation", "(", "final", "Class", "<", "?", "extends", "Component", "<", "?", ">", ">", "componentClass", ")", "{", "final", "SkipAnnotation", "skip", "=", "ClassUtility", ".", "getLastClassAnnotation", "(", "componentClass", ",", "SkipAnnotation", ".", "class", ")", ";", "// No annotation or annotation deactivated ==> skip annotation processing", "return", "!", "(", "skip", "==", "null", "||", "skip", ".", "value", "(", ")", ")", ";", "}" ]
Check if annotation can be processed for the given class. @param componentClass the class to check @return true if annotation can be processed
[ "Check", "if", "annotation", "can", "be", "processed", "for", "the", "given", "class", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/link/ComponentEnhancer.java#L72-L78
8,519
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/link/ComponentEnhancer.java
ComponentEnhancer.injectComponent
private static void injectComponent(final Component<?> component, final boolean inner) { // Retrieve all fields annotated with Link 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); } } } } }
java
private static void injectComponent(final Component<?> component, final boolean inner) { // Retrieve all fields annotated with Link 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); } } } } }
[ "private", "static", "void", "injectComponent", "(", "final", "Component", "<", "?", ">", "component", ",", "final", "boolean", "inner", ")", "{", "// Retrieve all fields annotated with Link", "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. @param component the component @param inner only manage innercomponent otherwise mange component
[ "Inject", "component", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/link/ComponentEnhancer.java#L104-L128
8,520
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/link/ComponentEnhancer.java
ComponentEnhancer.injectComponent
@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); } }
java
@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); } }
[ "@", "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. @param component the component @param field the field @param keyParts the key parts
[ "Inject", "a", "component", "into", "the", "property", "of", "an", "other", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/link/ComponentEnhancer.java#L137-L152
8,521
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/link/ComponentEnhancer.java
ComponentEnhancer.injectInnerComponent
@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); } }
java
@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); } }
[ "@", "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. @param component the component @param field the field @param keyParts the key parts
[ "Inject", "Inner", "component", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/link/ComponentEnhancer.java#L161-L174
8,522
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/link/ComponentEnhancer.java
ComponentEnhancer.defineLifecycleMethod
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; }
java
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; }
[ "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. @param component the JRebirth component to manage @return the map that store all method that should be call sorted by lifecycle phase
[ "Parse", "all", "methods", "to", "search", "annotated", "methods", "that", "are", "attached", "to", "a", "lifecycle", "phase", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/link/ComponentEnhancer.java#L194-L203
8,523
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/link/ComponentEnhancer.java
ComponentEnhancer.manageLifecycleAnnotation
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)) { // Add a method to the multimap entry // TODO sort lifecycleMethod.add(annotationClass.getName(), method); } }
java
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)) { // Add a method to the multimap entry // TODO sort lifecycleMethod.add(annotationClass.getName(), method); } }
[ "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", ")", ")", "{", "// Add a method to the multimap entry", "// TODO sort", "lifecycleMethod", ".", "add", "(", "annotationClass", ".", "getName", "(", ")", ",", "method", ")", ";", "}", "}" ]
Store annotated method related to a lifecycle phase. @param component the JRebirth component to manage @param lifecycleMethod the map that store methods @param annotationClass the annotation related to lifecycle phase
[ "Store", "annotated", "method", "related", "to", "a", "lifecycle", "phase", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/link/ComponentEnhancer.java#L212-L219
8,524
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/application/AbstractApplication.java
AbstractApplication.preloadAndLaunch
protected static void preloadAndLaunch(final Class<? extends Preloader> preloaderClass, final String... args) { preloadAndLaunch(ClassUtility.getClassFromStaticMethod(3), preloaderClass, args); }
java
protected static void preloadAndLaunch(final Class<? extends Preloader> preloaderClass, final String... args) { preloadAndLaunch(ClassUtility.getClassFromStaticMethod(3), preloaderClass, args); }
[ "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. @param preloaderClass the preloader class used as splash screen with progress @param args arguments passed to java command line
[ "Launch", "the", "Current", "JavaFX", "Application", "with", "given", "preloader", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/application/AbstractApplication.java#L113-L115
8,525
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/application/AbstractApplication.java
AbstractApplication.preloadAndLaunch
protected static void preloadAndLaunch(final Class<? extends Application> appClass, final Class<? extends Preloader> preloaderClass, final String... args) { LauncherImpl.launchApplication(appClass, preloaderClass, args); }
java
protected static void preloadAndLaunch(final Class<? extends Application> appClass, final Class<? extends Preloader> preloaderClass, final String... args) { LauncherImpl.launchApplication(appClass, preloaderClass, args); }
[ "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. @param appClass the JavaFX application class to launch @param preloaderClass the preloader class used as splash screen with progress @param args arguments passed to java command line
[ "Launch", "the", "given", "JavaFX", "Application", "with", "given", "preloader", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/application/AbstractApplication.java#L124-L126
8,526
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/application/AbstractApplication.java
AbstractApplication.loadConfigurationFiles
private void loadConfigurationFiles() { // Parse the first annotation found (manage overriding) final Configuration conf = ClassUtility.getLastClassAnnotation(this.getClass(), Configuration.class); // Conf variable cannot be null because it was defined in this class // It's possible to discard default behaviour by setting an empty string to the value. // launch the configuration search engine ResourceBuilders.PARAMETER_BUILDER.searchConfigurationFiles(conf.value(), conf.extension()); }
java
private void loadConfigurationFiles() { // Parse the first annotation found (manage overriding) final Configuration conf = ClassUtility.getLastClassAnnotation(this.getClass(), Configuration.class); // Conf variable cannot be null because it was defined in this class // It's possible to discard default behaviour by setting an empty string to the value. // launch the configuration search engine ResourceBuilders.PARAMETER_BUILDER.searchConfigurationFiles(conf.value(), conf.extension()); }
[ "private", "void", "loadConfigurationFiles", "(", ")", "{", "// Parse the first annotation found (manage overriding)", "final", "Configuration", "conf", "=", "ClassUtility", ".", "getLastClassAnnotation", "(", "this", ".", "getClass", "(", ")", ",", "Configuration", ".", "class", ")", ";", "// Conf variable cannot be null because it was defined in this class", "// It's possible to discard default behaviour by setting an empty string to the value.", "// launch the configuration search engine", "ResourceBuilders", ".", "PARAMETER_BUILDER", ".", "searchConfigurationFiles", "(", "conf", ".", "value", "(", ")", ",", "conf", ".", "extension", "(", ")", ")", ";", "}" ]
Load all configuration files before showing anything.
[ "Load", "all", "configuration", "files", "before", "showing", "anything", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/application/AbstractApplication.java#L254-L265
8,527
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/application/AbstractApplication.java
AbstractApplication.loadMessagesFiles
private void loadMessagesFiles() { // Parse the first annotation found (manage overriding) final Localized local = ClassUtility.getLastClassAnnotation(this.getClass(), Localized.class); // Conf variable cannot be null because it was defined in this class // It's possible to discard default behavior by setting an empty string to the value. // launch the configuration search engine ResourceBuilders.MESSAGE_BUILDER.searchMessagesFiles(local.value()); }
java
private void loadMessagesFiles() { // Parse the first annotation found (manage overriding) final Localized local = ClassUtility.getLastClassAnnotation(this.getClass(), Localized.class); // Conf variable cannot be null because it was defined in this class // It's possible to discard default behavior by setting an empty string to the value. // launch the configuration search engine ResourceBuilders.MESSAGE_BUILDER.searchMessagesFiles(local.value()); }
[ "private", "void", "loadMessagesFiles", "(", ")", "{", "// Parse the first annotation found (manage overriding)", "final", "Localized", "local", "=", "ClassUtility", ".", "getLastClassAnnotation", "(", "this", ".", "getClass", "(", ")", ",", "Localized", ".", "class", ")", ";", "// Conf variable cannot be null because it was defined in this class", "// It's possible to discard default behavior by setting an empty string to the value.", "// launch the configuration search engine", "ResourceBuilders", ".", "MESSAGE_BUILDER", ".", "searchMessagesFiles", "(", "local", ".", "value", "(", ")", ")", ";", "}" ]
Load all Messages files before showing anything.
[ "Load", "all", "Messages", "files", "before", "showing", "anything", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/application/AbstractApplication.java#L270-L280
8,528
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/application/AbstractApplication.java
AbstractApplication.initializeStage
private void initializeStage() { // Define the stage title this.stage.setTitle(applicationTitle()); // Define stage icons, the toolkit will use the best size final List<Image> stageIcons = stageIcons(); if (stageIcons != null && !stageIcons.isEmpty()) { this.stage.getIcons().addAll(stageIcons); } // and allow customization customizeStage(this.stage); }
java
private void initializeStage() { // Define the stage title this.stage.setTitle(applicationTitle()); // Define stage icons, the toolkit will use the best size final List<Image> stageIcons = stageIcons(); if (stageIcons != null && !stageIcons.isEmpty()) { this.stage.getIcons().addAll(stageIcons); } // and allow customization customizeStage(this.stage); }
[ "private", "void", "initializeStage", "(", ")", "{", "// Define the stage title", "this", ".", "stage", ".", "setTitle", "(", "applicationTitle", "(", ")", ")", ";", "// Define stage icons, the toolkit will use the best size", "final", "List", "<", "Image", ">", "stageIcons", "=", "stageIcons", "(", ")", ";", "if", "(", "stageIcons", "!=", "null", "&&", "!", "stageIcons", ".", "isEmpty", "(", ")", ")", "{", "this", ".", "stage", ".", "getIcons", "(", ")", ".", "addAll", "(", "stageIcons", ")", ";", "}", "// and allow customization", "customizeStage", "(", "this", ".", "stage", ")", ";", "}" ]
Customize the primary Stage.
[ "Customize", "the", "primary", "Stage", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/application/AbstractApplication.java#L340-L352
8,529
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/application/AbstractApplication.java
AbstractApplication.initializeScene
private void initializeScene() { final Stage currentStage = this.stage; final KeyCode fullKeyCode = fullScreenKeyCode(); final KeyCode iconKeyCode = iconifiedKeyCode(); // Attach the handler only if necessary, these 2 method can be overridden to return null if (fullKeyCode != null && iconKeyCode != null) { this.scene.addEventFilter(KeyEvent.KEY_PRESSED, keyEvent -> { // Manage F11 button to switch full screen if (fullKeyCode != null && fullKeyCode == keyEvent.getCode()) { currentStage.setFullScreen(!currentStage.isFullScreen()); keyEvent.consume(); // Manage F10 button to iconify } else if (iconKeyCode != null && iconKeyCode == keyEvent.getCode()) { currentStage.setIconified(!currentStage.isIconified()); keyEvent.consume(); } }); } // The call customize method to allow extension by sub class customizeScene(this.scene); // Add the default Style Sheet if none have been added manageDefaultStyleSheet(this.scene); }
java
private void initializeScene() { final Stage currentStage = this.stage; final KeyCode fullKeyCode = fullScreenKeyCode(); final KeyCode iconKeyCode = iconifiedKeyCode(); // Attach the handler only if necessary, these 2 method can be overridden to return null if (fullKeyCode != null && iconKeyCode != null) { this.scene.addEventFilter(KeyEvent.KEY_PRESSED, keyEvent -> { // Manage F11 button to switch full screen if (fullKeyCode != null && fullKeyCode == keyEvent.getCode()) { currentStage.setFullScreen(!currentStage.isFullScreen()); keyEvent.consume(); // Manage F10 button to iconify } else if (iconKeyCode != null && iconKeyCode == keyEvent.getCode()) { currentStage.setIconified(!currentStage.isIconified()); keyEvent.consume(); } }); } // The call customize method to allow extension by sub class customizeScene(this.scene); // Add the default Style Sheet if none have been added manageDefaultStyleSheet(this.scene); }
[ "private", "void", "initializeScene", "(", ")", "{", "final", "Stage", "currentStage", "=", "this", ".", "stage", ";", "final", "KeyCode", "fullKeyCode", "=", "fullScreenKeyCode", "(", ")", ";", "final", "KeyCode", "iconKeyCode", "=", "iconifiedKeyCode", "(", ")", ";", "// Attach the handler only if necessary, these 2 method can be overridden to return null", "if", "(", "fullKeyCode", "!=", "null", "&&", "iconKeyCode", "!=", "null", ")", "{", "this", ".", "scene", ".", "addEventFilter", "(", "KeyEvent", ".", "KEY_PRESSED", ",", "keyEvent", "->", "{", "// Manage F11 button to switch full screen", "if", "(", "fullKeyCode", "!=", "null", "&&", "fullKeyCode", "==", "keyEvent", ".", "getCode", "(", ")", ")", "{", "currentStage", ".", "setFullScreen", "(", "!", "currentStage", ".", "isFullScreen", "(", ")", ")", ";", "keyEvent", ".", "consume", "(", ")", ";", "// Manage F10 button to iconify", "}", "else", "if", "(", "iconKeyCode", "!=", "null", "&&", "iconKeyCode", "==", "keyEvent", ".", "getCode", "(", ")", ")", "{", "currentStage", ".", "setIconified", "(", "!", "currentStage", ".", "isIconified", "(", ")", ")", ";", "keyEvent", ".", "consume", "(", ")", ";", "}", "}", ")", ";", "}", "// The call customize method to allow extension by sub class", "customizeScene", "(", "this", ".", "scene", ")", ";", "// Add the default Style Sheet if none have been added", "manageDefaultStyleSheet", "(", "this", ".", "scene", ")", ";", "}" ]
Initialize the default scene.
[ "Initialize", "the", "default", "scene", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/application/AbstractApplication.java#L364-L395
8,530
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/application/AbstractApplication.java
AbstractApplication.preloadModules
protected void preloadModules() { // Add default ModuleModel component interface (because it cannot be added by module starter, API is not processed with annotation engine) 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); }
java
protected void preloadModules() { // Add default ModuleModel component interface (because it cannot be added by module starter, API is not processed with annotation engine) 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); }
[ "protected", "void", "preloadModules", "(", ")", "{", "// Add default ModuleModel component interface (because it cannot be added by module starter, API is not processed with annotation engine)", "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.
[ "Preload", "Module", ".", "xml", "files", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/application/AbstractApplication.java#L414-L432
8,531
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/application/AbstractApplication.java
AbstractApplication.addCSS
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()); } }
java
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()); } }
[ "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. @param scene the scene that will hold this new CSS file @param styleSheetItem the stylesheet item to add
[ "Attach", "a", "new", "CSS", "file", "to", "the", "scene", "using", "the", "default", "classloader", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/application/AbstractApplication.java#L456-L465
8,532
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/application/AbstractApplication.java
AbstractApplication.applicationTitle
protected String applicationTitle() { // Add application Name String name = StageParameters.APPLICATION_NAME.get(); if (name.contains(PARAM)) { name = name.replace(PARAM, computeShortClassName()); } // Add version with a space before 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(); }
java
protected String applicationTitle() { // Add application Name String name = StageParameters.APPLICATION_NAME.get(); if (name.contains(PARAM)) { name = name.replace(PARAM, computeShortClassName()); } // Add version with a space before 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(); }
[ "protected", "String", "applicationTitle", "(", ")", "{", "// Add application Name", "String", "name", "=", "StageParameters", ".", "APPLICATION_NAME", ".", "get", "(", ")", ";", "if", "(", "name", ".", "contains", "(", "PARAM", ")", ")", "{", "name", "=", "name", ".", "replace", "(", "PARAM", ",", "computeShortClassName", "(", ")", ")", ";", "}", "// Add version with a space before", "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. This method could be overridden. By default it will return {@link StageParameters.APPLICATION_NAME} {@link StageParameters.APPLICATION_VERSION} string. The default application is: ApplicationClass powered by JRebirth <br /> If version is equals to "0.0.0", it will not be appended @return the application title
[ "Return", "the", "application", "title", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/application/AbstractApplication.java#L479-L492
8,533
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/application/AbstractApplication.java
AbstractApplication.stageIcons
protected List<Image> stageIcons() { // TODO to be rewritten with ImageSet Resource when available return StageParameters.APPLICATION_ICONS.get() .stream() .map(p -> Resources.create(p).get()) .collect(Collectors.toList()); }
java
protected List<Image> stageIcons() { // TODO to be rewritten with ImageSet Resource when available return StageParameters.APPLICATION_ICONS.get() .stream() .map(p -> Resources.create(p).get()) .collect(Collectors.toList()); }
[ "protected", "List", "<", "Image", ">", "stageIcons", "(", ")", "{", "// TODO to be rewritten with ImageSet Resource when available", "return", "StageParameters", ".", "APPLICATION_ICONS", ".", "get", "(", ")", ".", "stream", "(", ")", ".", "map", "(", "p", "->", "Resources", ".", "create", "(", "p", ")", ".", "get", "(", ")", ")", ".", "collect", "(", "Collectors", ".", "toList", "(", ")", ")", ";", "}" ]
Return the application stage icon. This method could be overridden. By default it will return {@link StageParameters.APPLICATION_ICONS} list of JRebirth icons. Image Params parameterized will be converted as Image using anonymous ImageItem @return the list of image to use as stage icons
[ "Return", "the", "application", "stage", "icon", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/application/AbstractApplication.java#L505-L511
8,534
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/application/AbstractApplication.java
AbstractApplication.computeShortClassName
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; }
java
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; }
[ "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. @return the application class short name
[ "Return", "the", "application", "class", "name", "without", "the", "Application", "suffix", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/application/AbstractApplication.java#L518-L524
8,535
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/application/AbstractApplication.java
AbstractApplication.manageDefaultStyleSheet
private void manageDefaultStyleSheet(final Scene scene) { if (scene.getStylesheets().isEmpty()) { // No style sheet has been added to the scene LOGGER.log(NO_CSS_DEFINED); addCSS(scene, JRebirthStyles.DEFAULT); } }
java
private void manageDefaultStyleSheet(final Scene scene) { if (scene.getStylesheets().isEmpty()) { // No style sheet has been added to the scene LOGGER.log(NO_CSS_DEFINED); addCSS(scene, JRebirthStyles.DEFAULT); } }
[ "private", "void", "manageDefaultStyleSheet", "(", "final", "Scene", "scene", ")", "{", "if", "(", "scene", ".", "getStylesheets", "(", ")", ".", "isEmpty", "(", ")", ")", "{", "// No style sheet has been added to the scene", "LOGGER", ".", "log", "(", "NO_CSS_DEFINED", ")", ";", "addCSS", "(", "scene", ",", "JRebirthStyles", ".", "DEFAULT", ")", ";", "}", "}" ]
Attach default CSS file if none have been previously attached. @param scene the scene to check
[ "Attach", "default", "CSS", "file", "if", "none", "have", "been", "previously", "attached", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/application/AbstractApplication.java#L531-L538
8,536
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/application/AbstractApplication.java
AbstractApplication.buildScene
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; }
java
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; }
[ "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. 800x600 with transparent background and a Region as Parent Node @return the scene built @throws CoreException if build fails
[ "Initialize", "the", "properties", "of", "the", "scene", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/application/AbstractApplication.java#L549-L557
8,537
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/application/AbstractApplication.java
AbstractApplication.buildRootPane
@SuppressWarnings("unchecked") protected P buildRootPane() throws CoreException { // Build the root node by reflection without any parameter or excluded class this.rootNode = (P) ClassUtility.buildGenericType(this.getClass(), Pane.class); return this.rootNode; }
java
@SuppressWarnings("unchecked") protected P buildRootPane() throws CoreException { // Build the root node by reflection without any parameter or excluded class this.rootNode = (P) ClassUtility.buildGenericType(this.getClass(), Pane.class); return this.rootNode; }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "protected", "P", "buildRootPane", "(", ")", "throws", "CoreException", "{", "// Build the root node by reflection without any parameter or excluded class", "this", ".", "rootNode", "=", "(", "P", ")", "ClassUtility", ".", "buildGenericType", "(", "this", ".", "getClass", "(", ")", ",", "Pane", ".", "class", ")", ";", "return", "this", ".", "rootNode", ";", "}" ]
Build dynamically the root pane. @return the root pane @throws CoreException if build fails
[ "Build", "dynamically", "the", "root", "pane", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/application/AbstractApplication.java#L565-L571
8,538
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/application/AbstractApplication.java
AbstractApplication.initializeExceptionHandler
protected void initializeExceptionHandler() { // Initialize the default uncaught exception handler for all other threads Thread.setDefaultUncaughtExceptionHandler(getDefaultUncaughtExceptionHandler()); // Initialize the uncaught exception handler for JavaFX Application Thread JRebirth.runIntoJAT(ATTACH_JAT_UEH.getText(), () -> Thread.currentThread().setUncaughtExceptionHandler(getJatUncaughtExceptionHandler())); // Initialize the uncaught exception handler for JRebirth Internal Thread JRebirth.runIntoJIT(ATTACH_JIT_UEH.getText(), () -> Thread.currentThread().setUncaughtExceptionHandler(getJitUncaughtExceptionHandler())); }
java
protected void initializeExceptionHandler() { // Initialize the default uncaught exception handler for all other threads Thread.setDefaultUncaughtExceptionHandler(getDefaultUncaughtExceptionHandler()); // Initialize the uncaught exception handler for JavaFX Application Thread JRebirth.runIntoJAT(ATTACH_JAT_UEH.getText(), () -> Thread.currentThread().setUncaughtExceptionHandler(getJatUncaughtExceptionHandler())); // Initialize the uncaught exception handler for JRebirth Internal Thread JRebirth.runIntoJIT(ATTACH_JIT_UEH.getText(), () -> Thread.currentThread().setUncaughtExceptionHandler(getJitUncaughtExceptionHandler())); }
[ "protected", "void", "initializeExceptionHandler", "(", ")", "{", "// Initialize the default uncaught exception handler for all other threads", "Thread", ".", "setDefaultUncaughtExceptionHandler", "(", "getDefaultUncaughtExceptionHandler", "(", ")", ")", ";", "// Initialize the uncaught exception handler for JavaFX Application Thread", "JRebirth", ".", "runIntoJAT", "(", "ATTACH_JAT_UEH", ".", "getText", "(", ")", ",", "(", ")", "->", "Thread", ".", "currentThread", "(", ")", ".", "setUncaughtExceptionHandler", "(", "getJatUncaughtExceptionHandler", "(", ")", ")", ")", ";", "// Initialize the uncaught exception handler for JRebirth Internal Thread", "JRebirth", ".", "runIntoJIT", "(", "ATTACH_JIT_UEH", ".", "getText", "(", ")", ",", "(", ")", "->", "Thread", ".", "currentThread", "(", ")", ".", "setUncaughtExceptionHandler", "(", "getJitUncaughtExceptionHandler", "(", ")", ")", ")", ";", "}" ]
Initialize all Uncaught Exception Handler.
[ "Initialize", "all", "Uncaught", "Exception", "Handler", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/application/AbstractApplication.java#L576-L586
8,539
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClasspathUtility.java
ClasspathUtility.getClasspathResources
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; // System.out.println("URLs "+ wsLoader.getURLs()); 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) { // Parse the classpath entry and apply the given pattern as filter resources.addAll(getResources(urlEntry, searchPattern, false)); } } // Sort resources Collections.sort(resources); return resources; }
java
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; // System.out.println("URLs "+ wsLoader.getURLs()); 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) { // Parse the classpath entry and apply the given pattern as filter resources.addAll(getResources(urlEntry, searchPattern, false)); } } // Sort resources Collections.sort(resources); return resources; }
[ "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", ";", "// System.out.println(\"URLs \"+ wsLoader.getURLs());\r", "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", ")", "{", "// Parse the classpath entry and apply the given pattern as filter\r", "resources", ".", "addAll", "(", "getResources", "(", "urlEntry", ",", "searchPattern", ",", "false", ")", ")", ";", "}", "}", "// Sort resources\r", "Collections", ".", "sort", "(", "resources", ")", ";", "return", "resources", ";", "}" ]
Retrieve all resources that match the search pattern from the java.class.path. @param searchPattern the pattern used to filter all matching files @return Sorted list of resources that match the pattern
[ "Retrieve", "all", "resources", "that", "match", "the", "search", "pattern", "from", "the", "java", ".", "class", ".", "path", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClasspathUtility.java#L76-L117
8,540
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClasspathUtility.java
ClasspathUtility.hasJavaWebstartLibrary
private static boolean hasJavaWebstartLibrary() { boolean hasWebStartLibrary = true; try { Class.forName("com.sun.jnlp.JNLPClassLoaderIf"); } catch (final ClassNotFoundException e) { hasWebStartLibrary = false; } return hasWebStartLibrary; }
java
private static boolean hasJavaWebstartLibrary() { boolean hasWebStartLibrary = true; try { Class.forName("com.sun.jnlp.JNLPClassLoaderIf"); } catch (final ClassNotFoundException e) { hasWebStartLibrary = false; } return hasWebStartLibrary; }
[ "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. @return true if javaws.jar is accessible
[ "Check", "that", "javaws", ".", "jar", "is", "accessible", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClasspathUtility.java#L124-L132
8,541
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClasspathUtility.java
ClasspathUtility.getResources
private static List<String> getResources(final String classpathEntryPath, final Pattern searchPattern, final boolean cachedJar) { final List<String> resources = new ArrayList<>(); // System.out.println("Search into "+classpathEntryPath); final File classpathEntryFile = new File(classpathEntryPath); // The classpath entry could be a jar or a folder if (classpathEntryFile.isDirectory()) { // Browse the folder content resources.addAll(getResourcesFromDirectory(classpathEntryFile, searchPattern)); } else if (classpathEntryFile.getName().endsWith(".jar") || classpathEntryFile.getName().endsWith(".zip") || cachedJar) { // Explode and browse jar|zip content resources.addAll(getResourcesFromJarOrZipFile(classpathEntryFile, searchPattern)); } else { LOGGER.log(RESOURCE_IGNORED, classpathEntryFile.getAbsolutePath()); } return resources; }
java
private static List<String> getResources(final String classpathEntryPath, final Pattern searchPattern, final boolean cachedJar) { final List<String> resources = new ArrayList<>(); // System.out.println("Search into "+classpathEntryPath); final File classpathEntryFile = new File(classpathEntryPath); // The classpath entry could be a jar or a folder if (classpathEntryFile.isDirectory()) { // Browse the folder content resources.addAll(getResourcesFromDirectory(classpathEntryFile, searchPattern)); } else if (classpathEntryFile.getName().endsWith(".jar") || classpathEntryFile.getName().endsWith(".zip") || cachedJar) { // Explode and browse jar|zip content resources.addAll(getResourcesFromJarOrZipFile(classpathEntryFile, searchPattern)); } else { LOGGER.log(RESOURCE_IGNORED, classpathEntryFile.getAbsolutePath()); } return resources; }
[ "private", "static", "List", "<", "String", ">", "getResources", "(", "final", "String", "classpathEntryPath", ",", "final", "Pattern", "searchPattern", ",", "final", "boolean", "cachedJar", ")", "{", "final", "List", "<", "String", ">", "resources", "=", "new", "ArrayList", "<>", "(", ")", ";", "// System.out.println(\"Search into \"+classpathEntryPath);\r", "final", "File", "classpathEntryFile", "=", "new", "File", "(", "classpathEntryPath", ")", ";", "// The classpath entry could be a jar or a folder\r", "if", "(", "classpathEntryFile", ".", "isDirectory", "(", ")", ")", "{", "// Browse the folder content\r", "resources", ".", "addAll", "(", "getResourcesFromDirectory", "(", "classpathEntryFile", ",", "searchPattern", ")", ")", ";", "}", "else", "if", "(", "classpathEntryFile", ".", "getName", "(", ")", ".", "endsWith", "(", "\".jar\"", ")", "||", "classpathEntryFile", ".", "getName", "(", ")", ".", "endsWith", "(", "\".zip\"", ")", "||", "cachedJar", ")", "{", "// Explode and browse jar|zip content\r", "resources", ".", "addAll", "(", "getResourcesFromJarOrZipFile", "(", "classpathEntryFile", ",", "searchPattern", ")", ")", ";", "}", "else", "{", "LOGGER", ".", "log", "(", "RESOURCE_IGNORED", ",", "classpathEntryFile", ".", "getAbsolutePath", "(", ")", ")", ";", "}", "return", "resources", ";", "}" ]
Search all files that match the given Regex pattern. @param classpathEntryPath the root folder used for search @param searchPattern the regex pattern used as a filter @param cachedJar is a jar cached by Java Webstart without any extension @return list of resources that match the pattern
[ "Search", "all", "files", "that", "match", "the", "given", "Regex", "pattern", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClasspathUtility.java#L143-L159
8,542
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClasspathUtility.java
ClasspathUtility.getResourcesFromDirectory
private static List<String> getResourcesFromDirectory(final File directory, final Pattern searchPattern) { final List<String> resources = new ArrayList<>(); // Filter only properties files final File[] fileList = directory.listFiles(); if (fileList != null && fileList.length > 0) { // Iterate over each relevant file for (final File file : fileList) { // If the file is a directory process a recursive call to explorer the tree 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; }
java
private static List<String> getResourcesFromDirectory(final File directory, final Pattern searchPattern) { final List<String> resources = new ArrayList<>(); // Filter only properties files final File[] fileList = directory.listFiles(); if (fileList != null && fileList.length > 0) { // Iterate over each relevant file for (final File file : fileList) { // If the file is a directory process a recursive call to explorer the tree 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; }
[ "private", "static", "List", "<", "String", ">", "getResourcesFromDirectory", "(", "final", "File", "directory", ",", "final", "Pattern", "searchPattern", ")", "{", "final", "List", "<", "String", ">", "resources", "=", "new", "ArrayList", "<>", "(", ")", ";", "// Filter only properties files\r", "final", "File", "[", "]", "fileList", "=", "directory", ".", "listFiles", "(", ")", ";", "if", "(", "fileList", "!=", "null", "&&", "fileList", ".", "length", ">", "0", ")", "{", "// Iterate over each relevant file\r", "for", "(", "final", "File", "file", ":", "fileList", ")", "{", "// If the file is a directory process a recursive call to explorer the tree\r", "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. @param directory the root directory to browse @param searchPattern the regex pattern used as a filter @return list of resources that match the pattern
[ "Browse", "a", "directory", "to", "search", "resources", "that", "match", "the", "pattern", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClasspathUtility.java#L169-L191
8,543
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClasspathUtility.java
ClasspathUtility.getResourcesFromJarOrZipFile
@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; }
java
@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; }
[ "@", "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. @param jarOrZipFile the jar to explore @param searchPattern the regex pattern used as a filter @return list of resources that match the pattern
[ "Browse", "the", "jar", "content", "to", "search", "resources", "that", "match", "the", "pattern", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClasspathUtility.java#L201-L217
8,544
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClasspathUtility.java
ClasspathUtility.checkResource
private static void checkResource(final List<String> resources, final Pattern searchPattern, final String resourceName) { if (searchPattern.matcher(resourceName).matches()) { resources.add(resourceName); } }
java
private static void checkResource(final List<String> resources, final Pattern searchPattern, final String resourceName) { if (searchPattern.matcher(resourceName).matches()) { resources.add(resourceName); } }
[ "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. @param resources the list of found resources @param searchPattern the regex pattern @param resourceName the resource to check and to add
[ "Check", "if", "the", "resource", "match", "the", "regex", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClasspathUtility.java#L226-L230
8,545
JRebirth/JRebirth
org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClasspathUtility.java
ClasspathUtility.loadInputStream
public static InputStream loadInputStream(final String custConfFileName) { InputStream is = null; final File resourceFile = new File(custConfFileName); // Check if the file could be find if (resourceFile.exists()) { try { is = new FileInputStream(resourceFile); } catch (final FileNotFoundException e) { // Nothing to do } } else { // Otherwise try to load from context classloader is = Thread.currentThread().getContextClassLoader().getResourceAsStream(custConfFileName); } return is; }
java
public static InputStream loadInputStream(final String custConfFileName) { InputStream is = null; final File resourceFile = new File(custConfFileName); // Check if the file could be find if (resourceFile.exists()) { try { is = new FileInputStream(resourceFile); } catch (final FileNotFoundException e) { // Nothing to do } } else { // Otherwise try to load from context classloader is = Thread.currentThread().getContextClassLoader().getResourceAsStream(custConfFileName); } return is; }
[ "public", "static", "InputStream", "loadInputStream", "(", "final", "String", "custConfFileName", ")", "{", "InputStream", "is", "=", "null", ";", "final", "File", "resourceFile", "=", "new", "File", "(", "custConfFileName", ")", ";", "// Check if the file could be find\r", "if", "(", "resourceFile", ".", "exists", "(", ")", ")", "{", "try", "{", "is", "=", "new", "FileInputStream", "(", "resourceFile", ")", ";", "}", "catch", "(", "final", "FileNotFoundException", "e", ")", "{", "// Nothing to do\r", "}", "}", "else", "{", "// Otherwise try to load from context classloader\r", "is", "=", "Thread", ".", "currentThread", "(", ")", ".", "getContextClassLoader", "(", ")", ".", "getResourceAsStream", "(", "custConfFileName", ")", ";", "}", "return", "is", ";", "}" ]
TRy to load a custom resource file. @param custConfFileName the custom resource file to load @return the load input stream
[ "TRy", "to", "load", "a", "custom", "resource", "file", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/core/src/main/java/org/jrebirth/af/core/util/ClasspathUtility.java#L239-L255
8,546
JRebirth/JRebirth
org.jrebirth.af/component/src/main/java/org/jrebirth/af/component/ui/stack/StackModel.java
StackModel.getPageEnumClass
@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; }
java
@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; }
[ "@", "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. Checks the modelObject and return it only if it extends {@link PageEnum} @return the page enum class
[ "Returns", "the", "page", "enum", "class", "associated", "to", "this", "model", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/component/src/main/java/org/jrebirth/af/component/ui/stack/StackModel.java#L104-L113
8,547
JRebirth/JRebirth
org.jrebirth.af/component/src/main/java/org/jrebirth/af/component/ui/stack/StackModel.java
StackModel.getStackName
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; }
java
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; }
[ "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. Checks the modelObject and return it only if it is a String @return the stack name
[ "Returns", "the", "current", "stack", "name", "associated", "to", "this", "model", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/component/src/main/java/org/jrebirth/af/component/ui/stack/StackModel.java#L122-L130
8,548
JRebirth/JRebirth
org.jrebirth.af/component/src/main/java/org/jrebirth/af/component/ui/stack/StackModel.java
StackModel.showPage
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()); // Create the Wave Bean that will hold all data processed by chained commands final DisplayModelWaveBean waveBean = DisplayModelWaveBean.create() // Define the placeholder that will receive the content .childrenPlaceHolder(view().node().getChildren()) // Allow to add element behind the stack to allow transition .appendChild(false) .showModelKey(pageModelKey) .hideModelKey(this.currentModelKey); this.currentModelKey = waveBean.showModelKey(); if (wave != null) { // The method was called after having received a wave // It will show the next page by sending a regular command, processed asynchronously into JAT after a JIT cycle // This call is non-blocking sendWave(WBuilder.callCommand(ShowFadingModelCommand.class) .waveBean(waveBean) .relatedWave(wave) .addWaveListener(new RelatedWaveListener())); } else { // The showPage method has been called programmatically without any wave provided // This is the first call used to initialize the stack so we perform the show transition immediately final Wave showWave = WBuilder.callCommand(ShowFadingModelCommand.class) .waveBean(waveBean) .addDatas(JRebirthWaves.FORCE_SYNC); // Run synchronously into JAT immediately without a waiting a JIT cycle // This call will block current thread until page is shown getCommand(ShowFadingModelCommand.class, showWave.wUID()).run(showWave); } } else { LOGGER.debug("Page Model currently displayed: " + pageModelKey.toString()); } }
java
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()); // Create the Wave Bean that will hold all data processed by chained commands final DisplayModelWaveBean waveBean = DisplayModelWaveBean.create() // Define the placeholder that will receive the content .childrenPlaceHolder(view().node().getChildren()) // Allow to add element behind the stack to allow transition .appendChild(false) .showModelKey(pageModelKey) .hideModelKey(this.currentModelKey); this.currentModelKey = waveBean.showModelKey(); if (wave != null) { // The method was called after having received a wave // It will show the next page by sending a regular command, processed asynchronously into JAT after a JIT cycle // This call is non-blocking sendWave(WBuilder.callCommand(ShowFadingModelCommand.class) .waveBean(waveBean) .relatedWave(wave) .addWaveListener(new RelatedWaveListener())); } else { // The showPage method has been called programmatically without any wave provided // This is the first call used to initialize the stack so we perform the show transition immediately final Wave showWave = WBuilder.callCommand(ShowFadingModelCommand.class) .waveBean(waveBean) .addDatas(JRebirthWaves.FORCE_SYNC); // Run synchronously into JAT immediately without a waiting a JIT cycle // This call will block current thread until page is shown getCommand(ShowFadingModelCommand.class, showWave.wUID()).run(showWave); } } else { LOGGER.debug("Page Model currently displayed: " + pageModelKey.toString()); } }
[ "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", "(", ")", ")", ";", "// Create the Wave Bean that will hold all data processed by chained commands", "final", "DisplayModelWaveBean", "waveBean", "=", "DisplayModelWaveBean", ".", "create", "(", ")", "// Define the placeholder that will receive the content", ".", "childrenPlaceHolder", "(", "view", "(", ")", ".", "node", "(", ")", ".", "getChildren", "(", ")", ")", "// Allow to add element behind the stack to allow transition", ".", "appendChild", "(", "false", ")", ".", "showModelKey", "(", "pageModelKey", ")", ".", "hideModelKey", "(", "this", ".", "currentModelKey", ")", ";", "this", ".", "currentModelKey", "=", "waveBean", ".", "showModelKey", "(", ")", ";", "if", "(", "wave", "!=", "null", ")", "{", "// The method was called after having received a wave", "// It will show the next page by sending a regular command, processed asynchronously into JAT after a JIT cycle", "// This call is non-blocking", "sendWave", "(", "WBuilder", ".", "callCommand", "(", "ShowFadingModelCommand", ".", "class", ")", ".", "waveBean", "(", "waveBean", ")", ".", "relatedWave", "(", "wave", ")", ".", "addWaveListener", "(", "new", "RelatedWaveListener", "(", ")", ")", ")", ";", "}", "else", "{", "// The showPage method has been called programmatically without any wave provided", "// This is the first call used to initialize the stack so we perform the show transition immediately", "final", "Wave", "showWave", "=", "WBuilder", ".", "callCommand", "(", "ShowFadingModelCommand", ".", "class", ")", ".", "waveBean", "(", "waveBean", ")", ".", "addDatas", "(", "JRebirthWaves", ".", "FORCE_SYNC", ")", ";", "// Run synchronously into JAT immediately without a waiting a JIT cycle", "// This call will block current thread until page is shown", "getCommand", "(", "ShowFadingModelCommand", ".", "class", ",", "showWave", ".", "wUID", "(", ")", ")", ".", "run", "(", "showWave", ")", ";", "}", "}", "else", "{", "LOGGER", ".", "debug", "(", "\"Page Model currently displayed: \"", "+", "pageModelKey", ".", "toString", "(", ")", ")", ";", "}", "}" ]
Private method used to show another page. @param pageModelKey the mdoelKey for the page to show
[ "Private", "method", "used", "to", "show", "another", "page", "." ]
93f4fc087b83c73db540333b9686e97b4cec694d
https://github.com/JRebirth/JRebirth/blob/93f4fc087b83c73db540333b9686e97b4cec694d/org.jrebirth.af/component/src/main/java/org/jrebirth/af/component/ui/stack/StackModel.java#L137-L176
8,549
cqyijifu/watcher
watcher-http/src/main/java/com/yiji/framework/watcher/http/adaptor/web/util/IPRange.java
IPRange.parseRange
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 to convert the remaining part of the range into a decimal // value. 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) { // the remaining part is not a valid decimal value. // Check if it's a decimal-dotted notation. ipSubnetMask = new IPAddress(subnetStr); // create the corresponding subnet decimal extendedNetworkPrefix = computeNetworkPrefixFromMask(ipSubnetMask); if (extendedNetworkPrefix == -1) { throw new IllegalArgumentException("Invalid IP range [" + range + "]", ex); } } }
java
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 to convert the remaining part of the range into a decimal // value. 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) { // the remaining part is not a valid decimal value. // Check if it's a decimal-dotted notation. ipSubnetMask = new IPAddress(subnetStr); // create the corresponding subnet decimal extendedNetworkPrefix = computeNetworkPrefixFromMask(ipSubnetMask); if (extendedNetworkPrefix == -1) { throw new IllegalArgumentException("Invalid IP range [" + range + "]", ex); } } }
[ "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 to convert the remaining part of the range into a decimal", "// value.", "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", ")", "{", "// the remaining part is not a valid decimal value.", "// Check if it's a decimal-dotted notation.", "ipSubnetMask", "=", "new", "IPAddress", "(", "subnetStr", ")", ";", "// create the corresponding subnet decimal", "extendedNetworkPrefix", "=", "computeNetworkPrefixFromMask", "(", "ipSubnetMask", ")", ";", "if", "(", "extendedNetworkPrefix", "==", "-", "1", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Invalid IP range [\"", "+", "range", "+", "\"]\"", ",", "ex", ")", ";", "}", "}", "}" ]
Parse the IP range string representation. @param range String representation of the IP range.
[ "Parse", "the", "IP", "range", "string", "representation", "." ]
9032ede2743de751d8ae4b77ade39726f016457d
https://github.com/cqyijifu/watcher/blob/9032ede2743de751d8ae4b77ade39726f016457d/watcher-http/src/main/java/com/yiji/framework/watcher/http/adaptor/web/util/IPRange.java#L93-L129
8,550
cqyijifu/watcher
watcher-http/src/main/java/com/yiji/framework/watcher/http/adaptor/web/util/IPRange.java
IPRange.computeNetworkPrefixFromMask
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; }
java
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; }
[ "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. @param mask Reference to the subnet mask IP number. @return Return the extended network prefix. Return -1 if the specified mask cannot be converted into a extended prefix network.
[ "Compute", "the", "extended", "network", "prefix", "from", "the", "IP", "subnet", "mask", "." ]
9032ede2743de751d8ae4b77ade39726f016457d
https://github.com/cqyijifu/watcher/blob/9032ede2743de751d8ae4b77ade39726f016457d/watcher-http/src/main/java/com/yiji/framework/watcher/http/adaptor/web/util/IPRange.java#L139-L154
8,551
cqyijifu/watcher
watcher-http/src/main/java/com/yiji/framework/watcher/http/adaptor/web/util/IPRange.java
IPRange.computeMaskFromNetworkPrefix
private IPAddress computeMaskFromNetworkPrefix(int prefix) { /* * int subnet = 0; for (int i=0; i<prefix; i++) { subnet = subnet << 1; subnet += 1; } */ 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); }
java
private IPAddress computeMaskFromNetworkPrefix(int prefix) { /* * int subnet = 0; for (int i=0; i<prefix; i++) { subnet = subnet << 1; subnet += 1; } */ 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); }
[ "private", "IPAddress", "computeMaskFromNetworkPrefix", "(", "int", "prefix", ")", "{", "/*\n\t\t * int subnet = 0; for (int i=0; i<prefix; i++) { subnet = subnet << 1; subnet += 1; }\n\t\t */", "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. @param prefix The network prefix number. @return Return the IP number corresponding to the extended network prefix.
[ "Convert", "a", "extended", "network", "prefix", "integer", "into", "an", "IP", "number", "." ]
9032ede2743de751d8ae4b77ade39726f016457d
https://github.com/cqyijifu/watcher/blob/9032ede2743de751d8ae4b77ade39726f016457d/watcher-http/src/main/java/com/yiji/framework/watcher/http/adaptor/web/util/IPRange.java#L180-L198
8,552
cqyijifu/watcher
watcher-http/src/main/java/com/yiji/framework/watcher/http/adaptor/web/util/IPRange.java
IPRange.isIPAddressInRange
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; }
java
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; }
[ "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. @param address The IP address to be tested. @return Return <code>true</code> if the specified IP address is in the encapsulated IP range, otherwise return <code>false</code>.
[ "Check", "if", "the", "specified", "IP", "address", "is", "in", "the", "encapsulated", "range", "." ]
9032ede2743de751d8ae4b77ade39726f016457d
https://github.com/cqyijifu/watcher/blob/9032ede2743de751d8ae4b77ade39726f016457d/watcher-http/src/main/java/com/yiji/framework/watcher/http/adaptor/web/util/IPRange.java#L208-L217
8,553
cqyijifu/watcher
watcher-http/src/main/java/com/yiji/framework/watcher/http/adaptor/web/util/IPAddress.java
IPAddress.parseIPAddress
final int parseIPAddress(String ipAddressStr) { int result = 0; if (ipAddressStr == null) { throw new IllegalArgumentException(); } try { String tmp = ipAddressStr; // get the 3 first numbers int offset = 0; for (int i = 0; i < 3; i++) { // get the position of the first dot int index = tmp.indexOf('.'); // if there is not a dot then the ip string representation is // not compliant to the decimal-dotted notation. if (index != -1) { // get the number before the dot and convert it into // an integer. 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 + "]"); } } // the remaining part of the string should be the last number. 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; }
java
final int parseIPAddress(String ipAddressStr) { int result = 0; if (ipAddressStr == null) { throw new IllegalArgumentException(); } try { String tmp = ipAddressStr; // get the 3 first numbers int offset = 0; for (int i = 0; i < 3; i++) { // get the position of the first dot int index = tmp.indexOf('.'); // if there is not a dot then the ip string representation is // not compliant to the decimal-dotted notation. if (index != -1) { // get the number before the dot and convert it into // an integer. 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 + "]"); } } // the remaining part of the string should be the last number. 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; }
[ "final", "int", "parseIPAddress", "(", "String", "ipAddressStr", ")", "{", "int", "result", "=", "0", ";", "if", "(", "ipAddressStr", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", ")", ";", "}", "try", "{", "String", "tmp", "=", "ipAddressStr", ";", "// get the 3 first numbers", "int", "offset", "=", "0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "3", ";", "i", "++", ")", "{", "// get the position of the first dot", "int", "index", "=", "tmp", ".", "indexOf", "(", "'", "'", ")", ";", "// if there is not a dot then the ip string representation is", "// not compliant to the decimal-dotted notation.", "if", "(", "index", "!=", "-", "1", ")", "{", "// get the number before the dot and convert it into", "// an integer.", "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", "+", "\"]\"", ")", ";", "}", "}", "// the remaining part of the string should be the last number.", "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. @param ipAddressStr Decimal-dotted notation (xxx.xxx.xxx.xxx) of the IP address. @return Return the 32 bits integer representation of the IP address. decimal-dotted notation xxx.xxx.xxx.xxx.
[ "Convert", "a", "decimal", "-", "dotted", "notation", "representation", "of", "an", "IP", "address", "into", "an", "32", "bits", "interger", "value", "." ]
9032ede2743de751d8ae4b77ade39726f016457d
https://github.com/cqyijifu/watcher/blob/9032ede2743de751d8ae4b77ade39726f016457d/watcher-http/src/main/java/com/yiji/framework/watcher/http/adaptor/web/util/IPAddress.java#L123-L179
8,554
TGIO/ParseLiveQuery
parse-livequery/src/main/java/tgio/parselivequery/LiveQueryClient.java
LiveQueryClient.on
public static void on(String op, OnListener listener) { getInstance().mEvents.add(new Event(op, listener)); }
java
public static void on(String op, OnListener listener) { getInstance().mEvents.add(new Event(op, listener)); }
[ "public", "static", "void", "on", "(", "String", "op", ",", "OnListener", "listener", ")", "{", "getInstance", "(", ")", ".", "mEvents", ".", "add", "(", "new", "Event", "(", "op", ",", "listener", ")", ")", ";", "}" ]
Connect && Disconnect events
[ "Connect", "&&", "Disconnect", "events" ]
92ed9d0b1b7936bf714850044df2a2c564184aa3
https://github.com/TGIO/ParseLiveQuery/blob/92ed9d0b1b7936bf714850044df2a2c564184aa3/parse-livequery/src/main/java/tgio/parselivequery/LiveQueryClient.java#L195-L197
8,555
mikepenz/Crossfader
library/src/main/java/com/mikepenz/crossfader/view/CrossFadeSlidingPaneLayout.java
CrossFadeSlidingPaneLayout.enableDisableView
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); } } }
java
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); } } }
[ "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 @param view @param enabled
[ "helper", "method", "to", "disable", "a", "view", "and", "all", "its", "subviews" ]
b2e1ee461bc3bcdd897d83f0fad950663bdc73b4
https://github.com/mikepenz/Crossfader/blob/b2e1ee461bc3bcdd897d83f0fad950663bdc73b4/library/src/main/java/com/mikepenz/crossfader/view/CrossFadeSlidingPaneLayout.java#L152-L162
8,556
mikepenz/Crossfader
library/src/main/java/com/mikepenz/crossfader/Crossfader.java
Crossfader.withStructure
public Crossfader withStructure(View first, int firstWidth, View second, int secondWidth) { withFirst(first, firstWidth); withSecond(second, secondWidth); return this; }
java
public Crossfader withStructure(View first, int firstWidth, View second, int secondWidth) { withFirst(first, firstWidth); withSecond(second, secondWidth); return this; }
[ "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 @param first @param firstWidth @param second @param secondWidth @return
[ "define", "the", "default", "view", "and", "the", "slided", "view", "of", "the", "crossfader" ]
b2e1ee461bc3bcdd897d83f0fad950663bdc73b4
https://github.com/mikepenz/Crossfader/blob/b2e1ee461bc3bcdd897d83f0fad950663bdc73b4/library/src/main/java/com/mikepenz/crossfader/Crossfader.java#L111-L115
8,557
mikepenz/Crossfader
library/src/main/java/com/mikepenz/crossfader/Crossfader.java
Crossfader.withCanSlide
public Crossfader withCanSlide(boolean canSlide) { this.mCanSlide = canSlide; if (mCrossFadeSlidingPaneLayout != null) { mCrossFadeSlidingPaneLayout.setCanSlide(mCanSlide); } return this; }
java
public Crossfader withCanSlide(boolean canSlide) { this.mCanSlide = canSlide; if (mCrossFadeSlidingPaneLayout != null) { mCrossFadeSlidingPaneLayout.setCanSlide(mCanSlide); } return this; }
[ "public", "Crossfader", "withCanSlide", "(", "boolean", "canSlide", ")", "{", "this", ".", "mCanSlide", "=", "canSlide", ";", "if", "(", "mCrossFadeSlidingPaneLayout", "!=", "null", ")", "{", "mCrossFadeSlidingPaneLayout", ".", "setCanSlide", "(", "mCanSlide", ")", ";", "}", "return", "this", ";", "}" ]
Allow the panel to slide @param canSlide @return
[ "Allow", "the", "panel", "to", "slide" ]
b2e1ee461bc3bcdd897d83f0fad950663bdc73b4
https://github.com/mikepenz/Crossfader/blob/b2e1ee461bc3bcdd897d83f0fad950663bdc73b4/library/src/main/java/com/mikepenz/crossfader/Crossfader.java#L141-L147
8,558
mikepenz/Crossfader
library/src/main/java/com/mikepenz/crossfader/Crossfader.java
Crossfader.withPanelSlideListener
public Crossfader withPanelSlideListener(SlidingPaneLayout.PanelSlideListener panelSlideListener) { this.mPanelSlideListener = panelSlideListener; if (mCrossFadeSlidingPaneLayout != null) { mCrossFadeSlidingPaneLayout.setPanelSlideListener(mPanelSlideListener); } return this; }
java
public Crossfader withPanelSlideListener(SlidingPaneLayout.PanelSlideListener panelSlideListener) { this.mPanelSlideListener = panelSlideListener; if (mCrossFadeSlidingPaneLayout != null) { mCrossFadeSlidingPaneLayout.setPanelSlideListener(mPanelSlideListener); } return this; }
[ "public", "Crossfader", "withPanelSlideListener", "(", "SlidingPaneLayout", ".", "PanelSlideListener", "panelSlideListener", ")", "{", "this", ".", "mPanelSlideListener", "=", "panelSlideListener", ";", "if", "(", "mCrossFadeSlidingPaneLayout", "!=", "null", ")", "{", "mCrossFadeSlidingPaneLayout", ".", "setPanelSlideListener", "(", "mPanelSlideListener", ")", ";", "}", "return", "this", ";", "}" ]
set a PanelSlideListener used with the CrossFadeSlidingPaneLayout @param panelSlideListener @return
[ "set", "a", "PanelSlideListener", "used", "with", "the", "CrossFadeSlidingPaneLayout" ]
b2e1ee461bc3bcdd897d83f0fad950663bdc73b4
https://github.com/mikepenz/Crossfader/blob/b2e1ee461bc3bcdd897d83f0fad950663bdc73b4/library/src/main/java/com/mikepenz/crossfader/Crossfader.java#L158-L164
8,559
mikepenz/Crossfader
library/src/main/java/com/mikepenz/crossfader/Crossfader.java
Crossfader.build
public Crossfader build() { if (mFirstWidth < mSecondWidth) { throw new RuntimeException("the first layout has to be the layout with the greater width"); } //get the layout which should be replaced by the CrossFadeSlidingPaneLayout ViewGroup container = ((ViewGroup) mContent.getParent()); //remove the content from it's parent container.removeView(mContent); //create the cross fader container mCrossFadeSlidingPaneLayout = (T) LayoutInflater.from(mContent.getContext()).inflate(mBaseLayout, container, false); container.addView(mCrossFadeSlidingPaneLayout); //find the container layouts 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); //define the widths setWidth(mCrossFadePanel, mFirstWidth); setWidth(mCrossFadeFirst, mFirstWidth); setWidth(mCrossFadeSecond, mSecondWidth); setLeftMargin(mCrossFadeContainer, mSecondWidth); //add content to the panel mCrossFadeFirst.addView(mFirst, mFirstWidth, ViewGroup.LayoutParams.MATCH_PARENT); mCrossFadeSecond.addView(mSecond, mSecondWidth, ViewGroup.LayoutParams.MATCH_PARENT); //add back main content mCrossFadeContainer.addView(mContent, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); // try to restore all saved values again 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); } //set the PanelSlideListener for the CrossFadeSlidingPaneLayout mCrossFadeSlidingPaneLayout.setPanelSlideListener(mPanelSlideListener); //set the ability to slide mCrossFadeSlidingPaneLayout.setCanSlide(mCanSlide); //define that we don't want a slider color mCrossFadeSlidingPaneLayout.setSliderFadeColor(Color.TRANSPARENT); //enable / disable the resize functionality enableResizeContentPanel(mResizeContentPanel); return this; }
java
public Crossfader build() { if (mFirstWidth < mSecondWidth) { throw new RuntimeException("the first layout has to be the layout with the greater width"); } //get the layout which should be replaced by the CrossFadeSlidingPaneLayout ViewGroup container = ((ViewGroup) mContent.getParent()); //remove the content from it's parent container.removeView(mContent); //create the cross fader container mCrossFadeSlidingPaneLayout = (T) LayoutInflater.from(mContent.getContext()).inflate(mBaseLayout, container, false); container.addView(mCrossFadeSlidingPaneLayout); //find the container layouts 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); //define the widths setWidth(mCrossFadePanel, mFirstWidth); setWidth(mCrossFadeFirst, mFirstWidth); setWidth(mCrossFadeSecond, mSecondWidth); setLeftMargin(mCrossFadeContainer, mSecondWidth); //add content to the panel mCrossFadeFirst.addView(mFirst, mFirstWidth, ViewGroup.LayoutParams.MATCH_PARENT); mCrossFadeSecond.addView(mSecond, mSecondWidth, ViewGroup.LayoutParams.MATCH_PARENT); //add back main content mCrossFadeContainer.addView(mContent, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); // try to restore all saved values again 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); } //set the PanelSlideListener for the CrossFadeSlidingPaneLayout mCrossFadeSlidingPaneLayout.setPanelSlideListener(mPanelSlideListener); //set the ability to slide mCrossFadeSlidingPaneLayout.setCanSlide(mCanSlide); //define that we don't want a slider color mCrossFadeSlidingPaneLayout.setSliderFadeColor(Color.TRANSPARENT); //enable / disable the resize functionality enableResizeContentPanel(mResizeContentPanel); return this; }
[ "public", "Crossfader", "build", "(", ")", "{", "if", "(", "mFirstWidth", "<", "mSecondWidth", ")", "{", "throw", "new", "RuntimeException", "(", "\"the first layout has to be the layout with the greater width\"", ")", ";", "}", "//get the layout which should be replaced by the CrossFadeSlidingPaneLayout", "ViewGroup", "container", "=", "(", "(", "ViewGroup", ")", "mContent", ".", "getParent", "(", ")", ")", ";", "//remove the content from it's parent", "container", ".", "removeView", "(", "mContent", ")", ";", "//create the cross fader container", "mCrossFadeSlidingPaneLayout", "=", "(", "T", ")", "LayoutInflater", ".", "from", "(", "mContent", ".", "getContext", "(", ")", ")", ".", "inflate", "(", "mBaseLayout", ",", "container", ",", "false", ")", ";", "container", ".", "addView", "(", "mCrossFadeSlidingPaneLayout", ")", ";", "//find the container layouts", "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", ")", ";", "//define the widths", "setWidth", "(", "mCrossFadePanel", ",", "mFirstWidth", ")", ";", "setWidth", "(", "mCrossFadeFirst", ",", "mFirstWidth", ")", ";", "setWidth", "(", "mCrossFadeSecond", ",", "mSecondWidth", ")", ";", "setLeftMargin", "(", "mCrossFadeContainer", ",", "mSecondWidth", ")", ";", "//add content to the panel", "mCrossFadeFirst", ".", "addView", "(", "mFirst", ",", "mFirstWidth", ",", "ViewGroup", ".", "LayoutParams", ".", "MATCH_PARENT", ")", ";", "mCrossFadeSecond", ".", "addView", "(", "mSecond", ",", "mSecondWidth", ",", "ViewGroup", ".", "LayoutParams", ".", "MATCH_PARENT", ")", ";", "//add back main content", "mCrossFadeContainer", ".", "addView", "(", "mContent", ",", "ViewGroup", ".", "LayoutParams", ".", "MATCH_PARENT", ",", "ViewGroup", ".", "LayoutParams", ".", "MATCH_PARENT", ")", ";", "// try to restore all saved values again", "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", ")", ";", "}", "//set the PanelSlideListener for the CrossFadeSlidingPaneLayout", "mCrossFadeSlidingPaneLayout", ".", "setPanelSlideListener", "(", "mPanelSlideListener", ")", ";", "//set the ability to slide", "mCrossFadeSlidingPaneLayout", ".", "setCanSlide", "(", "mCanSlide", ")", ";", "//define that we don't want a slider color", "mCrossFadeSlidingPaneLayout", ".", "setSliderFadeColor", "(", "Color", ".", "TRANSPARENT", ")", ";", "//enable / disable the resize functionality", "enableResizeContentPanel", "(", "mResizeContentPanel", ")", ";", "return", "this", ";", "}" ]
builds the crossfader and it's content views will define all properties and define and add the layouts @return
[ "builds", "the", "crossfader", "and", "it", "s", "content", "views", "will", "define", "all", "properties", "and", "define", "and", "add", "the", "layouts" ]
b2e1ee461bc3bcdd897d83f0fad950663bdc73b4
https://github.com/mikepenz/Crossfader/blob/b2e1ee461bc3bcdd897d83f0fad950663bdc73b4/library/src/main/java/com/mikepenz/crossfader/Crossfader.java#L281-L340
8,560
mikepenz/Crossfader
library/src/main/java/com/mikepenz/crossfader/Crossfader.java
Crossfader.setWidth
protected void setWidth(View view, int width) { ViewGroup.LayoutParams lp = view.getLayoutParams(); lp.width = width; view.setLayoutParams(lp); }
java
protected void setWidth(View view, int width) { ViewGroup.LayoutParams lp = view.getLayoutParams(); lp.width = width; view.setLayoutParams(lp); }
[ "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 @param view @param width
[ "define", "the", "width", "of", "the", "given", "view" ]
b2e1ee461bc3bcdd897d83f0fad950663bdc73b4
https://github.com/mikepenz/Crossfader/blob/b2e1ee461bc3bcdd897d83f0fad950663bdc73b4/library/src/main/java/com/mikepenz/crossfader/Crossfader.java#L381-L385
8,561
mikepenz/Crossfader
library/src/main/java/com/mikepenz/crossfader/Crossfader.java
Crossfader.setLeftMargin
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); }
java
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); }
[ "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 @param view @param leftMargin
[ "define", "the", "left", "margin", "of", "the", "given", "view" ]
b2e1ee461bc3bcdd897d83f0fad950663bdc73b4
https://github.com/mikepenz/Crossfader/blob/b2e1ee461bc3bcdd897d83f0fad950663bdc73b4/library/src/main/java/com/mikepenz/crossfader/Crossfader.java#L393-L403
8,562
mikepenz/Crossfader
library/src/main/java/com/mikepenz/crossfader/util/UIUtils.java
UIUtils.isPointInsideView
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]; //point is inside view bounds if ((viewX < x && x < (viewX + view.getWidth())) && (viewY < y && y < (viewY + view.getHeight()))) { return true; } else { return false; } }
java
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]; //point is inside view bounds if ((viewX < x && x < (viewX + view.getWidth())) && (viewY < y && y < (viewY + view.getHeight()))) { return true; } else { return false; } }
[ "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", "]", ";", "//point is inside view bounds", "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 @param x - x coordinate of point @param y - y coordinate of point @param view - view object to compare @return true if the points are within view bounds, false otherwise
[ "Determines", "if", "given", "points", "are", "inside", "view" ]
b2e1ee461bc3bcdd897d83f0fad950663bdc73b4
https://github.com/mikepenz/Crossfader/blob/b2e1ee461bc3bcdd897d83f0fad950663bdc73b4/library/src/main/java/com/mikepenz/crossfader/util/UIUtils.java#L50-L63
8,563
rzwitserloot/lombok.ast
src/ast/lombok/ast/AbstractNode.java
AbstractNode.ensureParentage
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())); }
java
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())); }
[ "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. @param child This node must be a direct child of myself. @throws IllegalStateException If {@code child} isn't a direct child of myself.
[ "Checks", "if", "the", "provided", "node", "is", "a", "direct", "child", "of", "this", "node", "." ]
ed83541c1a5a08952a5d4d7e316a6be9a05311fb
https://github.com/rzwitserloot/lombok.ast/blob/ed83541c1a5a08952a5d4d7e316a6be9a05311fb/src/ast/lombok/ast/AbstractNode.java#L114-L120
8,564
jroyalty/jglm
src/main/java/com/hackoeur/jglm/Mat4.java
Mat4.add
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 ); }
java
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 ); }
[ "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 @param other
[ "Add", "two", "matrices", "together", "and", "return", "the", "result" ]
9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6
https://github.com/jroyalty/jglm/blob/9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6/src/main/java/com/hackoeur/jglm/Mat4.java#L421-L428
8,565
rzwitserloot/lombok.ast
src/main/lombok/ast/grammar/ProfilerParseRunner.java
ProfilerParseRunner.getOverviewReport
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(); }
java
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(); }
[ "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.
[ "Returns", "a", "string", "describing", "in", "order", "of", "expensiveness", "the", "top", "-", "level", "failed", "rule", "chains", "in", "the", "parse", "run", "." ]
ed83541c1a5a08952a5d4d7e316a6be9a05311fb
https://github.com/rzwitserloot/lombok.ast/blob/ed83541c1a5a08952a5d4d7e316a6be9a05311fb/src/main/lombok/ast/grammar/ProfilerParseRunner.java#L64-L74
8,566
rzwitserloot/lombok.ast
src/main/lombok/ast/grammar/ProfilerParseRunner.java
ProfilerParseRunner.getExtendedReport
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; }
java
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; }
[ "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. First all failed rules are sorted according to how long they took, then, for each such rule, a string is produced listing it and all its child rules. These are returned. @param topEntries Produce reports for the top {@code topEntries} most expensive failed rules. a negative number means: All of them.
[ "Lists", "the", "work", "done", "by", "the", "most", "expensive", "failed", "rules", "." ]
ed83541c1a5a08952a5d4d7e316a6be9a05311fb
https://github.com/rzwitserloot/lombok.ast/blob/ed83541c1a5a08952a5d4d7e316a6be9a05311fb/src/main/lombok/ast/grammar/ProfilerParseRunner.java#L85-L99
8,567
jroyalty/jglm
src/main/java/com/hackoeur/jglm/support/FastMath.java
FastMath.doubleHighPart
private static double doubleHighPart(double d) { if (d > -Precision.SAFE_MIN && d < Precision.SAFE_MIN){ return d; // These are un-normalised - don't try to convert } long xl = Double.doubleToLongBits(d); xl = xl & MASK_30BITS; // Drop low order bits return Double.longBitsToDouble(xl); }
java
private static double doubleHighPart(double d) { if (d > -Precision.SAFE_MIN && d < Precision.SAFE_MIN){ return d; // These are un-normalised - don't try to convert } long xl = Double.doubleToLongBits(d); xl = xl & MASK_30BITS; // Drop low order bits return Double.longBitsToDouble(xl); }
[ "private", "static", "double", "doubleHighPart", "(", "double", "d", ")", "{", "if", "(", "d", ">", "-", "Precision", ".", "SAFE_MIN", "&&", "d", "<", "Precision", ".", "SAFE_MIN", ")", "{", "return", "d", ";", "// These are un-normalised - don't try to convert", "}", "long", "xl", "=", "Double", ".", "doubleToLongBits", "(", "d", ")", ";", "xl", "=", "xl", "&", "MASK_30BITS", ";", "// Drop low order bits", "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 @param d the value to split @return the high order part of the mantissa
[ "Get", "the", "high", "order", "bits", "from", "the", "mantissa", ".", "Equivalent", "to", "adding", "and", "subtracting", "HEX_40000", "but", "also", "works", "for", "very", "large", "numbers" ]
9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6
https://github.com/jroyalty/jglm/blob/9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6/src/main/java/com/hackoeur/jglm/support/FastMath.java#L364-L371
8,568
jroyalty/jglm
src/main/java/com/hackoeur/jglm/support/FastMath.java
FastMath.cosh
public static double cosh(double x) { if (x != x) { return x; } // cosh[z] = (exp(z) + exp(-z))/2 // for numbers with magnitude 20 or so, // exp(-z) can be ignored in comparison with exp(z) if (x > 20) { if (x >= LOG_MAX_VALUE) { // Avoid overflow (MATH-905). 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) { // Avoid overflow (MATH-905). 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; // recip = 1/y double recip = 1.0/ya; temp = recip * HEX_40000000; double recipa = recip + temp - temp; double recipb = recip - recipa; // Correct for rounding in division recipb += (1.0 - yaa*recipa - yaa*recipb - yab*recipa - yab*recipb) * recip; // Account for yb recipb += -yb * recip * recip; // y = y + 1/y 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; }
java
public static double cosh(double x) { if (x != x) { return x; } // cosh[z] = (exp(z) + exp(-z))/2 // for numbers with magnitude 20 or so, // exp(-z) can be ignored in comparison with exp(z) if (x > 20) { if (x >= LOG_MAX_VALUE) { // Avoid overflow (MATH-905). 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) { // Avoid overflow (MATH-905). 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; // recip = 1/y double recip = 1.0/ya; temp = recip * HEX_40000000; double recipa = recip + temp - temp; double recipb = recip - recipa; // Correct for rounding in division recipb += (1.0 - yaa*recipa - yaa*recipb - yab*recipa - yab*recipb) * recip; // Account for yb recipb += -yb * recip * recip; // y = y + 1/y 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; }
[ "public", "static", "double", "cosh", "(", "double", "x", ")", "{", "if", "(", "x", "!=", "x", ")", "{", "return", "x", ";", "}", "// cosh[z] = (exp(z) + exp(-z))/2", "// for numbers with magnitude 20 or so,", "// exp(-z) can be ignored in comparison with exp(z)", "if", "(", "x", ">", "20", ")", "{", "if", "(", "x", ">=", "LOG_MAX_VALUE", ")", "{", "// Avoid overflow (MATH-905).", "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", ")", "{", "// Avoid overflow (MATH-905).", "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", ";", "// recip = 1/y", "double", "recip", "=", "1.0", "/", "ya", ";", "temp", "=", "recip", "*", "HEX_40000000", ";", "double", "recipa", "=", "recip", "+", "temp", "-", "temp", ";", "double", "recipb", "=", "recip", "-", "recipa", ";", "// Correct for rounding in division", "recipb", "+=", "(", "1.0", "-", "yaa", "*", "recipa", "-", "yaa", "*", "recipb", "-", "yab", "*", "recipa", "-", "yab", "*", "recipb", ")", "*", "recip", ";", "// Account for yb", "recipb", "+=", "-", "yb", "*", "recip", "*", "recip", ";", "// y = y + 1/y", "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. @param x number on which evaluation is done @return hyperbolic cosine of x
[ "Compute", "the", "hyperbolic", "cosine", "of", "a", "number", "." ]
9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6
https://github.com/jroyalty/jglm/blob/9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6/src/main/java/com/hackoeur/jglm/support/FastMath.java#L426-L489
8,569
jroyalty/jglm
src/main/java/com/hackoeur/jglm/support/FastMath.java
FastMath.exp
private static double exp(double x, double extra, double[] hiPrec) { double intPartA; double intPartB; int intVal; /* Lookup exp(floor(x)). * intPartA will have the upper 22 bits, intPartB will have the lower * 52 bits. */ 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) { /* This will produce a subnormal output */ 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) { /* exp(1.494140625) is nearly a machine number... */ 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]; } /* Get the fractional part of x, find the greatest multiple of 2^-10 less than * x and look up the exp function of it. * fracPartA will have the upper 22 bits, fracPartB the lower 52 bits. */ 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]; /* epsilon is the difference in x from the nearest multiple of 2^-10. It * has a value in the range 0 <= epsilon < 2^-10. * Do the subtraction from x as the last step to avoid possible loss of percison. */ final double epsilon = x - (intVal + intFrac / 1024.0); /* Compute z = exp(epsilon) - 1.0 via a minimax polynomial. z has full double precision (52 bits). Since z < 2^-10, we will have 62 bits of precision when combined with the contant 1. This will be used in the last addition below to get proper rounding. */ /* Remez generated polynomial. Converges on the interval [0, 2^-10], error is less than 0.5 ULP */ 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; /* Compute (intPartA+intPartB) * (fracPartA+fracPartB) by binomial expansion. tempA is exact since intPartA and intPartB only have 22 bits each. tempB will have 52 bits of precision. */ double tempA = intPartA * fracPartA; double tempB = intPartA * fracPartB + intPartB * fracPartA + intPartB * fracPartB; /* Compute the result. (1+z)(tempA+tempB). Order of operations is important. For accuracy add by increasing size. tempA is exact and much larger than the others. If there are extra bits specified from the pow() function, use them. */ 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) { // If requesting high precision hiPrec[0] = tempA; hiPrec[1] = tempC*extra*z + tempC*extra + tempC*z + tempB; } return result; }
java
private static double exp(double x, double extra, double[] hiPrec) { double intPartA; double intPartB; int intVal; /* Lookup exp(floor(x)). * intPartA will have the upper 22 bits, intPartB will have the lower * 52 bits. */ 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) { /* This will produce a subnormal output */ 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) { /* exp(1.494140625) is nearly a machine number... */ 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]; } /* Get the fractional part of x, find the greatest multiple of 2^-10 less than * x and look up the exp function of it. * fracPartA will have the upper 22 bits, fracPartB the lower 52 bits. */ 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]; /* epsilon is the difference in x from the nearest multiple of 2^-10. It * has a value in the range 0 <= epsilon < 2^-10. * Do the subtraction from x as the last step to avoid possible loss of percison. */ final double epsilon = x - (intVal + intFrac / 1024.0); /* Compute z = exp(epsilon) - 1.0 via a minimax polynomial. z has full double precision (52 bits). Since z < 2^-10, we will have 62 bits of precision when combined with the contant 1. This will be used in the last addition below to get proper rounding. */ /* Remez generated polynomial. Converges on the interval [0, 2^-10], error is less than 0.5 ULP */ 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; /* Compute (intPartA+intPartB) * (fracPartA+fracPartB) by binomial expansion. tempA is exact since intPartA and intPartB only have 22 bits each. tempB will have 52 bits of precision. */ double tempA = intPartA * fracPartA; double tempB = intPartA * fracPartB + intPartB * fracPartA + intPartB * fracPartB; /* Compute the result. (1+z)(tempA+tempB). Order of operations is important. For accuracy add by increasing size. tempA is exact and much larger than the others. If there are extra bits specified from the pow() function, use them. */ 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) { // If requesting high precision hiPrec[0] = tempA; hiPrec[1] = tempC*extra*z + tempC*extra + tempC*z + tempB; } return result; }
[ "private", "static", "double", "exp", "(", "double", "x", ",", "double", "extra", ",", "double", "[", "]", "hiPrec", ")", "{", "double", "intPartA", ";", "double", "intPartB", ";", "int", "intVal", ";", "/* Lookup exp(floor(x)).\n * intPartA will have the upper 22 bits, intPartB will have the lower\n * 52 bits.\n */", "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", ")", "{", "/* This will produce a subnormal output */", "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", ")", "{", "/* exp(1.494140625) is nearly a machine number... */", "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", "]", ";", "}", "/* Get the fractional part of x, find the greatest multiple of 2^-10 less than\n * x and look up the exp function of it.\n * fracPartA will have the upper 22 bits, fracPartB the lower 52 bits.\n */", "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", "]", ";", "/* epsilon is the difference in x from the nearest multiple of 2^-10. It\n * has a value in the range 0 <= epsilon < 2^-10.\n * Do the subtraction from x as the last step to avoid possible loss of percison.\n */", "final", "double", "epsilon", "=", "x", "-", "(", "intVal", "+", "intFrac", "/", "1024.0", ")", ";", "/* Compute z = exp(epsilon) - 1.0 via a minimax polynomial. z has\n full double precision (52 bits). Since z < 2^-10, we will have\n 62 bits of precision when combined with the contant 1. This will be\n used in the last addition below to get proper rounding. */", "/* Remez generated polynomial. Converges on the interval [0, 2^-10], error\n is less than 0.5 ULP */", "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", ";", "/* Compute (intPartA+intPartB) * (fracPartA+fracPartB) by binomial\n expansion.\n tempA is exact since intPartA and intPartB only have 22 bits each.\n tempB will have 52 bits of precision.\n */", "double", "tempA", "=", "intPartA", "*", "fracPartA", ";", "double", "tempB", "=", "intPartA", "*", "fracPartB", "+", "intPartB", "*", "fracPartA", "+", "intPartB", "*", "fracPartB", ";", "/* Compute the result. (1+z)(tempA+tempB). Order of operations is\n important. For accuracy add by increasing size. tempA is exact and\n much larger than the others. If there are extra bits specified from the\n pow() function, use them. */", "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", ")", "{", "// If requesting high precision", "hiPrec", "[", "0", "]", "=", "tempA", ";", "hiPrec", "[", "1", "]", "=", "tempC", "*", "extra", "*", "z", "+", "tempC", "*", "extra", "+", "tempC", "*", "z", "+", "tempB", ";", "}", "return", "result", ";", "}" ]
Internal helper method for exponential function. @param x original argument of the exponential function @param extra extra bits of precision on input (To Be Confirmed) @param hiPrec extra bits of precision on output (To Be Confirmed) @return exp(x)
[ "Internal", "helper", "method", "for", "exponential", "function", "." ]
9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6
https://github.com/jroyalty/jglm/blob/9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6/src/main/java/com/hackoeur/jglm/support/FastMath.java#L881-L996
8,570
jroyalty/jglm
src/main/java/com/hackoeur/jglm/support/FastMath.java
FastMath.log10
public static double log10(final double x) { final double hiPrec[] = new double[2]; final double lores = log(x, hiPrec); if (Double.isInfinite(lores)){ // don't allow this to be converted to NaN 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; }
java
public static double log10(final double x) { final double hiPrec[] = new double[2]; final double lores = log(x, hiPrec); if (Double.isInfinite(lores)){ // don't allow this to be converted to NaN 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; }
[ "public", "static", "double", "log10", "(", "final", "double", "x", ")", "{", "final", "double", "hiPrec", "[", "]", "=", "new", "double", "[", "2", "]", ";", "final", "double", "lores", "=", "log", "(", "x", ",", "hiPrec", ")", ";", "if", "(", "Double", ".", "isInfinite", "(", "lores", ")", ")", "{", "// don't allow this to be converted to NaN", "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. @param x a number @return log10(x)
[ "Compute", "the", "base", "10", "logarithm", "." ]
9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6
https://github.com/jroyalty/jglm/blob/9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6/src/main/java/com/hackoeur/jglm/support/FastMath.java#L1437-L1453
8,571
jroyalty/jglm
src/main/java/com/hackoeur/jglm/support/FastMath.java
FastMath.pow
public static double pow(double d, int e) { if (e == 0) { return 1.0; } else if (e < 0) { e = -e; d = 1.0 / d; } // split d as two 26 bits numbers // beware the following expressions must NOT be simplified, they rely on floating point arithmetic properties final int splitFactor = 0x8000001; final double cd = splitFactor * d; final double d1High = cd - (cd - d); final double d1Low = d - d1High; // prepare result double resultHigh = 1; double resultLow = 0; // d^(2p) double d2p = d; double d2pHigh = d1High; double d2pLow = d1Low; while (e != 0) { if ((e & 0x1) != 0) { // accurate multiplication result = result * d^(2p) using Veltkamp TwoProduct algorithm // beware the following expressions must NOT be simplified, they rely on floating point arithmetic properties 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; } // accurate squaring d^(2(p+1)) = d^(2p) * d^(2p) using Veltkamp TwoProduct algorithm // beware the following expressions must NOT be simplified, they rely on floating point arithmetic properties 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; }
java
public static double pow(double d, int e) { if (e == 0) { return 1.0; } else if (e < 0) { e = -e; d = 1.0 / d; } // split d as two 26 bits numbers // beware the following expressions must NOT be simplified, they rely on floating point arithmetic properties final int splitFactor = 0x8000001; final double cd = splitFactor * d; final double d1High = cd - (cd - d); final double d1Low = d - d1High; // prepare result double resultHigh = 1; double resultLow = 0; // d^(2p) double d2p = d; double d2pHigh = d1High; double d2pLow = d1Low; while (e != 0) { if ((e & 0x1) != 0) { // accurate multiplication result = result * d^(2p) using Veltkamp TwoProduct algorithm // beware the following expressions must NOT be simplified, they rely on floating point arithmetic properties 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; } // accurate squaring d^(2(p+1)) = d^(2p) * d^(2p) using Veltkamp TwoProduct algorithm // beware the following expressions must NOT be simplified, they rely on floating point arithmetic properties 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; }
[ "public", "static", "double", "pow", "(", "double", "d", ",", "int", "e", ")", "{", "if", "(", "e", "==", "0", ")", "{", "return", "1.0", ";", "}", "else", "if", "(", "e", "<", "0", ")", "{", "e", "=", "-", "e", ";", "d", "=", "1.0", "/", "d", ";", "}", "// split d as two 26 bits numbers", "// beware the following expressions must NOT be simplified, they rely on floating point arithmetic properties", "final", "int", "splitFactor", "=", "0x8000001", ";", "final", "double", "cd", "=", "splitFactor", "*", "d", ";", "final", "double", "d1High", "=", "cd", "-", "(", "cd", "-", "d", ")", ";", "final", "double", "d1Low", "=", "d", "-", "d1High", ";", "// prepare result", "double", "resultHigh", "=", "1", ";", "double", "resultLow", "=", "0", ";", "// d^(2p)", "double", "d2p", "=", "d", ";", "double", "d2pHigh", "=", "d1High", ";", "double", "d2pLow", "=", "d1Low", ";", "while", "(", "e", "!=", "0", ")", "{", "if", "(", "(", "e", "&", "0x1", ")", "!=", "0", ")", "{", "// accurate multiplication result = result * d^(2p) using Veltkamp TwoProduct algorithm", "// beware the following expressions must NOT be simplified, they rely on floating point arithmetic properties", "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", ";", "}", "// accurate squaring d^(2(p+1)) = d^(2p) * d^(2p) using Veltkamp TwoProduct algorithm", "// beware the following expressions must NOT be simplified, they rely on floating point arithmetic properties", "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. @param d Number to raise. @param e Exponent. @return d<sup>e</sup> @since 3.1
[ "Raise", "a", "double", "to", "an", "int", "power", "." ]
9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6
https://github.com/jroyalty/jglm/blob/9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6/src/main/java/com/hackoeur/jglm/support/FastMath.java#L1651-L1708
8,572
jroyalty/jglm
src/main/java/com/hackoeur/jglm/support/FastMath.java
FastMath.sin
public static double sin(double x) { boolean negative = false; int quadrant = 0; double xa; double xb = 0.0; /* Take absolute value of the input */ xa = x; if (x < 0) { negative = true; xa = -xa; } /* Check for zero and negative zero */ 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; } /* Perform any argument reduction */ if (xa > 3294198.0) { // PI * (2**20) // Argument too big for CodyWaite reduction. Must use // PayneHanek. 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; // Flip bit 1 } 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; } }
java
public static double sin(double x) { boolean negative = false; int quadrant = 0; double xa; double xb = 0.0; /* Take absolute value of the input */ xa = x; if (x < 0) { negative = true; xa = -xa; } /* Check for zero and negative zero */ 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; } /* Perform any argument reduction */ if (xa > 3294198.0) { // PI * (2**20) // Argument too big for CodyWaite reduction. Must use // PayneHanek. 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; // Flip bit 1 } 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; } }
[ "public", "static", "double", "sin", "(", "double", "x", ")", "{", "boolean", "negative", "=", "false", ";", "int", "quadrant", "=", "0", ";", "double", "xa", ";", "double", "xb", "=", "0.0", ";", "/* Take absolute value of the input */", "xa", "=", "x", ";", "if", "(", "x", "<", "0", ")", "{", "negative", "=", "true", ";", "xa", "=", "-", "xa", ";", "}", "/* Check for zero and negative zero */", "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", ";", "}", "/* Perform any argument reduction */", "if", "(", "xa", ">", "3294198.0", ")", "{", "// PI * (2**20)", "// Argument too big for CodyWaite reduction. Must use", "// PayneHanek.", "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", ";", "// Flip bit 1", "}", "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. @param x Argument. @return sin(x)
[ "Sine", "function", "." ]
9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6
https://github.com/jroyalty/jglm/blob/9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6/src/main/java/com/hackoeur/jglm/support/FastMath.java#L2265-L2324
8,573
jroyalty/jglm
src/main/java/com/hackoeur/jglm/support/FastMath.java
FastMath.cos
public static double cos(double x) { int quadrant = 0; /* Take absolute value of the input */ double xa = x; if (x < 0) { xa = -xa; } if (xa != xa || xa == Double.POSITIVE_INFINITY) { return Double.NaN; } /* Perform any argument reduction */ double xb = 0; if (xa > 3294198.0) { // PI * (2**20) // Argument too big for CodyWaite reduction. Must use // PayneHanek. 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 = (quadrant + 2) % 4; 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; } }
java
public static double cos(double x) { int quadrant = 0; /* Take absolute value of the input */ double xa = x; if (x < 0) { xa = -xa; } if (xa != xa || xa == Double.POSITIVE_INFINITY) { return Double.NaN; } /* Perform any argument reduction */ double xb = 0; if (xa > 3294198.0) { // PI * (2**20) // Argument too big for CodyWaite reduction. Must use // PayneHanek. 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 = (quadrant + 2) % 4; 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; } }
[ "public", "static", "double", "cos", "(", "double", "x", ")", "{", "int", "quadrant", "=", "0", ";", "/* Take absolute value of the input */", "double", "xa", "=", "x", ";", "if", "(", "x", "<", "0", ")", "{", "xa", "=", "-", "xa", ";", "}", "if", "(", "xa", "!=", "xa", "||", "xa", "==", "Double", ".", "POSITIVE_INFINITY", ")", "{", "return", "Double", ".", "NaN", ";", "}", "/* Perform any argument reduction */", "double", "xb", "=", "0", ";", "if", "(", "xa", ">", "3294198.0", ")", "{", "// PI * (2**20)", "// Argument too big for CodyWaite reduction. Must use", "// PayneHanek.", "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 = (quadrant + 2) % 4;", "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. @param x Argument. @return cos(x)
[ "Cosine", "function", "." ]
9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6
https://github.com/jroyalty/jglm/blob/9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6/src/main/java/com/hackoeur/jglm/support/FastMath.java#L2332-L2378
8,574
jroyalty/jglm
src/main/java/com/hackoeur/jglm/support/FastMath.java
FastMath.tan
public static double tan(double x) { boolean negative = false; int quadrant = 0; /* Take absolute value of the input */ double xa = x; if (x < 0) { negative = true; xa = -xa; } /* Check for zero and negative zero */ 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; } /* Perform any argument reduction */ double xb = 0; if (xa > 3294198.0) { // PI * (2**20) // Argument too big for CodyWaite reduction. Must use // PayneHanek. 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) { // Accuracy suffers between 1.5 and PI/2 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; }
java
public static double tan(double x) { boolean negative = false; int quadrant = 0; /* Take absolute value of the input */ double xa = x; if (x < 0) { negative = true; xa = -xa; } /* Check for zero and negative zero */ 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; } /* Perform any argument reduction */ double xb = 0; if (xa > 3294198.0) { // PI * (2**20) // Argument too big for CodyWaite reduction. Must use // PayneHanek. 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) { // Accuracy suffers between 1.5 and PI/2 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; }
[ "public", "static", "double", "tan", "(", "double", "x", ")", "{", "boolean", "negative", "=", "false", ";", "int", "quadrant", "=", "0", ";", "/* Take absolute value of the input */", "double", "xa", "=", "x", ";", "if", "(", "x", "<", "0", ")", "{", "negative", "=", "true", ";", "xa", "=", "-", "xa", ";", "}", "/* Check for zero and negative zero */", "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", ";", "}", "/* Perform any argument reduction */", "double", "xb", "=", "0", ";", "if", "(", "xa", ">", "3294198.0", ")", "{", "// PI * (2**20)", "// Argument too big for CodyWaite reduction. Must use", "// PayneHanek.", "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", ")", "{", "// Accuracy suffers between 1.5 and PI/2", "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. @param x Argument. @return tan(x)
[ "Tangent", "function", "." ]
9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6
https://github.com/jroyalty/jglm/blob/9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6/src/main/java/com/hackoeur/jglm/support/FastMath.java#L2386-L2455
8,575
jroyalty/jglm
src/main/java/com/hackoeur/jglm/support/FastMath.java
FastMath.asin
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) { // Matches +/- 0.0; return correct sign return x; } /* Compute asin(x) = atan(x/sqrt(1-x*x)) */ /* Split x */ double temp = x * HEX_40000000; final double xa = x + temp - temp; final double xb = x - xa; /* Square it */ double ya = xa*xa; double yb = xa*xb*2.0 + xb*xb; /* Subtract from 1 */ ya = -ya; yb = -yb; double za = 1.0 + ya; double zb = -(za - 1.0 - ya); temp = za + yb; zb += -(temp - za - yb); za = temp; /* Square root */ double y; y = sqrt(za); temp = y * HEX_40000000; ya = y + temp - temp; yb = y - ya; /* Extend precision of sqrt */ yb += (za - ya*ya - 2*ya*yb - yb*yb) / (2.0*y); /* Contribution of zb to sqrt */ double dx = zb / (2.0*y); // Compute ratio r = x/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; // Correct for rounding in division rb += -x * dx / y / y; // Add in effect additional bits of sqrt. temp = ra + rb; rb = -(temp - ra - rb); ra = temp; return atan(ra, rb, false); }
java
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) { // Matches +/- 0.0; return correct sign return x; } /* Compute asin(x) = atan(x/sqrt(1-x*x)) */ /* Split x */ double temp = x * HEX_40000000; final double xa = x + temp - temp; final double xb = x - xa; /* Square it */ double ya = xa*xa; double yb = xa*xb*2.0 + xb*xb; /* Subtract from 1 */ ya = -ya; yb = -yb; double za = 1.0 + ya; double zb = -(za - 1.0 - ya); temp = za + yb; zb += -(temp - za - yb); za = temp; /* Square root */ double y; y = sqrt(za); temp = y * HEX_40000000; ya = y + temp - temp; yb = y - ya; /* Extend precision of sqrt */ yb += (za - ya*ya - 2*ya*yb - yb*yb) / (2.0*y); /* Contribution of zb to sqrt */ double dx = zb / (2.0*y); // Compute ratio r = x/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; // Correct for rounding in division rb += -x * dx / y / y; // Add in effect additional bits of sqrt. temp = ra + rb; rb = -(temp - ra - rb); ra = temp; return atan(ra, rb, false); }
[ "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", ")", "{", "// Matches +/- 0.0; return correct sign", "return", "x", ";", "}", "/* Compute asin(x) = atan(x/sqrt(1-x*x)) */", "/* Split x */", "double", "temp", "=", "x", "*", "HEX_40000000", ";", "final", "double", "xa", "=", "x", "+", "temp", "-", "temp", ";", "final", "double", "xb", "=", "x", "-", "xa", ";", "/* Square it */", "double", "ya", "=", "xa", "*", "xa", ";", "double", "yb", "=", "xa", "*", "xb", "*", "2.0", "+", "xb", "*", "xb", ";", "/* Subtract from 1 */", "ya", "=", "-", "ya", ";", "yb", "=", "-", "yb", ";", "double", "za", "=", "1.0", "+", "ya", ";", "double", "zb", "=", "-", "(", "za", "-", "1.0", "-", "ya", ")", ";", "temp", "=", "za", "+", "yb", ";", "zb", "+=", "-", "(", "temp", "-", "za", "-", "yb", ")", ";", "za", "=", "temp", ";", "/* Square root */", "double", "y", ";", "y", "=", "sqrt", "(", "za", ")", ";", "temp", "=", "y", "*", "HEX_40000000", ";", "ya", "=", "y", "+", "temp", "-", "temp", ";", "yb", "=", "y", "-", "ya", ";", "/* Extend precision of sqrt */", "yb", "+=", "(", "za", "-", "ya", "*", "ya", "-", "2", "*", "ya", "*", "yb", "-", "yb", "*", "yb", ")", "/", "(", "2.0", "*", "y", ")", ";", "/* Contribution of zb to sqrt */", "double", "dx", "=", "zb", "/", "(", "2.0", "*", "y", ")", ";", "// Compute ratio r = x/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", ";", "// Correct for rounding in division", "rb", "+=", "-", "x", "*", "dx", "/", "y", "/", "y", ";", "// Add in effect additional bits of sqrt.", "temp", "=", "ra", "+", "rb", ";", "rb", "=", "-", "(", "temp", "-", "ra", "-", "rb", ")", ";", "ra", "=", "temp", ";", "return", "atan", "(", "ra", ",", "rb", ",", "false", ")", ";", "}" ]
Compute the arc sine of a number. @param x number on which evaluation is done @return arc sine of x
[ "Compute", "the", "arc", "sine", "of", "a", "number", "." ]
9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6
https://github.com/jroyalty/jglm/blob/9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6/src/main/java/com/hackoeur/jglm/support/FastMath.java#L2740-L2810
8,576
jroyalty/jglm
src/main/java/com/hackoeur/jglm/support/FastMath.java
FastMath.acos
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; } /* Compute acos(x) = atan(sqrt(1-x*x)/x) */ /* Split x */ double temp = x * HEX_40000000; final double xa = x + temp - temp; final double xb = x - xa; /* Square it */ double ya = xa*xa; double yb = xa*xb*2.0 + xb*xb; /* Subtract from 1 */ ya = -ya; yb = -yb; double za = 1.0 + ya; double zb = -(za - 1.0 - ya); temp = za + yb; zb += -(temp - za - yb); za = temp; /* Square root */ double y = sqrt(za); temp = y * HEX_40000000; ya = y + temp - temp; yb = y - ya; /* Extend precision of sqrt */ yb += (za - ya*ya - 2*ya*yb - yb*yb) / (2.0*y); /* Contribution of zb to sqrt */ yb += zb / (2.0*y); y = ya+yb; yb = -(y - ya - yb); // Compute ratio r = y/x double r = y/x; // Did r overflow? if (Double.isInfinite(r)) { // x is effectively zero return Math.PI/2; // so return the appropriate value } double ra = doubleHighPart(r); double rb = r - ra; rb += (y - ra*xa - ra*xb - rb*xa - rb*xb) / x; // Correct for rounding in division rb += yb / x; // Add in effect additional bits of sqrt. temp = ra + rb; rb = -(temp - ra - rb); ra = temp; return atan(ra, rb, x<0); }
java
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; } /* Compute acos(x) = atan(sqrt(1-x*x)/x) */ /* Split x */ double temp = x * HEX_40000000; final double xa = x + temp - temp; final double xb = x - xa; /* Square it */ double ya = xa*xa; double yb = xa*xb*2.0 + xb*xb; /* Subtract from 1 */ ya = -ya; yb = -yb; double za = 1.0 + ya; double zb = -(za - 1.0 - ya); temp = za + yb; zb += -(temp - za - yb); za = temp; /* Square root */ double y = sqrt(za); temp = y * HEX_40000000; ya = y + temp - temp; yb = y - ya; /* Extend precision of sqrt */ yb += (za - ya*ya - 2*ya*yb - yb*yb) / (2.0*y); /* Contribution of zb to sqrt */ yb += zb / (2.0*y); y = ya+yb; yb = -(y - ya - yb); // Compute ratio r = y/x double r = y/x; // Did r overflow? if (Double.isInfinite(r)) { // x is effectively zero return Math.PI/2; // so return the appropriate value } double ra = doubleHighPart(r); double rb = r - ra; rb += (y - ra*xa - ra*xb - rb*xa - rb*xb) / x; // Correct for rounding in division rb += yb / x; // Add in effect additional bits of sqrt. temp = ra + rb; rb = -(temp - ra - rb); ra = temp; return atan(ra, rb, x<0); }
[ "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", ";", "}", "/* Compute acos(x) = atan(sqrt(1-x*x)/x) */", "/* Split x */", "double", "temp", "=", "x", "*", "HEX_40000000", ";", "final", "double", "xa", "=", "x", "+", "temp", "-", "temp", ";", "final", "double", "xb", "=", "x", "-", "xa", ";", "/* Square it */", "double", "ya", "=", "xa", "*", "xa", ";", "double", "yb", "=", "xa", "*", "xb", "*", "2.0", "+", "xb", "*", "xb", ";", "/* Subtract from 1 */", "ya", "=", "-", "ya", ";", "yb", "=", "-", "yb", ";", "double", "za", "=", "1.0", "+", "ya", ";", "double", "zb", "=", "-", "(", "za", "-", "1.0", "-", "ya", ")", ";", "temp", "=", "za", "+", "yb", ";", "zb", "+=", "-", "(", "temp", "-", "za", "-", "yb", ")", ";", "za", "=", "temp", ";", "/* Square root */", "double", "y", "=", "sqrt", "(", "za", ")", ";", "temp", "=", "y", "*", "HEX_40000000", ";", "ya", "=", "y", "+", "temp", "-", "temp", ";", "yb", "=", "y", "-", "ya", ";", "/* Extend precision of sqrt */", "yb", "+=", "(", "za", "-", "ya", "*", "ya", "-", "2", "*", "ya", "*", "yb", "-", "yb", "*", "yb", ")", "/", "(", "2.0", "*", "y", ")", ";", "/* Contribution of zb to sqrt */", "yb", "+=", "zb", "/", "(", "2.0", "*", "y", ")", ";", "y", "=", "ya", "+", "yb", ";", "yb", "=", "-", "(", "y", "-", "ya", "-", "yb", ")", ";", "// Compute ratio r = y/x", "double", "r", "=", "y", "/", "x", ";", "// Did r overflow?", "if", "(", "Double", ".", "isInfinite", "(", "r", ")", ")", "{", "// x is effectively zero", "return", "Math", ".", "PI", "/", "2", ";", "// so return the appropriate value", "}", "double", "ra", "=", "doubleHighPart", "(", "r", ")", ";", "double", "rb", "=", "r", "-", "ra", ";", "rb", "+=", "(", "y", "-", "ra", "*", "xa", "-", "ra", "*", "xb", "-", "rb", "*", "xa", "-", "rb", "*", "xb", ")", "/", "x", ";", "// Correct for rounding in division", "rb", "+=", "yb", "/", "x", ";", "// Add in effect additional bits of sqrt.", "temp", "=", "ra", "+", "rb", ";", "rb", "=", "-", "(", "temp", "-", "ra", "-", "rb", ")", ";", "ra", "=", "temp", ";", "return", "atan", "(", "ra", ",", "rb", ",", "x", "<", "0", ")", ";", "}" ]
Compute the arc cosine of a number. @param x number on which evaluation is done @return arc cosine of x
[ "Compute", "the", "arc", "cosine", "of", "a", "number", "." ]
9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6
https://github.com/jroyalty/jglm/blob/9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6/src/main/java/com/hackoeur/jglm/support/FastMath.java#L2816-L2892
8,577
jroyalty/jglm
src/main/java/com/hackoeur/jglm/support/FastMath.java
FastMath.cbrt
public static double cbrt(double x) { /* Convert input double to bits */ long inbits = Double.doubleToLongBits(x); int exponent = (int) ((inbits >> 52) & 0x7ff) - 1023; boolean subnormal = false; if (exponent == -1023) { if (x == 0) { return x; } /* Subnormal, so normalize */ subnormal = true; x *= 1.8014398509481984E16; // 2^54 inbits = Double.doubleToLongBits(x); exponent = (int) ((inbits >> 52) & 0x7ff) - 1023; } if (exponent == 1024) { // Nan or infinity. Don't care which. return x; } /* Divide the exponent by 3 */ int exp3 = exponent / 3; /* p2 will be the nearest power of 2 to x with its exponent divided by 3 */ double p2 = Double.longBitsToDouble((inbits & 0x8000000000000000L) | (long)(((exp3 + 1023) & 0x7ff)) << 52); /* This will be a number between 1 and 2 */ final double mant = Double.longBitsToDouble((inbits & 0x000fffffffffffffL) | 0x3ff0000000000000L); /* Estimate the cube root of mant by polynomial */ 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]; // est should now be good to about 15 bits of precision. Do 2 rounds of // Newton's method to get closer, this should get us full double precision // Scale down x for the purpose of doing newtons method. This avoids over/under flows. final double xs = x / (p2*p2*p2); est += (xs - est*est*est) / (3*est*est); est += (xs - est*est*est) / (3*est*est); // Do one round of Newton's method in extended precision to get the last bit right. 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); /* Scale by a power of two, so this is exact. */ est *= p2; if (subnormal) { est *= 3.814697265625E-6; // 2^-18 } return est; }
java
public static double cbrt(double x) { /* Convert input double to bits */ long inbits = Double.doubleToLongBits(x); int exponent = (int) ((inbits >> 52) & 0x7ff) - 1023; boolean subnormal = false; if (exponent == -1023) { if (x == 0) { return x; } /* Subnormal, so normalize */ subnormal = true; x *= 1.8014398509481984E16; // 2^54 inbits = Double.doubleToLongBits(x); exponent = (int) ((inbits >> 52) & 0x7ff) - 1023; } if (exponent == 1024) { // Nan or infinity. Don't care which. return x; } /* Divide the exponent by 3 */ int exp3 = exponent / 3; /* p2 will be the nearest power of 2 to x with its exponent divided by 3 */ double p2 = Double.longBitsToDouble((inbits & 0x8000000000000000L) | (long)(((exp3 + 1023) & 0x7ff)) << 52); /* This will be a number between 1 and 2 */ final double mant = Double.longBitsToDouble((inbits & 0x000fffffffffffffL) | 0x3ff0000000000000L); /* Estimate the cube root of mant by polynomial */ 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]; // est should now be good to about 15 bits of precision. Do 2 rounds of // Newton's method to get closer, this should get us full double precision // Scale down x for the purpose of doing newtons method. This avoids over/under flows. final double xs = x / (p2*p2*p2); est += (xs - est*est*est) / (3*est*est); est += (xs - est*est*est) / (3*est*est); // Do one round of Newton's method in extended precision to get the last bit right. 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); /* Scale by a power of two, so this is exact. */ est *= p2; if (subnormal) { est *= 3.814697265625E-6; // 2^-18 } return est; }
[ "public", "static", "double", "cbrt", "(", "double", "x", ")", "{", "/* Convert input double to bits */", "long", "inbits", "=", "Double", ".", "doubleToLongBits", "(", "x", ")", ";", "int", "exponent", "=", "(", "int", ")", "(", "(", "inbits", ">>", "52", ")", "&", "0x7ff", ")", "-", "1023", ";", "boolean", "subnormal", "=", "false", ";", "if", "(", "exponent", "==", "-", "1023", ")", "{", "if", "(", "x", "==", "0", ")", "{", "return", "x", ";", "}", "/* Subnormal, so normalize */", "subnormal", "=", "true", ";", "x", "*=", "1.8014398509481984E16", ";", "// 2^54", "inbits", "=", "Double", ".", "doubleToLongBits", "(", "x", ")", ";", "exponent", "=", "(", "int", ")", "(", "(", "inbits", ">>", "52", ")", "&", "0x7ff", ")", "-", "1023", ";", "}", "if", "(", "exponent", "==", "1024", ")", "{", "// Nan or infinity. Don't care which.", "return", "x", ";", "}", "/* Divide the exponent by 3 */", "int", "exp3", "=", "exponent", "/", "3", ";", "/* p2 will be the nearest power of 2 to x with its exponent divided by 3 */", "double", "p2", "=", "Double", ".", "longBitsToDouble", "(", "(", "inbits", "&", "0x8000000000000000", "L", ")", "|", "(", "long", ")", "(", "(", "(", "exp3", "+", "1023", ")", "&", "0x7ff", ")", ")", "<<", "52", ")", ";", "/* This will be a number between 1 and 2 */", "final", "double", "mant", "=", "Double", ".", "longBitsToDouble", "(", "(", "inbits", "&", "0x000fffffffffffff", "L", ")", "|", "0x3ff0000000000000", "L", ")", ";", "/* Estimate the cube root of mant by polynomial */", "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", "]", ";", "// est should now be good to about 15 bits of precision. Do 2 rounds of", "// Newton's method to get closer, this should get us full double precision", "// Scale down x for the purpose of doing newtons method. This avoids over/under flows.", "final", "double", "xs", "=", "x", "/", "(", "p2", "*", "p2", "*", "p2", ")", ";", "est", "+=", "(", "xs", "-", "est", "*", "est", "*", "est", ")", "/", "(", "3", "*", "est", "*", "est", ")", ";", "est", "+=", "(", "xs", "-", "est", "*", "est", "*", "est", ")", "/", "(", "3", "*", "est", "*", "est", ")", ";", "// Do one round of Newton's method in extended precision to get the last bit right.", "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", ")", ";", "/* Scale by a power of two, so this is exact. */", "est", "*=", "p2", ";", "if", "(", "subnormal", ")", "{", "est", "*=", "3.814697265625E-6", ";", "// 2^-18", "}", "return", "est", ";", "}" ]
Compute the cubic root of a number. @param x number on which evaluation is done @return cubic root of x
[ "Compute", "the", "cubic", "root", "of", "a", "number", "." ]
9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6
https://github.com/jroyalty/jglm/blob/9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6/src/main/java/com/hackoeur/jglm/support/FastMath.java#L2898-L2976
8,578
jroyalty/jglm
src/main/java/com/hackoeur/jglm/support/FastMath.java
FastMath.toRadians
public static double toRadians(double x) { if (Double.isInfinite(x) || x == 0.0) { // Matches +/- 0.0; return correct sign return x; } // These are PI/180 split into high and low order bits 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; // ensure correct sign if calculation underflows } return result; }
java
public static double toRadians(double x) { if (Double.isInfinite(x) || x == 0.0) { // Matches +/- 0.0; return correct sign return x; } // These are PI/180 split into high and low order bits 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; // ensure correct sign if calculation underflows } return result; }
[ "public", "static", "double", "toRadians", "(", "double", "x", ")", "{", "if", "(", "Double", ".", "isInfinite", "(", "x", ")", "||", "x", "==", "0.0", ")", "{", "// Matches +/- 0.0; return correct sign", "return", "x", ";", "}", "// These are PI/180 split into high and low order bits", "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", ";", "// ensure correct sign if calculation underflows", "}", "return", "result", ";", "}" ]
Convert degrees to radians, with error of less than 0.5 ULP @param x angle in degrees @return x converted into radians
[ "Convert", "degrees", "to", "radians", "with", "error", "of", "less", "than", "0", ".", "5", "ULP" ]
9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6
https://github.com/jroyalty/jglm/blob/9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6/src/main/java/com/hackoeur/jglm/support/FastMath.java#L2983-L3001
8,579
jroyalty/jglm
src/main/java/com/hackoeur/jglm/support/FastMath.java
FastMath.toDegrees
public static double toDegrees(double x) { if (Double.isInfinite(x) || x == 0.0) { // Matches +/- 0.0; return correct sign return x; } // These are 180/PI split into high and low order bits 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; }
java
public static double toDegrees(double x) { if (Double.isInfinite(x) || x == 0.0) { // Matches +/- 0.0; return correct sign return x; } // These are 180/PI split into high and low order bits 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; }
[ "public", "static", "double", "toDegrees", "(", "double", "x", ")", "{", "if", "(", "Double", ".", "isInfinite", "(", "x", ")", "||", "x", "==", "0.0", ")", "{", "// Matches +/- 0.0; return correct sign", "return", "x", ";", "}", "// These are 180/PI split into high and low order bits", "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 @param x angle in radians @return x converted into degrees
[ "Convert", "radians", "to", "degrees", "with", "error", "of", "less", "than", "0", ".", "5", "ULP" ]
9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6
https://github.com/jroyalty/jglm/blob/9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6/src/main/java/com/hackoeur/jglm/support/FastMath.java#L3008-L3022
8,580
jroyalty/jglm
src/main/java/com/hackoeur/jglm/support/FastMath.java
FastMath.scalb
public static double scalb(final double d, final int n) { // first simple and fast handling when 2^n can be represented using normal numbers if ((n > -1023) && (n < 1024)) { return d * Double.longBitsToDouble(((long) (n + 1023)) << 52); } // handle special cases 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; } // decompose d final long bits = Double.doubleToLongBits(d); final long sign = bits & 0x8000000000000000L; int exponent = ((int) (bits >>> 52)) & 0x7ff; long mantissa = bits & 0x000fffffffffffffL; // compute scaled exponent int scaledExponent = exponent + n; if (n < 0) { // we are really in the case n <= -1023 if (scaledExponent > 0) { // both the input and the result are normal numbers, we only adjust the exponent return Double.longBitsToDouble(sign | (((long) scaledExponent) << 52) | mantissa); } else if (scaledExponent > -53) { // the input is a normal number and the result is a subnormal number // recover the hidden mantissa bit mantissa = mantissa | (1L << 52); // scales down complete mantissa, hence losing least significant bits final long mostSignificantLostBit = mantissa & (1L << (-scaledExponent)); mantissa = mantissa >>> (1 - scaledExponent); if (mostSignificantLostBit != 0) { // we need to add 1 bit to round up the result mantissa++; } return Double.longBitsToDouble(sign | mantissa); } else { // no need to compute the mantissa, the number scales down to 0 return (sign == 0L) ? 0.0 : -0.0; } } else { // we are really in the case n >= 1024 if (exponent == 0) { // the input number is subnormal, normalize it 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; } } }
java
public static double scalb(final double d, final int n) { // first simple and fast handling when 2^n can be represented using normal numbers if ((n > -1023) && (n < 1024)) { return d * Double.longBitsToDouble(((long) (n + 1023)) << 52); } // handle special cases 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; } // decompose d final long bits = Double.doubleToLongBits(d); final long sign = bits & 0x8000000000000000L; int exponent = ((int) (bits >>> 52)) & 0x7ff; long mantissa = bits & 0x000fffffffffffffL; // compute scaled exponent int scaledExponent = exponent + n; if (n < 0) { // we are really in the case n <= -1023 if (scaledExponent > 0) { // both the input and the result are normal numbers, we only adjust the exponent return Double.longBitsToDouble(sign | (((long) scaledExponent) << 52) | mantissa); } else if (scaledExponent > -53) { // the input is a normal number and the result is a subnormal number // recover the hidden mantissa bit mantissa = mantissa | (1L << 52); // scales down complete mantissa, hence losing least significant bits final long mostSignificantLostBit = mantissa & (1L << (-scaledExponent)); mantissa = mantissa >>> (1 - scaledExponent); if (mostSignificantLostBit != 0) { // we need to add 1 bit to round up the result mantissa++; } return Double.longBitsToDouble(sign | mantissa); } else { // no need to compute the mantissa, the number scales down to 0 return (sign == 0L) ? 0.0 : -0.0; } } else { // we are really in the case n >= 1024 if (exponent == 0) { // the input number is subnormal, normalize it 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; } } }
[ "public", "static", "double", "scalb", "(", "final", "double", "d", ",", "final", "int", "n", ")", "{", "// first simple and fast handling when 2^n can be represented using normal numbers", "if", "(", "(", "n", ">", "-", "1023", ")", "&&", "(", "n", "<", "1024", ")", ")", "{", "return", "d", "*", "Double", ".", "longBitsToDouble", "(", "(", "(", "long", ")", "(", "n", "+", "1023", ")", ")", "<<", "52", ")", ";", "}", "// handle special cases", "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", ";", "}", "// decompose d", "final", "long", "bits", "=", "Double", ".", "doubleToLongBits", "(", "d", ")", ";", "final", "long", "sign", "=", "bits", "&", "0x8000000000000000", "", "L", ";", "int", "exponent", "=", "(", "(", "int", ")", "(", "bits", ">>>", "52", ")", ")", "&", "0x7ff", ";", "long", "mantissa", "=", "bits", "&", "0x000fffffffffffff", "", "L", ";", "// compute scaled exponent", "int", "scaledExponent", "=", "exponent", "+", "n", ";", "if", "(", "n", "<", "0", ")", "{", "// we are really in the case n <= -1023", "if", "(", "scaledExponent", ">", "0", ")", "{", "// both the input and the result are normal numbers, we only adjust the exponent", "return", "Double", ".", "longBitsToDouble", "(", "sign", "|", "(", "(", "(", "long", ")", "scaledExponent", ")", "<<", "52", ")", "|", "mantissa", ")", ";", "}", "else", "if", "(", "scaledExponent", ">", "-", "53", ")", "{", "// the input is a normal number and the result is a subnormal number", "// recover the hidden mantissa bit", "mantissa", "=", "mantissa", "|", "(", "1L", "<<", "52", ")", ";", "// scales down complete mantissa, hence losing least significant bits", "final", "long", "mostSignificantLostBit", "=", "mantissa", "&", "(", "1L", "<<", "(", "-", "scaledExponent", ")", ")", ";", "mantissa", "=", "mantissa", ">>>", "(", "1", "-", "scaledExponent", ")", ";", "if", "(", "mostSignificantLostBit", "!=", "0", ")", "{", "// we need to add 1 bit to round up the result", "mantissa", "++", ";", "}", "return", "Double", ".", "longBitsToDouble", "(", "sign", "|", "mantissa", ")", ";", "}", "else", "{", "// no need to compute the mantissa, the number scales down to 0", "return", "(", "sign", "==", "0L", ")", "?", "0.0", ":", "-", "0.0", ";", "}", "}", "else", "{", "// we are really in the case n >= 1024", "if", "(", "exponent", "==", "0", ")", "{", "// the input number is subnormal, normalize it", "while", "(", "(", "mantissa", ">>>", "52", ")", "!=", "1", ")", "{", "mantissa", "=", "mantissa", "<<", "1", ";", "--", "scaledExponent", ";", "}", "++", "scaledExponent", ";", "mantissa", "=", "mantissa", "&", "0x000fffffffffffff", "", "L", ";", "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. @param d number to multiply @param n power of 2 @return d &times; 2<sup>n</sup>
[ "Multiply", "a", "double", "number", "by", "a", "power", "of", "2", "." ]
9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6
https://github.com/jroyalty/jglm/blob/9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6/src/main/java/com/hackoeur/jglm/support/FastMath.java#L3090-L3166
8,581
jroyalty/jglm
src/main/java/com/hackoeur/jglm/support/FastMath.java
FastMath.scalb
public static float scalb(final float f, final int n) { // first simple and fast handling when 2^n can be represented using normal numbers if ((n > -127) && (n < 128)) { return f * Float.intBitsToFloat((n + 127) << 23); } // handle special cases 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; } // decompose f final int bits = Float.floatToIntBits(f); final int sign = bits & 0x80000000; int exponent = (bits >>> 23) & 0xff; int mantissa = bits & 0x007fffff; // compute scaled exponent int scaledExponent = exponent + n; if (n < 0) { // we are really in the case n <= -127 if (scaledExponent > 0) { // both the input and the result are normal numbers, we only adjust the exponent return Float.intBitsToFloat(sign | (scaledExponent << 23) | mantissa); } else if (scaledExponent > -24) { // the input is a normal number and the result is a subnormal number // recover the hidden mantissa bit mantissa = mantissa | (1 << 23); // scales down complete mantissa, hence losing least significant bits final int mostSignificantLostBit = mantissa & (1 << (-scaledExponent)); mantissa = mantissa >>> (1 - scaledExponent); if (mostSignificantLostBit != 0) { // we need to add 1 bit to round up the result mantissa++; } return Float.intBitsToFloat(sign | mantissa); } else { // no need to compute the mantissa, the number scales down to 0 return (sign == 0) ? 0.0f : -0.0f; } } else { // we are really in the case n >= 128 if (exponent == 0) { // the input number is subnormal, normalize it 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; } } }
java
public static float scalb(final float f, final int n) { // first simple and fast handling when 2^n can be represented using normal numbers if ((n > -127) && (n < 128)) { return f * Float.intBitsToFloat((n + 127) << 23); } // handle special cases 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; } // decompose f final int bits = Float.floatToIntBits(f); final int sign = bits & 0x80000000; int exponent = (bits >>> 23) & 0xff; int mantissa = bits & 0x007fffff; // compute scaled exponent int scaledExponent = exponent + n; if (n < 0) { // we are really in the case n <= -127 if (scaledExponent > 0) { // both the input and the result are normal numbers, we only adjust the exponent return Float.intBitsToFloat(sign | (scaledExponent << 23) | mantissa); } else if (scaledExponent > -24) { // the input is a normal number and the result is a subnormal number // recover the hidden mantissa bit mantissa = mantissa | (1 << 23); // scales down complete mantissa, hence losing least significant bits final int mostSignificantLostBit = mantissa & (1 << (-scaledExponent)); mantissa = mantissa >>> (1 - scaledExponent); if (mostSignificantLostBit != 0) { // we need to add 1 bit to round up the result mantissa++; } return Float.intBitsToFloat(sign | mantissa); } else { // no need to compute the mantissa, the number scales down to 0 return (sign == 0) ? 0.0f : -0.0f; } } else { // we are really in the case n >= 128 if (exponent == 0) { // the input number is subnormal, normalize it 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; } } }
[ "public", "static", "float", "scalb", "(", "final", "float", "f", ",", "final", "int", "n", ")", "{", "// first simple and fast handling when 2^n can be represented using normal numbers", "if", "(", "(", "n", ">", "-", "127", ")", "&&", "(", "n", "<", "128", ")", ")", "{", "return", "f", "*", "Float", ".", "intBitsToFloat", "(", "(", "n", "+", "127", ")", "<<", "23", ")", ";", "}", "// handle special cases", "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", ";", "}", "// decompose f", "final", "int", "bits", "=", "Float", ".", "floatToIntBits", "(", "f", ")", ";", "final", "int", "sign", "=", "bits", "&", "0x80000000", ";", "int", "exponent", "=", "(", "bits", ">>>", "23", ")", "&", "0xff", ";", "int", "mantissa", "=", "bits", "&", "0x007fffff", ";", "// compute scaled exponent", "int", "scaledExponent", "=", "exponent", "+", "n", ";", "if", "(", "n", "<", "0", ")", "{", "// we are really in the case n <= -127", "if", "(", "scaledExponent", ">", "0", ")", "{", "// both the input and the result are normal numbers, we only adjust the exponent", "return", "Float", ".", "intBitsToFloat", "(", "sign", "|", "(", "scaledExponent", "<<", "23", ")", "|", "mantissa", ")", ";", "}", "else", "if", "(", "scaledExponent", ">", "-", "24", ")", "{", "// the input is a normal number and the result is a subnormal number", "// recover the hidden mantissa bit", "mantissa", "=", "mantissa", "|", "(", "1", "<<", "23", ")", ";", "// scales down complete mantissa, hence losing least significant bits", "final", "int", "mostSignificantLostBit", "=", "mantissa", "&", "(", "1", "<<", "(", "-", "scaledExponent", ")", ")", ";", "mantissa", "=", "mantissa", ">>>", "(", "1", "-", "scaledExponent", ")", ";", "if", "(", "mostSignificantLostBit", "!=", "0", ")", "{", "// we need to add 1 bit to round up the result", "mantissa", "++", ";", "}", "return", "Float", ".", "intBitsToFloat", "(", "sign", "|", "mantissa", ")", ";", "}", "else", "{", "// no need to compute the mantissa, the number scales down to 0", "return", "(", "sign", "==", "0", ")", "?", "0.0f", ":", "-", "0.0f", ";", "}", "}", "else", "{", "// we are really in the case n >= 128", "if", "(", "exponent", "==", "0", ")", "{", "// the input number is subnormal, normalize it", "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. @param f number to multiply @param n power of 2 @return f &times; 2<sup>n</sup>
[ "Multiply", "a", "float", "number", "by", "a", "power", "of", "2", "." ]
9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6
https://github.com/jroyalty/jglm/blob/9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6/src/main/java/com/hackoeur/jglm/support/FastMath.java#L3174-L3250
8,582
jroyalty/jglm
src/main/java/com/hackoeur/jglm/support/FastMath.java
FastMath.floor
public static double floor(double x) { long y; if (x != x) { // NaN 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; }
java
public static double floor(double x) { long y; if (x != x) { // NaN 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; }
[ "public", "static", "double", "floor", "(", "double", "x", ")", "{", "long", "y", ";", "if", "(", "x", "!=", "x", ")", "{", "// NaN", "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. @param x number from which floor is requested @return a double number f such that f is an integer f <= x < f + 1.0
[ "Get", "the", "largest", "whole", "number", "smaller", "than", "x", "." ]
9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6
https://github.com/jroyalty/jglm/blob/9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6/src/main/java/com/hackoeur/jglm/support/FastMath.java#L3368-L3389
8,583
jroyalty/jglm
src/main/java/com/hackoeur/jglm/support/FastMath.java
FastMath.ceil
public static double ceil(double x) { double y; if (x != x) { // NaN return x; } y = floor(x); if (y == x) { return y; } y += 1.0; if (y == 0) { return x*y; } return y; }
java
public static double ceil(double x) { double y; if (x != x) { // NaN return x; } y = floor(x); if (y == x) { return y; } y += 1.0; if (y == 0) { return x*y; } return y; }
[ "public", "static", "double", "ceil", "(", "double", "x", ")", "{", "double", "y", ";", "if", "(", "x", "!=", "x", ")", "{", "// NaN", "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. @param x number from which ceil is requested @return a double number c such that c is an integer c - 1.0 < x <= c
[ "Get", "the", "smallest", "whole", "number", "larger", "than", "x", "." ]
9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6
https://github.com/jroyalty/jglm/blob/9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6/src/main/java/com/hackoeur/jglm/support/FastMath.java#L3395-L3414
8,584
jroyalty/jglm
src/main/java/com/hackoeur/jglm/support/FastMath.java
FastMath.rint
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; // Preserve sign of operand } return y+1.0; } if (d < 0.5) { return y; } /* half way, round to even */ long z = (long) y; return (z & 1) == 0 ? y : y + 1.0; }
java
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; // Preserve sign of operand } return y+1.0; } if (d < 0.5) { return y; } /* half way, round to even */ long z = (long) y; return (z & 1) == 0 ? y : y + 1.0; }
[ "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", ";", "// Preserve sign of operand", "}", "return", "y", "+", "1.0", ";", "}", "if", "(", "d", "<", "0.5", ")", "{", "return", "y", ";", "}", "/* half way, round to even */", "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. @param x number from which nearest whole number is requested @return a double number r such that r is an integer r - 0.5 <= x <= r + 0.5
[ "Get", "the", "whole", "number", "that", "is", "the", "nearest", "to", "x", "or", "the", "even", "one", "if", "x", "is", "exactly", "half", "way", "between", "two", "integers", "." ]
9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6
https://github.com/jroyalty/jglm/blob/9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6/src/main/java/com/hackoeur/jglm/support/FastMath.java#L3420-L3437
8,585
jroyalty/jglm
src/main/java/com/hackoeur/jglm/support/FastMathCalc.java
FastMathCalc.resplit
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) { // MAGIC NUMBER 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; } }
java
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) { // MAGIC NUMBER 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; } }
[ "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", ")", "{", "// MAGIC NUMBER", "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. @param a input/out array containing the split, changed on output
[ "Recompute", "a", "split", "." ]
9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6
https://github.com/jroyalty/jglm/blob/9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6/src/main/java/com/hackoeur/jglm/support/FastMathCalc.java#L343-L356
8,586
jroyalty/jglm
src/main/java/com/hackoeur/jglm/support/FastMathCalc.java
FastMathCalc.splitMult
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 */ resplit(ans); }
java
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 */ resplit(ans); }
[ "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 */", "resplit", "(", "ans", ")", ";", "}" ]
Multiply two numbers in split form. @param a first term of multiplication @param b second term of multiplication @param ans placeholder where to put the result
[ "Multiply", "two", "numbers", "in", "split", "form", "." ]
9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6
https://github.com/jroyalty/jglm/blob/9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6/src/main/java/com/hackoeur/jglm/support/FastMathCalc.java#L363-L369
8,587
jroyalty/jglm
src/main/java/com/hackoeur/jglm/support/FastMathCalc.java
FastMathCalc.splitAdd
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); }
java
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); }
[ "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. @param a first term of addition @param b second term of addition @param ans placeholder where to put the result
[ "Add", "two", "numbers", "in", "split", "form", "." ]
9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6
https://github.com/jroyalty/jglm/blob/9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6/src/main/java/com/hackoeur/jglm/support/FastMathCalc.java#L376-L381
8,588
jroyalty/jglm
src/main/java/com/hackoeur/jglm/support/FastMathCalc.java
FastMathCalc.printarray
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) { // "double array[]" causes PMD parsing error out.print(" {"); for(double d : array) { // assume inner array has very few entries out.printf("%-25.25s", format(d)); // multiple entries per line } out.println("}, // " + i++); } out.println(TABLE_END_DECL); }
java
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) { // "double array[]" causes PMD parsing error out.print(" {"); for(double d : array) { // assume inner array has very few entries out.printf("%-25.25s", format(d)); // multiple entries per line } out.println("}, // " + i++); } out.println(TABLE_END_DECL); }
[ "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", ")", "{", "// \"double array[]\" causes PMD parsing error", "out", ".", "print", "(", "\" {\"", ")", ";", "for", "(", "double", "d", ":", "array", ")", "{", "// assume inner array has very few entries", "out", ".", "printf", "(", "\"%-25.25s\"", ",", "format", "(", "d", ")", ")", ";", "// multiple entries per line", "}", "out", ".", "println", "(", "\"}, // \"", "+", "i", "++", ")", ";", "}", "out", ".", "println", "(", "TABLE_END_DECL", ")", ";", "}" ]
Print an array. @param out text output stream where output should be printed @param name array name @param expectedLen expected length of the array @param array2d array data
[ "Print", "an", "array", "." ]
9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6
https://github.com/jroyalty/jglm/blob/9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6/src/main/java/com/hackoeur/jglm/support/FastMathCalc.java#L600-L613
8,589
rzwitserloot/lombok.ast
src/main/lombok/ast/grammar/StructuresParser.java
StructuresParser.variableDefinition
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")))); }
java
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")))); }
[ "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!
[ "Add", "your", "own", "modifiers!" ]
ed83541c1a5a08952a5d4d7e316a6be9a05311fb
https://github.com/rzwitserloot/lombok.ast/blob/ed83541c1a5a08952a5d4d7e316a6be9a05311fb/src/main/lombok/ast/grammar/StructuresParser.java#L289-L297
8,590
rzwitserloot/lombok.ast
src/main/lombok/ast/grammar/ExpressionsParser.java
ExpressionsParser.postfixIncrementExpressionChaining
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")))); }
java
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")))); }
[ "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.
[ "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", "." ]
ed83541c1a5a08952a5d4d7e316a6be9a05311fb
https://github.com/rzwitserloot/lombok.ast/blob/ed83541c1a5a08952a5d4d7e316a6be9a05311fb/src/main/lombok/ast/grammar/ExpressionsParser.java#L218-L225
8,591
jroyalty/jglm
src/main/java/com/hackoeur/jglm/support/Precision.java
Precision.compareTo
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; }
java
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; }
[ "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. @param x the first number @param y the second number @param eps the amount of error to allow when checking for equality @return <ul><li>0 if {@link #equals(double, double, double) equals(x, y, eps)}</li> <li>&lt; 0 if !{@link #equals(double, double, double) equals(x, y, eps)} &amp;&amp; x &lt; y</li> <li>> 0 if !{@link #equals(double, double, double) equals(x, y, eps)} &amp;&amp; x > y</li></ul>
[ "Compares", "two", "numbers", "given", "some", "amount", "of", "allowed", "error", "." ]
9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6
https://github.com/jroyalty/jglm/blob/9397c2fcf0d4d62844c64d0b14065ee7bf8cafc6/src/main/java/com/hackoeur/jglm/support/Precision.java#L91-L98
8,592
rzwitserloot/lombok.ast
src/main/lombok/ast/grammar/Source.java
Source.associateJavadoc
private void associateJavadoc(List<Comment> comments, List<Node> nodes) { final TreeMap<Integer, Node> startPosMap = Maps.newTreeMap(); for (Node node : nodes) node.accept(new ForwardingAstVisitor() { @Override 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); } }
java
private void associateJavadoc(List<Comment> comments, List<Node> nodes) { final TreeMap<Integer, Node> startPosMap = Maps.newTreeMap(); for (Node node : nodes) node.accept(new ForwardingAstVisitor() { @Override 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); } }
[ "private", "void", "associateJavadoc", "(", "List", "<", "Comment", ">", "comments", ",", "List", "<", "Node", ">", "nodes", ")", "{", "final", "TreeMap", "<", "Integer", ",", "Node", ">", "startPosMap", "=", "Maps", ".", "newTreeMap", "(", ")", ";", "for", "(", "Node", "node", ":", "nodes", ")", "node", ".", "accept", "(", "new", "ForwardingAstVisitor", "(", ")", "{", "@", "Override", "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.
[ "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", "." ]
ed83541c1a5a08952a5d4d7e316a6be9a05311fb
https://github.com/rzwitserloot/lombok.ast/blob/ed83541c1a5a08952a5d4d7e316a6be9a05311fb/src/main/lombok/ast/grammar/Source.java#L342-L369
8,593
rzwitserloot/lombok.ast
src/main/lombok/ast/grammar/Source.java
Source.gatherComments
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; }
java
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; }
[ "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.
[ "Delves", "through", "the", "parboiled", "node", "tree", "to", "find", "comments", "." ]
ed83541c1a5a08952a5d4d7e316a6be9a05311fb
https://github.com/rzwitserloot/lombok.ast/blob/ed83541c1a5a08952a5d4d7e316a6be9a05311fb/src/main/lombok/ast/grammar/Source.java#L383-L396
8,594
esmasui/AndroidJUnit4
android-junit4/src/main/java/android/os/PerformanceCollector.java
PerformanceCollector.startTiming
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(); }
java
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(); }
[ "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. @param label description of code block between startTiming and stopTiming, used to label output
[ "Start", "measurement", "of", "user", "and", "cpu", "time", "." ]
173b050663844f81ca9da6c9076dd13e1bde6a75
https://github.com/esmasui/AndroidJUnit4/blob/173b050663844f81ca9da6c9076dd13e1bde6a75/android-junit4/src/main/java/android/os/PerformanceCollector.java#L362-L370
8,595
esmasui/AndroidJUnit4
android-junit4/src/main/java/android/os/PerformanceCollector.java
PerformanceCollector.addIteration
public Bundle addIteration(String label) { mCpuTime = Process.getElapsedCpuTime() - mCpuTime; mExecTime = SystemClock.uptimeMillis() - mExecTime; Bundle iteration = new Bundle(); iteration.putString(METRIC_KEY_LABEL, label); iteration.putLong(METRIC_KEY_EXECUTION_TIME, mExecTime); iteration.putLong(METRIC_KEY_CPU_TIME, mCpuTime); mPerfMeasurement.getParcelableArrayList(METRIC_KEY_ITERATIONS).add(iteration); mExecTime = SystemClock.uptimeMillis(); mCpuTime = Process.getElapsedCpuTime(); return iteration; }
java
public Bundle addIteration(String label) { mCpuTime = Process.getElapsedCpuTime() - mCpuTime; mExecTime = SystemClock.uptimeMillis() - mExecTime; Bundle iteration = new Bundle(); iteration.putString(METRIC_KEY_LABEL, label); iteration.putLong(METRIC_KEY_EXECUTION_TIME, mExecTime); iteration.putLong(METRIC_KEY_CPU_TIME, mCpuTime); mPerfMeasurement.getParcelableArrayList(METRIC_KEY_ITERATIONS).add(iteration); mExecTime = SystemClock.uptimeMillis(); mCpuTime = Process.getElapsedCpuTime(); return iteration; }
[ "public", "Bundle", "addIteration", "(", "String", "label", ")", "{", "mCpuTime", "=", "Process", ".", "getElapsedCpuTime", "(", ")", "-", "mCpuTime", ";", "mExecTime", "=", "SystemClock", ".", "uptimeMillis", "(", ")", "-", "mExecTime", ";", "Bundle", "iteration", "=", "new", "Bundle", "(", ")", ";", "iteration", ".", "putString", "(", "METRIC_KEY_LABEL", ",", "label", ")", ";", "iteration", ".", "putLong", "(", "METRIC_KEY_EXECUTION_TIME", ",", "mExecTime", ")", ";", "iteration", ".", "putLong", "(", "METRIC_KEY_CPU_TIME", ",", "mCpuTime", ")", ";", "mPerfMeasurement", ".", "getParcelableArrayList", "(", "METRIC_KEY_ITERATIONS", ")", ".", "add", "(", "iteration", ")", ";", "mExecTime", "=", "SystemClock", ".", "uptimeMillis", "(", ")", ";", "mCpuTime", "=", "Process", ".", "getElapsedCpuTime", "(", ")", ";", "return", "iteration", ";", "}" ]
Add a measured segment, and start measuring the next segment. Returns collected data in a Bundle object. @param label description of code block between startTiming and addIteration, and between two calls to addIteration, used to label output @return Runtime metrics stored as key/value pairs. Values are of type long, and keys include: <ul> <li>{@link #METRIC_KEY_LABEL label} <li>{@link #METRIC_KEY_CPU_TIME cpu_time} <li>{@link #METRIC_KEY_EXECUTION_TIME execution_time} </ul>
[ "Add", "a", "measured", "segment", "and", "start", "measuring", "the", "next", "segment", ".", "Returns", "collected", "data", "in", "a", "Bundle", "object", "." ]
173b050663844f81ca9da6c9076dd13e1bde6a75
https://github.com/esmasui/AndroidJUnit4/blob/173b050663844f81ca9da6c9076dd13e1bde6a75/android-junit4/src/main/java/android/os/PerformanceCollector.java#L387-L400
8,596
esmasui/AndroidJUnit4
android-junit4/src/main/java/android/os/PerformanceCollector.java
PerformanceCollector.stopTiming
public Bundle stopTiming(String label) { addIteration(label); if (mPerfWriter != null) mPerfWriter.writeStopTiming(mPerfMeasurement); return mPerfMeasurement; }
java
public Bundle stopTiming(String label) { addIteration(label); if (mPerfWriter != null) mPerfWriter.writeStopTiming(mPerfMeasurement); return mPerfMeasurement; }
[ "public", "Bundle", "stopTiming", "(", "String", "label", ")", "{", "addIteration", "(", "label", ")", ";", "if", "(", "mPerfWriter", "!=", "null", ")", "mPerfWriter", ".", "writeStopTiming", "(", "mPerfMeasurement", ")", ";", "return", "mPerfMeasurement", ";", "}" ]
Stop measurement of user and cpu time. @param label description of code block between addIteration or startTiming and stopTiming, used to label output @return Runtime metrics stored in a bundle, including all iterations between calls to startTiming and stopTiming. List of iterations is keyed by {@link #METRIC_KEY_ITERATIONS iterations}.
[ "Stop", "measurement", "of", "user", "and", "cpu", "time", "." ]
173b050663844f81ca9da6c9076dd13e1bde6a75
https://github.com/esmasui/AndroidJUnit4/blob/173b050663844f81ca9da6c9076dd13e1bde6a75/android-junit4/src/main/java/android/os/PerformanceCollector.java#L411-L416
8,597
esmasui/AndroidJUnit4
android-junit4/src/main/java/android/os/PerformanceCollector.java
PerformanceCollector.addMeasurement
public void addMeasurement(String label, String value) { if (mPerfWriter != null) mPerfWriter.writeMeasurement(label, value); }
java
public void addMeasurement(String label, String value) { if (mPerfWriter != null) mPerfWriter.writeMeasurement(label, value); }
[ "public", "void", "addMeasurement", "(", "String", "label", ",", "String", "value", ")", "{", "if", "(", "mPerfWriter", "!=", "null", ")", "mPerfWriter", ".", "writeMeasurement", "(", "label", ",", "value", ")", ";", "}" ]
Add a string field to the collector. @param label short description of the metric that was measured @param value string summary of the measurement
[ "Add", "a", "string", "field", "to", "the", "collector", "." ]
173b050663844f81ca9da6c9076dd13e1bde6a75
https://github.com/esmasui/AndroidJUnit4/blob/173b050663844f81ca9da6c9076dd13e1bde6a75/android-junit4/src/main/java/android/os/PerformanceCollector.java#L446-L449
8,598
esmasui/AndroidJUnit4
android-junit4/src/main/java/com/android/internal/util/Predicates.java
Predicates.and
public static <T> Predicate<T> and(Predicate<? super T>... components) { return and(Arrays.asList(components)); }
java
public static <T> Predicate<T> and(Predicate<? super T>... components) { return and(Arrays.asList(components)); }
[ "public", "static", "<", "T", ">", "Predicate", "<", "T", ">", "and", "(", "Predicate", "<", "?", "super", "T", ">", "...", "components", ")", "{", "return", "and", "(", "Arrays", ".", "asList", "(", "components", ")", ")", ";", "}" ]
Returns a Predicate that evaluates to true iff each of its components evaluates to true. The components are evaluated in order, and evaluation will be "short-circuited" as soon as the answer is determined.
[ "Returns", "a", "Predicate", "that", "evaluates", "to", "true", "iff", "each", "of", "its", "components", "evaluates", "to", "true", ".", "The", "components", "are", "evaluated", "in", "order", "and", "evaluation", "will", "be", "short", "-", "circuited", "as", "soon", "as", "the", "answer", "is", "determined", "." ]
173b050663844f81ca9da6c9076dd13e1bde6a75
https://github.com/esmasui/AndroidJUnit4/blob/173b050663844f81ca9da6c9076dd13e1bde6a75/android-junit4/src/main/java/com/android/internal/util/Predicates.java#L35-L37
8,599
esmasui/AndroidJUnit4
android-junit4/src/main/java/com/android/internal/util/Predicates.java
Predicates.or
public static <T> Predicate<T> or(Predicate<? super T>... components) { return or(Arrays.asList(components)); }
java
public static <T> Predicate<T> or(Predicate<? super T>... components) { return or(Arrays.asList(components)); }
[ "public", "static", "<", "T", ">", "Predicate", "<", "T", ">", "or", "(", "Predicate", "<", "?", "super", "T", ">", "...", "components", ")", "{", "return", "or", "(", "Arrays", ".", "asList", "(", "components", ")", ")", ";", "}" ]
Returns a Predicate that evaluates to true iff any one of its components evaluates to true. The components are evaluated in order, and evaluation will be "short-circuited" as soon as the answer is determined.
[ "Returns", "a", "Predicate", "that", "evaluates", "to", "true", "iff", "any", "one", "of", "its", "components", "evaluates", "to", "true", ".", "The", "components", "are", "evaluated", "in", "order", "and", "evaluation", "will", "be", "short", "-", "circuited", "as", "soon", "as", "the", "answer", "is", "determined", "." ]
173b050663844f81ca9da6c9076dd13e1bde6a75
https://github.com/esmasui/AndroidJUnit4/blob/173b050663844f81ca9da6c9076dd13e1bde6a75/android-junit4/src/main/java/com/android/internal/util/Predicates.java#L56-L58