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
9,700
imsweb/naaccr-xml
src/main/java/com/imsweb/naaccrxml/PatientXmlReader.java
PatientXmlReader.convertSyntaxException
private NaaccrIOException convertSyntaxException(ConversionException ex) { String msg = ex.get("message"); // reading a file that has bad tags is very common, so let's try to get a better error message in that case: if (CannotResolveClassException.class.getName().equals(ex.get("cause-exception"))) msg = "invalid tag: " + ex.get("cause-message"); else if (StreamException.class.getName().equals(ex.get("cause-exception"))) msg = "invalid XML syntax"; if (msg == null) msg = ex.getMessage(); NaaccrIOException e = new NaaccrIOException(msg, ex); if (ex.get("line number") != null) e.setLineNumber(Integer.valueOf(ex.get("line number"))); e.setPath(ex.get("path")); return e; }
java
private NaaccrIOException convertSyntaxException(ConversionException ex) { String msg = ex.get("message"); // reading a file that has bad tags is very common, so let's try to get a better error message in that case: if (CannotResolveClassException.class.getName().equals(ex.get("cause-exception"))) msg = "invalid tag: " + ex.get("cause-message"); else if (StreamException.class.getName().equals(ex.get("cause-exception"))) msg = "invalid XML syntax"; if (msg == null) msg = ex.getMessage(); NaaccrIOException e = new NaaccrIOException(msg, ex); if (ex.get("line number") != null) e.setLineNumber(Integer.valueOf(ex.get("line number"))); e.setPath(ex.get("path")); return e; }
[ "private", "NaaccrIOException", "convertSyntaxException", "(", "ConversionException", "ex", ")", "{", "String", "msg", "=", "ex", ".", "get", "(", "\"message\"", ")", ";", "// reading a file that has bad tags is very common, so let's try to get a better error message in that case:", "if", "(", "CannotResolveClassException", ".", "class", ".", "getName", "(", ")", ".", "equals", "(", "ex", ".", "get", "(", "\"cause-exception\"", ")", ")", ")", "msg", "=", "\"invalid tag: \"", "+", "ex", ".", "get", "(", "\"cause-message\"", ")", ";", "else", "if", "(", "StreamException", ".", "class", ".", "getName", "(", ")", ".", "equals", "(", "ex", ".", "get", "(", "\"cause-exception\"", ")", ")", ")", "msg", "=", "\"invalid XML syntax\"", ";", "if", "(", "msg", "==", "null", ")", "msg", "=", "ex", ".", "getMessage", "(", ")", ";", "NaaccrIOException", "e", "=", "new", "NaaccrIOException", "(", "msg", ",", "ex", ")", ";", "if", "(", "ex", ".", "get", "(", "\"line number\"", ")", "!=", "null", ")", "e", ".", "setLineNumber", "(", "Integer", ".", "valueOf", "(", "ex", ".", "get", "(", "\"line number\"", ")", ")", ")", ";", "e", ".", "setPath", "(", "ex", ".", "get", "(", "\"path\"", ")", ")", ";", "return", "e", ";", "}" ]
We don't want to expose the conversion exceptions, so let's translate them into our own exception...
[ "We", "don", "t", "want", "to", "expose", "the", "conversion", "exceptions", "so", "let", "s", "translate", "them", "into", "our", "own", "exception", "..." ]
a3a501faa2a0c3411dd5248b2c1379f279131696
https://github.com/imsweb/naaccr-xml/blob/a3a501faa2a0c3411dd5248b2c1379f279131696/src/main/java/com/imsweb/naaccrxml/PatientXmlReader.java#L413-L430
9,701
imsweb/naaccr-xml
src/main/java/com/imsweb/naaccrxml/NaaccrXmlDictionaryUtils.java
NaaccrXmlDictionaryUtils.isFullLengthRequiredForType
public static boolean isFullLengthRequiredForType(String type) { boolean result = NAACCR_DATA_TYPE_ALPHA.equals(type); result |= NAACCR_DATA_TYPE_DIGITS.equals(type); result |= NAACCR_DATA_TYPE_MIXED.equals(type); return result; }
java
public static boolean isFullLengthRequiredForType(String type) { boolean result = NAACCR_DATA_TYPE_ALPHA.equals(type); result |= NAACCR_DATA_TYPE_DIGITS.equals(type); result |= NAACCR_DATA_TYPE_MIXED.equals(type); return result; }
[ "public", "static", "boolean", "isFullLengthRequiredForType", "(", "String", "type", ")", "{", "boolean", "result", "=", "NAACCR_DATA_TYPE_ALPHA", ".", "equals", "(", "type", ")", ";", "result", "|=", "NAACCR_DATA_TYPE_DIGITS", ".", "equals", "(", "type", ")", ";", "result", "|=", "NAACCR_DATA_TYPE_MIXED", ".", "equals", "(", "type", ")", ";", "return", "result", ";", "}" ]
Returns whether values for a given data type need to have the same length as their definition @param type given data type @return true if the values of that type needs to be fully filled-in
[ "Returns", "whether", "values", "for", "a", "given", "data", "type", "need", "to", "have", "the", "same", "length", "as", "their", "definition" ]
a3a501faa2a0c3411dd5248b2c1379f279131696
https://github.com/imsweb/naaccr-xml/blob/a3a501faa2a0c3411dd5248b2c1379f279131696/src/main/java/com/imsweb/naaccrxml/NaaccrXmlDictionaryUtils.java#L124-L129
9,702
imsweb/naaccr-xml
src/main/java/com/imsweb/naaccrxml/NaaccrXmlDictionaryUtils.java
NaaccrXmlDictionaryUtils.extractVersionFromUri
public static String extractVersionFromUri(String uri) { if (uri == null) return null; Matcher matcher = BASE_DICTIONARY_URI_PATTERN.matcher(uri); if (matcher.matches()) return matcher.group(1); else { matcher = DEFAULT_USER_DICTIONARY_URI_PATTERN.matcher(uri); if (matcher.matches()) return matcher.group(1); } return null; }
java
public static String extractVersionFromUri(String uri) { if (uri == null) return null; Matcher matcher = BASE_DICTIONARY_URI_PATTERN.matcher(uri); if (matcher.matches()) return matcher.group(1); else { matcher = DEFAULT_USER_DICTIONARY_URI_PATTERN.matcher(uri); if (matcher.matches()) return matcher.group(1); } return null; }
[ "public", "static", "String", "extractVersionFromUri", "(", "String", "uri", ")", "{", "if", "(", "uri", "==", "null", ")", "return", "null", ";", "Matcher", "matcher", "=", "BASE_DICTIONARY_URI_PATTERN", ".", "matcher", "(", "uri", ")", ";", "if", "(", "matcher", ".", "matches", "(", ")", ")", "return", "matcher", ".", "group", "(", "1", ")", ";", "else", "{", "matcher", "=", "DEFAULT_USER_DICTIONARY_URI_PATTERN", ".", "matcher", "(", "uri", ")", ";", "if", "(", "matcher", ".", "matches", "(", ")", ")", "return", "matcher", ".", "group", "(", "1", ")", ";", "}", "return", "null", ";", "}" ]
Extracts the NAACCR version from an internal dictionary URI. @param uri internal dictionary URI @return the corresponding NAACCR version, null if it can't be extracted
[ "Extracts", "the", "NAACCR", "version", "from", "an", "internal", "dictionary", "URI", "." ]
a3a501faa2a0c3411dd5248b2c1379f279131696
https://github.com/imsweb/naaccr-xml/blob/a3a501faa2a0c3411dd5248b2c1379f279131696/src/main/java/com/imsweb/naaccrxml/NaaccrXmlDictionaryUtils.java#L136-L148
9,703
imsweb/naaccr-xml
src/main/java/com/imsweb/naaccrxml/NaaccrXmlDictionaryUtils.java
NaaccrXmlDictionaryUtils.getBaseDictionaryByUri
public static NaaccrDictionary getBaseDictionaryByUri(String uri) { if (uri == null) throw new RuntimeException("URI is required for getting the base dictionary."); return getBaseDictionaryByVersion(extractVersionFromUri(uri)); }
java
public static NaaccrDictionary getBaseDictionaryByUri(String uri) { if (uri == null) throw new RuntimeException("URI is required for getting the base dictionary."); return getBaseDictionaryByVersion(extractVersionFromUri(uri)); }
[ "public", "static", "NaaccrDictionary", "getBaseDictionaryByUri", "(", "String", "uri", ")", "{", "if", "(", "uri", "==", "null", ")", "throw", "new", "RuntimeException", "(", "\"URI is required for getting the base dictionary.\"", ")", ";", "return", "getBaseDictionaryByVersion", "(", "extractVersionFromUri", "(", "uri", ")", ")", ";", "}" ]
Returns the base dictionary for the requested URI. @param uri URI, required @return the corresponding base dictionary, throws a runtime exception if not found
[ "Returns", "the", "base", "dictionary", "for", "the", "requested", "URI", "." ]
a3a501faa2a0c3411dd5248b2c1379f279131696
https://github.com/imsweb/naaccr-xml/blob/a3a501faa2a0c3411dd5248b2c1379f279131696/src/main/java/com/imsweb/naaccrxml/NaaccrXmlDictionaryUtils.java#L168-L172
9,704
imsweb/naaccr-xml
src/main/java/com/imsweb/naaccrxml/NaaccrXmlDictionaryUtils.java
NaaccrXmlDictionaryUtils.getDefaultUserDictionaryByUri
public static NaaccrDictionary getDefaultUserDictionaryByUri(String uri) { if (uri == null) throw new RuntimeException("URI is required for getting the default user dictionary."); return getDefaultUserDictionaryByVersion(extractVersionFromUri(uri)); }
java
public static NaaccrDictionary getDefaultUserDictionaryByUri(String uri) { if (uri == null) throw new RuntimeException("URI is required for getting the default user dictionary."); return getDefaultUserDictionaryByVersion(extractVersionFromUri(uri)); }
[ "public", "static", "NaaccrDictionary", "getDefaultUserDictionaryByUri", "(", "String", "uri", ")", "{", "if", "(", "uri", "==", "null", ")", "throw", "new", "RuntimeException", "(", "\"URI is required for getting the default user dictionary.\"", ")", ";", "return", "getDefaultUserDictionaryByVersion", "(", "extractVersionFromUri", "(", "uri", ")", ")", ";", "}" ]
Returns the default user dictionary for the requested URI. @param uri URI, required @return the corresponding default user dictionary, throws a runtime exception if not found
[ "Returns", "the", "default", "user", "dictionary", "for", "the", "requested", "URI", "." ]
a3a501faa2a0c3411dd5248b2c1379f279131696
https://github.com/imsweb/naaccr-xml/blob/a3a501faa2a0c3411dd5248b2c1379f279131696/src/main/java/com/imsweb/naaccrxml/NaaccrXmlDictionaryUtils.java#L204-L208
9,705
imsweb/naaccr-xml
src/main/java/com/imsweb/naaccrxml/NaaccrXmlDictionaryUtils.java
NaaccrXmlDictionaryUtils.getDefaultUserDictionaryByVersion
@SuppressWarnings("ConstantConditions") public static NaaccrDictionary getDefaultUserDictionaryByVersion(String naaccrVersion) { if (naaccrVersion == null) throw new RuntimeException("Version is required for getting the default user dictionary."); if (!NaaccrFormat.isVersionSupported(naaccrVersion)) throw new RuntimeException("Unsupported default user dictionary version: " + naaccrVersion); NaaccrDictionary result = _INTERNAL_DICTIONARIES.get("user_" + naaccrVersion); if (result == null) { String resName = "user-defined-naaccr-dictionary-" + naaccrVersion + ".xml"; try (Reader reader = new InputStreamReader(Thread.currentThread().getContextClassLoader().getResource(resName).openStream(), StandardCharsets.UTF_8)) { result = readDictionary(reader); _INTERNAL_DICTIONARIES.put("user_" + naaccrVersion, result); } catch (IOException e) { throw new RuntimeException("Unable to get base dictionary for version " + naaccrVersion, e); } } return result; }
java
@SuppressWarnings("ConstantConditions") public static NaaccrDictionary getDefaultUserDictionaryByVersion(String naaccrVersion) { if (naaccrVersion == null) throw new RuntimeException("Version is required for getting the default user dictionary."); if (!NaaccrFormat.isVersionSupported(naaccrVersion)) throw new RuntimeException("Unsupported default user dictionary version: " + naaccrVersion); NaaccrDictionary result = _INTERNAL_DICTIONARIES.get("user_" + naaccrVersion); if (result == null) { String resName = "user-defined-naaccr-dictionary-" + naaccrVersion + ".xml"; try (Reader reader = new InputStreamReader(Thread.currentThread().getContextClassLoader().getResource(resName).openStream(), StandardCharsets.UTF_8)) { result = readDictionary(reader); _INTERNAL_DICTIONARIES.put("user_" + naaccrVersion, result); } catch (IOException e) { throw new RuntimeException("Unable to get base dictionary for version " + naaccrVersion, e); } } return result; }
[ "@", "SuppressWarnings", "(", "\"ConstantConditions\"", ")", "public", "static", "NaaccrDictionary", "getDefaultUserDictionaryByVersion", "(", "String", "naaccrVersion", ")", "{", "if", "(", "naaccrVersion", "==", "null", ")", "throw", "new", "RuntimeException", "(", "\"Version is required for getting the default user dictionary.\"", ")", ";", "if", "(", "!", "NaaccrFormat", ".", "isVersionSupported", "(", "naaccrVersion", ")", ")", "throw", "new", "RuntimeException", "(", "\"Unsupported default user dictionary version: \"", "+", "naaccrVersion", ")", ";", "NaaccrDictionary", "result", "=", "_INTERNAL_DICTIONARIES", ".", "get", "(", "\"user_\"", "+", "naaccrVersion", ")", ";", "if", "(", "result", "==", "null", ")", "{", "String", "resName", "=", "\"user-defined-naaccr-dictionary-\"", "+", "naaccrVersion", "+", "\".xml\"", ";", "try", "(", "Reader", "reader", "=", "new", "InputStreamReader", "(", "Thread", ".", "currentThread", "(", ")", ".", "getContextClassLoader", "(", ")", ".", "getResource", "(", "resName", ")", ".", "openStream", "(", ")", ",", "StandardCharsets", ".", "UTF_8", ")", ")", "{", "result", "=", "readDictionary", "(", "reader", ")", ";", "_INTERNAL_DICTIONARIES", ".", "put", "(", "\"user_\"", "+", "naaccrVersion", ",", "result", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "new", "RuntimeException", "(", "\"Unable to get base dictionary for version \"", "+", "naaccrVersion", ",", "e", ")", ";", "}", "}", "return", "result", ";", "}" ]
Returns the default user dictionary for the requested NAACCR version. @param naaccrVersion NAACCR version, required (see constants in NaaccrFormat) @return the corresponding default user dictionary, throws a runtime exception if not found
[ "Returns", "the", "default", "user", "dictionary", "for", "the", "requested", "NAACCR", "version", "." ]
a3a501faa2a0c3411dd5248b2c1379f279131696
https://github.com/imsweb/naaccr-xml/blob/a3a501faa2a0c3411dd5248b2c1379f279131696/src/main/java/com/imsweb/naaccrxml/NaaccrXmlDictionaryUtils.java#L215-L233
9,706
imsweb/naaccr-xml
src/main/java/com/imsweb/naaccrxml/NaaccrXmlDictionaryUtils.java
NaaccrXmlDictionaryUtils.readDictionary
public static NaaccrDictionary readDictionary(File file) throws IOException { if (file == null) throw new IOException("File is required to load dictionary."); if (!file.exists()) throw new IOException("File must exist to load dictionary."); try (Reader reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)) { return readDictionary(reader); } }
java
public static NaaccrDictionary readDictionary(File file) throws IOException { if (file == null) throw new IOException("File is required to load dictionary."); if (!file.exists()) throw new IOException("File must exist to load dictionary."); try (Reader reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)) { return readDictionary(reader); } }
[ "public", "static", "NaaccrDictionary", "readDictionary", "(", "File", "file", ")", "throws", "IOException", "{", "if", "(", "file", "==", "null", ")", "throw", "new", "IOException", "(", "\"File is required to load dictionary.\"", ")", ";", "if", "(", "!", "file", ".", "exists", "(", ")", ")", "throw", "new", "IOException", "(", "\"File must exist to load dictionary.\"", ")", ";", "try", "(", "Reader", "reader", "=", "new", "InputStreamReader", "(", "new", "FileInputStream", "(", "file", ")", ",", "StandardCharsets", ".", "UTF_8", ")", ")", "{", "return", "readDictionary", "(", "reader", ")", ";", "}", "}" ]
Reads a dictionary from the provided file. @param file file, cannot be null @return the corresponding dictionary @throws IOException if the dictionary could not be read
[ "Reads", "a", "dictionary", "from", "the", "provided", "file", "." ]
a3a501faa2a0c3411dd5248b2c1379f279131696
https://github.com/imsweb/naaccr-xml/blob/a3a501faa2a0c3411dd5248b2c1379f279131696/src/main/java/com/imsweb/naaccrxml/NaaccrXmlDictionaryUtils.java#L248-L256
9,707
imsweb/naaccr-xml
src/main/java/com/imsweb/naaccrxml/NaaccrXmlDictionaryUtils.java
NaaccrXmlDictionaryUtils.readDictionary
public static NaaccrDictionary readDictionary(Reader reader) throws IOException { try { NaaccrDictionary dictionary = (NaaccrDictionary)instanciateXStream().fromXML(reader); // default value for specifications if (dictionary.getSpecificationVersion() == null) dictionary.setSpecificationVersion(SpecificationVersion.SPEC_1_0); // default value for record types if (dictionary.getItems() != null) for (NaaccrDictionaryItem item : dictionary.getItems()) if (item.getRecordTypes() == null) item.setRecordTypes(NaaccrFormat.ALL_RECORD_TYPES); // let's not validate the internal dictionaries, we know they are valid String uri = dictionary.getDictionaryUri(); if (uri == null || uri.trim().isEmpty()) throw new IOException("'dictionaryUri' attribute is required"); else if (!BASE_DICTIONARY_URI_PATTERN.matcher(uri).matches() && !DEFAULT_USER_DICTIONARY_URI_PATTERN.matcher(uri).matches()) { List<String> errors = validateUserDictionary(dictionary); if (!errors.isEmpty()) throw new IOException(errors.get(0)); } return dictionary; } catch (XStreamException ex) { throw new IOException("Unable to read dictionary", ex); } }
java
public static NaaccrDictionary readDictionary(Reader reader) throws IOException { try { NaaccrDictionary dictionary = (NaaccrDictionary)instanciateXStream().fromXML(reader); // default value for specifications if (dictionary.getSpecificationVersion() == null) dictionary.setSpecificationVersion(SpecificationVersion.SPEC_1_0); // default value for record types if (dictionary.getItems() != null) for (NaaccrDictionaryItem item : dictionary.getItems()) if (item.getRecordTypes() == null) item.setRecordTypes(NaaccrFormat.ALL_RECORD_TYPES); // let's not validate the internal dictionaries, we know they are valid String uri = dictionary.getDictionaryUri(); if (uri == null || uri.trim().isEmpty()) throw new IOException("'dictionaryUri' attribute is required"); else if (!BASE_DICTIONARY_URI_PATTERN.matcher(uri).matches() && !DEFAULT_USER_DICTIONARY_URI_PATTERN.matcher(uri).matches()) { List<String> errors = validateUserDictionary(dictionary); if (!errors.isEmpty()) throw new IOException(errors.get(0)); } return dictionary; } catch (XStreamException ex) { throw new IOException("Unable to read dictionary", ex); } }
[ "public", "static", "NaaccrDictionary", "readDictionary", "(", "Reader", "reader", ")", "throws", "IOException", "{", "try", "{", "NaaccrDictionary", "dictionary", "=", "(", "NaaccrDictionary", ")", "instanciateXStream", "(", ")", ".", "fromXML", "(", "reader", ")", ";", "// default value for specifications", "if", "(", "dictionary", ".", "getSpecificationVersion", "(", ")", "==", "null", ")", "dictionary", ".", "setSpecificationVersion", "(", "SpecificationVersion", ".", "SPEC_1_0", ")", ";", "// default value for record types", "if", "(", "dictionary", ".", "getItems", "(", ")", "!=", "null", ")", "for", "(", "NaaccrDictionaryItem", "item", ":", "dictionary", ".", "getItems", "(", ")", ")", "if", "(", "item", ".", "getRecordTypes", "(", ")", "==", "null", ")", "item", ".", "setRecordTypes", "(", "NaaccrFormat", ".", "ALL_RECORD_TYPES", ")", ";", "// let's not validate the internal dictionaries, we know they are valid", "String", "uri", "=", "dictionary", ".", "getDictionaryUri", "(", ")", ";", "if", "(", "uri", "==", "null", "||", "uri", ".", "trim", "(", ")", ".", "isEmpty", "(", ")", ")", "throw", "new", "IOException", "(", "\"'dictionaryUri' attribute is required\"", ")", ";", "else", "if", "(", "!", "BASE_DICTIONARY_URI_PATTERN", ".", "matcher", "(", "uri", ")", ".", "matches", "(", ")", "&&", "!", "DEFAULT_USER_DICTIONARY_URI_PATTERN", ".", "matcher", "(", "uri", ")", ".", "matches", "(", ")", ")", "{", "List", "<", "String", ">", "errors", "=", "validateUserDictionary", "(", "dictionary", ")", ";", "if", "(", "!", "errors", ".", "isEmpty", "(", ")", ")", "throw", "new", "IOException", "(", "errors", ".", "get", "(", "0", ")", ")", ";", "}", "return", "dictionary", ";", "}", "catch", "(", "XStreamException", "ex", ")", "{", "throw", "new", "IOException", "(", "\"Unable to read dictionary\"", ",", "ex", ")", ";", "}", "}" ]
Reads a dictionary from the provided reader. @param reader reader, cannot be null @return the corresponding dictionary @throws IOException if the dictionary could not be read
[ "Reads", "a", "dictionary", "from", "the", "provided", "reader", "." ]
a3a501faa2a0c3411dd5248b2c1379f279131696
https://github.com/imsweb/naaccr-xml/blob/a3a501faa2a0c3411dd5248b2c1379f279131696/src/main/java/com/imsweb/naaccrxml/NaaccrXmlDictionaryUtils.java#L264-L293
9,708
imsweb/naaccr-xml
src/main/java/com/imsweb/naaccrxml/NaaccrXmlDictionaryUtils.java
NaaccrXmlDictionaryUtils.writeDictionary
public static void writeDictionary(NaaccrDictionary dictionary, File file) throws IOException { try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) { writeDictionary(dictionary, writer); } }
java
public static void writeDictionary(NaaccrDictionary dictionary, File file) throws IOException { try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) { writeDictionary(dictionary, writer); } }
[ "public", "static", "void", "writeDictionary", "(", "NaaccrDictionary", "dictionary", ",", "File", "file", ")", "throws", "IOException", "{", "try", "(", "Writer", "writer", "=", "new", "OutputStreamWriter", "(", "new", "FileOutputStream", "(", "file", ")", ",", "StandardCharsets", ".", "UTF_8", ")", ")", "{", "writeDictionary", "(", "dictionary", ",", "writer", ")", ";", "}", "}" ]
Writes the given dictionary to the provided file. @param dictionary dictionary to write, cannot be null @param file file, cannot be null @throws IOException if the dictionary could not be written
[ "Writes", "the", "given", "dictionary", "to", "the", "provided", "file", "." ]
a3a501faa2a0c3411dd5248b2c1379f279131696
https://github.com/imsweb/naaccr-xml/blob/a3a501faa2a0c3411dd5248b2c1379f279131696/src/main/java/com/imsweb/naaccrxml/NaaccrXmlDictionaryUtils.java#L301-L305
9,709
imsweb/naaccr-xml
src/main/java/com/imsweb/naaccrxml/NaaccrXmlDictionaryUtils.java
NaaccrXmlDictionaryUtils.writeDictionary
public static void writeDictionary(NaaccrDictionary dictionary, Writer writer) throws IOException { try { instanciateXStream().marshal(dictionary, new NaaccrPrettyPrintWriter(dictionary, writer)); } catch (XStreamException ex) { throw new IOException("Unable to write dictionary", ex); } }
java
public static void writeDictionary(NaaccrDictionary dictionary, Writer writer) throws IOException { try { instanciateXStream().marshal(dictionary, new NaaccrPrettyPrintWriter(dictionary, writer)); } catch (XStreamException ex) { throw new IOException("Unable to write dictionary", ex); } }
[ "public", "static", "void", "writeDictionary", "(", "NaaccrDictionary", "dictionary", ",", "Writer", "writer", ")", "throws", "IOException", "{", "try", "{", "instanciateXStream", "(", ")", ".", "marshal", "(", "dictionary", ",", "new", "NaaccrPrettyPrintWriter", "(", "dictionary", ",", "writer", ")", ")", ";", "}", "catch", "(", "XStreamException", "ex", ")", "{", "throw", "new", "IOException", "(", "\"Unable to write dictionary\"", ",", "ex", ")", ";", "}", "}" ]
Writes the given dictionary to the provided writer. @param dictionary dictionary to write, cannot be null @param writer writer, cannot be null @throws IOException if the dictionary could not be written
[ "Writes", "the", "given", "dictionary", "to", "the", "provided", "writer", "." ]
a3a501faa2a0c3411dd5248b2c1379f279131696
https://github.com/imsweb/naaccr-xml/blob/a3a501faa2a0c3411dd5248b2c1379f279131696/src/main/java/com/imsweb/naaccrxml/NaaccrXmlDictionaryUtils.java#L313-L320
9,710
imsweb/naaccr-xml
src/main/java/com/imsweb/naaccrxml/NaaccrXmlDictionaryUtils.java
NaaccrXmlDictionaryUtils.validateUserDictionary
public static List<String> validateUserDictionary(NaaccrDictionary dictionary, String naaccrVersion) { return validateDictionary(dictionary, false, naaccrVersion); }
java
public static List<String> validateUserDictionary(NaaccrDictionary dictionary, String naaccrVersion) { return validateDictionary(dictionary, false, naaccrVersion); }
[ "public", "static", "List", "<", "String", ">", "validateUserDictionary", "(", "NaaccrDictionary", "dictionary", ",", "String", "naaccrVersion", ")", "{", "return", "validateDictionary", "(", "dictionary", ",", "false", ",", "naaccrVersion", ")", ";", "}" ]
Validates the provided user dictionary. @param dictionary dictionary to validate, can't be null @param naaccrVersion naaccrVersion to assume if it's not provided on the dictionary (can be null) @return list of errors, empty if valid
[ "Validates", "the", "provided", "user", "dictionary", "." ]
a3a501faa2a0c3411dd5248b2c1379f279131696
https://github.com/imsweb/naaccr-xml/blob/a3a501faa2a0c3411dd5248b2c1379f279131696/src/main/java/com/imsweb/naaccrxml/NaaccrXmlDictionaryUtils.java#L348-L350
9,711
imsweb/naaccr-xml
src/main/java/com/imsweb/naaccrxml/NaaccrXmlUtils.java
NaaccrXmlUtils.flatToXml
public static void flatToXml(File flatFile, File xmlFile, NaaccrOptions options, List<NaaccrDictionary> userDictionaries, NaaccrObserver observer) throws NaaccrIOException { if (flatFile == null) throw new NaaccrIOException("Source flat file is required"); if (!flatFile.exists()) throw new NaaccrIOException("Source flat file must exist"); if (!xmlFile.getParentFile().exists()) throw new NaaccrIOException("Target folder must exist"); // create the reader and writer and let them do all the work! try (PatientFlatReader reader = new PatientFlatReader(createReader(flatFile), options, userDictionaries)) { try (PatientXmlWriter writer = new PatientXmlWriter(createWriter(xmlFile), reader.getRootData(), options, userDictionaries)) { Patient patient = reader.readPatient(); while (patient != null && !Thread.currentThread().isInterrupted()) { if (observer != null) observer.patientRead(patient); writer.writePatient(patient); if (observer != null) observer.patientWritten(patient); patient = reader.readPatient(); } } } }
java
public static void flatToXml(File flatFile, File xmlFile, NaaccrOptions options, List<NaaccrDictionary> userDictionaries, NaaccrObserver observer) throws NaaccrIOException { if (flatFile == null) throw new NaaccrIOException("Source flat file is required"); if (!flatFile.exists()) throw new NaaccrIOException("Source flat file must exist"); if (!xmlFile.getParentFile().exists()) throw new NaaccrIOException("Target folder must exist"); // create the reader and writer and let them do all the work! try (PatientFlatReader reader = new PatientFlatReader(createReader(flatFile), options, userDictionaries)) { try (PatientXmlWriter writer = new PatientXmlWriter(createWriter(xmlFile), reader.getRootData(), options, userDictionaries)) { Patient patient = reader.readPatient(); while (patient != null && !Thread.currentThread().isInterrupted()) { if (observer != null) observer.patientRead(patient); writer.writePatient(patient); if (observer != null) observer.patientWritten(patient); patient = reader.readPatient(); } } } }
[ "public", "static", "void", "flatToXml", "(", "File", "flatFile", ",", "File", "xmlFile", ",", "NaaccrOptions", "options", ",", "List", "<", "NaaccrDictionary", ">", "userDictionaries", ",", "NaaccrObserver", "observer", ")", "throws", "NaaccrIOException", "{", "if", "(", "flatFile", "==", "null", ")", "throw", "new", "NaaccrIOException", "(", "\"Source flat file is required\"", ")", ";", "if", "(", "!", "flatFile", ".", "exists", "(", ")", ")", "throw", "new", "NaaccrIOException", "(", "\"Source flat file must exist\"", ")", ";", "if", "(", "!", "xmlFile", ".", "getParentFile", "(", ")", ".", "exists", "(", ")", ")", "throw", "new", "NaaccrIOException", "(", "\"Target folder must exist\"", ")", ";", "// create the reader and writer and let them do all the work!", "try", "(", "PatientFlatReader", "reader", "=", "new", "PatientFlatReader", "(", "createReader", "(", "flatFile", ")", ",", "options", ",", "userDictionaries", ")", ")", "{", "try", "(", "PatientXmlWriter", "writer", "=", "new", "PatientXmlWriter", "(", "createWriter", "(", "xmlFile", ")", ",", "reader", ".", "getRootData", "(", ")", ",", "options", ",", "userDictionaries", ")", ")", "{", "Patient", "patient", "=", "reader", ".", "readPatient", "(", ")", ";", "while", "(", "patient", "!=", "null", "&&", "!", "Thread", ".", "currentThread", "(", ")", ".", "isInterrupted", "(", ")", ")", "{", "if", "(", "observer", "!=", "null", ")", "observer", ".", "patientRead", "(", "patient", ")", ";", "writer", ".", "writePatient", "(", "patient", ")", ";", "if", "(", "observer", "!=", "null", ")", "observer", ".", "patientWritten", "(", "patient", ")", ";", "patient", "=", "reader", ".", "readPatient", "(", ")", ";", "}", "}", "}", "}" ]
Translates a flat data file into an XML data file. @param flatFile source flat data file, must exists @param xmlFile target XML data file, parent file must exists @param options optional validating options @param userDictionaries optional user-defined dictionaries (will be merged with the base dictionary) @param observer an optional observer, useful to keep track of the progress @throws NaaccrIOException if there is problem reading/writing the file
[ "Translates", "a", "flat", "data", "file", "into", "an", "XML", "data", "file", "." ]
a3a501faa2a0c3411dd5248b2c1379f279131696
https://github.com/imsweb/naaccr-xml/blob/a3a501faa2a0c3411dd5248b2c1379f279131696/src/main/java/com/imsweb/naaccrxml/NaaccrXmlUtils.java#L78-L100
9,712
imsweb/naaccr-xml
src/main/java/com/imsweb/naaccrxml/NaaccrXmlUtils.java
NaaccrXmlUtils.getFormatFromFlatFile
public static String getFormatFromFlatFile(File flatFile) { if (flatFile == null || !flatFile.exists()) return null; try (BufferedReader reader = new BufferedReader(createReader(flatFile))) { return getFormatFromFlatFileLine(reader.readLine()); } catch (IOException e) { return null; } }
java
public static String getFormatFromFlatFile(File flatFile) { if (flatFile == null || !flatFile.exists()) return null; try (BufferedReader reader = new BufferedReader(createReader(flatFile))) { return getFormatFromFlatFileLine(reader.readLine()); } catch (IOException e) { return null; } }
[ "public", "static", "String", "getFormatFromFlatFile", "(", "File", "flatFile", ")", "{", "if", "(", "flatFile", "==", "null", "||", "!", "flatFile", ".", "exists", "(", ")", ")", "return", "null", ";", "try", "(", "BufferedReader", "reader", "=", "new", "BufferedReader", "(", "createReader", "(", "flatFile", ")", ")", ")", "{", "return", "getFormatFromFlatFileLine", "(", "reader", ".", "readLine", "(", ")", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "return", "null", ";", "}", "}" ]
Returns the NAACCR format of the given flat file, based on it's first data line. @param flatFile provided data file @return the NAACCR format, null if it cannot be determined
[ "Returns", "the", "NAACCR", "format", "of", "the", "given", "flat", "file", "based", "on", "it", "s", "first", "data", "line", "." ]
a3a501faa2a0c3411dd5248b2c1379f279131696
https://github.com/imsweb/naaccr-xml/blob/a3a501faa2a0c3411dd5248b2c1379f279131696/src/main/java/com/imsweb/naaccrxml/NaaccrXmlUtils.java#L345-L355
9,713
imsweb/naaccr-xml
src/main/java/com/imsweb/naaccrxml/NaaccrXmlUtils.java
NaaccrXmlUtils.getFormatFromXmlFile
public static String getFormatFromXmlFile(File xmlFile) { if (xmlFile == null || !xmlFile.exists()) return null; try (Reader reader = createReader(xmlFile)) { return getFormatFromXmlReader(reader); } catch (IOException | RuntimeException e) { return null; } }
java
public static String getFormatFromXmlFile(File xmlFile) { if (xmlFile == null || !xmlFile.exists()) return null; try (Reader reader = createReader(xmlFile)) { return getFormatFromXmlReader(reader); } catch (IOException | RuntimeException e) { return null; } }
[ "public", "static", "String", "getFormatFromXmlFile", "(", "File", "xmlFile", ")", "{", "if", "(", "xmlFile", "==", "null", "||", "!", "xmlFile", ".", "exists", "(", ")", ")", "return", "null", ";", "try", "(", "Reader", "reader", "=", "createReader", "(", "xmlFile", ")", ")", "{", "return", "getFormatFromXmlReader", "(", "reader", ")", ";", "}", "catch", "(", "IOException", "|", "RuntimeException", "e", ")", "{", "return", "null", ";", "}", "}" ]
Returns the NAACCR format of the given XML file. @param xmlFile provided data file @return the NAACCR format, null if it cannot be determined
[ "Returns", "the", "NAACCR", "format", "of", "the", "given", "XML", "file", "." ]
a3a501faa2a0c3411dd5248b2c1379f279131696
https://github.com/imsweb/naaccr-xml/blob/a3a501faa2a0c3411dd5248b2c1379f279131696/src/main/java/com/imsweb/naaccrxml/NaaccrXmlUtils.java#L383-L393
9,714
imsweb/naaccr-xml
src/main/java/com/imsweb/naaccrxml/NaaccrXmlUtils.java
NaaccrXmlUtils.getFormatFromXmlReader
public static String getFormatFromXmlReader(Reader xmlReader) { Map<String, String> attributes = getAttributesFromXmlReader(xmlReader); String baseDictUri = attributes.get(NAACCR_XML_ROOT_ATT_BASE_DICT); String recordType = attributes.get(NAACCR_XML_ROOT_ATT_REC_TYPE); if (baseDictUri != null && recordType != null) { String version = NaaccrXmlDictionaryUtils.extractVersionFromUri(baseDictUri); if (NaaccrFormat.isVersionSupported(version) && NaaccrFormat.isRecordTypeSupported(recordType)) return NaaccrFormat.getInstance(version, recordType).toString(); } return null; }
java
public static String getFormatFromXmlReader(Reader xmlReader) { Map<String, String> attributes = getAttributesFromXmlReader(xmlReader); String baseDictUri = attributes.get(NAACCR_XML_ROOT_ATT_BASE_DICT); String recordType = attributes.get(NAACCR_XML_ROOT_ATT_REC_TYPE); if (baseDictUri != null && recordType != null) { String version = NaaccrXmlDictionaryUtils.extractVersionFromUri(baseDictUri); if (NaaccrFormat.isVersionSupported(version) && NaaccrFormat.isRecordTypeSupported(recordType)) return NaaccrFormat.getInstance(version, recordType).toString(); } return null; }
[ "public", "static", "String", "getFormatFromXmlReader", "(", "Reader", "xmlReader", ")", "{", "Map", "<", "String", ",", "String", ">", "attributes", "=", "getAttributesFromXmlReader", "(", "xmlReader", ")", ";", "String", "baseDictUri", "=", "attributes", ".", "get", "(", "NAACCR_XML_ROOT_ATT_BASE_DICT", ")", ";", "String", "recordType", "=", "attributes", ".", "get", "(", "NAACCR_XML_ROOT_ATT_REC_TYPE", ")", ";", "if", "(", "baseDictUri", "!=", "null", "&&", "recordType", "!=", "null", ")", "{", "String", "version", "=", "NaaccrXmlDictionaryUtils", ".", "extractVersionFromUri", "(", "baseDictUri", ")", ";", "if", "(", "NaaccrFormat", ".", "isVersionSupported", "(", "version", ")", "&&", "NaaccrFormat", ".", "isRecordTypeSupported", "(", "recordType", ")", ")", "return", "NaaccrFormat", ".", "getInstance", "(", "version", ",", "recordType", ")", ".", "toString", "(", ")", ";", "}", "return", "null", ";", "}" ]
Returns the NAACCR format of the given XML reader. @param xmlReader provided reader, cannot be null @return the NAACCR format, null if it cannot be determined
[ "Returns", "the", "NAACCR", "format", "of", "the", "given", "XML", "reader", "." ]
a3a501faa2a0c3411dd5248b2c1379f279131696
https://github.com/imsweb/naaccr-xml/blob/a3a501faa2a0c3411dd5248b2c1379f279131696/src/main/java/com/imsweb/naaccrxml/NaaccrXmlUtils.java#L400-L411
9,715
imsweb/naaccr-xml
src/main/java/com/imsweb/naaccrxml/NaaccrXmlUtils.java
NaaccrXmlUtils.getAttributesFromXmlFile
public static Map<String, String> getAttributesFromXmlFile(File xmlFile) { if (xmlFile == null || !xmlFile.exists()) return Collections.emptyMap(); try (Reader reader = createReader(xmlFile)) { return getAttributesFromXmlReader(reader); } catch (IOException | RuntimeException e) { return Collections.emptyMap(); } }
java
public static Map<String, String> getAttributesFromXmlFile(File xmlFile) { if (xmlFile == null || !xmlFile.exists()) return Collections.emptyMap(); try (Reader reader = createReader(xmlFile)) { return getAttributesFromXmlReader(reader); } catch (IOException | RuntimeException e) { return Collections.emptyMap(); } }
[ "public", "static", "Map", "<", "String", ",", "String", ">", "getAttributesFromXmlFile", "(", "File", "xmlFile", ")", "{", "if", "(", "xmlFile", "==", "null", "||", "!", "xmlFile", ".", "exists", "(", ")", ")", "return", "Collections", ".", "emptyMap", "(", ")", ";", "try", "(", "Reader", "reader", "=", "createReader", "(", "xmlFile", ")", ")", "{", "return", "getAttributesFromXmlReader", "(", "reader", ")", ";", "}", "catch", "(", "IOException", "|", "RuntimeException", "e", ")", "{", "return", "Collections", ".", "emptyMap", "(", ")", ";", "}", "}" ]
Returns all the available attributes from the given XML file. @param xmlFile provided data file @return the available attributes in a map, maybe empty but never null
[ "Returns", "all", "the", "available", "attributes", "from", "the", "given", "XML", "file", "." ]
a3a501faa2a0c3411dd5248b2c1379f279131696
https://github.com/imsweb/naaccr-xml/blob/a3a501faa2a0c3411dd5248b2c1379f279131696/src/main/java/com/imsweb/naaccrxml/NaaccrXmlUtils.java#L418-L428
9,716
imsweb/naaccr-xml
src/main/java/com/imsweb/naaccrxml/NaaccrXmlUtils.java
NaaccrXmlUtils.createReader
public static Reader createReader(File file) throws NaaccrIOException { InputStream is = null; try { is = new FileInputStream(file); if (file.getName().endsWith(".gz")) is = new GZIPInputStream(is); return new InputStreamReader(is, StandardCharsets.UTF_8); } catch (IOException e) { if (is != null) { try { is.close(); } catch (IOException e1) { // give up } } throw new NaaccrIOException(e.getMessage()); } }
java
public static Reader createReader(File file) throws NaaccrIOException { InputStream is = null; try { is = new FileInputStream(file); if (file.getName().endsWith(".gz")) is = new GZIPInputStream(is); return new InputStreamReader(is, StandardCharsets.UTF_8); } catch (IOException e) { if (is != null) { try { is.close(); } catch (IOException e1) { // give up } } throw new NaaccrIOException(e.getMessage()); } }
[ "public", "static", "Reader", "createReader", "(", "File", "file", ")", "throws", "NaaccrIOException", "{", "InputStream", "is", "=", "null", ";", "try", "{", "is", "=", "new", "FileInputStream", "(", "file", ")", ";", "if", "(", "file", ".", "getName", "(", ")", ".", "endsWith", "(", "\".gz\"", ")", ")", "is", "=", "new", "GZIPInputStream", "(", "is", ")", ";", "return", "new", "InputStreamReader", "(", "is", ",", "StandardCharsets", ".", "UTF_8", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "if", "(", "is", "!=", "null", ")", "{", "try", "{", "is", ".", "close", "(", ")", ";", "}", "catch", "(", "IOException", "e1", ")", "{", "// give up", "}", "}", "throw", "new", "NaaccrIOException", "(", "e", ".", "getMessage", "(", ")", ")", ";", "}", "}" ]
Returns a generic reader for the provided file, taking care of the optional GZ compression. @param file file to create the reader from, cannot be null @return a generic reader to the file, never null @throws NaaccrIOException if the reader cannot be created
[ "Returns", "a", "generic", "reader", "for", "the", "provided", "file", "taking", "care", "of", "the", "optional", "GZ", "compression", "." ]
a3a501faa2a0c3411dd5248b2c1379f279131696
https://github.com/imsweb/naaccr-xml/blob/a3a501faa2a0c3411dd5248b2c1379f279131696/src/main/java/com/imsweb/naaccrxml/NaaccrXmlUtils.java#L475-L496
9,717
imsweb/naaccr-xml
src/main/java/com/imsweb/naaccrxml/NaaccrXmlUtils.java
NaaccrXmlUtils.createWriter
public static Writer createWriter(File file) throws NaaccrIOException { OutputStream os = null; try { os = new FileOutputStream(file); if (file.getName().endsWith(".gz")) os = new GZIPOutputStream(os); return new OutputStreamWriter(os, StandardCharsets.UTF_8); } catch (IOException e) { if (os != null) { try { os.close(); } catch (IOException e1) { // give up } } throw new NaaccrIOException(e.getMessage()); } }
java
public static Writer createWriter(File file) throws NaaccrIOException { OutputStream os = null; try { os = new FileOutputStream(file); if (file.getName().endsWith(".gz")) os = new GZIPOutputStream(os); return new OutputStreamWriter(os, StandardCharsets.UTF_8); } catch (IOException e) { if (os != null) { try { os.close(); } catch (IOException e1) { // give up } } throw new NaaccrIOException(e.getMessage()); } }
[ "public", "static", "Writer", "createWriter", "(", "File", "file", ")", "throws", "NaaccrIOException", "{", "OutputStream", "os", "=", "null", ";", "try", "{", "os", "=", "new", "FileOutputStream", "(", "file", ")", ";", "if", "(", "file", ".", "getName", "(", ")", ".", "endsWith", "(", "\".gz\"", ")", ")", "os", "=", "new", "GZIPOutputStream", "(", "os", ")", ";", "return", "new", "OutputStreamWriter", "(", "os", ",", "StandardCharsets", ".", "UTF_8", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "if", "(", "os", "!=", "null", ")", "{", "try", "{", "os", ".", "close", "(", ")", ";", "}", "catch", "(", "IOException", "e1", ")", "{", "// give up", "}", "}", "throw", "new", "NaaccrIOException", "(", "e", ".", "getMessage", "(", ")", ")", ";", "}", "}" ]
Returns a generic writer for the provided file, taking care of the optional GZ compression. @param file file to create the writer from, cannot be null @return a generic writer to the file, never null @throws NaaccrIOException if the writer cannot be created
[ "Returns", "a", "generic", "writer", "for", "the", "provided", "file", "taking", "care", "of", "the", "optional", "GZ", "compression", "." ]
a3a501faa2a0c3411dd5248b2c1379f279131696
https://github.com/imsweb/naaccr-xml/blob/a3a501faa2a0c3411dd5248b2c1379f279131696/src/main/java/com/imsweb/naaccrxml/NaaccrXmlUtils.java#L504-L525
9,718
vincentk/joptimizer
src/main/java/com/joptimizer/optimizers/OptimizationRequestHandler.java
OptimizationRequestHandler.getMeq
protected final int getMeq(){ if(meq < 0){ meq = (this.request.getA()==null)? 0 : this.request.getA().rows(); } return meq; }
java
protected final int getMeq(){ if(meq < 0){ meq = (this.request.getA()==null)? 0 : this.request.getA().rows(); } return meq; }
[ "protected", "final", "int", "getMeq", "(", ")", "{", "if", "(", "meq", "<", "0", ")", "{", "meq", "=", "(", "this", ".", "request", ".", "getA", "(", ")", "==", "null", ")", "?", "0", ":", "this", ".", "request", ".", "getA", "(", ")", ".", "rows", "(", ")", ";", "}", "return", "meq", ";", "}" ]
Number of equalities.
[ "Number", "of", "equalities", "." ]
65064c1bb0b26c7261358021e4c93d06dd43564f
https://github.com/vincentk/joptimizer/blob/65064c1bb0b26c7261358021e4c93d06dd43564f/src/main/java/com/joptimizer/optimizers/OptimizationRequestHandler.java#L92-L97
9,719
vincentk/joptimizer
src/main/java/com/joptimizer/optimizers/OptimizationRequestHandler.java
OptimizationRequestHandler.isInDomainF0
protected boolean isInDomainF0(DoubleMatrix1D X) { double F0X = request.getF0().value(X.toArray()); return !Double.isInfinite(F0X) && !Double.isNaN(F0X); }
java
protected boolean isInDomainF0(DoubleMatrix1D X) { double F0X = request.getF0().value(X.toArray()); return !Double.isInfinite(F0X) && !Double.isNaN(F0X); }
[ "protected", "boolean", "isInDomainF0", "(", "DoubleMatrix1D", "X", ")", "{", "double", "F0X", "=", "request", ".", "getF0", "(", ")", ".", "value", "(", "X", ".", "toArray", "(", ")", ")", ";", "return", "!", "Double", ".", "isInfinite", "(", "F0X", ")", "&&", "!", "Double", ".", "isNaN", "(", "F0X", ")", ";", "}" ]
Objective function domain.
[ "Objective", "function", "domain", "." ]
65064c1bb0b26c7261358021e4c93d06dd43564f
https://github.com/vincentk/joptimizer/blob/65064c1bb0b26c7261358021e4c93d06dd43564f/src/main/java/com/joptimizer/optimizers/OptimizationRequestHandler.java#L185-L188
9,720
vincentk/joptimizer
src/main/java/com/joptimizer/optimizers/OptimizationRequestHandler.java
OptimizationRequestHandler.getGradF0
protected DoubleMatrix1D getGradF0(DoubleMatrix1D X) { return F1.make(request.getF0().gradient(X.toArray())); }
java
protected DoubleMatrix1D getGradF0(DoubleMatrix1D X) { return F1.make(request.getF0().gradient(X.toArray())); }
[ "protected", "DoubleMatrix1D", "getGradF0", "(", "DoubleMatrix1D", "X", ")", "{", "return", "F1", ".", "make", "(", "request", ".", "getF0", "(", ")", ".", "gradient", "(", "X", ".", "toArray", "(", ")", ")", ")", ";", "}" ]
Objective function gradient at X.
[ "Objective", "function", "gradient", "at", "X", "." ]
65064c1bb0b26c7261358021e4c93d06dd43564f
https://github.com/vincentk/joptimizer/blob/65064c1bb0b26c7261358021e4c93d06dd43564f/src/main/java/com/joptimizer/optimizers/OptimizationRequestHandler.java#L200-L202
9,721
vincentk/joptimizer
src/main/java/com/joptimizer/optimizers/OptimizationRequestHandler.java
OptimizationRequestHandler.getHessF0
protected DoubleMatrix2D getHessF0(DoubleMatrix1D X) { double[][] hess = request.getF0().hessian(X.toArray()); if(hess == FunctionsUtils.ZEROES_2D_ARRAY_PLACEHOLDER){ return F2.make(X.size(), X.size()); }else{ return F2.make(hess); } }
java
protected DoubleMatrix2D getHessF0(DoubleMatrix1D X) { double[][] hess = request.getF0().hessian(X.toArray()); if(hess == FunctionsUtils.ZEROES_2D_ARRAY_PLACEHOLDER){ return F2.make(X.size(), X.size()); }else{ return F2.make(hess); } }
[ "protected", "DoubleMatrix2D", "getHessF0", "(", "DoubleMatrix1D", "X", ")", "{", "double", "[", "]", "[", "]", "hess", "=", "request", ".", "getF0", "(", ")", ".", "hessian", "(", "X", ".", "toArray", "(", ")", ")", ";", "if", "(", "hess", "==", "FunctionsUtils", ".", "ZEROES_2D_ARRAY_PLACEHOLDER", ")", "{", "return", "F2", ".", "make", "(", "X", ".", "size", "(", ")", ",", "X", ".", "size", "(", ")", ")", ";", "}", "else", "{", "return", "F2", ".", "make", "(", "hess", ")", ";", "}", "}" ]
Objective function hessian at X.
[ "Objective", "function", "hessian", "at", "X", "." ]
65064c1bb0b26c7261358021e4c93d06dd43564f
https://github.com/vincentk/joptimizer/blob/65064c1bb0b26c7261358021e4c93d06dd43564f/src/main/java/com/joptimizer/optimizers/OptimizationRequestHandler.java#L207-L214
9,722
vincentk/joptimizer
src/main/java/com/joptimizer/optimizers/OptimizationRequestHandler.java
OptimizationRequestHandler.getFi
protected DoubleMatrix1D getFi(DoubleMatrix1D X){ final ConvexMultivariateRealFunction[] fis = request.getFi(); if(fis==null){ return null; } final double[] ret = new double[fis.length]; final double[] x = X.toArray(); for(int i=0; i<fis.length; i++){ final ConvexMultivariateRealFunction fi = fis[i]; final double fix = fi.value(x); ret[i] = fix; } return F1.make(ret); }
java
protected DoubleMatrix1D getFi(DoubleMatrix1D X){ final ConvexMultivariateRealFunction[] fis = request.getFi(); if(fis==null){ return null; } final double[] ret = new double[fis.length]; final double[] x = X.toArray(); for(int i=0; i<fis.length; i++){ final ConvexMultivariateRealFunction fi = fis[i]; final double fix = fi.value(x); ret[i] = fix; } return F1.make(ret); }
[ "protected", "DoubleMatrix1D", "getFi", "(", "DoubleMatrix1D", "X", ")", "{", "final", "ConvexMultivariateRealFunction", "[", "]", "fis", "=", "request", ".", "getFi", "(", ")", ";", "if", "(", "fis", "==", "null", ")", "{", "return", "null", ";", "}", "final", "double", "[", "]", "ret", "=", "new", "double", "[", "fis", ".", "length", "]", ";", "final", "double", "[", "]", "x", "=", "X", ".", "toArray", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "fis", ".", "length", ";", "i", "++", ")", "{", "final", "ConvexMultivariateRealFunction", "fi", "=", "fis", "[", "i", "]", ";", "final", "double", "fix", "=", "fi", ".", "value", "(", "x", ")", ";", "ret", "[", "i", "]", "=", "fix", ";", "}", "return", "F1", ".", "make", "(", "ret", ")", ";", "}" ]
Inequality functions values at X.
[ "Inequality", "functions", "values", "at", "X", "." ]
65064c1bb0b26c7261358021e4c93d06dd43564f
https://github.com/vincentk/joptimizer/blob/65064c1bb0b26c7261358021e4c93d06dd43564f/src/main/java/com/joptimizer/optimizers/OptimizationRequestHandler.java#L226-L239
9,723
vincentk/joptimizer
src/main/java/com/joptimizer/optimizers/OptimizationRequestHandler.java
OptimizationRequestHandler.getGradFi
protected DoubleMatrix2D getGradFi(DoubleMatrix1D X) { DoubleMatrix2D ret = F2.make(request.getFi().length, X.size()); double[] x = X.toArray(); for(int i=0; i<request.getFi().length; i++){ ret.viewRow(i).assign(request.getFi()[i].gradient(x)); } return ret; }
java
protected DoubleMatrix2D getGradFi(DoubleMatrix1D X) { DoubleMatrix2D ret = F2.make(request.getFi().length, X.size()); double[] x = X.toArray(); for(int i=0; i<request.getFi().length; i++){ ret.viewRow(i).assign(request.getFi()[i].gradient(x)); } return ret; }
[ "protected", "DoubleMatrix2D", "getGradFi", "(", "DoubleMatrix1D", "X", ")", "{", "DoubleMatrix2D", "ret", "=", "F2", ".", "make", "(", "request", ".", "getFi", "(", ")", ".", "length", ",", "X", ".", "size", "(", ")", ")", ";", "double", "[", "]", "x", "=", "X", ".", "toArray", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "request", ".", "getFi", "(", ")", ".", "length", ";", "i", "++", ")", "{", "ret", ".", "viewRow", "(", "i", ")", ".", "assign", "(", "request", ".", "getFi", "(", ")", "[", "i", "]", ".", "gradient", "(", "x", ")", ")", ";", "}", "return", "ret", ";", "}" ]
Inequality functions gradients values at X.
[ "Inequality", "functions", "gradients", "values", "at", "X", "." ]
65064c1bb0b26c7261358021e4c93d06dd43564f
https://github.com/vincentk/joptimizer/blob/65064c1bb0b26c7261358021e4c93d06dd43564f/src/main/java/com/joptimizer/optimizers/OptimizationRequestHandler.java#L244-L251
9,724
vincentk/joptimizer
src/main/java/com/joptimizer/optimizers/OptimizationRequestHandler.java
OptimizationRequestHandler.getHessFi
protected DoubleMatrix2D[] getHessFi(DoubleMatrix1D X){ DoubleMatrix2D[] ret = new DoubleMatrix2D[request.getFi().length]; double[] x = X.toArray(); for(int i=0; i<request.getFi().length; i++){ double[][] hess = request.getFi()[i].hessian(x); if(hess == FunctionsUtils.ZEROES_2D_ARRAY_PLACEHOLDER){ ret[i] = FunctionsUtils.ZEROES_MATRIX_PLACEHOLDER; }else{ ret[i] = F2.make(hess); } } return ret; }
java
protected DoubleMatrix2D[] getHessFi(DoubleMatrix1D X){ DoubleMatrix2D[] ret = new DoubleMatrix2D[request.getFi().length]; double[] x = X.toArray(); for(int i=0; i<request.getFi().length; i++){ double[][] hess = request.getFi()[i].hessian(x); if(hess == FunctionsUtils.ZEROES_2D_ARRAY_PLACEHOLDER){ ret[i] = FunctionsUtils.ZEROES_MATRIX_PLACEHOLDER; }else{ ret[i] = F2.make(hess); } } return ret; }
[ "protected", "DoubleMatrix2D", "[", "]", "getHessFi", "(", "DoubleMatrix1D", "X", ")", "{", "DoubleMatrix2D", "[", "]", "ret", "=", "new", "DoubleMatrix2D", "[", "request", ".", "getFi", "(", ")", ".", "length", "]", ";", "double", "[", "]", "x", "=", "X", ".", "toArray", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "request", ".", "getFi", "(", ")", ".", "length", ";", "i", "++", ")", "{", "double", "[", "]", "[", "]", "hess", "=", "request", ".", "getFi", "(", ")", "[", "i", "]", ".", "hessian", "(", "x", ")", ";", "if", "(", "hess", "==", "FunctionsUtils", ".", "ZEROES_2D_ARRAY_PLACEHOLDER", ")", "{", "ret", "[", "i", "]", "=", "FunctionsUtils", ".", "ZEROES_MATRIX_PLACEHOLDER", ";", "}", "else", "{", "ret", "[", "i", "]", "=", "F2", ".", "make", "(", "hess", ")", ";", "}", "}", "return", "ret", ";", "}" ]
Inequality functions hessians values at X.
[ "Inequality", "functions", "hessians", "values", "at", "X", "." ]
65064c1bb0b26c7261358021e4c93d06dd43564f
https://github.com/vincentk/joptimizer/blob/65064c1bb0b26c7261358021e4c93d06dd43564f/src/main/java/com/joptimizer/optimizers/OptimizationRequestHandler.java#L256-L268
9,725
vincentk/joptimizer
src/main/java/com/joptimizer/optimizers/LPPresolver.java
LPPresolver.presolve
public double[] presolve(double[] x){ if(x.length != originalN){ throw new IllegalArgumentException("wrong array dimension: " + x.length); } double[] presolvedX = Arrays.copyOf(x, x.length); for(int i=0; i<presolvingStack.size(); i++){ presolvingStack.get(i).preSolve(presolvedX); } double[] ret = new double[presolvedN]; int cntPosition = 0; for(int i=0; i<presolvedX.length; i++){ if(indipendentVariables[i]){ ret[cntPosition] = presolvedX[i]; cntPosition++; } } if(this.T != null){ //rescaling has been done: x = T.x1 for(int i=0; i<ret.length; i++){ ret[i] = ret[i] / T.getQuick(i); } } return ret; }
java
public double[] presolve(double[] x){ if(x.length != originalN){ throw new IllegalArgumentException("wrong array dimension: " + x.length); } double[] presolvedX = Arrays.copyOf(x, x.length); for(int i=0; i<presolvingStack.size(); i++){ presolvingStack.get(i).preSolve(presolvedX); } double[] ret = new double[presolvedN]; int cntPosition = 0; for(int i=0; i<presolvedX.length; i++){ if(indipendentVariables[i]){ ret[cntPosition] = presolvedX[i]; cntPosition++; } } if(this.T != null){ //rescaling has been done: x = T.x1 for(int i=0; i<ret.length; i++){ ret[i] = ret[i] / T.getQuick(i); } } return ret; }
[ "public", "double", "[", "]", "presolve", "(", "double", "[", "]", "x", ")", "{", "if", "(", "x", ".", "length", "!=", "originalN", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"wrong array dimension: \"", "+", "x", ".", "length", ")", ";", "}", "double", "[", "]", "presolvedX", "=", "Arrays", ".", "copyOf", "(", "x", ",", "x", ".", "length", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "presolvingStack", ".", "size", "(", ")", ";", "i", "++", ")", "{", "presolvingStack", ".", "get", "(", "i", ")", ".", "preSolve", "(", "presolvedX", ")", ";", "}", "double", "[", "]", "ret", "=", "new", "double", "[", "presolvedN", "]", ";", "int", "cntPosition", "=", "0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "presolvedX", ".", "length", ";", "i", "++", ")", "{", "if", "(", "indipendentVariables", "[", "i", "]", ")", "{", "ret", "[", "cntPosition", "]", "=", "presolvedX", "[", "i", "]", ";", "cntPosition", "++", ";", "}", "}", "if", "(", "this", ".", "T", "!=", "null", ")", "{", "//rescaling has been done: x = T.x1\r", "for", "(", "int", "i", "=", "0", ";", "i", "<", "ret", ".", "length", ";", "i", "++", ")", "{", "ret", "[", "i", "]", "=", "ret", "[", "i", "]", "/", "T", ".", "getQuick", "(", "i", ")", ";", "}", "}", "return", "ret", ";", "}" ]
From the full x, gives back its presolved elements.
[ "From", "the", "full", "x", "gives", "back", "its", "presolved", "elements", "." ]
65064c1bb0b26c7261358021e4c93d06dd43564f
https://github.com/vincentk/joptimizer/blob/65064c1bb0b26c7261358021e4c93d06dd43564f/src/main/java/com/joptimizer/optimizers/LPPresolver.java#L548-L571
9,726
vincentk/joptimizer
src/main/java/com/joptimizer/optimizers/LPStandardConverter.java
LPStandardConverter.postConvert
public double[] postConvert(double[] X) { if (X.length != standardN) { throw new IllegalArgumentException("wrong array dimension: " + X.length); } double[] ret = new double[originalN]; int cntSplitted = 0; for (int i = standardS; i < standardN; i++) { if (splittedVariablesList.contains(i - standardS)) { // this variable was splitted: x = xPlus-xMinus ret[i - standardS] = X[i] - X[standardN + cntSplitted]; cntSplitted++; } else { ret[i - standardS] = X[i]; } } // this.postconvertedX = ret; return ret; }
java
public double[] postConvert(double[] X) { if (X.length != standardN) { throw new IllegalArgumentException("wrong array dimension: " + X.length); } double[] ret = new double[originalN]; int cntSplitted = 0; for (int i = standardS; i < standardN; i++) { if (splittedVariablesList.contains(i - standardS)) { // this variable was splitted: x = xPlus-xMinus ret[i - standardS] = X[i] - X[standardN + cntSplitted]; cntSplitted++; } else { ret[i - standardS] = X[i]; } } // this.postconvertedX = ret; return ret; }
[ "public", "double", "[", "]", "postConvert", "(", "double", "[", "]", "X", ")", "{", "if", "(", "X", ".", "length", "!=", "standardN", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"wrong array dimension: \"", "+", "X", ".", "length", ")", ";", "}", "double", "[", "]", "ret", "=", "new", "double", "[", "originalN", "]", ";", "int", "cntSplitted", "=", "0", ";", "for", "(", "int", "i", "=", "standardS", ";", "i", "<", "standardN", ";", "i", "++", ")", "{", "if", "(", "splittedVariablesList", ".", "contains", "(", "i", "-", "standardS", ")", ")", "{", "// this variable was splitted: x = xPlus-xMinus\r", "ret", "[", "i", "-", "standardS", "]", "=", "X", "[", "i", "]", "-", "X", "[", "standardN", "+", "cntSplitted", "]", ";", "cntSplitted", "++", ";", "}", "else", "{", "ret", "[", "i", "-", "standardS", "]", "=", "X", "[", "i", "]", ";", "}", "}", "// this.postconvertedX = ret;\r", "return", "ret", ";", "}" ]
Get back the vector in the original components. @param X vector in the standard variables @return the original component
[ "Get", "back", "the", "vector", "in", "the", "original", "components", "." ]
65064c1bb0b26c7261358021e4c93d06dd43564f
https://github.com/vincentk/joptimizer/blob/65064c1bb0b26c7261358021e4c93d06dd43564f/src/main/java/com/joptimizer/optimizers/LPStandardConverter.java#L411-L428
9,727
vincentk/joptimizer
src/main/java/com/joptimizer/optimizers/LPStandardConverter.java
LPStandardConverter.getStandardComponents
public double[] getStandardComponents(double[] x){ if(x.length != originalN){ throw new IllegalArgumentException("wrong array dimension: " + x.length); } double[] ret = new double[standardN]; for(int i=0; i<x.length; i++){ if (splittedVariablesList.contains(i)) { // this variable was splitted: x = xPlus-xMinus if(x[i] >= 0){ //value for xPlus ret[standardS + i] = x[i]; }else{ int pos = -1; for(int k=0; k<splittedVariablesList.size(); k++){ if(splittedVariablesList.get(k)==i){ pos = k; break; } } //value for xMinus ret[standardS + x.length + pos] = -x[i]; } }else{ ret[standardS + i] = x[i]; } } if(standardS>0){ DoubleMatrix1D residuals = ColtUtils.zMult(standardA, F1.make(ret), standardB, -1); for(int i=0; i<standardS; i++){ ret[i] = -residuals.get(i) + ret[i]; } } return ret; }
java
public double[] getStandardComponents(double[] x){ if(x.length != originalN){ throw new IllegalArgumentException("wrong array dimension: " + x.length); } double[] ret = new double[standardN]; for(int i=0; i<x.length; i++){ if (splittedVariablesList.contains(i)) { // this variable was splitted: x = xPlus-xMinus if(x[i] >= 0){ //value for xPlus ret[standardS + i] = x[i]; }else{ int pos = -1; for(int k=0; k<splittedVariablesList.size(); k++){ if(splittedVariablesList.get(k)==i){ pos = k; break; } } //value for xMinus ret[standardS + x.length + pos] = -x[i]; } }else{ ret[standardS + i] = x[i]; } } if(standardS>0){ DoubleMatrix1D residuals = ColtUtils.zMult(standardA, F1.make(ret), standardB, -1); for(int i=0; i<standardS; i++){ ret[i] = -residuals.get(i) + ret[i]; } } return ret; }
[ "public", "double", "[", "]", "getStandardComponents", "(", "double", "[", "]", "x", ")", "{", "if", "(", "x", ".", "length", "!=", "originalN", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"wrong array dimension: \"", "+", "x", ".", "length", ")", ";", "}", "double", "[", "]", "ret", "=", "new", "double", "[", "standardN", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "x", ".", "length", ";", "i", "++", ")", "{", "if", "(", "splittedVariablesList", ".", "contains", "(", "i", ")", ")", "{", "// this variable was splitted: x = xPlus-xMinus\r", "if", "(", "x", "[", "i", "]", ">=", "0", ")", "{", "//value for xPlus\r", "ret", "[", "standardS", "+", "i", "]", "=", "x", "[", "i", "]", ";", "}", "else", "{", "int", "pos", "=", "-", "1", ";", "for", "(", "int", "k", "=", "0", ";", "k", "<", "splittedVariablesList", ".", "size", "(", ")", ";", "k", "++", ")", "{", "if", "(", "splittedVariablesList", ".", "get", "(", "k", ")", "==", "i", ")", "{", "pos", "=", "k", ";", "break", ";", "}", "}", "//value for xMinus\r", "ret", "[", "standardS", "+", "x", ".", "length", "+", "pos", "]", "=", "-", "x", "[", "i", "]", ";", "}", "}", "else", "{", "ret", "[", "standardS", "+", "i", "]", "=", "x", "[", "i", "]", ";", "}", "}", "if", "(", "standardS", ">", "0", ")", "{", "DoubleMatrix1D", "residuals", "=", "ColtUtils", ".", "zMult", "(", "standardA", ",", "F1", ".", "make", "(", "ret", ")", ",", "standardB", ",", "-", "1", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "standardS", ";", "i", "++", ")", "{", "ret", "[", "i", "]", "=", "-", "residuals", ".", "get", "(", "i", ")", "+", "ret", "[", "i", "]", ";", "}", "}", "return", "ret", ";", "}" ]
Express a vector in the original variables in the final standard variable form @param x vector in the original variables @return vector in the standard variables
[ "Express", "a", "vector", "in", "the", "original", "variables", "in", "the", "final", "standard", "variable", "form" ]
65064c1bb0b26c7261358021e4c93d06dd43564f
https://github.com/vincentk/joptimizer/blob/65064c1bb0b26c7261358021e4c93d06dd43564f/src/main/java/com/joptimizer/optimizers/LPStandardConverter.java#L435-L468
9,728
vincentk/joptimizer
src/main/java/com/joptimizer/algebra/MatrixLogSumRescaler.java
MatrixLogSumRescaler.getMatrixScalingFactorsSymm
@Override public DoubleMatrix1D getMatrixScalingFactorsSymm(DoubleMatrix2D A) { int n = A.rows(); final double log10_b = Math.log10(base); final int[] x = new int[n]; final double[] cHolder = new double[1]; final double[] tHolder = new double[1]; final int[] currentColumnIndexHolder = new int[] { -1 }; IntIntDoubleFunction myFunct = new IntIntDoubleFunction() { @Override public double apply(int i, int j, double pij) { int currentColumnIndex = currentColumnIndexHolder[0]; // we take into account only the lower left subdiagonal part of Q (that is symmetric) if(i == currentColumnIndex){ //diagonal element //log.debug("i:" + i + ", j:" + currentColumnIndex + ": " + pij); tHolder[0] = tHolder[0] - 0.5 * (Math.log10(Math.abs(pij))/log10_b + 0.5);//log(b, x) = log(k, x) / log(k, b) cHolder[0] = cHolder[0] + 1; }else if (i > currentColumnIndex) { //sub-diagonal elements //log.debug("i:" + i + ", j:" + currentColumnIndex + ": " + pij); tHolder[0] = tHolder[0] - 2 * (Math.log10(Math.abs(pij))/log10_b + 0.5) -2*x[i];//log(b, x) = log(k, x) / log(k, b) cHolder[0] = cHolder[0] + 2;//- 2*x[i] } return pij; } }; //view A column by column for (int currentColumnIndex = n - 1; currentColumnIndex >= 0; currentColumnIndex--) { //log.debug("currentColumnIndex:" + currentColumnIndex); cHolder[0] = 0;//reset tHolder[0] = 0;//reset currentColumnIndexHolder[0] = currentColumnIndex; DoubleMatrix2D P = A.viewPart(0, currentColumnIndex, n, 1); P.forEachNonZero(myFunct); if(cHolder[0] > 0){ x[currentColumnIndex] = (int)Math.round(tHolder[0] / cHolder[0]); } } //log.debug("x: " + ArrayUtils.toString(x)); DoubleMatrix1D u = new DenseDoubleMatrix1D(n); for (int k = 0; k < n; k++) { u.setQuick(k, Math.pow(base, x[k])); } return u; }
java
@Override public DoubleMatrix1D getMatrixScalingFactorsSymm(DoubleMatrix2D A) { int n = A.rows(); final double log10_b = Math.log10(base); final int[] x = new int[n]; final double[] cHolder = new double[1]; final double[] tHolder = new double[1]; final int[] currentColumnIndexHolder = new int[] { -1 }; IntIntDoubleFunction myFunct = new IntIntDoubleFunction() { @Override public double apply(int i, int j, double pij) { int currentColumnIndex = currentColumnIndexHolder[0]; // we take into account only the lower left subdiagonal part of Q (that is symmetric) if(i == currentColumnIndex){ //diagonal element //log.debug("i:" + i + ", j:" + currentColumnIndex + ": " + pij); tHolder[0] = tHolder[0] - 0.5 * (Math.log10(Math.abs(pij))/log10_b + 0.5);//log(b, x) = log(k, x) / log(k, b) cHolder[0] = cHolder[0] + 1; }else if (i > currentColumnIndex) { //sub-diagonal elements //log.debug("i:" + i + ", j:" + currentColumnIndex + ": " + pij); tHolder[0] = tHolder[0] - 2 * (Math.log10(Math.abs(pij))/log10_b + 0.5) -2*x[i];//log(b, x) = log(k, x) / log(k, b) cHolder[0] = cHolder[0] + 2;//- 2*x[i] } return pij; } }; //view A column by column for (int currentColumnIndex = n - 1; currentColumnIndex >= 0; currentColumnIndex--) { //log.debug("currentColumnIndex:" + currentColumnIndex); cHolder[0] = 0;//reset tHolder[0] = 0;//reset currentColumnIndexHolder[0] = currentColumnIndex; DoubleMatrix2D P = A.viewPart(0, currentColumnIndex, n, 1); P.forEachNonZero(myFunct); if(cHolder[0] > 0){ x[currentColumnIndex] = (int)Math.round(tHolder[0] / cHolder[0]); } } //log.debug("x: " + ArrayUtils.toString(x)); DoubleMatrix1D u = new DenseDoubleMatrix1D(n); for (int k = 0; k < n; k++) { u.setQuick(k, Math.pow(base, x[k])); } return u; }
[ "@", "Override", "public", "DoubleMatrix1D", "getMatrixScalingFactorsSymm", "(", "DoubleMatrix2D", "A", ")", "{", "int", "n", "=", "A", ".", "rows", "(", ")", ";", "final", "double", "log10_b", "=", "Math", ".", "log10", "(", "base", ")", ";", "final", "int", "[", "]", "x", "=", "new", "int", "[", "n", "]", ";", "final", "double", "[", "]", "cHolder", "=", "new", "double", "[", "1", "]", ";", "final", "double", "[", "]", "tHolder", "=", "new", "double", "[", "1", "]", ";", "final", "int", "[", "]", "currentColumnIndexHolder", "=", "new", "int", "[", "]", "{", "-", "1", "}", ";", "IntIntDoubleFunction", "myFunct", "=", "new", "IntIntDoubleFunction", "(", ")", "{", "@", "Override", "public", "double", "apply", "(", "int", "i", ",", "int", "j", ",", "double", "pij", ")", "{", "int", "currentColumnIndex", "=", "currentColumnIndexHolder", "[", "0", "]", ";", "// we take into account only the lower left subdiagonal part of Q (that is symmetric)\r", "if", "(", "i", "==", "currentColumnIndex", ")", "{", "//diagonal element\r", "//log.debug(\"i:\" + i + \", j:\" + currentColumnIndex + \": \" + pij);\r", "tHolder", "[", "0", "]", "=", "tHolder", "[", "0", "]", "-", "0.5", "*", "(", "Math", ".", "log10", "(", "Math", ".", "abs", "(", "pij", ")", ")", "/", "log10_b", "+", "0.5", ")", ";", "//log(b, x) = log(k, x) / log(k, b)\r", "cHolder", "[", "0", "]", "=", "cHolder", "[", "0", "]", "+", "1", ";", "}", "else", "if", "(", "i", ">", "currentColumnIndex", ")", "{", "//sub-diagonal elements\r", "//log.debug(\"i:\" + i + \", j:\" + currentColumnIndex + \": \" + pij);\r", "tHolder", "[", "0", "]", "=", "tHolder", "[", "0", "]", "-", "2", "*", "(", "Math", ".", "log10", "(", "Math", ".", "abs", "(", "pij", ")", ")", "/", "log10_b", "+", "0.5", ")", "-", "2", "*", "x", "[", "i", "]", ";", "//log(b, x) = log(k, x) / log(k, b)\r", "cHolder", "[", "0", "]", "=", "cHolder", "[", "0", "]", "+", "2", ";", "//- 2*x[i]\r", "}", "return", "pij", ";", "}", "}", ";", "//view A column by column\r", "for", "(", "int", "currentColumnIndex", "=", "n", "-", "1", ";", "currentColumnIndex", ">=", "0", ";", "currentColumnIndex", "--", ")", "{", "//log.debug(\"currentColumnIndex:\" + currentColumnIndex);\r", "cHolder", "[", "0", "]", "=", "0", ";", "//reset\r", "tHolder", "[", "0", "]", "=", "0", ";", "//reset\r", "currentColumnIndexHolder", "[", "0", "]", "=", "currentColumnIndex", ";", "DoubleMatrix2D", "P", "=", "A", ".", "viewPart", "(", "0", ",", "currentColumnIndex", ",", "n", ",", "1", ")", ";", "P", ".", "forEachNonZero", "(", "myFunct", ")", ";", "if", "(", "cHolder", "[", "0", "]", ">", "0", ")", "{", "x", "[", "currentColumnIndex", "]", "=", "(", "int", ")", "Math", ".", "round", "(", "tHolder", "[", "0", "]", "/", "cHolder", "[", "0", "]", ")", ";", "}", "}", "//log.debug(\"x: \" + ArrayUtils.toString(x));\r", "DoubleMatrix1D", "u", "=", "new", "DenseDoubleMatrix1D", "(", "n", ")", ";", "for", "(", "int", "k", "=", "0", ";", "k", "<", "n", ";", "k", "++", ")", "{", "u", ".", "setQuick", "(", "k", ",", "Math", ".", "pow", "(", "base", ",", "x", "[", "k", "]", ")", ")", ";", "}", "return", "u", ";", "}" ]
Symmetry preserving scale factors @see Gajulapalli, Lasdon "Scaling Sparse Matrices for Optimization Algorithms", algorithm 3
[ "Symmetry", "preserving", "scale", "factors" ]
65064c1bb0b26c7261358021e4c93d06dd43564f
https://github.com/vincentk/joptimizer/blob/65064c1bb0b26c7261358021e4c93d06dd43564f/src/main/java/com/joptimizer/algebra/MatrixLogSumRescaler.java#L181-L230
9,729
vincentk/joptimizer
src/main/java/com/joptimizer/algebra/MatrixLogSumRescaler.java
MatrixLogSumRescaler.checkScaling
@Override public boolean checkScaling(final DoubleMatrix2D A, final DoubleMatrix1D U, final DoubleMatrix1D V){ final double log10_2 = Math.log10(base); final double[] originalOFValue = {0}; final double[] scaledOFValue = {0}; final double[] x = new double[A.rows()]; final double[] y = new double[A.columns()]; A.forEachNonZero(new IntIntDoubleFunction() { @Override public double apply(int i, int j, double aij) { double v = Math.log10(Math.abs(aij)) / log10_2 + 0.5; originalOFValue[0] = originalOFValue[0] + Math.pow(v, 2); double xi = Math.log10(U.getQuick(i)) / log10_2; double yj = Math.log10(V.getQuick(j)) / log10_2; scaledOFValue[0] = scaledOFValue[0] + Math.pow(xi + yj + v, 2); x[i] = xi; y[j] = yj; return aij; } }); originalOFValue[0] = 0.5 * originalOFValue[0]; scaledOFValue[0] = 0.5 * scaledOFValue[0]; logger.debug("x: " + ArrayUtils.toString(x)); logger.debug("y: " + ArrayUtils.toString(y)); logger.debug("originalOFValue: " + originalOFValue[0]); logger.debug("scaledOFValue : " + scaledOFValue[0]); return !(originalOFValue[0] < scaledOFValue[0]); }
java
@Override public boolean checkScaling(final DoubleMatrix2D A, final DoubleMatrix1D U, final DoubleMatrix1D V){ final double log10_2 = Math.log10(base); final double[] originalOFValue = {0}; final double[] scaledOFValue = {0}; final double[] x = new double[A.rows()]; final double[] y = new double[A.columns()]; A.forEachNonZero(new IntIntDoubleFunction() { @Override public double apply(int i, int j, double aij) { double v = Math.log10(Math.abs(aij)) / log10_2 + 0.5; originalOFValue[0] = originalOFValue[0] + Math.pow(v, 2); double xi = Math.log10(U.getQuick(i)) / log10_2; double yj = Math.log10(V.getQuick(j)) / log10_2; scaledOFValue[0] = scaledOFValue[0] + Math.pow(xi + yj + v, 2); x[i] = xi; y[j] = yj; return aij; } }); originalOFValue[0] = 0.5 * originalOFValue[0]; scaledOFValue[0] = 0.5 * scaledOFValue[0]; logger.debug("x: " + ArrayUtils.toString(x)); logger.debug("y: " + ArrayUtils.toString(y)); logger.debug("originalOFValue: " + originalOFValue[0]); logger.debug("scaledOFValue : " + scaledOFValue[0]); return !(originalOFValue[0] < scaledOFValue[0]); }
[ "@", "Override", "public", "boolean", "checkScaling", "(", "final", "DoubleMatrix2D", "A", ",", "final", "DoubleMatrix1D", "U", ",", "final", "DoubleMatrix1D", "V", ")", "{", "final", "double", "log10_2", "=", "Math", ".", "log10", "(", "base", ")", ";", "final", "double", "[", "]", "originalOFValue", "=", "{", "0", "}", ";", "final", "double", "[", "]", "scaledOFValue", "=", "{", "0", "}", ";", "final", "double", "[", "]", "x", "=", "new", "double", "[", "A", ".", "rows", "(", ")", "]", ";", "final", "double", "[", "]", "y", "=", "new", "double", "[", "A", ".", "columns", "(", ")", "]", ";", "A", ".", "forEachNonZero", "(", "new", "IntIntDoubleFunction", "(", ")", "{", "@", "Override", "public", "double", "apply", "(", "int", "i", ",", "int", "j", ",", "double", "aij", ")", "{", "double", "v", "=", "Math", ".", "log10", "(", "Math", ".", "abs", "(", "aij", ")", ")", "/", "log10_2", "+", "0.5", ";", "originalOFValue", "[", "0", "]", "=", "originalOFValue", "[", "0", "]", "+", "Math", ".", "pow", "(", "v", ",", "2", ")", ";", "double", "xi", "=", "Math", ".", "log10", "(", "U", ".", "getQuick", "(", "i", ")", ")", "/", "log10_2", ";", "double", "yj", "=", "Math", ".", "log10", "(", "V", ".", "getQuick", "(", "j", ")", ")", "/", "log10_2", ";", "scaledOFValue", "[", "0", "]", "=", "scaledOFValue", "[", "0", "]", "+", "Math", ".", "pow", "(", "xi", "+", "yj", "+", "v", ",", "2", ")", ";", "x", "[", "i", "]", "=", "xi", ";", "y", "[", "j", "]", "=", "yj", ";", "return", "aij", ";", "}", "}", ")", ";", "originalOFValue", "[", "0", "]", "=", "0.5", "*", "originalOFValue", "[", "0", "]", ";", "scaledOFValue", "[", "0", "]", "=", "0.5", "*", "scaledOFValue", "[", "0", "]", ";", "logger", ".", "debug", "(", "\"x: \"", "+", "ArrayUtils", ".", "toString", "(", "x", ")", ")", ";", "logger", ".", "debug", "(", "\"y: \"", "+", "ArrayUtils", ".", "toString", "(", "y", ")", ")", ";", "logger", ".", "debug", "(", "\"originalOFValue: \"", "+", "originalOFValue", "[", "0", "]", ")", ";", "logger", ".", "debug", "(", "\"scaledOFValue : \"", "+", "scaledOFValue", "[", "0", "]", ")", ";", "return", "!", "(", "originalOFValue", "[", "0", "]", "<", "scaledOFValue", "[", "0", "]", ")", ";", "}" ]
Check if the scaling algorithm returned proper results. Note that the scaling algorithm is for minimizing a given objective function of the original matrix elements, and the check will be done on the value of this objective function. @param A the ORIGINAL (before scaling) matrix @param U the return of the scaling algorithm @param V the return of the scaling algorithm @param base @return
[ "Check", "if", "the", "scaling", "algorithm", "returned", "proper", "results", ".", "Note", "that", "the", "scaling", "algorithm", "is", "for", "minimizing", "a", "given", "objective", "function", "of", "the", "original", "matrix", "elements", "and", "the", "check", "will", "be", "done", "on", "the", "value", "of", "this", "objective", "function", "." ]
65064c1bb0b26c7261358021e4c93d06dd43564f
https://github.com/vincentk/joptimizer/blob/65064c1bb0b26c7261358021e4c93d06dd43564f/src/main/java/com/joptimizer/algebra/MatrixLogSumRescaler.java#L242-L274
9,730
vincentk/joptimizer
src/main/java/com/joptimizer/algebra/CholeskyUpperDiagonalFactorization.java
CholeskyUpperDiagonalFactorization.solve
public DoubleMatrix1D solve(DoubleMatrix1D b) { if (b.size() != dim) { log.error("wrong dimension of vector b: expected " + dim + ", actual " + b.size()); throw new RuntimeException("wrong dimension of vector b: expected " + dim + ", actual " + b.size()); } // with scaling, we must solve U.Q.U.z = U.b, after that we have x = U.z if (this.rescaler != null) { // b = ALG.mult(this.U, b); b = ColtUtils.diagonalMatrixMult(this.U, b); } // Solve L.y = b final double[] y = new double[dim]; // L is upper left diagonal for (int i = 0; i < diagonalLength; i++) { double LII = LData[0][i]; y[i] = b.getQuick(i) / LII; } for (int i = diagonalLength; i < dim; i++) { double[] LI = LData[i - diagonalLength + 1]; double LII = LI[i]; double sum = 0; for (int j = 0; j < i; j++) { sum += LI[j] * y[j]; } y[i] = (b.getQuick(i) - sum) / LII; } // logger.debug("b: " + ArrayUtils.toString(b)); // logger.debug("L.y: " + ArrayUtils.toString(getL().operate(y))); // Solve L[T].x = y final DoubleMatrix1D x = F1.make(dim); // for (int i = dim-1; i > -1; i--) { // double sum = 0; // int ll = Math.max(i, diagonalLength-1); // for (int j = dim-1; j > ll; j--) { // sum += LData[j][i] * x.getQuick(j); // // } // x.setQuick(i, (y[i] - sum)/ LData[i][i]); // } for (int i = dim - 1; i > diagonalLength - 1; i--) { double sum = 0; for (int j = dim - 1; j > i; j--) { sum += LData[j - diagonalLength + 1][i] * x.getQuick(j); } x.setQuick(i, (y[i] - sum) / LData[i - diagonalLength + 1][i]); } for (int i = diagonalLength - 1; i > -1; i--) { double sum = 0; for (int j = dim - 1; j > diagonalLength - 1; j--) { sum += LData[j - diagonalLength + 1][i] * x.getQuick(j); } x.setQuick(i, (y[i] - sum) / LData[0][i]); } if (this.rescaler != null) { // return ALG.mult(this.U, x); return ColtUtils.diagonalMatrixMult(this.U, x); } else { return x; } }
java
public DoubleMatrix1D solve(DoubleMatrix1D b) { if (b.size() != dim) { log.error("wrong dimension of vector b: expected " + dim + ", actual " + b.size()); throw new RuntimeException("wrong dimension of vector b: expected " + dim + ", actual " + b.size()); } // with scaling, we must solve U.Q.U.z = U.b, after that we have x = U.z if (this.rescaler != null) { // b = ALG.mult(this.U, b); b = ColtUtils.diagonalMatrixMult(this.U, b); } // Solve L.y = b final double[] y = new double[dim]; // L is upper left diagonal for (int i = 0; i < diagonalLength; i++) { double LII = LData[0][i]; y[i] = b.getQuick(i) / LII; } for (int i = diagonalLength; i < dim; i++) { double[] LI = LData[i - diagonalLength + 1]; double LII = LI[i]; double sum = 0; for (int j = 0; j < i; j++) { sum += LI[j] * y[j]; } y[i] = (b.getQuick(i) - sum) / LII; } // logger.debug("b: " + ArrayUtils.toString(b)); // logger.debug("L.y: " + ArrayUtils.toString(getL().operate(y))); // Solve L[T].x = y final DoubleMatrix1D x = F1.make(dim); // for (int i = dim-1; i > -1; i--) { // double sum = 0; // int ll = Math.max(i, diagonalLength-1); // for (int j = dim-1; j > ll; j--) { // sum += LData[j][i] * x.getQuick(j); // // } // x.setQuick(i, (y[i] - sum)/ LData[i][i]); // } for (int i = dim - 1; i > diagonalLength - 1; i--) { double sum = 0; for (int j = dim - 1; j > i; j--) { sum += LData[j - diagonalLength + 1][i] * x.getQuick(j); } x.setQuick(i, (y[i] - sum) / LData[i - diagonalLength + 1][i]); } for (int i = diagonalLength - 1; i > -1; i--) { double sum = 0; for (int j = dim - 1; j > diagonalLength - 1; j--) { sum += LData[j - diagonalLength + 1][i] * x.getQuick(j); } x.setQuick(i, (y[i] - sum) / LData[0][i]); } if (this.rescaler != null) { // return ALG.mult(this.U, x); return ColtUtils.diagonalMatrixMult(this.U, x); } else { return x; } }
[ "public", "DoubleMatrix1D", "solve", "(", "DoubleMatrix1D", "b", ")", "{", "if", "(", "b", ".", "size", "(", ")", "!=", "dim", ")", "{", "log", ".", "error", "(", "\"wrong dimension of vector b: expected \"", "+", "dim", "+", "\", actual \"", "+", "b", ".", "size", "(", ")", ")", ";", "throw", "new", "RuntimeException", "(", "\"wrong dimension of vector b: expected \"", "+", "dim", "+", "\", actual \"", "+", "b", ".", "size", "(", ")", ")", ";", "}", "// with scaling, we must solve U.Q.U.z = U.b, after that we have x = U.z\r", "if", "(", "this", ".", "rescaler", "!=", "null", ")", "{", "// b = ALG.mult(this.U, b);\r", "b", "=", "ColtUtils", ".", "diagonalMatrixMult", "(", "this", ".", "U", ",", "b", ")", ";", "}", "// Solve L.y = b\r", "final", "double", "[", "]", "y", "=", "new", "double", "[", "dim", "]", ";", "// L is upper left diagonal\r", "for", "(", "int", "i", "=", "0", ";", "i", "<", "diagonalLength", ";", "i", "++", ")", "{", "double", "LII", "=", "LData", "[", "0", "]", "[", "i", "]", ";", "y", "[", "i", "]", "=", "b", ".", "getQuick", "(", "i", ")", "/", "LII", ";", "}", "for", "(", "int", "i", "=", "diagonalLength", ";", "i", "<", "dim", ";", "i", "++", ")", "{", "double", "[", "]", "LI", "=", "LData", "[", "i", "-", "diagonalLength", "+", "1", "]", ";", "double", "LII", "=", "LI", "[", "i", "]", ";", "double", "sum", "=", "0", ";", "for", "(", "int", "j", "=", "0", ";", "j", "<", "i", ";", "j", "++", ")", "{", "sum", "+=", "LI", "[", "j", "]", "*", "y", "[", "j", "]", ";", "}", "y", "[", "i", "]", "=", "(", "b", ".", "getQuick", "(", "i", ")", "-", "sum", ")", "/", "LII", ";", "}", "// logger.debug(\"b: \" + ArrayUtils.toString(b));\r", "// logger.debug(\"L.y: \" + ArrayUtils.toString(getL().operate(y)));\r", "// Solve L[T].x = y\r", "final", "DoubleMatrix1D", "x", "=", "F1", ".", "make", "(", "dim", ")", ";", "// for (int i = dim-1; i > -1; i--) {\r", "// double sum = 0;\r", "// int ll = Math.max(i, diagonalLength-1);\r", "// for (int j = dim-1; j > ll; j--) {\r", "// sum += LData[j][i] * x.getQuick(j);\r", "//\r", "// }\r", "// x.setQuick(i, (y[i] - sum)/ LData[i][i]);\r", "// }\r", "for", "(", "int", "i", "=", "dim", "-", "1", ";", "i", ">", "diagonalLength", "-", "1", ";", "i", "--", ")", "{", "double", "sum", "=", "0", ";", "for", "(", "int", "j", "=", "dim", "-", "1", ";", "j", ">", "i", ";", "j", "--", ")", "{", "sum", "+=", "LData", "[", "j", "-", "diagonalLength", "+", "1", "]", "[", "i", "]", "*", "x", ".", "getQuick", "(", "j", ")", ";", "}", "x", ".", "setQuick", "(", "i", ",", "(", "y", "[", "i", "]", "-", "sum", ")", "/", "LData", "[", "i", "-", "diagonalLength", "+", "1", "]", "[", "i", "]", ")", ";", "}", "for", "(", "int", "i", "=", "diagonalLength", "-", "1", ";", "i", ">", "-", "1", ";", "i", "--", ")", "{", "double", "sum", "=", "0", ";", "for", "(", "int", "j", "=", "dim", "-", "1", ";", "j", ">", "diagonalLength", "-", "1", ";", "j", "--", ")", "{", "sum", "+=", "LData", "[", "j", "-", "diagonalLength", "+", "1", "]", "[", "i", "]", "*", "x", ".", "getQuick", "(", "j", ")", ";", "}", "x", ".", "setQuick", "(", "i", ",", "(", "y", "[", "i", "]", "-", "sum", ")", "/", "LData", "[", "0", "]", "[", "i", "]", ")", ";", "}", "if", "(", "this", ".", "rescaler", "!=", "null", ")", "{", "// return ALG.mult(this.U, x);\r", "return", "ColtUtils", ".", "diagonalMatrixMult", "(", "this", ".", "U", ",", "x", ")", ";", "}", "else", "{", "return", "x", ";", "}", "}" ]
Solve Q.x = b @param b vector @return the solution vector x
[ "Solve", "Q", ".", "x", "=", "b" ]
65064c1bb0b26c7261358021e4c93d06dd43564f
https://github.com/vincentk/joptimizer/blob/65064c1bb0b26c7261358021e4c93d06dd43564f/src/main/java/com/joptimizer/algebra/CholeskyUpperDiagonalFactorization.java#L207-L273
9,731
vincentk/joptimizer
src/main/java/com/joptimizer/optimizers/NewtonUnconstrained.java
NewtonUnconstrained.calculateNewtonStep
private DoubleMatrix1D calculateNewtonStep(DoubleMatrix2D hessX, DoubleMatrix1D gradX) throws Exception { final KKTSolver kktSolver = new BasicKKTSolver(); if(isCheckKKTSolutionAccuracy()){ kktSolver.setCheckKKTSolutionAccuracy(isCheckKKTSolutionAccuracy()); kktSolver.setToleranceKKT(getToleranceKKT()); } kktSolver.setHMatrix(hessX); kktSolver.setGVector(gradX); DoubleMatrix1D[] sol = kktSolver.solve(); DoubleMatrix1D step = sol[0]; return step; }
java
private DoubleMatrix1D calculateNewtonStep(DoubleMatrix2D hessX, DoubleMatrix1D gradX) throws Exception { final KKTSolver kktSolver = new BasicKKTSolver(); if(isCheckKKTSolutionAccuracy()){ kktSolver.setCheckKKTSolutionAccuracy(isCheckKKTSolutionAccuracy()); kktSolver.setToleranceKKT(getToleranceKKT()); } kktSolver.setHMatrix(hessX); kktSolver.setGVector(gradX); DoubleMatrix1D[] sol = kktSolver.solve(); DoubleMatrix1D step = sol[0]; return step; }
[ "private", "DoubleMatrix1D", "calculateNewtonStep", "(", "DoubleMatrix2D", "hessX", ",", "DoubleMatrix1D", "gradX", ")", "throws", "Exception", "{", "final", "KKTSolver", "kktSolver", "=", "new", "BasicKKTSolver", "(", ")", ";", "if", "(", "isCheckKKTSolutionAccuracy", "(", ")", ")", "{", "kktSolver", ".", "setCheckKKTSolutionAccuracy", "(", "isCheckKKTSolutionAccuracy", "(", ")", ")", ";", "kktSolver", ".", "setToleranceKKT", "(", "getToleranceKKT", "(", ")", ")", ";", "}", "kktSolver", ".", "setHMatrix", "(", "hessX", ")", ";", "kktSolver", ".", "setGVector", "(", "gradX", ")", ";", "DoubleMatrix1D", "[", "]", "sol", "=", "kktSolver", ".", "solve", "(", ")", ";", "DoubleMatrix1D", "step", "=", "sol", "[", "0", "]", ";", "return", "step", ";", "}" ]
Hess.step = -Grad
[ "Hess", ".", "step", "=", "-", "Grad" ]
65064c1bb0b26c7261358021e4c93d06dd43564f
https://github.com/vincentk/joptimizer/blob/65064c1bb0b26c7261358021e4c93d06dd43564f/src/main/java/com/joptimizer/optimizers/NewtonUnconstrained.java#L160-L171
9,732
visenze/visearch-sdk-java
src/main/java/com/visenze/visearch/internal/SearchOperationsImpl.java
SearchOperationsImpl.postImageSearch
private PagedSearchResult postImageSearch(UploadSearchParams uploadSearchParams, String endpointMethod) { ViSearchHttpResponse response = getPostImageSearchHttpResponse(uploadSearchParams, endpointMethod); return getPagedResult(response); }
java
private PagedSearchResult postImageSearch(UploadSearchParams uploadSearchParams, String endpointMethod) { ViSearchHttpResponse response = getPostImageSearchHttpResponse(uploadSearchParams, endpointMethod); return getPagedResult(response); }
[ "private", "PagedSearchResult", "postImageSearch", "(", "UploadSearchParams", "uploadSearchParams", ",", "String", "endpointMethod", ")", "{", "ViSearchHttpResponse", "response", "=", "getPostImageSearchHttpResponse", "(", "uploadSearchParams", ",", "endpointMethod", ")", ";", "return", "getPagedResult", "(", "response", ")", ";", "}" ]
Perform upload search by image @param uploadSearchParams @return
[ "Perform", "upload", "search", "by", "image" ]
133611b84a7489f08bf40b55912ccd2acc7f002c
https://github.com/visenze/visearch-sdk-java/blob/133611b84a7489f08bf40b55912ccd2acc7f002c/src/main/java/com/visenze/visearch/internal/SearchOperationsImpl.java#L124-L127
9,733
vincentk/joptimizer
src/main/java/com/joptimizer/util/Utils.java
Utils.getMaxIndex
public static int getMaxIndex(DoubleMatrix1D v){ int maxIndex = -1; double maxValue = -Double.MAX_VALUE; for(int i=0; i<v.size(); i++){ if(v.getQuick(i)>maxValue){ maxIndex = i; maxValue = v.getQuick(i); } } return maxIndex; }
java
public static int getMaxIndex(DoubleMatrix1D v){ int maxIndex = -1; double maxValue = -Double.MAX_VALUE; for(int i=0; i<v.size(); i++){ if(v.getQuick(i)>maxValue){ maxIndex = i; maxValue = v.getQuick(i); } } return maxIndex; }
[ "public", "static", "int", "getMaxIndex", "(", "DoubleMatrix1D", "v", ")", "{", "int", "maxIndex", "=", "-", "1", ";", "double", "maxValue", "=", "-", "Double", ".", "MAX_VALUE", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "v", ".", "size", "(", ")", ";", "i", "++", ")", "{", "if", "(", "v", ".", "getQuick", "(", "i", ")", ">", "maxValue", ")", "{", "maxIndex", "=", "i", ";", "maxValue", "=", "v", ".", "getQuick", "(", "i", ")", ";", "}", "}", "return", "maxIndex", ";", "}" ]
Get the index of the maximum entry.
[ "Get", "the", "index", "of", "the", "maximum", "entry", "." ]
65064c1bb0b26c7261358021e4c93d06dd43564f
https://github.com/vincentk/joptimizer/blob/65064c1bb0b26c7261358021e4c93d06dd43564f/src/main/java/com/joptimizer/util/Utils.java#L234-L244
9,734
vincentk/joptimizer
src/main/java/com/joptimizer/util/Utils.java
Utils.getMinIndex
public static int getMinIndex(DoubleMatrix1D v){ int minIndex = -1; double minValue = Double.MAX_VALUE; for(int i=0; i<v.size(); i++){ if(v.getQuick(i)<minValue){ minIndex = i; minValue = v.getQuick(i); } } return minIndex; }
java
public static int getMinIndex(DoubleMatrix1D v){ int minIndex = -1; double minValue = Double.MAX_VALUE; for(int i=0; i<v.size(); i++){ if(v.getQuick(i)<minValue){ minIndex = i; minValue = v.getQuick(i); } } return minIndex; }
[ "public", "static", "int", "getMinIndex", "(", "DoubleMatrix1D", "v", ")", "{", "int", "minIndex", "=", "-", "1", ";", "double", "minValue", "=", "Double", ".", "MAX_VALUE", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "v", ".", "size", "(", ")", ";", "i", "++", ")", "{", "if", "(", "v", ".", "getQuick", "(", "i", ")", "<", "minValue", ")", "{", "minIndex", "=", "i", ";", "minValue", "=", "v", ".", "getQuick", "(", "i", ")", ";", "}", "}", "return", "minIndex", ";", "}" ]
Get the index of the minimum entry.
[ "Get", "the", "index", "of", "the", "minimum", "entry", "." ]
65064c1bb0b26c7261358021e4c93d06dd43564f
https://github.com/vincentk/joptimizer/blob/65064c1bb0b26c7261358021e4c93d06dd43564f/src/main/java/com/joptimizer/util/Utils.java#L251-L261
9,735
vincentk/joptimizer
src/main/java/com/joptimizer/util/Utils.java
Utils.calculateDeterminant
public static final double calculateDeterminant(double[][] ai, int dim) { double det = 0; if (dim == 1) { det = ai[0][0]; } else if (dim == 2) { det = ai[0][0] * ai[1][1] - ai[0][1] * ai[1][0]; } else { double ai1[][] = new double[dim - 1][dim - 1]; for (int k = 0; k < dim; k++) { for (int i1 = 1; i1 < dim; i1++) { int j = 0; for (int j1 = 0; j1 < dim; j1++) { if (j1 != k) { ai1[i1 - 1][j] = ai[i1][j1]; j++; } } } if (k % 2 == 0) { det += ai[0][k] * calculateDeterminant(ai1, dim - 1); } else { det -= ai[0][k] * calculateDeterminant(ai1, dim - 1); } } } return det; }
java
public static final double calculateDeterminant(double[][] ai, int dim) { double det = 0; if (dim == 1) { det = ai[0][0]; } else if (dim == 2) { det = ai[0][0] * ai[1][1] - ai[0][1] * ai[1][0]; } else { double ai1[][] = new double[dim - 1][dim - 1]; for (int k = 0; k < dim; k++) { for (int i1 = 1; i1 < dim; i1++) { int j = 0; for (int j1 = 0; j1 < dim; j1++) { if (j1 != k) { ai1[i1 - 1][j] = ai[i1][j1]; j++; } } } if (k % 2 == 0) { det += ai[0][k] * calculateDeterminant(ai1, dim - 1); } else { det -= ai[0][k] * calculateDeterminant(ai1, dim - 1); } } } return det; }
[ "public", "static", "final", "double", "calculateDeterminant", "(", "double", "[", "]", "[", "]", "ai", ",", "int", "dim", ")", "{", "double", "det", "=", "0", ";", "if", "(", "dim", "==", "1", ")", "{", "det", "=", "ai", "[", "0", "]", "[", "0", "]", ";", "}", "else", "if", "(", "dim", "==", "2", ")", "{", "det", "=", "ai", "[", "0", "]", "[", "0", "]", "*", "ai", "[", "1", "]", "[", "1", "]", "-", "ai", "[", "0", "]", "[", "1", "]", "*", "ai", "[", "1", "]", "[", "0", "]", ";", "}", "else", "{", "double", "ai1", "[", "]", "[", "]", "=", "new", "double", "[", "dim", "-", "1", "]", "[", "dim", "-", "1", "]", ";", "for", "(", "int", "k", "=", "0", ";", "k", "<", "dim", ";", "k", "++", ")", "{", "for", "(", "int", "i1", "=", "1", ";", "i1", "<", "dim", ";", "i1", "++", ")", "{", "int", "j", "=", "0", ";", "for", "(", "int", "j1", "=", "0", ";", "j1", "<", "dim", ";", "j1", "++", ")", "{", "if", "(", "j1", "!=", "k", ")", "{", "ai1", "[", "i1", "-", "1", "]", "[", "j", "]", "=", "ai", "[", "i1", "]", "[", "j1", "]", ";", "j", "++", ";", "}", "}", "}", "if", "(", "k", "%", "2", "==", "0", ")", "{", "det", "+=", "ai", "[", "0", "]", "[", "k", "]", "*", "calculateDeterminant", "(", "ai1", ",", "dim", "-", "1", ")", ";", "}", "else", "{", "det", "-=", "ai", "[", "0", "]", "[", "k", "]", "*", "calculateDeterminant", "(", "ai1", ",", "dim", "-", "1", ")", ";", "}", "}", "}", "return", "det", ";", "}" ]
Brute-force determinant calculation.
[ "Brute", "-", "force", "determinant", "calculation", "." ]
65064c1bb0b26c7261358021e4c93d06dd43564f
https://github.com/vincentk/joptimizer/blob/65064c1bb0b26c7261358021e4c93d06dd43564f/src/main/java/com/joptimizer/util/Utils.java#L312-L338
9,736
vincentk/joptimizer
src/main/java/com/joptimizer/optimizers/BasicPhaseIPDM.java
BasicPhaseIPDM.findOneRoot
private DoubleMatrix1D findOneRoot(DoubleMatrix2D A, DoubleMatrix1D b) throws Exception{ return originalProblem.findEqFeasiblePoint(A, b); }
java
private DoubleMatrix1D findOneRoot(DoubleMatrix2D A, DoubleMatrix1D b) throws Exception{ return originalProblem.findEqFeasiblePoint(A, b); }
[ "private", "DoubleMatrix1D", "findOneRoot", "(", "DoubleMatrix2D", "A", ",", "DoubleMatrix1D", "b", ")", "throws", "Exception", "{", "return", "originalProblem", ".", "findEqFeasiblePoint", "(", "A", ",", "b", ")", ";", "}" ]
Just looking for one out of all the possible solutions. @see "Convex Optimization, C.5 p. 681".
[ "Just", "looking", "for", "one", "out", "of", "all", "the", "possible", "solutions", "." ]
65064c1bb0b26c7261358021e4c93d06dd43564f
https://github.com/vincentk/joptimizer/blob/65064c1bb0b26c7261358021e4c93d06dd43564f/src/main/java/com/joptimizer/optimizers/BasicPhaseIPDM.java#L226-L228
9,737
vincentk/joptimizer
src/main/java/com/joptimizer/util/ColtUtils.java
ColtUtils.diagonalMatrixMult
public static final DoubleMatrix1D diagonalMatrixMult(DoubleMatrix1D diagonalM, DoubleMatrix1D vector){ int n = diagonalM.size(); DoubleMatrix1D ret = DoubleFactory1D.dense.make(n); for(int i=0; i<n; i++){ ret.setQuick(i, diagonalM.getQuick(i) * vector.getQuick(i)); } return ret; }
java
public static final DoubleMatrix1D diagonalMatrixMult(DoubleMatrix1D diagonalM, DoubleMatrix1D vector){ int n = diagonalM.size(); DoubleMatrix1D ret = DoubleFactory1D.dense.make(n); for(int i=0; i<n; i++){ ret.setQuick(i, diagonalM.getQuick(i) * vector.getQuick(i)); } return ret; }
[ "public", "static", "final", "DoubleMatrix1D", "diagonalMatrixMult", "(", "DoubleMatrix1D", "diagonalM", ",", "DoubleMatrix1D", "vector", ")", "{", "int", "n", "=", "diagonalM", ".", "size", "(", ")", ";", "DoubleMatrix1D", "ret", "=", "DoubleFactory1D", ".", "dense", ".", "make", "(", "n", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "n", ";", "i", "++", ")", "{", "ret", ".", "setQuick", "(", "i", ",", "diagonalM", ".", "getQuick", "(", "i", ")", "*", "vector", ".", "getQuick", "(", "i", ")", ")", ";", "}", "return", "ret", ";", "}" ]
Matrix-vector multiplication with diagonal matrix. @param diagonalM diagonal matrix M, in the form of a vector of its diagonal elements @param vector @return M.x
[ "Matrix", "-", "vector", "multiplication", "with", "diagonal", "matrix", "." ]
65064c1bb0b26c7261358021e4c93d06dd43564f
https://github.com/vincentk/joptimizer/blob/65064c1bb0b26c7261358021e4c93d06dd43564f/src/main/java/com/joptimizer/util/ColtUtils.java#L47-L54
9,738
vincentk/joptimizer
src/main/java/com/joptimizer/util/ColtUtils.java
ColtUtils.diagonalMatrixMult
public static final DoubleMatrix2D diagonalMatrixMult(final DoubleMatrix1D diagonalU, DoubleMatrix2D A, final DoubleMatrix1D diagonalV){ int r = A.rows(); int c = A.columns(); final DoubleMatrix2D ret; if (A instanceof SparseDoubleMatrix2D) { ret = DoubleFactory2D.sparse.make(r, c); A.forEachNonZero(new IntIntDoubleFunction() { @Override public double apply(int i, int j, double aij) { ret.setQuick(i, j, aij * diagonalU.getQuick(i) * diagonalV.getQuick(j)); return aij; } }); } else { ret = DoubleFactory2D.dense.make(r, c); for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { ret.setQuick(i, j, A.getQuick(i, j) * diagonalU.getQuick(i) * diagonalV.getQuick(j)); } } } return ret; }
java
public static final DoubleMatrix2D diagonalMatrixMult(final DoubleMatrix1D diagonalU, DoubleMatrix2D A, final DoubleMatrix1D diagonalV){ int r = A.rows(); int c = A.columns(); final DoubleMatrix2D ret; if (A instanceof SparseDoubleMatrix2D) { ret = DoubleFactory2D.sparse.make(r, c); A.forEachNonZero(new IntIntDoubleFunction() { @Override public double apply(int i, int j, double aij) { ret.setQuick(i, j, aij * diagonalU.getQuick(i) * diagonalV.getQuick(j)); return aij; } }); } else { ret = DoubleFactory2D.dense.make(r, c); for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { ret.setQuick(i, j, A.getQuick(i, j) * diagonalU.getQuick(i) * diagonalV.getQuick(j)); } } } return ret; }
[ "public", "static", "final", "DoubleMatrix2D", "diagonalMatrixMult", "(", "final", "DoubleMatrix1D", "diagonalU", ",", "DoubleMatrix2D", "A", ",", "final", "DoubleMatrix1D", "diagonalV", ")", "{", "int", "r", "=", "A", ".", "rows", "(", ")", ";", "int", "c", "=", "A", ".", "columns", "(", ")", ";", "final", "DoubleMatrix2D", "ret", ";", "if", "(", "A", "instanceof", "SparseDoubleMatrix2D", ")", "{", "ret", "=", "DoubleFactory2D", ".", "sparse", ".", "make", "(", "r", ",", "c", ")", ";", "A", ".", "forEachNonZero", "(", "new", "IntIntDoubleFunction", "(", ")", "{", "@", "Override", "public", "double", "apply", "(", "int", "i", ",", "int", "j", ",", "double", "aij", ")", "{", "ret", ".", "setQuick", "(", "i", ",", "j", ",", "aij", "*", "diagonalU", ".", "getQuick", "(", "i", ")", "*", "diagonalV", ".", "getQuick", "(", "j", ")", ")", ";", "return", "aij", ";", "}", "}", ")", ";", "}", "else", "{", "ret", "=", "DoubleFactory2D", ".", "dense", ".", "make", "(", "r", ",", "c", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "r", ";", "i", "++", ")", "{", "for", "(", "int", "j", "=", "0", ";", "j", "<", "c", ";", "j", "++", ")", "{", "ret", ".", "setQuick", "(", "i", ",", "j", ",", "A", ".", "getQuick", "(", "i", ",", "j", ")", "*", "diagonalU", ".", "getQuick", "(", "i", ")", "*", "diagonalV", ".", "getQuick", "(", "j", ")", ")", ";", "}", "}", "}", "return", "ret", ";", "}" ]
Return diagonalU.A.diagonalV with diagonalU and diagonalV diagonal. @param diagonalU diagonal matrix U, in the form of a vector of its diagonal elements @param diagonalV diagonal matrix V, in the form of a vector of its diagonal elements @return U.A.V
[ "Return", "diagonalU", ".", "A", ".", "diagonalV", "with", "diagonalU", "and", "diagonalV", "diagonal", "." ]
65064c1bb0b26c7261358021e4c93d06dd43564f
https://github.com/vincentk/joptimizer/blob/65064c1bb0b26c7261358021e4c93d06dd43564f/src/main/java/com/joptimizer/util/ColtUtils.java#L122-L145
9,739
vincentk/joptimizer
src/main/java/com/joptimizer/util/ColtUtils.java
ColtUtils.fillSubdiagonalSymmetricMatrix
public static final DoubleMatrix2D fillSubdiagonalSymmetricMatrix(DoubleMatrix2D S){ if(S.rows() != S.columns()){ throw new IllegalArgumentException("Not square matrix"); } boolean isSparse = S instanceof SparseDoubleMatrix2D; DoubleFactory2D F2D = (isSparse)? DoubleFactory2D.sparse: DoubleFactory2D.dense; final DoubleMatrix2D SFull = F2D.make(S.rows(), S.rows()); if (isSparse) { S.forEachNonZero(new IntIntDoubleFunction() { @Override public double apply(int i, int j, double hij) { SFull.setQuick(i, j, hij); SFull.setQuick(j, i, hij); return hij; } }); } else { for (int i = 0; i < S.rows(); i++) { for (int j = 0; j < i + 1; j++) { double sij = S.getQuick(i, j); SFull.setQuick(i, j, sij); SFull.setQuick(j, i, sij); } } } return SFull; }
java
public static final DoubleMatrix2D fillSubdiagonalSymmetricMatrix(DoubleMatrix2D S){ if(S.rows() != S.columns()){ throw new IllegalArgumentException("Not square matrix"); } boolean isSparse = S instanceof SparseDoubleMatrix2D; DoubleFactory2D F2D = (isSparse)? DoubleFactory2D.sparse: DoubleFactory2D.dense; final DoubleMatrix2D SFull = F2D.make(S.rows(), S.rows()); if (isSparse) { S.forEachNonZero(new IntIntDoubleFunction() { @Override public double apply(int i, int j, double hij) { SFull.setQuick(i, j, hij); SFull.setQuick(j, i, hij); return hij; } }); } else { for (int i = 0; i < S.rows(); i++) { for (int j = 0; j < i + 1; j++) { double sij = S.getQuick(i, j); SFull.setQuick(i, j, sij); SFull.setQuick(j, i, sij); } } } return SFull; }
[ "public", "static", "final", "DoubleMatrix2D", "fillSubdiagonalSymmetricMatrix", "(", "DoubleMatrix2D", "S", ")", "{", "if", "(", "S", ".", "rows", "(", ")", "!=", "S", ".", "columns", "(", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Not square matrix\"", ")", ";", "}", "boolean", "isSparse", "=", "S", "instanceof", "SparseDoubleMatrix2D", ";", "DoubleFactory2D", "F2D", "=", "(", "isSparse", ")", "?", "DoubleFactory2D", ".", "sparse", ":", "DoubleFactory2D", ".", "dense", ";", "final", "DoubleMatrix2D", "SFull", "=", "F2D", ".", "make", "(", "S", ".", "rows", "(", ")", ",", "S", ".", "rows", "(", ")", ")", ";", "if", "(", "isSparse", ")", "{", "S", ".", "forEachNonZero", "(", "new", "IntIntDoubleFunction", "(", ")", "{", "@", "Override", "public", "double", "apply", "(", "int", "i", ",", "int", "j", ",", "double", "hij", ")", "{", "SFull", ".", "setQuick", "(", "i", ",", "j", ",", "hij", ")", ";", "SFull", ".", "setQuick", "(", "j", ",", "i", ",", "hij", ")", ";", "return", "hij", ";", "}", "}", ")", ";", "}", "else", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "S", ".", "rows", "(", ")", ";", "i", "++", ")", "{", "for", "(", "int", "j", "=", "0", ";", "j", "<", "i", "+", "1", ";", "j", "++", ")", "{", "double", "sij", "=", "S", ".", "getQuick", "(", "i", ",", "j", ")", ";", "SFull", ".", "setQuick", "(", "i", ",", "j", ",", "sij", ")", ";", "SFull", ".", "setQuick", "(", "j", ",", "i", ",", "sij", ")", ";", "}", "}", "}", "return", "SFull", ";", "}" ]
Given a symm matrix S that stores just its subdiagonal elements, reconstructs the full symmetric matrix. @FIXME: evitare il doppio setQuick
[ "Given", "a", "symm", "matrix", "S", "that", "stores", "just", "its", "subdiagonal", "elements", "reconstructs", "the", "full", "symmetric", "matrix", "." ]
65064c1bb0b26c7261358021e4c93d06dd43564f
https://github.com/vincentk/joptimizer/blob/65064c1bb0b26c7261358021e4c93d06dd43564f/src/main/java/com/joptimizer/util/ColtUtils.java#L584-L614
9,740
vincentk/joptimizer
src/main/java/com/joptimizer/algebra/QRSparseFactorization.java
QRSparseFactorization.factorize
public void factorize() throws Exception { m = A.rows(); n = A.columns(); if(this.rescaler != null){ double[] cn_00_original = null; double[] cn_2_original = null; double[] cn_00_scaled = null; double[] cn_2_scaled = null; if(log.isDebugEnabled()){ cn_00_original = ColtUtils.getConditionNumberRange(new Array2DRowRealMatrix(A.toArray()), Integer.MAX_VALUE); log.debug("cn_00_original Q before scaling: " + ArrayUtils.toString(cn_00_original)); cn_2_original = ColtUtils.getConditionNumberRange(new Array2DRowRealMatrix(A.toArray()), 2); log.debug("cn_2_original Q before scaling : " + ArrayUtils.toString(cn_2_original)); } //scaling the A matrix, we have: //A1 = U.A.V[T] DoubleMatrix1D[] UV = rescaler.getMatrixScalingFactors(A); this.U = UV[0]; this.V = UV[1]; if(log.isDebugEnabled()){ boolean checkOK = rescaler.checkScaling(A, U, V); if(!checkOK){ log.warn("Scaling failed (checkScaling = false)"); } } this.A = (SparseDoubleMatrix2D) ColtUtils.diagonalMatrixMult(U, A, V); if(log.isDebugEnabled()){ cn_00_scaled = ColtUtils.getConditionNumberRange(new Array2DRowRealMatrix(A.toArray()), Integer.MAX_VALUE); log.debug("cn_00_scaled Q after scaling : " + ArrayUtils.toString(cn_00_scaled)); cn_2_scaled = ColtUtils.getConditionNumberRange(new Array2DRowRealMatrix(A.toArray()), 2); log.debug("cn_2_scaled Q after scaling : " + ArrayUtils.toString(cn_2_scaled)); if(cn_00_original[0] < cn_00_scaled[0] || cn_2_original[0] < cn_2_scaled[0]){ log.warn("Problematic scaling"); //throw new RuntimeException("Scaling failed"); } } } Dcs dcs; if (m >= n) { dcs = ColtUtils.matrixToDcs(A); } else { dcs = ColtUtils.matrixToDcs((SparseDoubleMatrix2D) ALG.transpose(A)); } S = Dcs_sqr.cs_sqr(order, dcs, true); if (S == null) { throw new IllegalArgumentException("Exception occured in cs_sqr()"); } N = Dcs_qr.cs_qr(dcs, S); if (N == null) { throw new IllegalArgumentException("Exception occured in cs_qr()"); } }
java
public void factorize() throws Exception { m = A.rows(); n = A.columns(); if(this.rescaler != null){ double[] cn_00_original = null; double[] cn_2_original = null; double[] cn_00_scaled = null; double[] cn_2_scaled = null; if(log.isDebugEnabled()){ cn_00_original = ColtUtils.getConditionNumberRange(new Array2DRowRealMatrix(A.toArray()), Integer.MAX_VALUE); log.debug("cn_00_original Q before scaling: " + ArrayUtils.toString(cn_00_original)); cn_2_original = ColtUtils.getConditionNumberRange(new Array2DRowRealMatrix(A.toArray()), 2); log.debug("cn_2_original Q before scaling : " + ArrayUtils.toString(cn_2_original)); } //scaling the A matrix, we have: //A1 = U.A.V[T] DoubleMatrix1D[] UV = rescaler.getMatrixScalingFactors(A); this.U = UV[0]; this.V = UV[1]; if(log.isDebugEnabled()){ boolean checkOK = rescaler.checkScaling(A, U, V); if(!checkOK){ log.warn("Scaling failed (checkScaling = false)"); } } this.A = (SparseDoubleMatrix2D) ColtUtils.diagonalMatrixMult(U, A, V); if(log.isDebugEnabled()){ cn_00_scaled = ColtUtils.getConditionNumberRange(new Array2DRowRealMatrix(A.toArray()), Integer.MAX_VALUE); log.debug("cn_00_scaled Q after scaling : " + ArrayUtils.toString(cn_00_scaled)); cn_2_scaled = ColtUtils.getConditionNumberRange(new Array2DRowRealMatrix(A.toArray()), 2); log.debug("cn_2_scaled Q after scaling : " + ArrayUtils.toString(cn_2_scaled)); if(cn_00_original[0] < cn_00_scaled[0] || cn_2_original[0] < cn_2_scaled[0]){ log.warn("Problematic scaling"); //throw new RuntimeException("Scaling failed"); } } } Dcs dcs; if (m >= n) { dcs = ColtUtils.matrixToDcs(A); } else { dcs = ColtUtils.matrixToDcs((SparseDoubleMatrix2D) ALG.transpose(A)); } S = Dcs_sqr.cs_sqr(order, dcs, true); if (S == null) { throw new IllegalArgumentException("Exception occured in cs_sqr()"); } N = Dcs_qr.cs_qr(dcs, S); if (N == null) { throw new IllegalArgumentException("Exception occured in cs_qr()"); } }
[ "public", "void", "factorize", "(", ")", "throws", "Exception", "{", "m", "=", "A", ".", "rows", "(", ")", ";", "n", "=", "A", ".", "columns", "(", ")", ";", "if", "(", "this", ".", "rescaler", "!=", "null", ")", "{", "double", "[", "]", "cn_00_original", "=", "null", ";", "double", "[", "]", "cn_2_original", "=", "null", ";", "double", "[", "]", "cn_00_scaled", "=", "null", ";", "double", "[", "]", "cn_2_scaled", "=", "null", ";", "if", "(", "log", ".", "isDebugEnabled", "(", ")", ")", "{", "cn_00_original", "=", "ColtUtils", ".", "getConditionNumberRange", "(", "new", "Array2DRowRealMatrix", "(", "A", ".", "toArray", "(", ")", ")", ",", "Integer", ".", "MAX_VALUE", ")", ";", "log", ".", "debug", "(", "\"cn_00_original Q before scaling: \"", "+", "ArrayUtils", ".", "toString", "(", "cn_00_original", ")", ")", ";", "cn_2_original", "=", "ColtUtils", ".", "getConditionNumberRange", "(", "new", "Array2DRowRealMatrix", "(", "A", ".", "toArray", "(", ")", ")", ",", "2", ")", ";", "log", ".", "debug", "(", "\"cn_2_original Q before scaling : \"", "+", "ArrayUtils", ".", "toString", "(", "cn_2_original", ")", ")", ";", "}", "//scaling the A matrix, we have:\r", "//A1 = U.A.V[T] \r", "DoubleMatrix1D", "[", "]", "UV", "=", "rescaler", ".", "getMatrixScalingFactors", "(", "A", ")", ";", "this", ".", "U", "=", "UV", "[", "0", "]", ";", "this", ".", "V", "=", "UV", "[", "1", "]", ";", "if", "(", "log", ".", "isDebugEnabled", "(", ")", ")", "{", "boolean", "checkOK", "=", "rescaler", ".", "checkScaling", "(", "A", ",", "U", ",", "V", ")", ";", "if", "(", "!", "checkOK", ")", "{", "log", ".", "warn", "(", "\"Scaling failed (checkScaling = false)\"", ")", ";", "}", "}", "this", ".", "A", "=", "(", "SparseDoubleMatrix2D", ")", "ColtUtils", ".", "diagonalMatrixMult", "(", "U", ",", "A", ",", "V", ")", ";", "if", "(", "log", ".", "isDebugEnabled", "(", ")", ")", "{", "cn_00_scaled", "=", "ColtUtils", ".", "getConditionNumberRange", "(", "new", "Array2DRowRealMatrix", "(", "A", ".", "toArray", "(", ")", ")", ",", "Integer", ".", "MAX_VALUE", ")", ";", "log", ".", "debug", "(", "\"cn_00_scaled Q after scaling : \"", "+", "ArrayUtils", ".", "toString", "(", "cn_00_scaled", ")", ")", ";", "cn_2_scaled", "=", "ColtUtils", ".", "getConditionNumberRange", "(", "new", "Array2DRowRealMatrix", "(", "A", ".", "toArray", "(", ")", ")", ",", "2", ")", ";", "log", ".", "debug", "(", "\"cn_2_scaled Q after scaling : \"", "+", "ArrayUtils", ".", "toString", "(", "cn_2_scaled", ")", ")", ";", "if", "(", "cn_00_original", "[", "0", "]", "<", "cn_00_scaled", "[", "0", "]", "||", "cn_2_original", "[", "0", "]", "<", "cn_2_scaled", "[", "0", "]", ")", "{", "log", ".", "warn", "(", "\"Problematic scaling\"", ")", ";", "//throw new RuntimeException(\"Scaling failed\");\r", "}", "}", "}", "Dcs", "dcs", ";", "if", "(", "m", ">=", "n", ")", "{", "dcs", "=", "ColtUtils", ".", "matrixToDcs", "(", "A", ")", ";", "}", "else", "{", "dcs", "=", "ColtUtils", ".", "matrixToDcs", "(", "(", "SparseDoubleMatrix2D", ")", "ALG", ".", "transpose", "(", "A", ")", ")", ";", "}", "S", "=", "Dcs_sqr", ".", "cs_sqr", "(", "order", ",", "dcs", ",", "true", ")", ";", "if", "(", "S", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Exception occured in cs_sqr()\"", ")", ";", "}", "N", "=", "Dcs_qr", ".", "cs_qr", "(", "dcs", ",", "S", ")", ";", "if", "(", "N", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Exception occured in cs_qr()\"", ")", ";", "}", "}" ]
Constructs and returns a new QR decomposition object; computed by Householder reflections; If m < n then then the QR of A' is computed. The decomposed matrices can be retrieved via instance methods of the returned decomposition object. @param A A rectangular matrix. @param order ordering option (0 to 3); 0: natural ordering, 1: amd(A+A'), 2: amd(S'*S), 3: amd(A'*A) @throws IllegalArgumentException if <tt>A</tt> is not sparse @throws IllegalArgumentException if <tt>order</tt> is not in [0,3]
[ "Constructs", "and", "returns", "a", "new", "QR", "decomposition", "object", ";", "computed", "by", "Householder", "reflections", ";", "If", "m", "<", "n", "then", "then", "the", "QR", "of", "A", "is", "computed", ".", "The", "decomposed", "matrices", "can", "be", "retrieved", "via", "instance", "methods", "of", "the", "returned", "decomposition", "object", "." ]
65064c1bb0b26c7261358021e4c93d06dd43564f
https://github.com/vincentk/joptimizer/blob/65064c1bb0b26c7261358021e4c93d06dd43564f/src/main/java/com/joptimizer/algebra/QRSparseFactorization.java#L115-L169
9,741
vincentk/joptimizer
src/main/java/com/joptimizer/algebra/CholeskySparseFactorization.java
CholeskySparseFactorization.solve
public DoubleMatrix2D solve(DoubleMatrix2D B) { if (B.rows() != dim) { log.error("wrong dimension of vector b: expected " + dim +", actual " + B.rows()); throw new RuntimeException("wrong dimension of vector b: expected " + dim +", actual " + B.rows()); } // with scaling, we must solve U.Q.U.z = U.b, after that we have x = U.z if (this.rescaler != null) { // B = ALG.mult(this.U, B); B = ColtUtils.diagonalMatrixMult(this.U, B); } int nOfColumns = B.columns(); // copy final double[][] Y = B.copy().toArray(); // Solve LY = B (same as L.Yc = Bc for every column of Y and B) for (int j = 0; j < dim; j++) { final double[] LTJ = LcolumnsValues[j]; for (int col = 0; col < nOfColumns; col++) { Y[j][col] /= LTJ[0];// the diagonal of the matrix L final double YJCol = Y[j][col]; if(Double.compare(YJCol, 0.)!=0){ for (int i = j + 1; i < dim; i++) { Y[i][col] -= YJCol * LTJ[i - j]; } } } } // Solve L[T].X = Y (same as L[T].Xc = Yc for every column of X and Y) final DoubleMatrix2D X = F2.make(dim, nOfColumns); for (int i = dim - 1; i > -1; i--) { final double[] LTI = LcolumnsValues[i]; double[] sum = new double[nOfColumns]; for (int col = 0; col < nOfColumns; col++) { for (int j = dim - 1; j > i; j--) { sum[col] += LTI[j - i] * X.getQuick(j, col); } X.setQuick(i, col, (Y[i][col] - sum[col]) / LTI[0]); } } if (this.rescaler != null) { // return ALG.mult(this.U, X); return ColtUtils.diagonalMatrixMult(this.U, X); } else { return X; } }
java
public DoubleMatrix2D solve(DoubleMatrix2D B) { if (B.rows() != dim) { log.error("wrong dimension of vector b: expected " + dim +", actual " + B.rows()); throw new RuntimeException("wrong dimension of vector b: expected " + dim +", actual " + B.rows()); } // with scaling, we must solve U.Q.U.z = U.b, after that we have x = U.z if (this.rescaler != null) { // B = ALG.mult(this.U, B); B = ColtUtils.diagonalMatrixMult(this.U, B); } int nOfColumns = B.columns(); // copy final double[][] Y = B.copy().toArray(); // Solve LY = B (same as L.Yc = Bc for every column of Y and B) for (int j = 0; j < dim; j++) { final double[] LTJ = LcolumnsValues[j]; for (int col = 0; col < nOfColumns; col++) { Y[j][col] /= LTJ[0];// the diagonal of the matrix L final double YJCol = Y[j][col]; if(Double.compare(YJCol, 0.)!=0){ for (int i = j + 1; i < dim; i++) { Y[i][col] -= YJCol * LTJ[i - j]; } } } } // Solve L[T].X = Y (same as L[T].Xc = Yc for every column of X and Y) final DoubleMatrix2D X = F2.make(dim, nOfColumns); for (int i = dim - 1; i > -1; i--) { final double[] LTI = LcolumnsValues[i]; double[] sum = new double[nOfColumns]; for (int col = 0; col < nOfColumns; col++) { for (int j = dim - 1; j > i; j--) { sum[col] += LTI[j - i] * X.getQuick(j, col); } X.setQuick(i, col, (Y[i][col] - sum[col]) / LTI[0]); } } if (this.rescaler != null) { // return ALG.mult(this.U, X); return ColtUtils.diagonalMatrixMult(this.U, X); } else { return X; } }
[ "public", "DoubleMatrix2D", "solve", "(", "DoubleMatrix2D", "B", ")", "{", "if", "(", "B", ".", "rows", "(", ")", "!=", "dim", ")", "{", "log", ".", "error", "(", "\"wrong dimension of vector b: expected \"", "+", "dim", "+", "\", actual \"", "+", "B", ".", "rows", "(", ")", ")", ";", "throw", "new", "RuntimeException", "(", "\"wrong dimension of vector b: expected \"", "+", "dim", "+", "\", actual \"", "+", "B", ".", "rows", "(", ")", ")", ";", "}", "// with scaling, we must solve U.Q.U.z = U.b, after that we have x = U.z\r", "if", "(", "this", ".", "rescaler", "!=", "null", ")", "{", "// B = ALG.mult(this.U, B);\r", "B", "=", "ColtUtils", ".", "diagonalMatrixMult", "(", "this", ".", "U", ",", "B", ")", ";", "}", "int", "nOfColumns", "=", "B", ".", "columns", "(", ")", ";", "// copy\r", "final", "double", "[", "]", "[", "]", "Y", "=", "B", ".", "copy", "(", ")", ".", "toArray", "(", ")", ";", "// Solve LY = B (same as L.Yc = Bc for every column of Y and B)\r", "for", "(", "int", "j", "=", "0", ";", "j", "<", "dim", ";", "j", "++", ")", "{", "final", "double", "[", "]", "LTJ", "=", "LcolumnsValues", "[", "j", "]", ";", "for", "(", "int", "col", "=", "0", ";", "col", "<", "nOfColumns", ";", "col", "++", ")", "{", "Y", "[", "j", "]", "[", "col", "]", "/=", "LTJ", "[", "0", "]", ";", "// the diagonal of the matrix L\r", "final", "double", "YJCol", "=", "Y", "[", "j", "]", "[", "col", "]", ";", "if", "(", "Double", ".", "compare", "(", "YJCol", ",", "0.", ")", "!=", "0", ")", "{", "for", "(", "int", "i", "=", "j", "+", "1", ";", "i", "<", "dim", ";", "i", "++", ")", "{", "Y", "[", "i", "]", "[", "col", "]", "-=", "YJCol", "*", "LTJ", "[", "i", "-", "j", "]", ";", "}", "}", "}", "}", "// Solve L[T].X = Y (same as L[T].Xc = Yc for every column of X and Y)\r", "final", "DoubleMatrix2D", "X", "=", "F2", ".", "make", "(", "dim", ",", "nOfColumns", ")", ";", "for", "(", "int", "i", "=", "dim", "-", "1", ";", "i", ">", "-", "1", ";", "i", "--", ")", "{", "final", "double", "[", "]", "LTI", "=", "LcolumnsValues", "[", "i", "]", ";", "double", "[", "]", "sum", "=", "new", "double", "[", "nOfColumns", "]", ";", "for", "(", "int", "col", "=", "0", ";", "col", "<", "nOfColumns", ";", "col", "++", ")", "{", "for", "(", "int", "j", "=", "dim", "-", "1", ";", "j", ">", "i", ";", "j", "--", ")", "{", "sum", "[", "col", "]", "+=", "LTI", "[", "j", "-", "i", "]", "*", "X", ".", "getQuick", "(", "j", ",", "col", ")", ";", "}", "X", ".", "setQuick", "(", "i", ",", "col", ",", "(", "Y", "[", "i", "]", "[", "col", "]", "-", "sum", "[", "col", "]", ")", "/", "LTI", "[", "0", "]", ")", ";", "}", "}", "if", "(", "this", ".", "rescaler", "!=", "null", ")", "{", "// return ALG.mult(this.U, X);\r", "return", "ColtUtils", ".", "diagonalMatrixMult", "(", "this", ".", "U", ",", "X", ")", ";", "}", "else", "{", "return", "X", ";", "}", "}" ]
Solves Q.X = B
[ "Solves", "Q", ".", "X", "=", "B" ]
65064c1bb0b26c7261358021e4c93d06dd43564f
https://github.com/vincentk/joptimizer/blob/65064c1bb0b26c7261358021e4c93d06dd43564f/src/main/java/com/joptimizer/algebra/CholeskySparseFactorization.java#L242-L292
9,742
vincentk/joptimizer
src/main/java/com/joptimizer/solvers/KKTSolver.java
KKTSolver.checkKKTSolutionAccuracy
protected boolean checkKKTSolutionAccuracy(DoubleMatrix1D v, DoubleMatrix1D w) { DoubleMatrix2D KKT = null; DoubleMatrix1D x = null; DoubleMatrix1D b = null; if (this.A != null) { if(this.AT==null){ this.AT = ALG.transpose(A); } if(h!=null){ //H.v + [A]T.w = -g //A.v = -h DoubleMatrix2D[][] parts = { { this.H, this.AT }, { this.A, null } }; if(H instanceof SparseDoubleMatrix2D && A instanceof SparseDoubleMatrix2D){ KKT = DoubleFactory2D.sparse.compose(parts); }else{ KKT = DoubleFactory2D.dense.compose(parts); } x = F1.append(v, w); b = F1.append(g, h).assign(Mult.mult(-1)); }else{ //H.v + [A]T.w = -g DoubleMatrix2D[][] parts = {{ this.H, this.AT }}; if(H instanceof SparseDoubleMatrix2D && A instanceof SparseDoubleMatrix2D){ KKT = DoubleFactory2D.sparse.compose(parts); }else{ KKT = DoubleFactory2D.dense.compose(parts); } x = F1.append(v, w); //b = g.copy().assign(Mult.mult(-1)); b = ColtUtils.scalarMult(g, -1); } }else{ //H.v = -g KKT = this.H; x = v; //b = g.copy().assign(Mult.mult(-1)); b = ColtUtils.scalarMult(g, -1); } //checking residual double scaledResidual = Utils.calculateScaledResidual(KKT, x, b); return scaledResidual < toleranceKKT; }
java
protected boolean checkKKTSolutionAccuracy(DoubleMatrix1D v, DoubleMatrix1D w) { DoubleMatrix2D KKT = null; DoubleMatrix1D x = null; DoubleMatrix1D b = null; if (this.A != null) { if(this.AT==null){ this.AT = ALG.transpose(A); } if(h!=null){ //H.v + [A]T.w = -g //A.v = -h DoubleMatrix2D[][] parts = { { this.H, this.AT }, { this.A, null } }; if(H instanceof SparseDoubleMatrix2D && A instanceof SparseDoubleMatrix2D){ KKT = DoubleFactory2D.sparse.compose(parts); }else{ KKT = DoubleFactory2D.dense.compose(parts); } x = F1.append(v, w); b = F1.append(g, h).assign(Mult.mult(-1)); }else{ //H.v + [A]T.w = -g DoubleMatrix2D[][] parts = {{ this.H, this.AT }}; if(H instanceof SparseDoubleMatrix2D && A instanceof SparseDoubleMatrix2D){ KKT = DoubleFactory2D.sparse.compose(parts); }else{ KKT = DoubleFactory2D.dense.compose(parts); } x = F1.append(v, w); //b = g.copy().assign(Mult.mult(-1)); b = ColtUtils.scalarMult(g, -1); } }else{ //H.v = -g KKT = this.H; x = v; //b = g.copy().assign(Mult.mult(-1)); b = ColtUtils.scalarMult(g, -1); } //checking residual double scaledResidual = Utils.calculateScaledResidual(KKT, x, b); return scaledResidual < toleranceKKT; }
[ "protected", "boolean", "checkKKTSolutionAccuracy", "(", "DoubleMatrix1D", "v", ",", "DoubleMatrix1D", "w", ")", "{", "DoubleMatrix2D", "KKT", "=", "null", ";", "DoubleMatrix1D", "x", "=", "null", ";", "DoubleMatrix1D", "b", "=", "null", ";", "if", "(", "this", ".", "A", "!=", "null", ")", "{", "if", "(", "this", ".", "AT", "==", "null", ")", "{", "this", ".", "AT", "=", "ALG", ".", "transpose", "(", "A", ")", ";", "}", "if", "(", "h", "!=", "null", ")", "{", "//H.v + [A]T.w = -g\r", "//A.v = -h\r", "DoubleMatrix2D", "[", "]", "[", "]", "parts", "=", "{", "{", "this", ".", "H", ",", "this", ".", "AT", "}", ",", "{", "this", ".", "A", ",", "null", "}", "}", ";", "if", "(", "H", "instanceof", "SparseDoubleMatrix2D", "&&", "A", "instanceof", "SparseDoubleMatrix2D", ")", "{", "KKT", "=", "DoubleFactory2D", ".", "sparse", ".", "compose", "(", "parts", ")", ";", "}", "else", "{", "KKT", "=", "DoubleFactory2D", ".", "dense", ".", "compose", "(", "parts", ")", ";", "}", "x", "=", "F1", ".", "append", "(", "v", ",", "w", ")", ";", "b", "=", "F1", ".", "append", "(", "g", ",", "h", ")", ".", "assign", "(", "Mult", ".", "mult", "(", "-", "1", ")", ")", ";", "}", "else", "{", "//H.v + [A]T.w = -g\r", "DoubleMatrix2D", "[", "]", "[", "]", "parts", "=", "{", "{", "this", ".", "H", ",", "this", ".", "AT", "}", "}", ";", "if", "(", "H", "instanceof", "SparseDoubleMatrix2D", "&&", "A", "instanceof", "SparseDoubleMatrix2D", ")", "{", "KKT", "=", "DoubleFactory2D", ".", "sparse", ".", "compose", "(", "parts", ")", ";", "}", "else", "{", "KKT", "=", "DoubleFactory2D", ".", "dense", ".", "compose", "(", "parts", ")", ";", "}", "x", "=", "F1", ".", "append", "(", "v", ",", "w", ")", ";", "//b = g.copy().assign(Mult.mult(-1));\r", "b", "=", "ColtUtils", ".", "scalarMult", "(", "g", ",", "-", "1", ")", ";", "}", "}", "else", "{", "//H.v = -g\r", "KKT", "=", "this", ".", "H", ";", "x", "=", "v", ";", "//b = g.copy().assign(Mult.mult(-1));\r", "b", "=", "ColtUtils", ".", "scalarMult", "(", "g", ",", "-", "1", ")", ";", "}", "//checking residual\r", "double", "scaledResidual", "=", "Utils", ".", "calculateScaledResidual", "(", "KKT", ",", "x", ",", "b", ")", ";", "return", "scaledResidual", "<", "toleranceKKT", ";", "}" ]
Check the solution of the system KKT.x = b against the scaled residual beta < gamma, where gamma is a parameter chosen by the user and beta is the scaled residual, beta = ||KKT.x-b||_oo/( ||KKT||_oo . ||x||_oo + ||b||_oo ), with ||x||_oo = max(||x[i]||)
[ "Check", "the", "solution", "of", "the", "system" ]
65064c1bb0b26c7261358021e4c93d06dd43564f
https://github.com/vincentk/joptimizer/blob/65064c1bb0b26c7261358021e4c93d06dd43564f/src/main/java/com/joptimizer/solvers/KKTSolver.java#L125-L170
9,743
vincentk/joptimizer
src/main/java/com/joptimizer/solvers/KKTSolver.java
KKTSolver.createFullDataMatrix
protected DoubleMatrix2D createFullDataMatrix(DoubleMatrix2D SubDiagonalSymmMatrix){ int c = SubDiagonalSymmMatrix.columns(); DoubleMatrix2D ret = F2.make(c, c); for(int i=0; i<c; i++){ for(int j=0; j<=i; j++){ ret.setQuick(i, j, SubDiagonalSymmMatrix.getQuick(i, j)); ret.setQuick(j, i, SubDiagonalSymmMatrix.getQuick(i, j)); } } return ret; }
java
protected DoubleMatrix2D createFullDataMatrix(DoubleMatrix2D SubDiagonalSymmMatrix){ int c = SubDiagonalSymmMatrix.columns(); DoubleMatrix2D ret = F2.make(c, c); for(int i=0; i<c; i++){ for(int j=0; j<=i; j++){ ret.setQuick(i, j, SubDiagonalSymmMatrix.getQuick(i, j)); ret.setQuick(j, i, SubDiagonalSymmMatrix.getQuick(i, j)); } } return ret; }
[ "protected", "DoubleMatrix2D", "createFullDataMatrix", "(", "DoubleMatrix2D", "SubDiagonalSymmMatrix", ")", "{", "int", "c", "=", "SubDiagonalSymmMatrix", ".", "columns", "(", ")", ";", "DoubleMatrix2D", "ret", "=", "F2", ".", "make", "(", "c", ",", "c", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "c", ";", "i", "++", ")", "{", "for", "(", "int", "j", "=", "0", ";", "j", "<=", "i", ";", "j", "++", ")", "{", "ret", ".", "setQuick", "(", "i", ",", "j", ",", "SubDiagonalSymmMatrix", ".", "getQuick", "(", "i", ",", "j", ")", ")", ";", "ret", ".", "setQuick", "(", "j", ",", "i", ",", "SubDiagonalSymmMatrix", ".", "getQuick", "(", "i", ",", "j", ")", ")", ";", "}", "}", "return", "ret", ";", "}" ]
Create a full data matrix starting form a symmetric matrix filled only in its subdiagonal elements.
[ "Create", "a", "full", "data", "matrix", "starting", "form", "a", "symmetric", "matrix", "filled", "only", "in", "its", "subdiagonal", "elements", "." ]
65064c1bb0b26c7261358021e4c93d06dd43564f
https://github.com/vincentk/joptimizer/blob/65064c1bb0b26c7261358021e4c93d06dd43564f/src/main/java/com/joptimizer/solvers/KKTSolver.java#L175-L185
9,744
vincentk/joptimizer
src/main/java/com/joptimizer/algebra/Matrix1NornRescaler.java
Matrix1NornRescaler.getMatrixScalingFactors
@Override public DoubleMatrix1D[] getMatrixScalingFactors(DoubleMatrix2D A){ DoubleFactory1D F1 = DoubleFactory1D.dense; Algebra ALG = Algebra.DEFAULT; int r = A.rows(); int c = A.columns(); DoubleMatrix1D D1 = F1.make(r, 1); DoubleMatrix1D D2 = F1.make(c, 1); DoubleMatrix2D AK = A.copy(); DoubleMatrix1D DR = F1.make(r, 1); DoubleMatrix1D DC = F1.make(c, 1); DoubleMatrix1D DRInv = F1.make(r); DoubleMatrix1D DCInv = F1.make(c); log.debug("eps : " + eps); int maxIteration = 50; for(int k=0; k<=maxIteration; k++){ double normR = -Double.MAX_VALUE; double normC = -Double.MAX_VALUE; for(int i=0; i<r; i++){ double dri = ALG.normInfinity(AK.viewRow(i)); DR.setQuick(i, Math.sqrt(dri)); DRInv.setQuick(i, 1./Math.sqrt(dri)); normR = Math.max(normR, Math.abs(1-dri)); } for(int j=0; j<c; j++){ double dci = ALG.normInfinity(AK.viewColumn(j)); DC.setQuick(j, Math.sqrt(dci)); DCInv.setQuick(j, 1./Math.sqrt(dci)); normC = Math.max(normC, Math.abs(1-dci)); } log.debug("normR: " + normR); log.debug("normC: " + normC); if(normR < eps && normC < eps){ break; } //D1 = ALG.mult(D1, DRInv); for(int i=0; i<r; i++){ double prevD1I = D1.getQuick(i); double newD1I = prevD1I * DRInv.getQuick(i); D1.setQuick(i, newD1I); } //D2 = ALG.mult(D2, DCInv); for(int j=0; j<c; j++){ double prevD2J = D2.getQuick(j); double newD2J = prevD2J * DCInv.getQuick(j); D2.setQuick(j, newD2J); } //log.debug("D1: " + ArrayUtils.toString(D1.toArray())); //log.debug("D2: " + ArrayUtils.toString(D2.toArray())); if(k==maxIteration){ log.warn("max iteration reached"); } //AK = ALG.mult(DRInv, ALG.mult(AK, DCInv)); AK = ColtUtils.diagonalMatrixMult(DRInv, AK, DCInv); } return new DoubleMatrix1D[]{D1, D2}; }
java
@Override public DoubleMatrix1D[] getMatrixScalingFactors(DoubleMatrix2D A){ DoubleFactory1D F1 = DoubleFactory1D.dense; Algebra ALG = Algebra.DEFAULT; int r = A.rows(); int c = A.columns(); DoubleMatrix1D D1 = F1.make(r, 1); DoubleMatrix1D D2 = F1.make(c, 1); DoubleMatrix2D AK = A.copy(); DoubleMatrix1D DR = F1.make(r, 1); DoubleMatrix1D DC = F1.make(c, 1); DoubleMatrix1D DRInv = F1.make(r); DoubleMatrix1D DCInv = F1.make(c); log.debug("eps : " + eps); int maxIteration = 50; for(int k=0; k<=maxIteration; k++){ double normR = -Double.MAX_VALUE; double normC = -Double.MAX_VALUE; for(int i=0; i<r; i++){ double dri = ALG.normInfinity(AK.viewRow(i)); DR.setQuick(i, Math.sqrt(dri)); DRInv.setQuick(i, 1./Math.sqrt(dri)); normR = Math.max(normR, Math.abs(1-dri)); } for(int j=0; j<c; j++){ double dci = ALG.normInfinity(AK.viewColumn(j)); DC.setQuick(j, Math.sqrt(dci)); DCInv.setQuick(j, 1./Math.sqrt(dci)); normC = Math.max(normC, Math.abs(1-dci)); } log.debug("normR: " + normR); log.debug("normC: " + normC); if(normR < eps && normC < eps){ break; } //D1 = ALG.mult(D1, DRInv); for(int i=0; i<r; i++){ double prevD1I = D1.getQuick(i); double newD1I = prevD1I * DRInv.getQuick(i); D1.setQuick(i, newD1I); } //D2 = ALG.mult(D2, DCInv); for(int j=0; j<c; j++){ double prevD2J = D2.getQuick(j); double newD2J = prevD2J * DCInv.getQuick(j); D2.setQuick(j, newD2J); } //log.debug("D1: " + ArrayUtils.toString(D1.toArray())); //log.debug("D2: " + ArrayUtils.toString(D2.toArray())); if(k==maxIteration){ log.warn("max iteration reached"); } //AK = ALG.mult(DRInv, ALG.mult(AK, DCInv)); AK = ColtUtils.diagonalMatrixMult(DRInv, AK, DCInv); } return new DoubleMatrix1D[]{D1, D2}; }
[ "@", "Override", "public", "DoubleMatrix1D", "[", "]", "getMatrixScalingFactors", "(", "DoubleMatrix2D", "A", ")", "{", "DoubleFactory1D", "F1", "=", "DoubleFactory1D", ".", "dense", ";", "Algebra", "ALG", "=", "Algebra", ".", "DEFAULT", ";", "int", "r", "=", "A", ".", "rows", "(", ")", ";", "int", "c", "=", "A", ".", "columns", "(", ")", ";", "DoubleMatrix1D", "D1", "=", "F1", ".", "make", "(", "r", ",", "1", ")", ";", "DoubleMatrix1D", "D2", "=", "F1", ".", "make", "(", "c", ",", "1", ")", ";", "DoubleMatrix2D", "AK", "=", "A", ".", "copy", "(", ")", ";", "DoubleMatrix1D", "DR", "=", "F1", ".", "make", "(", "r", ",", "1", ")", ";", "DoubleMatrix1D", "DC", "=", "F1", ".", "make", "(", "c", ",", "1", ")", ";", "DoubleMatrix1D", "DRInv", "=", "F1", ".", "make", "(", "r", ")", ";", "DoubleMatrix1D", "DCInv", "=", "F1", ".", "make", "(", "c", ")", ";", "log", ".", "debug", "(", "\"eps : \"", "+", "eps", ")", ";", "int", "maxIteration", "=", "50", ";", "for", "(", "int", "k", "=", "0", ";", "k", "<=", "maxIteration", ";", "k", "++", ")", "{", "double", "normR", "=", "-", "Double", ".", "MAX_VALUE", ";", "double", "normC", "=", "-", "Double", ".", "MAX_VALUE", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "r", ";", "i", "++", ")", "{", "double", "dri", "=", "ALG", ".", "normInfinity", "(", "AK", ".", "viewRow", "(", "i", ")", ")", ";", "DR", ".", "setQuick", "(", "i", ",", "Math", ".", "sqrt", "(", "dri", ")", ")", ";", "DRInv", ".", "setQuick", "(", "i", ",", "1.", "/", "Math", ".", "sqrt", "(", "dri", ")", ")", ";", "normR", "=", "Math", ".", "max", "(", "normR", ",", "Math", ".", "abs", "(", "1", "-", "dri", ")", ")", ";", "}", "for", "(", "int", "j", "=", "0", ";", "j", "<", "c", ";", "j", "++", ")", "{", "double", "dci", "=", "ALG", ".", "normInfinity", "(", "AK", ".", "viewColumn", "(", "j", ")", ")", ";", "DC", ".", "setQuick", "(", "j", ",", "Math", ".", "sqrt", "(", "dci", ")", ")", ";", "DCInv", ".", "setQuick", "(", "j", ",", "1.", "/", "Math", ".", "sqrt", "(", "dci", ")", ")", ";", "normC", "=", "Math", ".", "max", "(", "normC", ",", "Math", ".", "abs", "(", "1", "-", "dci", ")", ")", ";", "}", "log", ".", "debug", "(", "\"normR: \"", "+", "normR", ")", ";", "log", ".", "debug", "(", "\"normC: \"", "+", "normC", ")", ";", "if", "(", "normR", "<", "eps", "&&", "normC", "<", "eps", ")", "{", "break", ";", "}", "//D1 = ALG.mult(D1, DRInv);\r", "for", "(", "int", "i", "=", "0", ";", "i", "<", "r", ";", "i", "++", ")", "{", "double", "prevD1I", "=", "D1", ".", "getQuick", "(", "i", ")", ";", "double", "newD1I", "=", "prevD1I", "*", "DRInv", ".", "getQuick", "(", "i", ")", ";", "D1", ".", "setQuick", "(", "i", ",", "newD1I", ")", ";", "}", "//D2 = ALG.mult(D2, DCInv);\r", "for", "(", "int", "j", "=", "0", ";", "j", "<", "c", ";", "j", "++", ")", "{", "double", "prevD2J", "=", "D2", ".", "getQuick", "(", "j", ")", ";", "double", "newD2J", "=", "prevD2J", "*", "DCInv", ".", "getQuick", "(", "j", ")", ";", "D2", ".", "setQuick", "(", "j", ",", "newD2J", ")", ";", "}", "//log.debug(\"D1: \" + ArrayUtils.toString(D1.toArray()));\r", "//log.debug(\"D2: \" + ArrayUtils.toString(D2.toArray()));\r", "if", "(", "k", "==", "maxIteration", ")", "{", "log", ".", "warn", "(", "\"max iteration reached\"", ")", ";", "}", "//AK = ALG.mult(DRInv, ALG.mult(AK, DCInv));\r", "AK", "=", "ColtUtils", ".", "diagonalMatrixMult", "(", "DRInv", ",", "AK", ",", "DCInv", ")", ";", "}", "return", "new", "DoubleMatrix1D", "[", "]", "{", "D1", ",", "D2", "}", ";", "}" ]
Scaling factors for not singular matrices. @see Daniel Ruiz, "A scaling algorithm to equilibrate both rows and columns norms in matrices" @see Philip A. Knight, Daniel Ruiz, Bora Ucar "A Symmetry Preserving Algorithm for Matrix Scaling"
[ "Scaling", "factors", "for", "not", "singular", "matrices", "." ]
65064c1bb0b26c7261358021e4c93d06dd43564f
https://github.com/vincentk/joptimizer/blob/65064c1bb0b26c7261358021e4c93d06dd43564f/src/main/java/com/joptimizer/algebra/Matrix1NornRescaler.java#L56-L117
9,745
vincentk/joptimizer
src/main/java/com/joptimizer/algebra/Matrix1NornRescaler.java
Matrix1NornRescaler.checkScaling
@Override public boolean checkScaling(final DoubleMatrix2D AOriginal, final DoubleMatrix1D U, final DoubleMatrix1D V){ int c = AOriginal.columns(); int r = AOriginal.rows(); final double[] maxValueHolder = new double[]{-Double.MAX_VALUE}; IntIntDoubleFunction myFunct = new IntIntDoubleFunction() { @Override public double apply(int i, int j, double pij) { maxValueHolder[0] = Math.max(maxValueHolder[0], Math.abs(pij)); return pij; } }; DoubleMatrix2D AScaled = ColtUtils.diagonalMatrixMult(U, AOriginal, V); //view A row by row boolean isOk = true; for (int i = 0; isOk && i < r; i++) { maxValueHolder[0] = -Double.MAX_VALUE; DoubleMatrix2D P = AScaled.viewPart(i, 0, 1, c); P.forEachNonZero(myFunct); isOk = Math.abs(1. - maxValueHolder[0]) < eps; } //view A col by col for (int j = 0; isOk && j < c; j++) { maxValueHolder[0] = -Double.MAX_VALUE; DoubleMatrix2D P = AScaled.viewPart(0, j, r, 1); P.forEachNonZero(myFunct); isOk = Math.abs(1. - maxValueHolder[0]) < eps; } return isOk; }
java
@Override public boolean checkScaling(final DoubleMatrix2D AOriginal, final DoubleMatrix1D U, final DoubleMatrix1D V){ int c = AOriginal.columns(); int r = AOriginal.rows(); final double[] maxValueHolder = new double[]{-Double.MAX_VALUE}; IntIntDoubleFunction myFunct = new IntIntDoubleFunction() { @Override public double apply(int i, int j, double pij) { maxValueHolder[0] = Math.max(maxValueHolder[0], Math.abs(pij)); return pij; } }; DoubleMatrix2D AScaled = ColtUtils.diagonalMatrixMult(U, AOriginal, V); //view A row by row boolean isOk = true; for (int i = 0; isOk && i < r; i++) { maxValueHolder[0] = -Double.MAX_VALUE; DoubleMatrix2D P = AScaled.viewPart(i, 0, 1, c); P.forEachNonZero(myFunct); isOk = Math.abs(1. - maxValueHolder[0]) < eps; } //view A col by col for (int j = 0; isOk && j < c; j++) { maxValueHolder[0] = -Double.MAX_VALUE; DoubleMatrix2D P = AScaled.viewPart(0, j, r, 1); P.forEachNonZero(myFunct); isOk = Math.abs(1. - maxValueHolder[0]) < eps; } return isOk; }
[ "@", "Override", "public", "boolean", "checkScaling", "(", "final", "DoubleMatrix2D", "AOriginal", ",", "final", "DoubleMatrix1D", "U", ",", "final", "DoubleMatrix1D", "V", ")", "{", "int", "c", "=", "AOriginal", ".", "columns", "(", ")", ";", "int", "r", "=", "AOriginal", ".", "rows", "(", ")", ";", "final", "double", "[", "]", "maxValueHolder", "=", "new", "double", "[", "]", "{", "-", "Double", ".", "MAX_VALUE", "}", ";", "IntIntDoubleFunction", "myFunct", "=", "new", "IntIntDoubleFunction", "(", ")", "{", "@", "Override", "public", "double", "apply", "(", "int", "i", ",", "int", "j", ",", "double", "pij", ")", "{", "maxValueHolder", "[", "0", "]", "=", "Math", ".", "max", "(", "maxValueHolder", "[", "0", "]", ",", "Math", ".", "abs", "(", "pij", ")", ")", ";", "return", "pij", ";", "}", "}", ";", "DoubleMatrix2D", "AScaled", "=", "ColtUtils", ".", "diagonalMatrixMult", "(", "U", ",", "AOriginal", ",", "V", ")", ";", "//view A row by row\r", "boolean", "isOk", "=", "true", ";", "for", "(", "int", "i", "=", "0", ";", "isOk", "&&", "i", "<", "r", ";", "i", "++", ")", "{", "maxValueHolder", "[", "0", "]", "=", "-", "Double", ".", "MAX_VALUE", ";", "DoubleMatrix2D", "P", "=", "AScaled", ".", "viewPart", "(", "i", ",", "0", ",", "1", ",", "c", ")", ";", "P", ".", "forEachNonZero", "(", "myFunct", ")", ";", "isOk", "=", "Math", ".", "abs", "(", "1.", "-", "maxValueHolder", "[", "0", "]", ")", "<", "eps", ";", "}", "//view A col by col\r", "for", "(", "int", "j", "=", "0", ";", "isOk", "&&", "j", "<", "c", ";", "j", "++", ")", "{", "maxValueHolder", "[", "0", "]", "=", "-", "Double", ".", "MAX_VALUE", ";", "DoubleMatrix2D", "P", "=", "AScaled", ".", "viewPart", "(", "0", ",", "j", ",", "r", ",", "1", ")", ";", "P", ".", "forEachNonZero", "(", "myFunct", ")", ";", "isOk", "=", "Math", ".", "abs", "(", "1.", "-", "maxValueHolder", "[", "0", "]", ")", "<", "eps", ";", "}", "return", "isOk", ";", "}" ]
Check if the scaling algorithm returned proper results. Note that AOriginal cannot be only subdiagonal filled, because this check is for both symm and bath notsymm matrices. @param AOriginal the ORIGINAL (before scaling) matrix @param U the return of the scaling algorithm @param V the return of the scaling algorithm @param base @return
[ "Check", "if", "the", "scaling", "algorithm", "returned", "proper", "results", ".", "Note", "that", "AOriginal", "cannot", "be", "only", "subdiagonal", "filled", "because", "this", "check", "is", "for", "both", "symm", "and", "bath", "notsymm", "matrices", "." ]
65064c1bb0b26c7261358021e4c93d06dd43564f
https://github.com/vincentk/joptimizer/blob/65064c1bb0b26c7261358021e4c93d06dd43564f/src/main/java/com/joptimizer/algebra/Matrix1NornRescaler.java#L177-L210
9,746
visenze/visearch-sdk-java
src/main/java/com/visenze/visearch/FeatureResponseResult.java
FeatureResponseResult.getReqId
public String getReqId(){ if(this.headers!=null && this.headers.containsKey(ViSearchHttpConstants.X_LOG_ID)){ return headers.get(ViSearchHttpConstants.X_LOG_ID); } return ViSearchHttpConstants.X_LOG_ID_EMPTY; }
java
public String getReqId(){ if(this.headers!=null && this.headers.containsKey(ViSearchHttpConstants.X_LOG_ID)){ return headers.get(ViSearchHttpConstants.X_LOG_ID); } return ViSearchHttpConstants.X_LOG_ID_EMPTY; }
[ "public", "String", "getReqId", "(", ")", "{", "if", "(", "this", ".", "headers", "!=", "null", "&&", "this", ".", "headers", ".", "containsKey", "(", "ViSearchHttpConstants", ".", "X_LOG_ID", ")", ")", "{", "return", "headers", ".", "get", "(", "ViSearchHttpConstants", ".", "X_LOG_ID", ")", ";", "}", "return", "ViSearchHttpConstants", ".", "X_LOG_ID_EMPTY", ";", "}" ]
Get the request id to identify this request.
[ "Get", "the", "request", "id", "to", "identify", "this", "request", "." ]
133611b84a7489f08bf40b55912ccd2acc7f002c
https://github.com/visenze/visearch-sdk-java/blob/133611b84a7489f08bf40b55912ccd2acc7f002c/src/main/java/com/visenze/visearch/FeatureResponseResult.java#L51-L56
9,747
visenze/visearch-sdk-java
src/main/java/com/visenze/visearch/ViSearch.java
ViSearch.insertStatus
@Override public InsertStatus insertStatus(String transId, Integer errorPage, Integer errorLimit) { return dataOperations.insertStatus(transId, errorPage, errorLimit); }
java
@Override public InsertStatus insertStatus(String transId, Integer errorPage, Integer errorLimit) { return dataOperations.insertStatus(transId, errorPage, errorLimit); }
[ "@", "Override", "public", "InsertStatus", "insertStatus", "(", "String", "transId", ",", "Integer", "errorPage", ",", "Integer", "errorLimit", ")", "{", "return", "dataOperations", ".", "insertStatus", "(", "transId", ",", "errorPage", ",", "errorLimit", ")", ";", "}" ]
Get insert status by insert trans id, and get errors page. @param transId the id of the insert transaction. @param errorPage page number of the error list @param errorLimit per page limit number of the error list @return the insert transaction
[ "Get", "insert", "status", "by", "insert", "trans", "id", "and", "get", "errors", "page", "." ]
133611b84a7489f08bf40b55912ccd2acc7f002c
https://github.com/visenze/visearch-sdk-java/blob/133611b84a7489f08bf40b55912ccd2acc7f002c/src/main/java/com/visenze/visearch/ViSearch.java#L184-L187
9,748
visenze/visearch-sdk-java
src/main/java/com/visenze/visearch/ViSearch.java
ViSearch.search
@Override public PagedSearchResult search(SearchParams searchParams) { PagedSearchResult result = searchOperations.search(searchParams); if(result!=null && enableAutoSolutionActionTrack) { String reqId = result.getReqId(); this.sendSolutionActions("search", reqId); } return result; }
java
@Override public PagedSearchResult search(SearchParams searchParams) { PagedSearchResult result = searchOperations.search(searchParams); if(result!=null && enableAutoSolutionActionTrack) { String reqId = result.getReqId(); this.sendSolutionActions("search", reqId); } return result; }
[ "@", "Override", "public", "PagedSearchResult", "search", "(", "SearchParams", "searchParams", ")", "{", "PagedSearchResult", "result", "=", "searchOperations", ".", "search", "(", "searchParams", ")", ";", "if", "(", "result", "!=", "null", "&&", "enableAutoSolutionActionTrack", ")", "{", "String", "reqId", "=", "result", ".", "getReqId", "(", ")", ";", "this", ".", "sendSolutionActions", "(", "\"search\"", ",", "reqId", ")", ";", "}", "return", "result", ";", "}" ]
Search for similar images from the ViSearch App given an existing image in the App. @param searchParams the search parameters, must contain the im_name of the existing image @return the page of search result
[ "Search", "for", "similar", "images", "from", "the", "ViSearch", "App", "given", "an", "existing", "image", "in", "the", "App", "." ]
133611b84a7489f08bf40b55912ccd2acc7f002c
https://github.com/visenze/visearch-sdk-java/blob/133611b84a7489f08bf40b55912ccd2acc7f002c/src/main/java/com/visenze/visearch/ViSearch.java#L222-L230
9,749
visenze/visearch-sdk-java
src/main/java/com/visenze/visearch/ViSearch.java
ViSearch.recommendation
public PagedSearchResult recommendation(SearchParams searchParams) { PagedSearchResult result = searchOperations.recommendation(searchParams); if(result!=null && enableAutoSolutionActionTrack) { String reqId = result.getReqId(); this.sendSolutionActions("recommendation", reqId); } return result; }
java
public PagedSearchResult recommendation(SearchParams searchParams) { PagedSearchResult result = searchOperations.recommendation(searchParams); if(result!=null && enableAutoSolutionActionTrack) { String reqId = result.getReqId(); this.sendSolutionActions("recommendation", reqId); } return result; }
[ "public", "PagedSearchResult", "recommendation", "(", "SearchParams", "searchParams", ")", "{", "PagedSearchResult", "result", "=", "searchOperations", ".", "recommendation", "(", "searchParams", ")", ";", "if", "(", "result", "!=", "null", "&&", "enableAutoSolutionActionTrack", ")", "{", "String", "reqId", "=", "result", ".", "getReqId", "(", ")", ";", "this", ".", "sendSolutionActions", "(", "\"recommendation\"", ",", "reqId", ")", ";", "}", "return", "result", ";", "}" ]
Recommendation for similar images from the ViSearch App given an existing image in the App. @param searchParams @return
[ "Recommendation", "for", "similar", "images", "from", "the", "ViSearch", "App", "given", "an", "existing", "image", "in", "the", "App", "." ]
133611b84a7489f08bf40b55912ccd2acc7f002c
https://github.com/visenze/visearch-sdk-java/blob/133611b84a7489f08bf40b55912ccd2acc7f002c/src/main/java/com/visenze/visearch/ViSearch.java#L237-L244
9,750
visenze/visearch-sdk-java
src/main/java/com/visenze/visearch/ViSearch.java
ViSearch.colorSearch
@Override public PagedSearchResult colorSearch(ColorSearchParams colorSearchParams) { PagedSearchResult result = searchOperations.colorSearch(colorSearchParams); if(result!=null && enableAutoSolutionActionTrack) { String reqId = result.getReqId(); this.sendSolutionActions("colorsearch", reqId); } return result; }
java
@Override public PagedSearchResult colorSearch(ColorSearchParams colorSearchParams) { PagedSearchResult result = searchOperations.colorSearch(colorSearchParams); if(result!=null && enableAutoSolutionActionTrack) { String reqId = result.getReqId(); this.sendSolutionActions("colorsearch", reqId); } return result; }
[ "@", "Override", "public", "PagedSearchResult", "colorSearch", "(", "ColorSearchParams", "colorSearchParams", ")", "{", "PagedSearchResult", "result", "=", "searchOperations", ".", "colorSearch", "(", "colorSearchParams", ")", ";", "if", "(", "result", "!=", "null", "&&", "enableAutoSolutionActionTrack", ")", "{", "String", "reqId", "=", "result", ".", "getReqId", "(", ")", ";", "this", ".", "sendSolutionActions", "(", "\"colorsearch\"", ",", "reqId", ")", ";", "}", "return", "result", ";", "}" ]
Search for similar images from the ViSearch App given a hex color. @param colorSearchParams the color search parameters, must contain the hex color @return the page of color search result
[ "Search", "for", "similar", "images", "from", "the", "ViSearch", "App", "given", "a", "hex", "color", "." ]
133611b84a7489f08bf40b55912ccd2acc7f002c
https://github.com/visenze/visearch-sdk-java/blob/133611b84a7489f08bf40b55912ccd2acc7f002c/src/main/java/com/visenze/visearch/ViSearch.java#L252-L260
9,751
visenze/visearch-sdk-java
src/main/java/com/visenze/visearch/ViSearch.java
ViSearch.uploadSearch
@Override public PagedSearchResult uploadSearch(UploadSearchParams uploadSearchParams) { PagedSearchResult result = searchOperations.uploadSearch(uploadSearchParams); if(result!=null && enableAutoSolutionActionTrack) { String reqId = result.getReqId(); this.sendSolutionActions("uploadsearch", reqId); } return result; }
java
@Override public PagedSearchResult uploadSearch(UploadSearchParams uploadSearchParams) { PagedSearchResult result = searchOperations.uploadSearch(uploadSearchParams); if(result!=null && enableAutoSolutionActionTrack) { String reqId = result.getReqId(); this.sendSolutionActions("uploadsearch", reqId); } return result; }
[ "@", "Override", "public", "PagedSearchResult", "uploadSearch", "(", "UploadSearchParams", "uploadSearchParams", ")", "{", "PagedSearchResult", "result", "=", "searchOperations", ".", "uploadSearch", "(", "uploadSearchParams", ")", ";", "if", "(", "result", "!=", "null", "&&", "enableAutoSolutionActionTrack", ")", "{", "String", "reqId", "=", "result", ".", "getReqId", "(", ")", ";", "this", ".", "sendSolutionActions", "(", "\"uploadsearch\"", ",", "reqId", ")", ";", "}", "return", "result", ";", "}" ]
Search for similar images from the ViSearch App given an image file or url. @param uploadSearchParams the upload search parameters, must contain a image file or a url @return the page of upload search result
[ "Search", "for", "similar", "images", "from", "the", "ViSearch", "App", "given", "an", "image", "file", "or", "url", "." ]
133611b84a7489f08bf40b55912ccd2acc7f002c
https://github.com/visenze/visearch-sdk-java/blob/133611b84a7489f08bf40b55912ccd2acc7f002c/src/main/java/com/visenze/visearch/ViSearch.java#L268-L276
9,752
visenze/visearch-sdk-java
src/main/java/com/visenze/visearch/ViSearch.java
ViSearch.sendSolutionActions
private void sendSolutionActions(String action, String reqId){ if(reqId!=null && !reqId.equals("")) { Map<String, String> map = Maps.newHashMap(); map.put("action", action); map.put("reqid", reqId); this.sendEvent(map); } }
java
private void sendSolutionActions(String action, String reqId){ if(reqId!=null && !reqId.equals("")) { Map<String, String> map = Maps.newHashMap(); map.put("action", action); map.put("reqid", reqId); this.sendEvent(map); } }
[ "private", "void", "sendSolutionActions", "(", "String", "action", ",", "String", "reqId", ")", "{", "if", "(", "reqId", "!=", "null", "&&", "!", "reqId", ".", "equals", "(", "\"\"", ")", ")", "{", "Map", "<", "String", ",", "String", ">", "map", "=", "Maps", ".", "newHashMap", "(", ")", ";", "map", ".", "put", "(", "\"action\"", ",", "action", ")", ";", "map", ".", "put", "(", "\"reqid\"", ",", "reqId", ")", ";", "this", ".", "sendEvent", "(", "map", ")", ";", "}", "}" ]
send search actions after finishing search @param action @param reqId
[ "send", "search", "actions", "after", "finishing", "search" ]
133611b84a7489f08bf40b55912ccd2acc7f002c
https://github.com/visenze/visearch-sdk-java/blob/133611b84a7489f08bf40b55912ccd2acc7f002c/src/main/java/com/visenze/visearch/ViSearch.java#L330-L337
9,753
vincentk/joptimizer
src/main/java/com/joptimizer/algebra/CholeskyRCTFactorization.java
CholeskyRCTFactorization.factorize
public void factorize(boolean checkSymmetry) throws Exception{ if (checkSymmetry && !Property.TWELVE.isSymmetric(Q)) { throw new Exception("Matrix is not symmetric"); } double threshold = Utils.getDoubleMachineEpsilon(); this.LData = new double[(dim+1)*dim/2]; for (int i = 0; i < dim; i++) { int iShift = (i+1)*i/2; for (int j = 0; j < i+1; j++) { int jShift = (j+1)*j/2; double sum = 0.0; for (int k = 0; k < j; k++) { sum += LData[jShift + k] * LData[iShift + k]; } if (i == j){ double d = Q.getQuick(i, i) - sum; if(!(d > threshold)){ throw new Exception("not positive definite matrix"); } LData[iShift + i] = Math.sqrt(d); } else { LData[iShift + j] = 1.0 / LData[jShift + j] * (Q.getQuick(i, j) - sum); } } } }
java
public void factorize(boolean checkSymmetry) throws Exception{ if (checkSymmetry && !Property.TWELVE.isSymmetric(Q)) { throw new Exception("Matrix is not symmetric"); } double threshold = Utils.getDoubleMachineEpsilon(); this.LData = new double[(dim+1)*dim/2]; for (int i = 0; i < dim; i++) { int iShift = (i+1)*i/2; for (int j = 0; j < i+1; j++) { int jShift = (j+1)*j/2; double sum = 0.0; for (int k = 0; k < j; k++) { sum += LData[jShift + k] * LData[iShift + k]; } if (i == j){ double d = Q.getQuick(i, i) - sum; if(!(d > threshold)){ throw new Exception("not positive definite matrix"); } LData[iShift + i] = Math.sqrt(d); } else { LData[iShift + j] = 1.0 / LData[jShift + j] * (Q.getQuick(i, j) - sum); } } } }
[ "public", "void", "factorize", "(", "boolean", "checkSymmetry", ")", "throws", "Exception", "{", "if", "(", "checkSymmetry", "&&", "!", "Property", ".", "TWELVE", ".", "isSymmetric", "(", "Q", ")", ")", "{", "throw", "new", "Exception", "(", "\"Matrix is not symmetric\"", ")", ";", "}", "double", "threshold", "=", "Utils", ".", "getDoubleMachineEpsilon", "(", ")", ";", "this", ".", "LData", "=", "new", "double", "[", "(", "dim", "+", "1", ")", "*", "dim", "/", "2", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "dim", ";", "i", "++", ")", "{", "int", "iShift", "=", "(", "i", "+", "1", ")", "*", "i", "/", "2", ";", "for", "(", "int", "j", "=", "0", ";", "j", "<", "i", "+", "1", ";", "j", "++", ")", "{", "int", "jShift", "=", "(", "j", "+", "1", ")", "*", "j", "/", "2", ";", "double", "sum", "=", "0.0", ";", "for", "(", "int", "k", "=", "0", ";", "k", "<", "j", ";", "k", "++", ")", "{", "sum", "+=", "LData", "[", "jShift", "+", "k", "]", "*", "LData", "[", "iShift", "+", "k", "]", ";", "}", "if", "(", "i", "==", "j", ")", "{", "double", "d", "=", "Q", ".", "getQuick", "(", "i", ",", "i", ")", "-", "sum", ";", "if", "(", "!", "(", "d", ">", "threshold", ")", ")", "{", "throw", "new", "Exception", "(", "\"not positive definite matrix\"", ")", ";", "}", "LData", "[", "iShift", "+", "i", "]", "=", "Math", ".", "sqrt", "(", "d", ")", ";", "}", "else", "{", "LData", "[", "iShift", "+", "j", "]", "=", "1.0", "/", "LData", "[", "jShift", "+", "j", "]", "*", "(", "Q", ".", "getQuick", "(", "i", ",", "j", ")", "-", "sum", ")", ";", "}", "}", "}", "}" ]
Cholesky factorization L of psd matrix, Q = L.LT
[ "Cholesky", "factorization", "L", "of", "psd", "matrix", "Q", "=", "L", ".", "LT" ]
65064c1bb0b26c7261358021e4c93d06dd43564f
https://github.com/vincentk/joptimizer/blob/65064c1bb0b26c7261358021e4c93d06dd43564f/src/main/java/com/joptimizer/algebra/CholeskyRCTFactorization.java#L61-L88
9,754
cryptomator/webdav-nio-adapter
src/main/java/org/cryptomator/frontend/webdav/WebDavServer.java
WebDavServer.bind
public void bind(InetSocketAddress socketBindAddress) { try { localConnector.stop(); LOG.info("Binding server socket to {}:{}", socketBindAddress.getHostString(), socketBindAddress.getPort()); localConnector.setHost(socketBindAddress.getHostString()); localConnector.setPort(socketBindAddress.getPort()); localConnector.start(); } catch (Exception e) { throw new ServerLifecycleException("Failed to restart socket.", e); } }
java
public void bind(InetSocketAddress socketBindAddress) { try { localConnector.stop(); LOG.info("Binding server socket to {}:{}", socketBindAddress.getHostString(), socketBindAddress.getPort()); localConnector.setHost(socketBindAddress.getHostString()); localConnector.setPort(socketBindAddress.getPort()); localConnector.start(); } catch (Exception e) { throw new ServerLifecycleException("Failed to restart socket.", e); } }
[ "public", "void", "bind", "(", "InetSocketAddress", "socketBindAddress", ")", "{", "try", "{", "localConnector", ".", "stop", "(", ")", ";", "LOG", ".", "info", "(", "\"Binding server socket to {}:{}\"", ",", "socketBindAddress", ".", "getHostString", "(", ")", ",", "socketBindAddress", ".", "getPort", "(", ")", ")", ";", "localConnector", ".", "setHost", "(", "socketBindAddress", ".", "getHostString", "(", ")", ")", ";", "localConnector", ".", "setPort", "(", "socketBindAddress", ".", "getPort", "(", ")", ")", ";", "localConnector", ".", "start", "(", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "ServerLifecycleException", "(", "\"Failed to restart socket.\"", ",", "e", ")", ";", "}", "}" ]
Reconfigures the server socket to listen on the specified bindAddr and port. @param socketBindAddress Socket address and port of the server. Use <code>0.0.0.0:0</code> to listen on all interfaces and auto-assign a port. @throws ServerLifecycleException If any exception occurs during socket reconfiguration (e.g. port not available).
[ "Reconfigures", "the", "server", "socket", "to", "listen", "on", "the", "specified", "bindAddr", "and", "port", "." ]
55b0d7dccea9a4ede0a30a95583d8f04c8a86d18
https://github.com/cryptomator/webdav-nio-adapter/blob/55b0d7dccea9a4ede0a30a95583d8f04c8a86d18/src/main/java/org/cryptomator/frontend/webdav/WebDavServer.java#L70-L80
9,755
cryptomator/webdav-nio-adapter
src/main/java/org/cryptomator/frontend/webdav/WebDavServer.java
WebDavServer.start
public synchronized void start() throws ServerLifecycleException { if (executorService.isShutdown()) { throw new IllegalStateException("Server has already been terminated."); } try { server.start(); LOG.info("WebDavServer started."); } catch (Exception e) { throw new ServerLifecycleException("Server couldn't be started", e); } }
java
public synchronized void start() throws ServerLifecycleException { if (executorService.isShutdown()) { throw new IllegalStateException("Server has already been terminated."); } try { server.start(); LOG.info("WebDavServer started."); } catch (Exception e) { throw new ServerLifecycleException("Server couldn't be started", e); } }
[ "public", "synchronized", "void", "start", "(", ")", "throws", "ServerLifecycleException", "{", "if", "(", "executorService", ".", "isShutdown", "(", ")", ")", "{", "throw", "new", "IllegalStateException", "(", "\"Server has already been terminated.\"", ")", ";", "}", "try", "{", "server", ".", "start", "(", ")", ";", "LOG", ".", "info", "(", "\"WebDavServer started.\"", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "ServerLifecycleException", "(", "\"Server couldn't be started\"", ",", "e", ")", ";", "}", "}" ]
Starts the WebDAV server. @throws ServerLifecycleException If any exception occurs during server start (e.g. port not available).
[ "Starts", "the", "WebDAV", "server", "." ]
55b0d7dccea9a4ede0a30a95583d8f04c8a86d18
https://github.com/cryptomator/webdav-nio-adapter/blob/55b0d7dccea9a4ede0a30a95583d8f04c8a86d18/src/main/java/org/cryptomator/frontend/webdav/WebDavServer.java#L94-L104
9,756
cryptomator/webdav-nio-adapter
src/main/java/org/cryptomator/frontend/webdav/WebDavServer.java
WebDavServer.stop
public synchronized void stop() throws ServerLifecycleException { try { server.stop(); LOG.info("WebDavServer stopped."); } catch (Exception e) { throw new ServerLifecycleException("Server couldn't be stopped", e); } }
java
public synchronized void stop() throws ServerLifecycleException { try { server.stop(); LOG.info("WebDavServer stopped."); } catch (Exception e) { throw new ServerLifecycleException("Server couldn't be stopped", e); } }
[ "public", "synchronized", "void", "stop", "(", ")", "throws", "ServerLifecycleException", "{", "try", "{", "server", ".", "stop", "(", ")", ";", "LOG", ".", "info", "(", "\"WebDavServer stopped.\"", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "ServerLifecycleException", "(", "\"Server couldn't be stopped\"", ",", "e", ")", ";", "}", "}" ]
Stops the WebDAV server. @throws ServerLifecycleException If the server could not be stopped for any unexpected reason.
[ "Stops", "the", "WebDAV", "server", "." ]
55b0d7dccea9a4ede0a30a95583d8f04c8a86d18
https://github.com/cryptomator/webdav-nio-adapter/blob/55b0d7dccea9a4ede0a30a95583d8f04c8a86d18/src/main/java/org/cryptomator/frontend/webdav/WebDavServer.java#L111-L118
9,757
cryptomator/webdav-nio-adapter
src/main/java/org/cryptomator/frontend/webdav/mount/ProcessUtil.java
ProcessUtil.assertExitValue
public static void assertExitValue(Process proc, int expectedExitValue) throws CommandFailedException { int actualExitValue = proc.exitValue(); if (actualExitValue != expectedExitValue) { try { String error = toString(proc.getErrorStream(), StandardCharsets.UTF_8); throw new CommandFailedException("Command failed with exit code " + actualExitValue + ". Expected " + expectedExitValue + ". Stderr: " + error); } catch (IOException e) { throw new CommandFailedException("Command failed with exit code " + actualExitValue + ". Expected " + expectedExitValue + "."); } } }
java
public static void assertExitValue(Process proc, int expectedExitValue) throws CommandFailedException { int actualExitValue = proc.exitValue(); if (actualExitValue != expectedExitValue) { try { String error = toString(proc.getErrorStream(), StandardCharsets.UTF_8); throw new CommandFailedException("Command failed with exit code " + actualExitValue + ". Expected " + expectedExitValue + ". Stderr: " + error); } catch (IOException e) { throw new CommandFailedException("Command failed with exit code " + actualExitValue + ". Expected " + expectedExitValue + "."); } } }
[ "public", "static", "void", "assertExitValue", "(", "Process", "proc", ",", "int", "expectedExitValue", ")", "throws", "CommandFailedException", "{", "int", "actualExitValue", "=", "proc", ".", "exitValue", "(", ")", ";", "if", "(", "actualExitValue", "!=", "expectedExitValue", ")", "{", "try", "{", "String", "error", "=", "toString", "(", "proc", ".", "getErrorStream", "(", ")", ",", "StandardCharsets", ".", "UTF_8", ")", ";", "throw", "new", "CommandFailedException", "(", "\"Command failed with exit code \"", "+", "actualExitValue", "+", "\". Expected \"", "+", "expectedExitValue", "+", "\". Stderr: \"", "+", "error", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "new", "CommandFailedException", "(", "\"Command failed with exit code \"", "+", "actualExitValue", "+", "\". Expected \"", "+", "expectedExitValue", "+", "\".\"", ")", ";", "}", "}", "}" ]
Fails with a CommandFailedException, if the process did not finish with the expected exit code. @param proc A finished process @param expectedExitValue Exit code returned by the process @throws CommandFailedException Thrown in case of unexpected exit values
[ "Fails", "with", "a", "CommandFailedException", "if", "the", "process", "did", "not", "finish", "with", "the", "expected", "exit", "code", "." ]
55b0d7dccea9a4ede0a30a95583d8f04c8a86d18
https://github.com/cryptomator/webdav-nio-adapter/blob/55b0d7dccea9a4ede0a30a95583d8f04c8a86d18/src/main/java/org/cryptomator/frontend/webdav/mount/ProcessUtil.java#L23-L33
9,758
cryptomator/webdav-nio-adapter
src/main/java/org/cryptomator/frontend/webdav/mount/ProcessUtil.java
ProcessUtil.waitFor
public static void waitFor(Process proc, long timeout, TimeUnit unit) throws CommandTimeoutException { try { boolean finishedInTime = proc.waitFor(timeout, unit); if (!finishedInTime) { proc.destroyForcibly(); throw new CommandTimeoutException(); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); } }
java
public static void waitFor(Process proc, long timeout, TimeUnit unit) throws CommandTimeoutException { try { boolean finishedInTime = proc.waitFor(timeout, unit); if (!finishedInTime) { proc.destroyForcibly(); throw new CommandTimeoutException(); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); } }
[ "public", "static", "void", "waitFor", "(", "Process", "proc", ",", "long", "timeout", ",", "TimeUnit", "unit", ")", "throws", "CommandTimeoutException", "{", "try", "{", "boolean", "finishedInTime", "=", "proc", ".", "waitFor", "(", "timeout", ",", "unit", ")", ";", "if", "(", "!", "finishedInTime", ")", "{", "proc", ".", "destroyForcibly", "(", ")", ";", "throw", "new", "CommandTimeoutException", "(", ")", ";", "}", "}", "catch", "(", "InterruptedException", "e", ")", "{", "Thread", ".", "currentThread", "(", ")", ".", "interrupt", "(", ")", ";", "}", "}" ]
Waits for the process to terminate or throws an exception if it fails to do so within the given timeout. @param proc A started process @param timeout Maximum time to wait @param unit Time unit of <code>timeout</code> @throws CommandTimeoutException Thrown in case of a timeout
[ "Waits", "for", "the", "process", "to", "terminate", "or", "throws", "an", "exception", "if", "it", "fails", "to", "do", "so", "within", "the", "given", "timeout", "." ]
55b0d7dccea9a4ede0a30a95583d8f04c8a86d18
https://github.com/cryptomator/webdav-nio-adapter/blob/55b0d7dccea9a4ede0a30a95583d8f04c8a86d18/src/main/java/org/cryptomator/frontend/webdav/mount/ProcessUtil.java#L63-L73
9,759
cryptomator/webdav-nio-adapter
src/main/java/org/cryptomator/frontend/webdav/servlet/WebDavServletController.java
WebDavServletController.start
public void start() throws ServerLifecycleException { try { contextHandlerCollection.addHandler(contextHandler); contextHandlerCollection.mapContexts(); contextHandler.start(); LOG.info("WebDavServlet started: " + contextPath); } catch (Exception e) { throw new ServerLifecycleException("Servlet couldn't be started", e); } }
java
public void start() throws ServerLifecycleException { try { contextHandlerCollection.addHandler(contextHandler); contextHandlerCollection.mapContexts(); contextHandler.start(); LOG.info("WebDavServlet started: " + contextPath); } catch (Exception e) { throw new ServerLifecycleException("Servlet couldn't be started", e); } }
[ "public", "void", "start", "(", ")", "throws", "ServerLifecycleException", "{", "try", "{", "contextHandlerCollection", ".", "addHandler", "(", "contextHandler", ")", ";", "contextHandlerCollection", ".", "mapContexts", "(", ")", ";", "contextHandler", ".", "start", "(", ")", ";", "LOG", ".", "info", "(", "\"WebDavServlet started: \"", "+", "contextPath", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "ServerLifecycleException", "(", "\"Servlet couldn't be started\"", ",", "e", ")", ";", "}", "}" ]
Convenience function to start this servlet. @throws ServerLifecycleException If the servlet could not be started for any unexpected reason.
[ "Convenience", "function", "to", "start", "this", "servlet", "." ]
55b0d7dccea9a4ede0a30a95583d8f04c8a86d18
https://github.com/cryptomator/webdav-nio-adapter/blob/55b0d7dccea9a4ede0a30a95583d8f04c8a86d18/src/main/java/org/cryptomator/frontend/webdav/servlet/WebDavServletController.java#L47-L56
9,760
cryptomator/webdav-nio-adapter
src/main/java/org/cryptomator/frontend/webdav/servlet/WebDavServletController.java
WebDavServletController.stop
public void stop() throws ServerLifecycleException { try { contextHandler.stop(); contextHandlerCollection.removeHandler(contextHandler); contextHandlerCollection.mapContexts(); LOG.info("WebDavServlet stopped: " + contextPath); } catch (Exception e) { throw new ServerLifecycleException("Servlet couldn't be stopped", e); } }
java
public void stop() throws ServerLifecycleException { try { contextHandler.stop(); contextHandlerCollection.removeHandler(contextHandler); contextHandlerCollection.mapContexts(); LOG.info("WebDavServlet stopped: " + contextPath); } catch (Exception e) { throw new ServerLifecycleException("Servlet couldn't be stopped", e); } }
[ "public", "void", "stop", "(", ")", "throws", "ServerLifecycleException", "{", "try", "{", "contextHandler", ".", "stop", "(", ")", ";", "contextHandlerCollection", ".", "removeHandler", "(", "contextHandler", ")", ";", "contextHandlerCollection", ".", "mapContexts", "(", ")", ";", "LOG", ".", "info", "(", "\"WebDavServlet stopped: \"", "+", "contextPath", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "ServerLifecycleException", "(", "\"Servlet couldn't be stopped\"", ",", "e", ")", ";", "}", "}" ]
Convenience function to stop this servlet. @throws ServerLifecycleException If the servlet could not be stopped for any unexpected reason.
[ "Convenience", "function", "to", "stop", "this", "servlet", "." ]
55b0d7dccea9a4ede0a30a95583d8f04c8a86d18
https://github.com/cryptomator/webdav-nio-adapter/blob/55b0d7dccea9a4ede0a30a95583d8f04c8a86d18/src/main/java/org/cryptomator/frontend/webdav/servlet/WebDavServletController.java#L63-L72
9,761
cryptomator/webdav-nio-adapter
src/main/java/org/cryptomator/frontend/webdav/servlet/WebDavServletController.java
WebDavServletController.mount
public Mount mount(MountParams mountParams) throws CommandFailedException { if (!contextHandler.isStarted()) { throw new IllegalStateException("Mounting only possible for running servlets."); } URI uri = getServletRootUri(mountParams.getOrDefault(MountParam.WEBDAV_HOSTNAME, connector.getHost())); LOG.info("Mounting {} using {}", uri, mounter.getClass().getName()); return mounter.mount(uri, mountParams); }
java
public Mount mount(MountParams mountParams) throws CommandFailedException { if (!contextHandler.isStarted()) { throw new IllegalStateException("Mounting only possible for running servlets."); } URI uri = getServletRootUri(mountParams.getOrDefault(MountParam.WEBDAV_HOSTNAME, connector.getHost())); LOG.info("Mounting {} using {}", uri, mounter.getClass().getName()); return mounter.mount(uri, mountParams); }
[ "public", "Mount", "mount", "(", "MountParams", "mountParams", ")", "throws", "CommandFailedException", "{", "if", "(", "!", "contextHandler", ".", "isStarted", "(", ")", ")", "{", "throw", "new", "IllegalStateException", "(", "\"Mounting only possible for running servlets.\"", ")", ";", "}", "URI", "uri", "=", "getServletRootUri", "(", "mountParams", ".", "getOrDefault", "(", "MountParam", ".", "WEBDAV_HOSTNAME", ",", "connector", ".", "getHost", "(", ")", ")", ")", ";", "LOG", ".", "info", "(", "\"Mounting {} using {}\"", ",", "uri", ",", "mounter", ".", "getClass", "(", ")", ".", "getName", "(", ")", ")", ";", "return", "mounter", ".", "mount", "(", "uri", ",", "mountParams", ")", ";", "}" ]
Tries to mount the resource served by this servlet as a WebDAV drive on the local machine. @param mountParams Optional mount parameters, that may be required for certain operating systems. @return A {@link Mount} instance allowing unmounting and revealing the drive. @throws CommandFailedException If mounting failed.
[ "Tries", "to", "mount", "the", "resource", "served", "by", "this", "servlet", "as", "a", "WebDAV", "drive", "on", "the", "local", "machine", "." ]
55b0d7dccea9a4ede0a30a95583d8f04c8a86d18
https://github.com/cryptomator/webdav-nio-adapter/blob/55b0d7dccea9a4ede0a30a95583d8f04c8a86d18/src/main/java/org/cryptomator/frontend/webdav/servlet/WebDavServletController.java#L96-L103
9,762
bcecchinato/spring-postinitialize
src/main/java/fr/zebasto/spring/post/initialize/PostInitializeProcessor.java
PostInitializeProcessor.processInitialization
private void processInitialization() { ExecutorService executorService = Executors.newFixedThreadPool(this.maxThread); this.postInitializingMethods.entrySet().stream().sorted(Comparator.comparing(Map.Entry::getKey)).forEach(entry -> { log.debug("Found {} beans with max threads {} and order {}", entry.getValue().size(), this.maxThread, entry.getKey()); try { executorService.invokeAll(entry.getValue()); } catch (InterruptedException e) { log.warn("Failed to invoke {} method(s) on executorService {}", entry.getValue().size(), executorService); } }); executorService.shutdown(); }
java
private void processInitialization() { ExecutorService executorService = Executors.newFixedThreadPool(this.maxThread); this.postInitializingMethods.entrySet().stream().sorted(Comparator.comparing(Map.Entry::getKey)).forEach(entry -> { log.debug("Found {} beans with max threads {} and order {}", entry.getValue().size(), this.maxThread, entry.getKey()); try { executorService.invokeAll(entry.getValue()); } catch (InterruptedException e) { log.warn("Failed to invoke {} method(s) on executorService {}", entry.getValue().size(), executorService); } }); executorService.shutdown(); }
[ "private", "void", "processInitialization", "(", ")", "{", "ExecutorService", "executorService", "=", "Executors", ".", "newFixedThreadPool", "(", "this", ".", "maxThread", ")", ";", "this", ".", "postInitializingMethods", ".", "entrySet", "(", ")", ".", "stream", "(", ")", ".", "sorted", "(", "Comparator", ".", "comparing", "(", "Map", ".", "Entry", "::", "getKey", ")", ")", ".", "forEach", "(", "entry", "->", "{", "log", ".", "debug", "(", "\"Found {} beans with max threads {} and order {}\"", ",", "entry", ".", "getValue", "(", ")", ".", "size", "(", ")", ",", "this", ".", "maxThread", ",", "entry", ".", "getKey", "(", ")", ")", ";", "try", "{", "executorService", ".", "invokeAll", "(", "entry", ".", "getValue", "(", ")", ")", ";", "}", "catch", "(", "InterruptedException", "e", ")", "{", "log", ".", "warn", "(", "\"Failed to invoke {} method(s) on executorService {}\"", ",", "entry", ".", "getValue", "(", ")", ".", "size", "(", ")", ",", "executorService", ")", ";", "}", "}", ")", ";", "executorService", ".", "shutdown", "(", ")", ";", "}" ]
Launch the initialization of eligible beans @since 1.0.2
[ "Launch", "the", "initialization", "of", "eligible", "beans" ]
5acd221a6aac8f03cbad63205e3157b0aeaf4bba
https://github.com/bcecchinato/spring-postinitialize/blob/5acd221a6aac8f03cbad63205e3157b0aeaf4bba/src/main/java/fr/zebasto/spring/post/initialize/PostInitializeProcessor.java#L86-L97
9,763
evant/rxloader
rxloader/src/main/java/me/tatarka/rxloader/BaseRxLoader.java
BaseRxLoader.unsubscribe
public boolean unsubscribe() { CachingWeakRefSubscriber<T> subscriber = manager.get(tag); if (subscriber != null) { subscriber.unsubscribe(); return true; } return false; }
java
public boolean unsubscribe() { CachingWeakRefSubscriber<T> subscriber = manager.get(tag); if (subscriber != null) { subscriber.unsubscribe(); return true; } return false; }
[ "public", "boolean", "unsubscribe", "(", ")", "{", "CachingWeakRefSubscriber", "<", "T", ">", "subscriber", "=", "manager", ".", "get", "(", "tag", ")", ";", "if", "(", "subscriber", "!=", "null", ")", "{", "subscriber", ".", "unsubscribe", "(", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Cancels the task. @return true if the task was started, false otherwise
[ "Cancels", "the", "task", "." ]
d1344b5c60175d7f81beb8cbf3555c20fc79b03c
https://github.com/evant/rxloader/blob/d1344b5c60175d7f81beb8cbf3555c20fc79b03c/rxloader/src/main/java/me/tatarka/rxloader/BaseRxLoader.java#L69-L76
9,764
sarxos/v4l4j
src/main/java/au/edu/jcu/v4l4j/TunerList.java
TunerList.getTuner
public synchronized Tuner getTuner(int i){ checkReleased(); for(Tuner t: tuners) if(t.getIndex()==i) return t; throw new ArrayIndexOutOfBoundsException("No tuner with such index"); }
java
public synchronized Tuner getTuner(int i){ checkReleased(); for(Tuner t: tuners) if(t.getIndex()==i) return t; throw new ArrayIndexOutOfBoundsException("No tuner with such index"); }
[ "public", "synchronized", "Tuner", "getTuner", "(", "int", "i", ")", "{", "checkReleased", "(", ")", ";", "for", "(", "Tuner", "t", ":", "tuners", ")", "if", "(", "t", ".", "getIndex", "(", ")", "==", "i", ")", "return", "t", ";", "throw", "new", "ArrayIndexOutOfBoundsException", "(", "\"No tuner with such index\"", ")", ";", "}" ]
This method returns a tuner given its index. @return the tuner matching the given index, null otherwise @throws StateException if this tuner list has been released and must not be used anymore @throws ArrayIndexOutOfBoundsException if the given index is out of bounds
[ "This", "method", "returns", "a", "tuner", "given", "its", "index", "." ]
4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9
https://github.com/sarxos/v4l4j/blob/4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9/src/main/java/au/edu/jcu/v4l4j/TunerList.java#L71-L78
9,765
Headline/CleverBotAPI-Java
src/main/java/com/michaelwflaherty/cleverbotapi/CleverBotQuery.java
CleverBotQuery.sendRequest
public void sendRequest() throws IOException { /* Create & Format URL */ URL url = new URL(CleverBotQuery.formatRequest(CleverBotQuery.URL_STRING, this.key, this.phrase, this.conversationID)); /* Open Connection */ URLConnection urlConnection = url.openConnection(); /* Read input */ BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); String inputLine = in.readLine(); /* Create JSON Object */ JsonObject jsonObject = new JsonParser().parse(inputLine).getAsJsonObject(); // convert to JSON /* Get params */ this.setConversationID(jsonObject.get("cs").getAsString()); // update conversation ID this.setResponse(jsonObject.get("output").getAsString()); // get output this.setRandomNumber(Integer.parseInt(jsonObject.get("random_number").getAsString())); // get output in.close(); // close! }
java
public void sendRequest() throws IOException { /* Create & Format URL */ URL url = new URL(CleverBotQuery.formatRequest(CleverBotQuery.URL_STRING, this.key, this.phrase, this.conversationID)); /* Open Connection */ URLConnection urlConnection = url.openConnection(); /* Read input */ BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); String inputLine = in.readLine(); /* Create JSON Object */ JsonObject jsonObject = new JsonParser().parse(inputLine).getAsJsonObject(); // convert to JSON /* Get params */ this.setConversationID(jsonObject.get("cs").getAsString()); // update conversation ID this.setResponse(jsonObject.get("output").getAsString()); // get output this.setRandomNumber(Integer.parseInt(jsonObject.get("random_number").getAsString())); // get output in.close(); // close! }
[ "public", "void", "sendRequest", "(", ")", "throws", "IOException", "{", "/* Create & Format URL */", "URL", "url", "=", "new", "URL", "(", "CleverBotQuery", ".", "formatRequest", "(", "CleverBotQuery", ".", "URL_STRING", ",", "this", ".", "key", ",", "this", ".", "phrase", ",", "this", ".", "conversationID", ")", ")", ";", "/* Open Connection */", "URLConnection", "urlConnection", "=", "url", ".", "openConnection", "(", ")", ";", "/* Read input */", "BufferedReader", "in", "=", "new", "BufferedReader", "(", "new", "InputStreamReader", "(", "urlConnection", ".", "getInputStream", "(", ")", ")", ")", ";", "String", "inputLine", "=", "in", ".", "readLine", "(", ")", ";", "/* Create JSON Object */", "JsonObject", "jsonObject", "=", "new", "JsonParser", "(", ")", ".", "parse", "(", "inputLine", ")", ".", "getAsJsonObject", "(", ")", ";", "// convert to JSON", "/* Get params */", "this", ".", "setConversationID", "(", "jsonObject", ".", "get", "(", "\"cs\"", ")", ".", "getAsString", "(", ")", ")", ";", "// update conversation ID", "this", ".", "setResponse", "(", "jsonObject", ".", "get", "(", "\"output\"", ")", ".", "getAsString", "(", ")", ")", ";", "// get output", "this", ".", "setRandomNumber", "(", "Integer", ".", "parseInt", "(", "jsonObject", ".", "get", "(", "\"random_number\"", ")", ".", "getAsString", "(", ")", ")", ")", ";", "// get output", "in", ".", "close", "(", ")", ";", "// close!", "}" ]
Sends request to CleverBot servers. API key and phrase should be set prior to this call @throws IOException exception upon query failure
[ "Sends", "request", "to", "CleverBot", "servers", ".", "API", "key", "and", "phrase", "should", "be", "set", "prior", "to", "this", "call" ]
fe6818362eec687cdfeb7ee8deb4d2ee19611676
https://github.com/Headline/CleverBotAPI-Java/blob/fe6818362eec687cdfeb7ee8deb4d2ee19611676/src/main/java/com/michaelwflaherty/cleverbotapi/CleverBotQuery.java#L174-L194
9,766
Headline/CleverBotAPI-Java
src/main/java/com/michaelwflaherty/cleverbotapi/CleverBotQuery.java
CleverBotQuery.formatRequest
private static String formatRequest(String url, String key, String phrase, String conversationID) { String formattedPhrase = phrase.replaceAll("\\s+", "+"); return String.format("%s%s&input=%s&wrapper=Headline22JavaAPI%s", url, key, formattedPhrase, ((conversationID.equals("")) ? "" : ("&cs=" + conversationID))); }
java
private static String formatRequest(String url, String key, String phrase, String conversationID) { String formattedPhrase = phrase.replaceAll("\\s+", "+"); return String.format("%s%s&input=%s&wrapper=Headline22JavaAPI%s", url, key, formattedPhrase, ((conversationID.equals("")) ? "" : ("&cs=" + conversationID))); }
[ "private", "static", "String", "formatRequest", "(", "String", "url", ",", "String", "key", ",", "String", "phrase", ",", "String", "conversationID", ")", "{", "String", "formattedPhrase", "=", "phrase", ".", "replaceAll", "(", "\"\\\\s+\"", ",", "\"+\"", ")", ";", "return", "String", ".", "format", "(", "\"%s%s&input=%s&wrapper=Headline22JavaAPI%s\"", ",", "url", ",", "key", ",", "formattedPhrase", ",", "(", "(", "conversationID", ".", "equals", "(", "\"\"", ")", ")", "?", "\"\"", ":", "(", "\"&cs=\"", "+", "conversationID", ")", ")", ")", ";", "}" ]
URL request formater @param url starting url to connect to @param key API key (cleverbot.com/api) @param phrase input to be sent to CleverBot servers @param conversationID unique conversation identifer @return String object containing properly formatted URL
[ "URL", "request", "formater" ]
fe6818362eec687cdfeb7ee8deb4d2ee19611676
https://github.com/Headline/CleverBotAPI-Java/blob/fe6818362eec687cdfeb7ee8deb4d2ee19611676/src/main/java/com/michaelwflaherty/cleverbotapi/CleverBotQuery.java#L206-L210
9,767
sarxos/v4l4j
src/main/java/au/edu/jcu/v4l4j/ImageFormatList.java
ImageFormatList.moveNativeFirst
private void moveNativeFirst(List<ImageFormat> v){ int index=0; for(int i=0; i<v.size();i++) //if not native format if(!formats.contains(v.get(index))){ //put it at the end v.add(v.remove(index)); } else index++; }
java
private void moveNativeFirst(List<ImageFormat> v){ int index=0; for(int i=0; i<v.size();i++) //if not native format if(!formats.contains(v.get(index))){ //put it at the end v.add(v.remove(index)); } else index++; }
[ "private", "void", "moveNativeFirst", "(", "List", "<", "ImageFormat", ">", "v", ")", "{", "int", "index", "=", "0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "v", ".", "size", "(", ")", ";", "i", "++", ")", "//if not native format", "if", "(", "!", "formats", ".", "contains", "(", "v", ".", "get", "(", "index", ")", ")", ")", "{", "//put it at the end", "v", ".", "add", "(", "v", ".", "remove", "(", "index", ")", ")", ";", "}", "else", "index", "++", ";", "}" ]
This method moves the native formats in the given vector to the beginning of the vector. @param v the vector to be sorted
[ "This", "method", "moves", "the", "native", "formats", "in", "the", "given", "vector", "to", "the", "beginning", "of", "the", "vector", "." ]
4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9
https://github.com/sarxos/v4l4j/blob/4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9/src/main/java/au/edu/jcu/v4l4j/ImageFormatList.java#L191-L200
9,768
sarxos/v4l4j
src/main/java/au/edu/jcu/v4l4j/ImageFormatList.java
ImageFormatList.getFormat
private ImageFormat getFormat(List<ImageFormat> l, String n){ for(ImageFormat f:l) if(f.getName().equals(n)) return f; return null; }
java
private ImageFormat getFormat(List<ImageFormat> l, String n){ for(ImageFormat f:l) if(f.getName().equals(n)) return f; return null; }
[ "private", "ImageFormat", "getFormat", "(", "List", "<", "ImageFormat", ">", "l", ",", "String", "n", ")", "{", "for", "(", "ImageFormat", "f", ":", "l", ")", "if", "(", "f", ".", "getName", "(", ")", ".", "equals", "(", "n", ")", ")", "return", "f", ";", "return", "null", ";", "}" ]
this method returns a format in a list given its name @param l the image format list @param n the name of the format @return the image format with the given name, or null
[ "this", "method", "returns", "a", "format", "in", "a", "list", "given", "its", "name" ]
4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9
https://github.com/sarxos/v4l4j/blob/4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9/src/main/java/au/edu/jcu/v4l4j/ImageFormatList.java#L208-L213
9,769
sarxos/v4l4j
src/main/java/au/edu/jcu/v4l4j/ImageFormatList.java
ImageFormatList.getFormat
private ImageFormat getFormat(List<ImageFormat> l, int i){ for(ImageFormat f:l) if(f.getIndex()==i) return f; return null; }
java
private ImageFormat getFormat(List<ImageFormat> l, int i){ for(ImageFormat f:l) if(f.getIndex()==i) return f; return null; }
[ "private", "ImageFormat", "getFormat", "(", "List", "<", "ImageFormat", ">", "l", ",", "int", "i", ")", "{", "for", "(", "ImageFormat", "f", ":", "l", ")", "if", "(", "f", ".", "getIndex", "(", ")", "==", "i", ")", "return", "f", ";", "return", "null", ";", "}" ]
this method returns a format in a list given its index @param l the image format list @param i the index of the format @return the image format with the given index, or null
[ "this", "method", "returns", "a", "format", "in", "a", "list", "given", "its", "index" ]
4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9
https://github.com/sarxos/v4l4j/blob/4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9/src/main/java/au/edu/jcu/v4l4j/ImageFormatList.java#L221-L226
9,770
sarxos/v4l4j
src/main/java/com/github/sarxos/v4l4j/NativeUtils.java
NativeUtils.loadLibraryFromJar
public static void loadLibraryFromJar(String jarpath, String[] libs) throws IOException { File libspath = File.createTempFile("libs", ""); if (!libspath.delete()) { throw new IOException("Cannot clean " + libspath); } if (!libspath.exists()) { if (!libspath.mkdirs()) { throw new IOException("Cannot create directory " + libspath); } } libspath.deleteOnExit(); try { addLibraryPath(libspath.getAbsolutePath()); } catch (Exception e) { throw new IOException(e); } for (String lib : libs) { String libfile = "lib" + lib + ".so"; String path = jarpath + "/" + libfile; if (!path.startsWith("/")) { throw new IllegalArgumentException("The path to be absolute (start with '/')."); } File file = new File(libspath, libfile); file.createNewFile(); file.deleteOnExit(); byte[] buffer = new byte[1024]; int readBytes; InputStream is = NativeUtils.class.getResourceAsStream(path); if (is == null) { throw new FileNotFoundException("File " + path + " was not found inside JAR."); } OutputStream os = new FileOutputStream(file); try { while ((readBytes = is.read(buffer)) != -1) { os.write(buffer, 0, readBytes); } } finally { os.close(); is.close(); } } for (String lib : libs) { System.loadLibrary(lib); } }
java
public static void loadLibraryFromJar(String jarpath, String[] libs) throws IOException { File libspath = File.createTempFile("libs", ""); if (!libspath.delete()) { throw new IOException("Cannot clean " + libspath); } if (!libspath.exists()) { if (!libspath.mkdirs()) { throw new IOException("Cannot create directory " + libspath); } } libspath.deleteOnExit(); try { addLibraryPath(libspath.getAbsolutePath()); } catch (Exception e) { throw new IOException(e); } for (String lib : libs) { String libfile = "lib" + lib + ".so"; String path = jarpath + "/" + libfile; if (!path.startsWith("/")) { throw new IllegalArgumentException("The path to be absolute (start with '/')."); } File file = new File(libspath, libfile); file.createNewFile(); file.deleteOnExit(); byte[] buffer = new byte[1024]; int readBytes; InputStream is = NativeUtils.class.getResourceAsStream(path); if (is == null) { throw new FileNotFoundException("File " + path + " was not found inside JAR."); } OutputStream os = new FileOutputStream(file); try { while ((readBytes = is.read(buffer)) != -1) { os.write(buffer, 0, readBytes); } } finally { os.close(); is.close(); } } for (String lib : libs) { System.loadLibrary(lib); } }
[ "public", "static", "void", "loadLibraryFromJar", "(", "String", "jarpath", ",", "String", "[", "]", "libs", ")", "throws", "IOException", "{", "File", "libspath", "=", "File", ".", "createTempFile", "(", "\"libs\"", ",", "\"\"", ")", ";", "if", "(", "!", "libspath", ".", "delete", "(", ")", ")", "{", "throw", "new", "IOException", "(", "\"Cannot clean \"", "+", "libspath", ")", ";", "}", "if", "(", "!", "libspath", ".", "exists", "(", ")", ")", "{", "if", "(", "!", "libspath", ".", "mkdirs", "(", ")", ")", "{", "throw", "new", "IOException", "(", "\"Cannot create directory \"", "+", "libspath", ")", ";", "}", "}", "libspath", ".", "deleteOnExit", "(", ")", ";", "try", "{", "addLibraryPath", "(", "libspath", ".", "getAbsolutePath", "(", ")", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "IOException", "(", "e", ")", ";", "}", "for", "(", "String", "lib", ":", "libs", ")", "{", "String", "libfile", "=", "\"lib\"", "+", "lib", "+", "\".so\"", ";", "String", "path", "=", "jarpath", "+", "\"/\"", "+", "libfile", ";", "if", "(", "!", "path", ".", "startsWith", "(", "\"/\"", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"The path to be absolute (start with '/').\"", ")", ";", "}", "File", "file", "=", "new", "File", "(", "libspath", ",", "libfile", ")", ";", "file", ".", "createNewFile", "(", ")", ";", "file", ".", "deleteOnExit", "(", ")", ";", "byte", "[", "]", "buffer", "=", "new", "byte", "[", "1024", "]", ";", "int", "readBytes", ";", "InputStream", "is", "=", "NativeUtils", ".", "class", ".", "getResourceAsStream", "(", "path", ")", ";", "if", "(", "is", "==", "null", ")", "{", "throw", "new", "FileNotFoundException", "(", "\"File \"", "+", "path", "+", "\" was not found inside JAR.\"", ")", ";", "}", "OutputStream", "os", "=", "new", "FileOutputStream", "(", "file", ")", ";", "try", "{", "while", "(", "(", "readBytes", "=", "is", ".", "read", "(", "buffer", ")", ")", "!=", "-", "1", ")", "{", "os", ".", "write", "(", "buffer", ",", "0", ",", "readBytes", ")", ";", "}", "}", "finally", "{", "os", ".", "close", "(", ")", ";", "is", ".", "close", "(", ")", ";", "}", "}", "for", "(", "String", "lib", ":", "libs", ")", "{", "System", ".", "loadLibrary", "(", "lib", ")", ";", "}", "}" ]
Loads library from current JAR archive The file from JAR is copied into system temporary directory and then loaded. The temporary file is deleted after exiting. Method uses String as filename because the pathname is "abstract", not system-dependent. @param filename The filename inside JAR as absolute path (beginning with '/'), e.g. /package/File.ext @throws IOException If temporary file creation or read/write operation fails @throws IllegalArgumentException If source file (param path) does not exist @throws IllegalArgumentException If the path is not absolute or if the filename is shorter than three characters (restriction of {@see File#createTempFile(java.lang.String, java.lang.String)}).
[ "Loads", "library", "from", "current", "JAR", "archive" ]
4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9
https://github.com/sarxos/v4l4j/blob/4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9/src/main/java/com/github/sarxos/v4l4j/NativeUtils.java#L45-L100
9,771
sarxos/v4l4j
src/main/java/com/github/sarxos/v4l4j/NativeUtils.java
NativeUtils.addLibraryPath
public static void addLibraryPath(String pathToAdd) throws Exception { Field usrPathsField = ClassLoader.class.getDeclaredField("usr_paths"); usrPathsField.setAccessible(true); // get array of paths final String[] paths = (String[]) usrPathsField.get(null); // check if the path to add is already present for (String path : paths) { if (path.equals(pathToAdd)) { return; } } // add the new path final String[] newPaths = Arrays.copyOf(paths, paths.length + 1); newPaths[newPaths.length - 1] = pathToAdd; usrPathsField.set(null, newPaths); }
java
public static void addLibraryPath(String pathToAdd) throws Exception { Field usrPathsField = ClassLoader.class.getDeclaredField("usr_paths"); usrPathsField.setAccessible(true); // get array of paths final String[] paths = (String[]) usrPathsField.get(null); // check if the path to add is already present for (String path : paths) { if (path.equals(pathToAdd)) { return; } } // add the new path final String[] newPaths = Arrays.copyOf(paths, paths.length + 1); newPaths[newPaths.length - 1] = pathToAdd; usrPathsField.set(null, newPaths); }
[ "public", "static", "void", "addLibraryPath", "(", "String", "pathToAdd", ")", "throws", "Exception", "{", "Field", "usrPathsField", "=", "ClassLoader", ".", "class", ".", "getDeclaredField", "(", "\"usr_paths\"", ")", ";", "usrPathsField", ".", "setAccessible", "(", "true", ")", ";", "// get array of paths", "final", "String", "[", "]", "paths", "=", "(", "String", "[", "]", ")", "usrPathsField", ".", "get", "(", "null", ")", ";", "// check if the path to add is already present", "for", "(", "String", "path", ":", "paths", ")", "{", "if", "(", "path", ".", "equals", "(", "pathToAdd", ")", ")", "{", "return", ";", "}", "}", "// add the new path", "final", "String", "[", "]", "newPaths", "=", "Arrays", ".", "copyOf", "(", "paths", ",", "paths", ".", "length", "+", "1", ")", ";", "newPaths", "[", "newPaths", ".", "length", "-", "1", "]", "=", "pathToAdd", ";", "usrPathsField", ".", "set", "(", "null", ",", "newPaths", ")", ";", "}" ]
Adds the specified path to the java library path @param pathToAdd the path to add @throws Exception
[ "Adds", "the", "specified", "path", "to", "the", "java", "library", "path" ]
4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9
https://github.com/sarxos/v4l4j/blob/4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9/src/main/java/com/github/sarxos/v4l4j/NativeUtils.java#L108-L126
9,772
google/identity-toolkit-java-client
src/main/java/com/google/identitytoolkit/RpcHelper.java
RpcHelper.getAccountInfo
public JSONObject getAccountInfo(String idToken) throws GitkitClientException, GitkitServerException { try { // Uses idToken to make the server call to GITKit JSONObject params = new JSONObject().put("idToken", idToken); return invokeGoogle2LegOauthApi("getAccountInfo", params); } catch (JSONException e) { throw new GitkitServerException("OAuth API failed"); } }
java
public JSONObject getAccountInfo(String idToken) throws GitkitClientException, GitkitServerException { try { // Uses idToken to make the server call to GITKit JSONObject params = new JSONObject().put("idToken", idToken); return invokeGoogle2LegOauthApi("getAccountInfo", params); } catch (JSONException e) { throw new GitkitServerException("OAuth API failed"); } }
[ "public", "JSONObject", "getAccountInfo", "(", "String", "idToken", ")", "throws", "GitkitClientException", ",", "GitkitServerException", "{", "try", "{", "// Uses idToken to make the server call to GITKit", "JSONObject", "params", "=", "new", "JSONObject", "(", ")", ".", "put", "(", "\"idToken\"", ",", "idToken", ")", ";", "return", "invokeGoogle2LegOauthApi", "(", "\"getAccountInfo\"", ",", "params", ")", ";", "}", "catch", "(", "JSONException", "e", ")", "{", "throw", "new", "GitkitServerException", "(", "\"OAuth API failed\"", ")", ";", "}", "}" ]
Uses idToken to retrieve the user account information from GITkit service. @param idToken
[ "Uses", "idToken", "to", "retrieve", "the", "user", "account", "information", "from", "GITkit", "service", "." ]
61dda1aabbd541ad5e431e840fd266bfca5f8a4a
https://github.com/google/identity-toolkit-java-client/blob/61dda1aabbd541ad5e431e840fd266bfca5f8a4a/src/main/java/com/google/identitytoolkit/RpcHelper.java#L129-L138
9,773
sonatype/jarjar-maven-plugin
src/main/java/com/tonicsystems/jarjar/util/IoUtil.java
IoUtil.copyZipWithoutEmptyDirectories
public static void copyZipWithoutEmptyDirectories(final File inputFile, final File outputFile) throws IOException { final byte[] buf = new byte[0x2000]; final ZipFile inputZip = new ZipFile(inputFile); final ZipOutputStream outputStream = new ZipOutputStream(new FileOutputStream(outputFile)); try { // read a the entries of the input zip file and sort them final Enumeration<? extends ZipEntry> e = inputZip.entries(); final ArrayList<ZipEntry> sortedList = new ArrayList<ZipEntry>(); while (e.hasMoreElements()) { final ZipEntry entry = e.nextElement(); sortedList.add(entry); } Collections.sort(sortedList, new Comparator<ZipEntry>() { public int compare(ZipEntry o1, ZipEntry o2) { String n1 = o1.getName(), n2 = o2.getName(); if (metaOverride(n1, n2)) { return -1; } if (metaOverride(n2, n1)) { return 1; } return n1.compareTo(n2); } // make sure that META-INF/MANIFEST.MF is always the first entry after META-INF/ private boolean metaOverride(String n1, String n2) { return (n1.startsWith("META-INF/") && !n2.startsWith("META-INF/")) || (n1.equals("META-INF/MANIFEST.MF") && !n2.equals(n1) && !n2.equals("META-INF/")) || (n1.equals("META-INF/") && !n2.equals(n1)); } }); // treat them again and write them in output, wenn they not are empty directories for (int i = sortedList.size()-1; i>=0; i--) { final ZipEntry inputEntry = sortedList.get(i); final String name = inputEntry.getName(); final boolean isEmptyDirectory; if (inputEntry.isDirectory()) { if (i == sortedList.size()-1) { // no item afterwards; it was an empty directory isEmptyDirectory = true; } else { final String nextName = sortedList.get(i+1).getName(); isEmptyDirectory = !nextName.startsWith(name); } } else { isEmptyDirectory = false; } if (isEmptyDirectory) { sortedList.remove(i); } } // finally write entries in normal order for (int i = 0; i < sortedList.size(); i++) { final ZipEntry inputEntry = sortedList.get(i); final ZipEntry outputEntry = new ZipEntry(inputEntry); outputStream.putNextEntry(outputEntry); ByteArrayOutputStream baos = new ByteArrayOutputStream(); final InputStream is = inputZip.getInputStream(inputEntry); IoUtil.pipe(is, baos, buf); is.close(); outputStream.write(baos.toByteArray()); } } finally { outputStream.close(); inputZip.close(); } }
java
public static void copyZipWithoutEmptyDirectories(final File inputFile, final File outputFile) throws IOException { final byte[] buf = new byte[0x2000]; final ZipFile inputZip = new ZipFile(inputFile); final ZipOutputStream outputStream = new ZipOutputStream(new FileOutputStream(outputFile)); try { // read a the entries of the input zip file and sort them final Enumeration<? extends ZipEntry> e = inputZip.entries(); final ArrayList<ZipEntry> sortedList = new ArrayList<ZipEntry>(); while (e.hasMoreElements()) { final ZipEntry entry = e.nextElement(); sortedList.add(entry); } Collections.sort(sortedList, new Comparator<ZipEntry>() { public int compare(ZipEntry o1, ZipEntry o2) { String n1 = o1.getName(), n2 = o2.getName(); if (metaOverride(n1, n2)) { return -1; } if (metaOverride(n2, n1)) { return 1; } return n1.compareTo(n2); } // make sure that META-INF/MANIFEST.MF is always the first entry after META-INF/ private boolean metaOverride(String n1, String n2) { return (n1.startsWith("META-INF/") && !n2.startsWith("META-INF/")) || (n1.equals("META-INF/MANIFEST.MF") && !n2.equals(n1) && !n2.equals("META-INF/")) || (n1.equals("META-INF/") && !n2.equals(n1)); } }); // treat them again and write them in output, wenn they not are empty directories for (int i = sortedList.size()-1; i>=0; i--) { final ZipEntry inputEntry = sortedList.get(i); final String name = inputEntry.getName(); final boolean isEmptyDirectory; if (inputEntry.isDirectory()) { if (i == sortedList.size()-1) { // no item afterwards; it was an empty directory isEmptyDirectory = true; } else { final String nextName = sortedList.get(i+1).getName(); isEmptyDirectory = !nextName.startsWith(name); } } else { isEmptyDirectory = false; } if (isEmptyDirectory) { sortedList.remove(i); } } // finally write entries in normal order for (int i = 0; i < sortedList.size(); i++) { final ZipEntry inputEntry = sortedList.get(i); final ZipEntry outputEntry = new ZipEntry(inputEntry); outputStream.putNextEntry(outputEntry); ByteArrayOutputStream baos = new ByteArrayOutputStream(); final InputStream is = inputZip.getInputStream(inputEntry); IoUtil.pipe(is, baos, buf); is.close(); outputStream.write(baos.toByteArray()); } } finally { outputStream.close(); inputZip.close(); } }
[ "public", "static", "void", "copyZipWithoutEmptyDirectories", "(", "final", "File", "inputFile", ",", "final", "File", "outputFile", ")", "throws", "IOException", "{", "final", "byte", "[", "]", "buf", "=", "new", "byte", "[", "0x2000", "]", ";", "final", "ZipFile", "inputZip", "=", "new", "ZipFile", "(", "inputFile", ")", ";", "final", "ZipOutputStream", "outputStream", "=", "new", "ZipOutputStream", "(", "new", "FileOutputStream", "(", "outputFile", ")", ")", ";", "try", "{", "// read a the entries of the input zip file and sort them", "final", "Enumeration", "<", "?", "extends", "ZipEntry", ">", "e", "=", "inputZip", ".", "entries", "(", ")", ";", "final", "ArrayList", "<", "ZipEntry", ">", "sortedList", "=", "new", "ArrayList", "<", "ZipEntry", ">", "(", ")", ";", "while", "(", "e", ".", "hasMoreElements", "(", ")", ")", "{", "final", "ZipEntry", "entry", "=", "e", ".", "nextElement", "(", ")", ";", "sortedList", ".", "add", "(", "entry", ")", ";", "}", "Collections", ".", "sort", "(", "sortedList", ",", "new", "Comparator", "<", "ZipEntry", ">", "(", ")", "{", "public", "int", "compare", "(", "ZipEntry", "o1", ",", "ZipEntry", "o2", ")", "{", "String", "n1", "=", "o1", ".", "getName", "(", ")", ",", "n2", "=", "o2", ".", "getName", "(", ")", ";", "if", "(", "metaOverride", "(", "n1", ",", "n2", ")", ")", "{", "return", "-", "1", ";", "}", "if", "(", "metaOverride", "(", "n2", ",", "n1", ")", ")", "{", "return", "1", ";", "}", "return", "n1", ".", "compareTo", "(", "n2", ")", ";", "}", "// make sure that META-INF/MANIFEST.MF is always the first entry after META-INF/", "private", "boolean", "metaOverride", "(", "String", "n1", ",", "String", "n2", ")", "{", "return", "(", "n1", ".", "startsWith", "(", "\"META-INF/\"", ")", "&&", "!", "n2", ".", "startsWith", "(", "\"META-INF/\"", ")", ")", "||", "(", "n1", ".", "equals", "(", "\"META-INF/MANIFEST.MF\"", ")", "&&", "!", "n2", ".", "equals", "(", "n1", ")", "&&", "!", "n2", ".", "equals", "(", "\"META-INF/\"", ")", ")", "||", "(", "n1", ".", "equals", "(", "\"META-INF/\"", ")", "&&", "!", "n2", ".", "equals", "(", "n1", ")", ")", ";", "}", "}", ")", ";", "// treat them again and write them in output, wenn they not are empty directories", "for", "(", "int", "i", "=", "sortedList", ".", "size", "(", ")", "-", "1", ";", "i", ">=", "0", ";", "i", "--", ")", "{", "final", "ZipEntry", "inputEntry", "=", "sortedList", ".", "get", "(", "i", ")", ";", "final", "String", "name", "=", "inputEntry", ".", "getName", "(", ")", ";", "final", "boolean", "isEmptyDirectory", ";", "if", "(", "inputEntry", ".", "isDirectory", "(", ")", ")", "{", "if", "(", "i", "==", "sortedList", ".", "size", "(", ")", "-", "1", ")", "{", "// no item afterwards; it was an empty directory", "isEmptyDirectory", "=", "true", ";", "}", "else", "{", "final", "String", "nextName", "=", "sortedList", ".", "get", "(", "i", "+", "1", ")", ".", "getName", "(", ")", ";", "isEmptyDirectory", "=", "!", "nextName", ".", "startsWith", "(", "name", ")", ";", "}", "}", "else", "{", "isEmptyDirectory", "=", "false", ";", "}", "if", "(", "isEmptyDirectory", ")", "{", "sortedList", ".", "remove", "(", "i", ")", ";", "}", "}", "// finally write entries in normal order", "for", "(", "int", "i", "=", "0", ";", "i", "<", "sortedList", ".", "size", "(", ")", ";", "i", "++", ")", "{", "final", "ZipEntry", "inputEntry", "=", "sortedList", ".", "get", "(", "i", ")", ";", "final", "ZipEntry", "outputEntry", "=", "new", "ZipEntry", "(", "inputEntry", ")", ";", "outputStream", ".", "putNextEntry", "(", "outputEntry", ")", ";", "ByteArrayOutputStream", "baos", "=", "new", "ByteArrayOutputStream", "(", ")", ";", "final", "InputStream", "is", "=", "inputZip", ".", "getInputStream", "(", "inputEntry", ")", ";", "IoUtil", ".", "pipe", "(", "is", ",", "baos", ",", "buf", ")", ";", "is", ".", "close", "(", ")", ";", "outputStream", ".", "write", "(", "baos", ".", "toByteArray", "(", ")", ")", ";", "}", "}", "finally", "{", "outputStream", ".", "close", "(", ")", ";", "inputZip", ".", "close", "(", ")", ";", "}", "}" ]
Create a copy of an zip file without its empty directories. @param inputFile @param outputFile @throws IOException
[ "Create", "a", "copy", "of", "an", "zip", "file", "without", "its", "empty", "directories", "." ]
3fe3f8db91da18f7ded73e09d19525bc1d83631b
https://github.com/sonatype/jarjar-maven-plugin/blob/3fe3f8db91da18f7ded73e09d19525bc1d83631b/src/main/java/com/tonicsystems/jarjar/util/IoUtil.java#L60-L145
9,774
google/identity-toolkit-java-client
src/main/java/com/google/identitytoolkit/GitkitClient.java
GitkitClient.validateTokenInRequest
public GitkitUser validateTokenInRequest(HttpServletRequest request) throws GitkitClientException { Cookie[] cookies = request.getCookies(); if (cookieName == null || cookies == null) { return null; } for (Cookie cookie : cookies) { if (cookieName.equals(cookie.getName())) { return validateToken(cookie.getValue()); } } return null; }
java
public GitkitUser validateTokenInRequest(HttpServletRequest request) throws GitkitClientException { Cookie[] cookies = request.getCookies(); if (cookieName == null || cookies == null) { return null; } for (Cookie cookie : cookies) { if (cookieName.equals(cookie.getName())) { return validateToken(cookie.getValue()); } } return null; }
[ "public", "GitkitUser", "validateTokenInRequest", "(", "HttpServletRequest", "request", ")", "throws", "GitkitClientException", "{", "Cookie", "[", "]", "cookies", "=", "request", ".", "getCookies", "(", ")", ";", "if", "(", "cookieName", "==", "null", "||", "cookies", "==", "null", ")", "{", "return", "null", ";", "}", "for", "(", "Cookie", "cookie", ":", "cookies", ")", "{", "if", "(", "cookieName", ".", "equals", "(", "cookie", ".", "getName", "(", ")", ")", ")", "{", "return", "validateToken", "(", "cookie", ".", "getValue", "(", ")", ")", ";", "}", "}", "return", "null", ";", "}" ]
Verifies Gitkit token in http request. @param request http request @return Gitkit user if valid token is found in the request. @throws GitkitClientException if there is token but signature is invalid
[ "Verifies", "Gitkit", "token", "in", "http", "request", "." ]
61dda1aabbd541ad5e431e840fd266bfca5f8a4a
https://github.com/google/identity-toolkit-java-client/blob/61dda1aabbd541ad5e431e840fd266bfca5f8a4a/src/main/java/com/google/identitytoolkit/GitkitClient.java#L205-L218
9,775
google/identity-toolkit-java-client
src/main/java/com/google/identitytoolkit/GitkitClient.java
GitkitClient.getUserByToken
public GitkitUser getUserByToken(String token) throws GitkitClientException, GitkitServerException { GitkitUser gitkitUser = validateToken(token); if (gitkitUser == null) { throw new GitkitClientException("invalid gitkit token"); } try { JSONObject result = rpcHelper.getAccountInfo(token); JSONObject jsonUser = result.getJSONArray("users").getJSONObject(0); return jsonToUser(jsonUser) // gitkit server does not return current provider .setCurrentProvider(gitkitUser.getCurrentProvider()); } catch (JSONException e) { throw new GitkitServerException(e); } }
java
public GitkitUser getUserByToken(String token) throws GitkitClientException, GitkitServerException { GitkitUser gitkitUser = validateToken(token); if (gitkitUser == null) { throw new GitkitClientException("invalid gitkit token"); } try { JSONObject result = rpcHelper.getAccountInfo(token); JSONObject jsonUser = result.getJSONArray("users").getJSONObject(0); return jsonToUser(jsonUser) // gitkit server does not return current provider .setCurrentProvider(gitkitUser.getCurrentProvider()); } catch (JSONException e) { throw new GitkitServerException(e); } }
[ "public", "GitkitUser", "getUserByToken", "(", "String", "token", ")", "throws", "GitkitClientException", ",", "GitkitServerException", "{", "GitkitUser", "gitkitUser", "=", "validateToken", "(", "token", ")", ";", "if", "(", "gitkitUser", "==", "null", ")", "{", "throw", "new", "GitkitClientException", "(", "\"invalid gitkit token\"", ")", ";", "}", "try", "{", "JSONObject", "result", "=", "rpcHelper", ".", "getAccountInfo", "(", "token", ")", ";", "JSONObject", "jsonUser", "=", "result", ".", "getJSONArray", "(", "\"users\"", ")", ".", "getJSONObject", "(", "0", ")", ";", "return", "jsonToUser", "(", "jsonUser", ")", "// gitkit server does not return current provider", ".", "setCurrentProvider", "(", "gitkitUser", ".", "getCurrentProvider", "(", ")", ")", ";", "}", "catch", "(", "JSONException", "e", ")", "{", "throw", "new", "GitkitServerException", "(", "e", ")", ";", "}", "}" ]
Gets user info from GITkit service using Gitkit token. Can be used to verify a Gitkit token remotely. @param token the gitkit token. @return Gitkit user info if token is valid. @throws GitkitClientException if request is invalid @throws GitkitServerException for Gitkit server error
[ "Gets", "user", "info", "from", "GITkit", "service", "using", "Gitkit", "token", ".", "Can", "be", "used", "to", "verify", "a", "Gitkit", "token", "remotely", "." ]
61dda1aabbd541ad5e431e840fd266bfca5f8a4a
https://github.com/google/identity-toolkit-java-client/blob/61dda1aabbd541ad5e431e840fd266bfca5f8a4a/src/main/java/com/google/identitytoolkit/GitkitClient.java#L264-L279
9,776
google/identity-toolkit-java-client
src/main/java/com/google/identitytoolkit/GitkitClient.java
GitkitClient.getUserByEmail
public GitkitUser getUserByEmail(String email) throws GitkitClientException, GitkitServerException { Preconditions.checkNotNull(email); try { JSONObject result = rpcHelper.getAccountInfoByEmail(email); return jsonToUser(result.getJSONArray("users").getJSONObject(0)); } catch (JSONException e) { throw new GitkitServerException(e); } }
java
public GitkitUser getUserByEmail(String email) throws GitkitClientException, GitkitServerException { Preconditions.checkNotNull(email); try { JSONObject result = rpcHelper.getAccountInfoByEmail(email); return jsonToUser(result.getJSONArray("users").getJSONObject(0)); } catch (JSONException e) { throw new GitkitServerException(e); } }
[ "public", "GitkitUser", "getUserByEmail", "(", "String", "email", ")", "throws", "GitkitClientException", ",", "GitkitServerException", "{", "Preconditions", ".", "checkNotNull", "(", "email", ")", ";", "try", "{", "JSONObject", "result", "=", "rpcHelper", ".", "getAccountInfoByEmail", "(", "email", ")", ";", "return", "jsonToUser", "(", "result", ".", "getJSONArray", "(", "\"users\"", ")", ".", "getJSONObject", "(", "0", ")", ")", ";", "}", "catch", "(", "JSONException", "e", ")", "{", "throw", "new", "GitkitServerException", "(", "e", ")", ";", "}", "}" ]
Gets user info given an email. @param email user email. @return Gitkit user info. @throws GitkitClientException if request is invalid @throws GitkitServerException for Gitkit server error
[ "Gets", "user", "info", "given", "an", "email", "." ]
61dda1aabbd541ad5e431e840fd266bfca5f8a4a
https://github.com/google/identity-toolkit-java-client/blob/61dda1aabbd541ad5e431e840fd266bfca5f8a4a/src/main/java/com/google/identitytoolkit/GitkitClient.java#L289-L298
9,777
google/identity-toolkit-java-client
src/main/java/com/google/identitytoolkit/GitkitClient.java
GitkitClient.getUserByLocalId
public GitkitUser getUserByLocalId(String localId) throws GitkitClientException, GitkitServerException { Preconditions.checkNotNull(localId); try { JSONObject result = rpcHelper.getAccountInfoById(localId); return jsonToUser(result.getJSONArray("users").getJSONObject(0)); } catch (JSONException e) { throw new GitkitServerException(e); } }
java
public GitkitUser getUserByLocalId(String localId) throws GitkitClientException, GitkitServerException { Preconditions.checkNotNull(localId); try { JSONObject result = rpcHelper.getAccountInfoById(localId); return jsonToUser(result.getJSONArray("users").getJSONObject(0)); } catch (JSONException e) { throw new GitkitServerException(e); } }
[ "public", "GitkitUser", "getUserByLocalId", "(", "String", "localId", ")", "throws", "GitkitClientException", ",", "GitkitServerException", "{", "Preconditions", ".", "checkNotNull", "(", "localId", ")", ";", "try", "{", "JSONObject", "result", "=", "rpcHelper", ".", "getAccountInfoById", "(", "localId", ")", ";", "return", "jsonToUser", "(", "result", ".", "getJSONArray", "(", "\"users\"", ")", ".", "getJSONObject", "(", "0", ")", ")", ";", "}", "catch", "(", "JSONException", "e", ")", "{", "throw", "new", "GitkitServerException", "(", "e", ")", ";", "}", "}" ]
Gets user info given a user id. @param localId user identifier at Gitkit. @return Gitkit user info. @throws GitkitClientException if request is invalid @throws GitkitServerException for Gitkit server error
[ "Gets", "user", "info", "given", "a", "user", "id", "." ]
61dda1aabbd541ad5e431e840fd266bfca5f8a4a
https://github.com/google/identity-toolkit-java-client/blob/61dda1aabbd541ad5e431e840fd266bfca5f8a4a/src/main/java/com/google/identitytoolkit/GitkitClient.java#L308-L317
9,778
google/identity-toolkit-java-client
src/main/java/com/google/identitytoolkit/GitkitClient.java
GitkitClient.getAllUsers
public Iterator<GitkitUser> getAllUsers(final Integer resultsPerRequest) { return new DownloadIterator<GitkitUser>() { private String nextPageToken = null; @Override protected Iterator<GitkitUser> getNextResults() { try { JSONObject response = rpcHelper.downloadAccount(nextPageToken, resultsPerRequest); nextPageToken = response.has("nextPageToken") ? response.getString("nextPageToken") : null; if (response.has("users")) { return jsonToList(response.getJSONArray("users")).iterator(); } } catch (JSONException e) { logger.warning(e.getMessage()); } catch (GitkitServerException e) { logger.warning(e.getMessage()); } catch (GitkitClientException e) { logger.warning(e.getMessage()); } return ImmutableSet.<GitkitUser>of().iterator(); } }; }
java
public Iterator<GitkitUser> getAllUsers(final Integer resultsPerRequest) { return new DownloadIterator<GitkitUser>() { private String nextPageToken = null; @Override protected Iterator<GitkitUser> getNextResults() { try { JSONObject response = rpcHelper.downloadAccount(nextPageToken, resultsPerRequest); nextPageToken = response.has("nextPageToken") ? response.getString("nextPageToken") : null; if (response.has("users")) { return jsonToList(response.getJSONArray("users")).iterator(); } } catch (JSONException e) { logger.warning(e.getMessage()); } catch (GitkitServerException e) { logger.warning(e.getMessage()); } catch (GitkitClientException e) { logger.warning(e.getMessage()); } return ImmutableSet.<GitkitUser>of().iterator(); } }; }
[ "public", "Iterator", "<", "GitkitUser", ">", "getAllUsers", "(", "final", "Integer", "resultsPerRequest", ")", "{", "return", "new", "DownloadIterator", "<", "GitkitUser", ">", "(", ")", "{", "private", "String", "nextPageToken", "=", "null", ";", "@", "Override", "protected", "Iterator", "<", "GitkitUser", ">", "getNextResults", "(", ")", "{", "try", "{", "JSONObject", "response", "=", "rpcHelper", ".", "downloadAccount", "(", "nextPageToken", ",", "resultsPerRequest", ")", ";", "nextPageToken", "=", "response", ".", "has", "(", "\"nextPageToken\"", ")", "?", "response", ".", "getString", "(", "\"nextPageToken\"", ")", ":", "null", ";", "if", "(", "response", ".", "has", "(", "\"users\"", ")", ")", "{", "return", "jsonToList", "(", "response", ".", "getJSONArray", "(", "\"users\"", ")", ")", ".", "iterator", "(", ")", ";", "}", "}", "catch", "(", "JSONException", "e", ")", "{", "logger", ".", "warning", "(", "e", ".", "getMessage", "(", ")", ")", ";", "}", "catch", "(", "GitkitServerException", "e", ")", "{", "logger", ".", "warning", "(", "e", ".", "getMessage", "(", ")", ")", ";", "}", "catch", "(", "GitkitClientException", "e", ")", "{", "logger", ".", "warning", "(", "e", ".", "getMessage", "(", ")", ")", ";", "}", "return", "ImmutableSet", ".", "<", "GitkitUser", ">", "of", "(", ")", ".", "iterator", "(", ")", ";", "}", "}", ";", "}" ]
Gets all user info of this web site. Underlying requests are paginated and send on demand with given size. @param resultsPerRequest pagination size @return lazy iterator over all user accounts.
[ "Gets", "all", "user", "info", "of", "this", "web", "site", ".", "Underlying", "requests", "are", "paginated", "and", "send", "on", "demand", "with", "given", "size", "." ]
61dda1aabbd541ad5e431e840fd266bfca5f8a4a
https://github.com/google/identity-toolkit-java-client/blob/61dda1aabbd541ad5e431e840fd266bfca5f8a4a/src/main/java/com/google/identitytoolkit/GitkitClient.java#L335-L360
9,779
google/identity-toolkit-java-client
src/main/java/com/google/identitytoolkit/GitkitClient.java
GitkitClient.updateUser
public GitkitUser updateUser(GitkitUser user) throws GitkitClientException, GitkitServerException { try { return jsonToUser(rpcHelper.updateAccount(user)); } catch (JSONException e) { throw new GitkitServerException(e); } }
java
public GitkitUser updateUser(GitkitUser user) throws GitkitClientException, GitkitServerException { try { return jsonToUser(rpcHelper.updateAccount(user)); } catch (JSONException e) { throw new GitkitServerException(e); } }
[ "public", "GitkitUser", "updateUser", "(", "GitkitUser", "user", ")", "throws", "GitkitClientException", ",", "GitkitServerException", "{", "try", "{", "return", "jsonToUser", "(", "rpcHelper", ".", "updateAccount", "(", "user", ")", ")", ";", "}", "catch", "(", "JSONException", "e", ")", "{", "throw", "new", "GitkitServerException", "(", "e", ")", ";", "}", "}" ]
Updates a user info at Gitkit server. @param user user info to be updated. @return the updated user info @throws GitkitClientException for invalid request @throws GitkitServerException for server error
[ "Updates", "a", "user", "info", "at", "Gitkit", "server", "." ]
61dda1aabbd541ad5e431e840fd266bfca5f8a4a
https://github.com/google/identity-toolkit-java-client/blob/61dda1aabbd541ad5e431e840fd266bfca5f8a4a/src/main/java/com/google/identitytoolkit/GitkitClient.java#L370-L377
9,780
sarxos/v4l4j
src/main/java/au/edu/jcu/v4l4j/AbstractGrabber.java
AbstractGrabber.recycleVideoBuffer
final void recycleVideoBuffer(BaseVideoFrame frame) { // Make sure we are in started state if (state.isStarted()) { enqueueBuffer(object, frame.getBufferInex()); synchronized(availableVideoFrames){ availableVideoFrames.add(frame); availableVideoFrames.notify(); } } }
java
final void recycleVideoBuffer(BaseVideoFrame frame) { // Make sure we are in started state if (state.isStarted()) { enqueueBuffer(object, frame.getBufferInex()); synchronized(availableVideoFrames){ availableVideoFrames.add(frame); availableVideoFrames.notify(); } } }
[ "final", "void", "recycleVideoBuffer", "(", "BaseVideoFrame", "frame", ")", "{", "// Make sure we are in started state", "if", "(", "state", ".", "isStarted", "(", ")", ")", "{", "enqueueBuffer", "(", "object", ",", "frame", ".", "getBufferInex", "(", ")", ")", ";", "synchronized", "(", "availableVideoFrames", ")", "{", "availableVideoFrames", ".", "add", "(", "frame", ")", ";", "availableVideoFrames", ".", "notify", "(", ")", ";", "}", "}", "}" ]
This method is called by a video frame, when it is being recycled. @param frame the frame being recycled.
[ "This", "method", "is", "called", "by", "a", "video", "frame", "when", "it", "is", "being", "recycled", "." ]
4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9
https://github.com/sarxos/v4l4j/blob/4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9/src/main/java/au/edu/jcu/v4l4j/AbstractGrabber.java#L415-L426
9,781
sarxos/v4l4j
src/main/java/au/edu/jcu/v4l4j/AbstractGrabber.java
AbstractGrabber.release
final void release(){ try {stopCapture();} catch (StateException se) { //capture already stopped } state.release(); doRelease(object); state.commit(); }
java
final void release(){ try {stopCapture();} catch (StateException se) { //capture already stopped } state.release(); doRelease(object); state.commit(); }
[ "final", "void", "release", "(", ")", "{", "try", "{", "stopCapture", "(", ")", ";", "}", "catch", "(", "StateException", "se", ")", "{", "//capture already stopped ", "}", "state", ".", "release", "(", ")", ";", "doRelease", "(", "object", ")", ";", "state", ".", "commit", "(", ")", ";", "}" ]
This method releases resources used by the FrameCapture object. @throws StateException if if this <code>FrameGrabber</code> has been already released, and therefore must not be used anymore.
[ "This", "method", "releases", "resources", "used", "by", "the", "FrameCapture", "object", "." ]
4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9
https://github.com/sarxos/v4l4j/blob/4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9/src/main/java/au/edu/jcu/v4l4j/AbstractGrabber.java#L477-L486
9,782
sarxos/v4l4j
src/main/java/au/edu/jcu/v4l4j/Control.java
Control.getStringValue
public String getStringValue() throws ControlException{ String v; if(type!=V4L4JConstants.CTRL_TYPE_STRING) throw new UnsupportedMethod("This control is not a string control"); state.get(); try {v = doGetStringValue(v4l4jObject, id);} finally{state.put(); } return v; }
java
public String getStringValue() throws ControlException{ String v; if(type!=V4L4JConstants.CTRL_TYPE_STRING) throw new UnsupportedMethod("This control is not a string control"); state.get(); try {v = doGetStringValue(v4l4jObject, id);} finally{state.put(); } return v; }
[ "public", "String", "getStringValue", "(", ")", "throws", "ControlException", "{", "String", "v", ";", "if", "(", "type", "!=", "V4L4JConstants", ".", "CTRL_TYPE_STRING", ")", "throw", "new", "UnsupportedMethod", "(", "\"This control is not a string control\"", ")", ";", "state", ".", "get", "(", ")", ";", "try", "{", "v", "=", "doGetStringValue", "(", "v4l4jObject", ",", "id", ")", ";", "}", "finally", "{", "state", ".", "put", "(", ")", ";", "}", "return", "v", ";", "}" ]
This method retrieves the current string value of this control. Some controls may be write-only and getting their value does not make sense. Invoking this method on this kind of controls will trigger a ControlException. @return the current value of this control @throws ControlException if the value cannot be retrieved @throws UnsupportedMethod if this control is not of type {@link V4L4JConstants#CTRL_TYPE_STRING}. @throws StateException if this control has been released and must not be used anymore.
[ "This", "method", "retrieves", "the", "current", "string", "value", "of", "this", "control", ".", "Some", "controls", "may", "be", "write", "-", "only", "and", "getting", "their", "value", "does", "not", "make", "sense", ".", "Invoking", "this", "method", "on", "this", "kind", "of", "controls", "will", "trigger", "a", "ControlException", "." ]
4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9
https://github.com/sarxos/v4l4j/blob/4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9/src/main/java/au/edu/jcu/v4l4j/Control.java#L271-L283
9,783
sarxos/v4l4j
src/main/java/au/edu/jcu/v4l4j/Control.java
Control.setStringValue
public String setStringValue(String value) throws ControlException { String v = null; if(type!=V4L4JConstants.CTRL_TYPE_STRING) throw new UnsupportedMethod("This control is not a string control"); if (value.length() > max) throw new ControlException("The new string value for this control exceeds the maximum length"); if (value.length() < min) throw new ControlException("The new string value for this control is below the minimum length"); state.get(); try { doSetStringValue(v4l4jObject,id, value); v = doGetStringValue( v4l4jObject, id); } finally { state.put(); } return v; }
java
public String setStringValue(String value) throws ControlException { String v = null; if(type!=V4L4JConstants.CTRL_TYPE_STRING) throw new UnsupportedMethod("This control is not a string control"); if (value.length() > max) throw new ControlException("The new string value for this control exceeds the maximum length"); if (value.length() < min) throw new ControlException("The new string value for this control is below the minimum length"); state.get(); try { doSetStringValue(v4l4jObject,id, value); v = doGetStringValue( v4l4jObject, id); } finally { state.put(); } return v; }
[ "public", "String", "setStringValue", "(", "String", "value", ")", "throws", "ControlException", "{", "String", "v", "=", "null", ";", "if", "(", "type", "!=", "V4L4JConstants", ".", "CTRL_TYPE_STRING", ")", "throw", "new", "UnsupportedMethod", "(", "\"This control is not a string control\"", ")", ";", "if", "(", "value", ".", "length", "(", ")", ">", "max", ")", "throw", "new", "ControlException", "(", "\"The new string value for this control exceeds the maximum length\"", ")", ";", "if", "(", "value", ".", "length", "(", ")", "<", "min", ")", "throw", "new", "ControlException", "(", "\"The new string value for this control is below the minimum length\"", ")", ";", "state", ".", "get", "(", ")", ";", "try", "{", "doSetStringValue", "(", "v4l4jObject", ",", "id", ",", "value", ")", ";", "v", "=", "doGetStringValue", "(", "v4l4jObject", ",", "id", ")", ";", "}", "finally", "{", "state", ".", "put", "(", ")", ";", "}", "return", "v", ";", "}" ]
This method sets a new string value for this control. The returned value is the new value of the control. @param value the new value @return the new value of the control after setting it @throws ControlException if the value can not be set, or if the new string value's length is under / over the minimum / maximum length. @throws UnsupportedMethod if this control is not of type {@link V4L4JConstants#CTRL_TYPE_STRING}, @throws StateException if this control has been released and must not be used anymore.
[ "This", "method", "sets", "a", "new", "string", "value", "for", "this", "control", ".", "The", "returned", "value", "is", "the", "new", "value", "of", "the", "control", "." ]
4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9
https://github.com/sarxos/v4l4j/blob/4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9/src/main/java/au/edu/jcu/v4l4j/Control.java#L295-L316
9,784
sarxos/v4l4j
src/main/java/au/edu/jcu/v4l4j/Control.java
Control.getLongValue
public long getLongValue() throws ControlException{ long v; if(type!=V4L4JConstants.CTRL_TYPE_LONG) throw new UnsupportedMethod("This control is not a long control"); state.get(); try {v = doGetLongValue(v4l4jObject, id);} finally{state.put(); } return v; }
java
public long getLongValue() throws ControlException{ long v; if(type!=V4L4JConstants.CTRL_TYPE_LONG) throw new UnsupportedMethod("This control is not a long control"); state.get(); try {v = doGetLongValue(v4l4jObject, id);} finally{state.put(); } return v; }
[ "public", "long", "getLongValue", "(", ")", "throws", "ControlException", "{", "long", "v", ";", "if", "(", "type", "!=", "V4L4JConstants", ".", "CTRL_TYPE_LONG", ")", "throw", "new", "UnsupportedMethod", "(", "\"This control is not a long control\"", ")", ";", "state", ".", "get", "(", ")", ";", "try", "{", "v", "=", "doGetLongValue", "(", "v4l4jObject", ",", "id", ")", ";", "}", "finally", "{", "state", ".", "put", "(", ")", ";", "}", "return", "v", ";", "}" ]
This method retrieves the current long value of this control. Some controls may be write-only and getting their value does not make sense. Invoking this method on this kind of controls will trigger a ControlException. @return the current value of this control @throws ControlException if the value cannot be retrieved @throws UnsupportedMethod if this control is not of type {@link V4L4JConstants#CTRL_TYPE_LONG}. @throws StateException if this control has been released and must not be used anymore.
[ "This", "method", "retrieves", "the", "current", "long", "value", "of", "this", "control", ".", "Some", "controls", "may", "be", "write", "-", "only", "and", "getting", "their", "value", "does", "not", "make", "sense", ".", "Invoking", "this", "method", "on", "this", "kind", "of", "controls", "will", "trigger", "a", "ControlException", "." ]
4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9
https://github.com/sarxos/v4l4j/blob/4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9/src/main/java/au/edu/jcu/v4l4j/Control.java#L329-L341
9,785
sarxos/v4l4j
src/main/java/au/edu/jcu/v4l4j/Control.java
Control.setLongValue
public long setLongValue(long value) throws ControlException { long v = 0; if(type!=V4L4JConstants.CTRL_TYPE_LONG) throw new UnsupportedMethod("This control is not a long control"); state.get(); try { doSetLongValue(v4l4jObject,id, value); v = doGetLongValue(v4l4jObject, id); } finally { state.put(); } return v; }
java
public long setLongValue(long value) throws ControlException { long v = 0; if(type!=V4L4JConstants.CTRL_TYPE_LONG) throw new UnsupportedMethod("This control is not a long control"); state.get(); try { doSetLongValue(v4l4jObject,id, value); v = doGetLongValue(v4l4jObject, id); } finally { state.put(); } return v; }
[ "public", "long", "setLongValue", "(", "long", "value", ")", "throws", "ControlException", "{", "long", "v", "=", "0", ";", "if", "(", "type", "!=", "V4L4JConstants", ".", "CTRL_TYPE_LONG", ")", "throw", "new", "UnsupportedMethod", "(", "\"This control is not a long control\"", ")", ";", "state", ".", "get", "(", ")", ";", "try", "{", "doSetLongValue", "(", "v4l4jObject", ",", "id", ",", "value", ")", ";", "v", "=", "doGetLongValue", "(", "v4l4jObject", ",", "id", ")", ";", "}", "finally", "{", "state", ".", "put", "(", ")", ";", "}", "return", "v", ";", "}" ]
This method sets a new long value for this control. The returned value is the new value of the control. @param value the new value @return the new value of the control after setting it @throws ControlException if the value can not be set. @throws UnsupportedMethod if this control is not of type {@link V4L4JConstants#CTRL_TYPE_LONG}, @throws StateException if this control has been released and must not be used anymore.
[ "This", "method", "sets", "a", "new", "long", "value", "for", "this", "control", ".", "The", "returned", "value", "is", "the", "new", "value", "of", "the", "control", "." ]
4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9
https://github.com/sarxos/v4l4j/blob/4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9/src/main/java/au/edu/jcu/v4l4j/Control.java#L352-L368
9,786
sarxos/v4l4j
src/main/java/au/edu/jcu/v4l4j/Control.java
Control.getMaxValue
public int getMaxValue() { if(type==V4L4JConstants.CTRL_TYPE_LONG) throw new UnsupportedMethod("This control is a long control and does not support calls to getMaxValue()"); synchronized(state){ if(state.isNotReleased()) return max; else throw new StateException("This control has been released and must not be used"); } }
java
public int getMaxValue() { if(type==V4L4JConstants.CTRL_TYPE_LONG) throw new UnsupportedMethod("This control is a long control and does not support calls to getMaxValue()"); synchronized(state){ if(state.isNotReleased()) return max; else throw new StateException("This control has been released and must not be used"); } }
[ "public", "int", "getMaxValue", "(", ")", "{", "if", "(", "type", "==", "V4L4JConstants", ".", "CTRL_TYPE_LONG", ")", "throw", "new", "UnsupportedMethod", "(", "\"This control is a long control and does not support calls to getMaxValue()\"", ")", ";", "synchronized", "(", "state", ")", "{", "if", "(", "state", ".", "isNotReleased", "(", ")", ")", "return", "max", ";", "else", "throw", "new", "StateException", "(", "\"This control has been released and must not be used\"", ")", ";", "}", "}" ]
This method retrieves the maximum value this control will accept. If this control is a string control, this method returns the maximum string size that can be set on this control. @return the maximum value, or the largest string size @throws StateException if this control has been released and must not be used anymore. @throws UnsupportedMethod if this control is of type {@link V4L4JConstants#CTRL_TYPE_LONG}
[ "This", "method", "retrieves", "the", "maximum", "value", "this", "control", "will", "accept", ".", "If", "this", "control", "is", "a", "string", "control", "this", "method", "returns", "the", "maximum", "string", "size", "that", "can", "be", "set", "on", "this", "control", "." ]
4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9
https://github.com/sarxos/v4l4j/blob/4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9/src/main/java/au/edu/jcu/v4l4j/Control.java#L459-L469
9,787
sarxos/v4l4j
src/main/java/au/edu/jcu/v4l4j/Control.java
Control.getMinValue
public int getMinValue() { if(type==V4L4JConstants.CTRL_TYPE_LONG) throw new UnsupportedMethod("This control is a long control and does not support calls to getMinValue()"); synchronized(state){ if(state.isNotReleased()) return min; else throw new StateException("This control has been released and must not be used"); } }
java
public int getMinValue() { if(type==V4L4JConstants.CTRL_TYPE_LONG) throw new UnsupportedMethod("This control is a long control and does not support calls to getMinValue()"); synchronized(state){ if(state.isNotReleased()) return min; else throw new StateException("This control has been released and must not be used"); } }
[ "public", "int", "getMinValue", "(", ")", "{", "if", "(", "type", "==", "V4L4JConstants", ".", "CTRL_TYPE_LONG", ")", "throw", "new", "UnsupportedMethod", "(", "\"This control is a long control and does not support calls to getMinValue()\"", ")", ";", "synchronized", "(", "state", ")", "{", "if", "(", "state", ".", "isNotReleased", "(", ")", ")", "return", "min", ";", "else", "throw", "new", "StateException", "(", "\"This control has been released and must not be used\"", ")", ";", "}", "}" ]
This method retrieves the minimum value this control will accept. If this control is a string control, this method returns the minimum string size that can be set on this control. @return the minimum value or the smallest string size @throws StateException if this control has been released and must not be used anymore. @throws UnsupportedMethod if this control is of type {@link V4L4JConstants#CTRL_TYPE_LONG}
[ "This", "method", "retrieves", "the", "minimum", "value", "this", "control", "will", "accept", ".", "If", "this", "control", "is", "a", "string", "control", "this", "method", "returns", "the", "minimum", "string", "size", "that", "can", "be", "set", "on", "this", "control", "." ]
4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9
https://github.com/sarxos/v4l4j/blob/4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9/src/main/java/au/edu/jcu/v4l4j/Control.java#L480-L490
9,788
sarxos/v4l4j
src/main/java/au/edu/jcu/v4l4j/Control.java
Control.getDefaultValue
public int getDefaultValue() { if(type==V4L4JConstants.CTRL_TYPE_STRING) throw new UnsupportedMethod("This control is a string control and does not support calls to getDefaultValue()"); if(type==V4L4JConstants.CTRL_TYPE_LONG) throw new UnsupportedMethod("This control is a long control and does not support calls to getDefaultValue()"); synchronized(state){ if(state.isNotReleased()) return defaultValue; else throw new StateException("This control has been released and must not be used"); } }
java
public int getDefaultValue() { if(type==V4L4JConstants.CTRL_TYPE_STRING) throw new UnsupportedMethod("This control is a string control and does not support calls to getDefaultValue()"); if(type==V4L4JConstants.CTRL_TYPE_LONG) throw new UnsupportedMethod("This control is a long control and does not support calls to getDefaultValue()"); synchronized(state){ if(state.isNotReleased()) return defaultValue; else throw new StateException("This control has been released and must not be used"); } }
[ "public", "int", "getDefaultValue", "(", ")", "{", "if", "(", "type", "==", "V4L4JConstants", ".", "CTRL_TYPE_STRING", ")", "throw", "new", "UnsupportedMethod", "(", "\"This control is a string control and does not support calls to getDefaultValue()\"", ")", ";", "if", "(", "type", "==", "V4L4JConstants", ".", "CTRL_TYPE_LONG", ")", "throw", "new", "UnsupportedMethod", "(", "\"This control is a long control and does not support calls to getDefaultValue()\"", ")", ";", "synchronized", "(", "state", ")", "{", "if", "(", "state", ".", "isNotReleased", "(", ")", ")", "return", "defaultValue", ";", "else", "throw", "new", "StateException", "(", "\"This control has been released and must not be used\"", ")", ";", "}", "}" ]
This method returns the default value for this control @return the default value for this control @throws UnsupportedMethod if this control is of type {@link V4L4JConstants#CTRL_TYPE_STRING} @throws StateException if this control has been released and must not be used anymore
[ "This", "method", "returns", "the", "default", "value", "for", "this", "control" ]
4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9
https://github.com/sarxos/v4l4j/blob/4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9/src/main/java/au/edu/jcu/v4l4j/Control.java#L550-L562
9,789
jacobtabak/Fragment-Switcher
library/src/main/java/me/tabak/fragmentswitcher/FragmentArrayPagerAdapter.java
FragmentArrayPagerAdapter.addAll
public void addAll(T... fragments) { for (T fragment : fragments) { mItems.add(fragment); } notifyDataSetChanged(); }
java
public void addAll(T... fragments) { for (T fragment : fragments) { mItems.add(fragment); } notifyDataSetChanged(); }
[ "public", "void", "addAll", "(", "T", "...", "fragments", ")", "{", "for", "(", "T", "fragment", ":", "fragments", ")", "{", "mItems", ".", "add", "(", "fragment", ")", ";", "}", "notifyDataSetChanged", "(", ")", ";", "}" ]
Adds the specified fragments at the end of the array. @param fragments
[ "Adds", "the", "specified", "fragments", "at", "the", "end", "of", "the", "array", "." ]
9d4cd33d68057ebfb8c5910cd49c65fb6bdfdbed
https://github.com/jacobtabak/Fragment-Switcher/blob/9d4cd33d68057ebfb8c5910cd49c65fb6bdfdbed/library/src/main/java/me/tabak/fragmentswitcher/FragmentArrayPagerAdapter.java#L72-L77
9,790
sarxos/v4l4j
src/main/java/au/edu/jcu/v4l4j/JPEGFrameGrabber.java
JPEGFrameGrabber.setJPGQuality
public void setJPGQuality(int q){ state.checkReleased(); if(q<V4L4JConstants.MIN_JPEG_QUALITY) q =V4L4JConstants.MIN_JPEG_QUALITY; if(q>V4L4JConstants.MAX_JPEG_QUALITY) q = V4L4JConstants.MAX_JPEG_QUALITY; setQuality(object, q); quality = q; }
java
public void setJPGQuality(int q){ state.checkReleased(); if(q<V4L4JConstants.MIN_JPEG_QUALITY) q =V4L4JConstants.MIN_JPEG_QUALITY; if(q>V4L4JConstants.MAX_JPEG_QUALITY) q = V4L4JConstants.MAX_JPEG_QUALITY; setQuality(object, q); quality = q; }
[ "public", "void", "setJPGQuality", "(", "int", "q", ")", "{", "state", ".", "checkReleased", "(", ")", ";", "if", "(", "q", "<", "V4L4JConstants", ".", "MIN_JPEG_QUALITY", ")", "q", "=", "V4L4JConstants", ".", "MIN_JPEG_QUALITY", ";", "if", "(", "q", ">", "V4L4JConstants", ".", "MAX_JPEG_QUALITY", ")", "q", "=", "V4L4JConstants", ".", "MAX_JPEG_QUALITY", ";", "setQuality", "(", "object", ",", "q", ")", ";", "quality", "=", "q", ";", "}" ]
This method sets the desired JPEG quality. @param q the quality (between {@link V4L4JConstants#MIN_JPEG_QUALITY} and {@link V4L4JConstants#MAX_JPEG_QUALITY} inclusive) @throws StateException if this <code>FrameGrabber</code> has been already released, and therefore must not be used anymore.
[ "This", "method", "sets", "the", "desired", "JPEG", "quality", "." ]
4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9
https://github.com/sarxos/v4l4j/blob/4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9/src/main/java/au/edu/jcu/v4l4j/JPEGFrameGrabber.java#L131-L140
9,791
finnyb/javampd
src/main/java/org/bff/javampd/song/MPDSongDatabase.java
MPDSongDatabase.removeSlashes
private static String removeSlashes(String path) { String retString = path; String slash = System.getProperty("file.separator"); //if non-Unix slashes replace retString = retString.replace(slash, "/"); retString = retString.replaceFirst("^/", ""); retString = retString.replaceFirst("/$", ""); return retString; }
java
private static String removeSlashes(String path) { String retString = path; String slash = System.getProperty("file.separator"); //if non-Unix slashes replace retString = retString.replace(slash, "/"); retString = retString.replaceFirst("^/", ""); retString = retString.replaceFirst("/$", ""); return retString; }
[ "private", "static", "String", "removeSlashes", "(", "String", "path", ")", "{", "String", "retString", "=", "path", ";", "String", "slash", "=", "System", ".", "getProperty", "(", "\"file.separator\"", ")", ";", "//if non-Unix slashes replace", "retString", "=", "retString", ".", "replace", "(", "slash", ",", "\"/\"", ")", ";", "retString", "=", "retString", ".", "replaceFirst", "(", "\"^/\"", ",", "\"\"", ")", ";", "retString", "=", "retString", ".", "replaceFirst", "(", "\"/$\"", ",", "\"\"", ")", ";", "return", "retString", ";", "}" ]
Removes leading or trailing slashes from a string. @param path the string to remove leading or trailing slashes @return the string without leading or trailing slashes
[ "Removes", "leading", "or", "trailing", "slashes", "from", "a", "string", "." ]
186736e85fc238b4208cc9ee23373f9249376b4c
https://github.com/finnyb/javampd/blob/186736e85fc238b4208cc9ee23373f9249376b4c/src/main/java/org/bff/javampd/song/MPDSongDatabase.java#L195-L206
9,792
jacobtabak/Fragment-Switcher
sample/src/main/java/me/tabak/fragmentswitcher/sample/DrawerActivity.java
DrawerActivity.initializeFragmentSwitcher
private void initializeFragmentSwitcher() { mFragmentSwitcher = (FragmentSwitcher) findViewById(R.id.fragment_switcher); mFragmentAdapter = new FragmentStateArrayPagerAdapter(getSupportFragmentManager()); mFragmentSwitcher.setAdapter(mFragmentAdapter); }
java
private void initializeFragmentSwitcher() { mFragmentSwitcher = (FragmentSwitcher) findViewById(R.id.fragment_switcher); mFragmentAdapter = new FragmentStateArrayPagerAdapter(getSupportFragmentManager()); mFragmentSwitcher.setAdapter(mFragmentAdapter); }
[ "private", "void", "initializeFragmentSwitcher", "(", ")", "{", "mFragmentSwitcher", "=", "(", "FragmentSwitcher", ")", "findViewById", "(", "R", ".", "id", ".", "fragment_switcher", ")", ";", "mFragmentAdapter", "=", "new", "FragmentStateArrayPagerAdapter", "(", "getSupportFragmentManager", "(", ")", ")", ";", "mFragmentSwitcher", ".", "setAdapter", "(", "mFragmentAdapter", ")", ";", "}" ]
Initializes the fragment switcher. It works just like a viewpager.
[ "Initializes", "the", "fragment", "switcher", ".", "It", "works", "just", "like", "a", "viewpager", "." ]
9d4cd33d68057ebfb8c5910cd49c65fb6bdfdbed
https://github.com/jacobtabak/Fragment-Switcher/blob/9d4cd33d68057ebfb8c5910cd49c65fb6bdfdbed/sample/src/main/java/me/tabak/fragmentswitcher/sample/DrawerActivity.java#L58-L62
9,793
jacobtabak/Fragment-Switcher
sample/src/main/java/me/tabak/fragmentswitcher/sample/DrawerActivity.java
DrawerActivity.initializeDrawer
private void initializeDrawer() { mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.show, R.string.hide); mDrawerLayout.setDrawerListener(mDrawerToggle); getActionBar().setDisplayHomeAsUpEnabled(true); mDrawerToggle.syncState(); }
java
private void initializeDrawer() { mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.show, R.string.hide); mDrawerLayout.setDrawerListener(mDrawerToggle); getActionBar().setDisplayHomeAsUpEnabled(true); mDrawerToggle.syncState(); }
[ "private", "void", "initializeDrawer", "(", ")", "{", "mDrawerLayout", "=", "(", "DrawerLayout", ")", "findViewById", "(", "R", ".", "id", ".", "drawer_layout", ")", ";", "mDrawerToggle", "=", "new", "ActionBarDrawerToggle", "(", "this", ",", "mDrawerLayout", ",", "R", ".", "drawable", ".", "ic_drawer", ",", "R", ".", "string", ".", "show", ",", "R", ".", "string", ".", "hide", ")", ";", "mDrawerLayout", ".", "setDrawerListener", "(", "mDrawerToggle", ")", ";", "getActionBar", "(", ")", ".", "setDisplayHomeAsUpEnabled", "(", "true", ")", ";", "mDrawerToggle", ".", "syncState", "(", ")", ";", "}" ]
Sets up the UI for the navigation drawer.
[ "Sets", "up", "the", "UI", "for", "the", "navigation", "drawer", "." ]
9d4cd33d68057ebfb8c5910cd49c65fb6bdfdbed
https://github.com/jacobtabak/Fragment-Switcher/blob/9d4cd33d68057ebfb8c5910cd49c65fb6bdfdbed/sample/src/main/java/me/tabak/fragmentswitcher/sample/DrawerActivity.java#L67-L74
9,794
jacobtabak/Fragment-Switcher
sample/src/main/java/me/tabak/fragmentswitcher/sample/DrawerActivity.java
DrawerActivity.initializeList
private void initializeList() { mListView = (ListView) findViewById(R.id.drawer_list); mListAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1); mListView.setAdapter(mListAdapter); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { mFragmentSwitcher.setCurrentItem(position); mDrawerLayout.closeDrawer(Gravity.START); } }); }
java
private void initializeList() { mListView = (ListView) findViewById(R.id.drawer_list); mListAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1); mListView.setAdapter(mListAdapter); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { mFragmentSwitcher.setCurrentItem(position); mDrawerLayout.closeDrawer(Gravity.START); } }); }
[ "private", "void", "initializeList", "(", ")", "{", "mListView", "=", "(", "ListView", ")", "findViewById", "(", "R", ".", "id", ".", "drawer_list", ")", ";", "mListAdapter", "=", "new", "ArrayAdapter", "<", "String", ">", "(", "this", ",", "android", ".", "R", ".", "layout", ".", "simple_list_item_1", ")", ";", "mListView", ".", "setAdapter", "(", "mListAdapter", ")", ";", "mListView", ".", "setOnItemClickListener", "(", "new", "AdapterView", ".", "OnItemClickListener", "(", ")", "{", "@", "Override", "public", "void", "onItemClick", "(", "AdapterView", "<", "?", ">", "adapterView", ",", "View", "view", ",", "int", "position", ",", "long", "id", ")", "{", "mFragmentSwitcher", ".", "setCurrentItem", "(", "position", ")", ";", "mDrawerLayout", ".", "closeDrawer", "(", "Gravity", ".", "START", ")", ";", "}", "}", ")", ";", "}" ]
Initializes the list that controls which fragment will be shown.
[ "Initializes", "the", "list", "that", "controls", "which", "fragment", "will", "be", "shown", "." ]
9d4cd33d68057ebfb8c5910cd49c65fb6bdfdbed
https://github.com/jacobtabak/Fragment-Switcher/blob/9d4cd33d68057ebfb8c5910cd49c65fb6bdfdbed/sample/src/main/java/me/tabak/fragmentswitcher/sample/DrawerActivity.java#L79-L90
9,795
jacobtabak/Fragment-Switcher
sample/src/main/java/me/tabak/fragmentswitcher/sample/DrawerActivity.java
DrawerActivity.fillAdapters
private void fillAdapters() { List<Fragment> fragments = new ArrayList<Fragment>(); List<String> listItems = new ArrayList<String>(); for (int i = 0; i < 100; i++) { String title = "Fragment #" + i; fragments.add(SampleFragment.newInstance(title)); listItems.add(title); } mFragmentAdapter.addAll(fragments); mListAdapter.addAll(listItems); }
java
private void fillAdapters() { List<Fragment> fragments = new ArrayList<Fragment>(); List<String> listItems = new ArrayList<String>(); for (int i = 0; i < 100; i++) { String title = "Fragment #" + i; fragments.add(SampleFragment.newInstance(title)); listItems.add(title); } mFragmentAdapter.addAll(fragments); mListAdapter.addAll(listItems); }
[ "private", "void", "fillAdapters", "(", ")", "{", "List", "<", "Fragment", ">", "fragments", "=", "new", "ArrayList", "<", "Fragment", ">", "(", ")", ";", "List", "<", "String", ">", "listItems", "=", "new", "ArrayList", "<", "String", ">", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "100", ";", "i", "++", ")", "{", "String", "title", "=", "\"Fragment #\"", "+", "i", ";", "fragments", ".", "add", "(", "SampleFragment", ".", "newInstance", "(", "title", ")", ")", ";", "listItems", ".", "add", "(", "title", ")", ";", "}", "mFragmentAdapter", ".", "addAll", "(", "fragments", ")", ";", "mListAdapter", ".", "addAll", "(", "listItems", ")", ";", "}" ]
Creates a list of fragments and list items and loads up the adapters.
[ "Creates", "a", "list", "of", "fragments", "and", "list", "items", "and", "loads", "up", "the", "adapters", "." ]
9d4cd33d68057ebfb8c5910cd49c65fb6bdfdbed
https://github.com/jacobtabak/Fragment-Switcher/blob/9d4cd33d68057ebfb8c5910cd49c65fb6bdfdbed/sample/src/main/java/me/tabak/fragmentswitcher/sample/DrawerActivity.java#L95-L105
9,796
google/identity-toolkit-java-client
src/main/java/com/google/identitytoolkit/HttpSender.java
HttpSender.get
public String get(String url, Map<String, String> headers) throws IOException { return doHttpTransfer(url, null, headers); }
java
public String get(String url, Map<String, String> headers) throws IOException { return doHttpTransfer(url, null, headers); }
[ "public", "String", "get", "(", "String", "url", ",", "Map", "<", "String", ",", "String", ">", "headers", ")", "throws", "IOException", "{", "return", "doHttpTransfer", "(", "url", ",", "null", ",", "headers", ")", ";", "}" ]
Sends a HTTP Get request. @param url request url @return http response content @throws IOException
[ "Sends", "a", "HTTP", "Get", "request", "." ]
61dda1aabbd541ad5e431e840fd266bfca5f8a4a
https://github.com/google/identity-toolkit-java-client/blob/61dda1aabbd541ad5e431e840fd266bfca5f8a4a/src/main/java/com/google/identitytoolkit/HttpSender.java#L51-L53
9,797
google/identity-toolkit-java-client
src/main/java/com/google/identitytoolkit/HttpSender.java
HttpSender.post
public String post(String url, String data, Map<String, String> headers) throws IOException { return doHttpTransfer(url, data, headers); }
java
public String post(String url, String data, Map<String, String> headers) throws IOException { return doHttpTransfer(url, data, headers); }
[ "public", "String", "post", "(", "String", "url", ",", "String", "data", ",", "Map", "<", "String", ",", "String", ">", "headers", ")", "throws", "IOException", "{", "return", "doHttpTransfer", "(", "url", ",", "data", ",", "headers", ")", ";", "}" ]
Sends a HTTP POST request. @param url request url @param data json-encoded post body @param headers http headers to send @return content of the http response @throws IOException
[ "Sends", "a", "HTTP", "POST", "request", "." ]
61dda1aabbd541ad5e431e840fd266bfca5f8a4a
https://github.com/google/identity-toolkit-java-client/blob/61dda1aabbd541ad5e431e840fd266bfca5f8a4a/src/main/java/com/google/identitytoolkit/HttpSender.java#L64-L66
9,798
sarxos/v4l4j
src/main/java/au/edu/jcu/v4l4j/BaseVideoFrame.java
BaseVideoFrame.prepareForDelivery
final synchronized void prepareForDelivery(int length, int index, long sequence, long timeUs){ frameLength = length; dataBuffer.setNewFrameSize(length); sequenceNumber = sequence; captureTime = timeUs; bufferIndex = index; recycled = false; }
java
final synchronized void prepareForDelivery(int length, int index, long sequence, long timeUs){ frameLength = length; dataBuffer.setNewFrameSize(length); sequenceNumber = sequence; captureTime = timeUs; bufferIndex = index; recycled = false; }
[ "final", "synchronized", "void", "prepareForDelivery", "(", "int", "length", ",", "int", "index", ",", "long", "sequence", ",", "long", "timeUs", ")", "{", "frameLength", "=", "length", ";", "dataBuffer", ".", "setNewFrameSize", "(", "length", ")", ";", "sequenceNumber", "=", "sequence", ";", "captureTime", "=", "timeUs", ";", "bufferIndex", "=", "index", ";", "recycled", "=", "false", ";", "}" ]
This method marks this frame as ready to be delivered to the user, as its buffer has just been filled with a new frame of the given length. @param length the length of the new frame. @param sequence this frame's sequence number @param timeUs this frame capture timestamp in elapsed microseconds since startup
[ "This", "method", "marks", "this", "frame", "as", "ready", "to", "be", "delivered", "to", "the", "user", "as", "its", "buffer", "has", "just", "been", "filled", "with", "a", "new", "frame", "of", "the", "given", "length", "." ]
4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9
https://github.com/sarxos/v4l4j/blob/4fc0eec2c3a1a4260593f6ac03b7a8013e3804c9/src/main/java/au/edu/jcu/v4l4j/BaseVideoFrame.java#L75-L83
9,799
bThink-BGU/BPjs
src/main/java/il/ac/bgu/cs/bp/bpjs/analysis/DfsTraversalNode.java
DfsTraversalNode.getNextNode
public DfsTraversalNode getNextNode(BEvent e, ExecutorService exSvc) throws BPjsRuntimeException { try { return new DfsTraversalNode(bp, BProgramSyncSnapshotCloner.clone(systemState).triggerEvent(e, exSvc, Collections.emptySet()), e); } catch ( InterruptedException ie ) { throw new BPjsRuntimeException("Thread interrupted during event invocaiton", ie); } }
java
public DfsTraversalNode getNextNode(BEvent e, ExecutorService exSvc) throws BPjsRuntimeException { try { return new DfsTraversalNode(bp, BProgramSyncSnapshotCloner.clone(systemState).triggerEvent(e, exSvc, Collections.emptySet()), e); } catch ( InterruptedException ie ) { throw new BPjsRuntimeException("Thread interrupted during event invocaiton", ie); } }
[ "public", "DfsTraversalNode", "getNextNode", "(", "BEvent", "e", ",", "ExecutorService", "exSvc", ")", "throws", "BPjsRuntimeException", "{", "try", "{", "return", "new", "DfsTraversalNode", "(", "bp", ",", "BProgramSyncSnapshotCloner", ".", "clone", "(", "systemState", ")", ".", "triggerEvent", "(", "e", ",", "exSvc", ",", "Collections", ".", "emptySet", "(", ")", ")", ",", "e", ")", ";", "}", "catch", "(", "InterruptedException", "ie", ")", "{", "throw", "new", "BPjsRuntimeException", "(", "\"Thread interrupted during event invocaiton\"", ",", "ie", ")", ";", "}", "}" ]
Get a Node object for each possible state of the system after triggering the given event. @param e the selected event @param exSvc The executor service that will run the threads @return State of the BProgram after event {@code e} was selected while the program was at {@code this} node's state. @throws BPjsRuntimeException In case there's an error running the JavaScript code.
[ "Get", "a", "Node", "object", "for", "each", "possible", "state", "of", "the", "system", "after", "triggering", "the", "given", "event", "." ]
2d388365a27ad79ded108eaf98a35a7ef292ae1f
https://github.com/bThink-BGU/BPjs/blob/2d388365a27ad79ded108eaf98a35a7ef292ae1f/src/main/java/il/ac/bgu/cs/bp/bpjs/analysis/DfsTraversalNode.java#L88-L94