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
141,800
MTDdk/jawn
jawn-core/src/main/java/net/javapla/jawn/core/templates/TemplateEngineHelper.java
TemplateEngineHelper.getControllerForResult
public static String getControllerForResult(Route route) { if (route == null || route.getController() == null) return Constants.ROOT_CONTROLLER_NAME; return RouterHelper.getReverseRouteFast(route.getController()).substring(1); }
java
public static String getControllerForResult(Route route) { if (route == null || route.getController() == null) return Constants.ROOT_CONTROLLER_NAME; return RouterHelper.getReverseRouteFast(route.getController()).substring(1); }
[ "public", "static", "String", "getControllerForResult", "(", "Route", "route", ")", "{", "if", "(", "route", "==", "null", "||", "route", ".", "getController", "(", ")", "==", "null", ")", "return", "Constants", ".", "ROOT_CONTROLLER_NAME", ";", "return", "RouterHelper", ".", "getReverseRouteFast", "(", "route", ".", "getController", "(", ")", ")", ".", "substring", "(", "1", ")", ";", "}" ]
Getting the controller from the route @param route @return
[ "Getting", "the", "controller", "from", "the", "route" ]
4ec2d09b97d413efdead7487e6075e5bfd13b925
https://github.com/MTDdk/jawn/blob/4ec2d09b97d413efdead7487e6075e5bfd13b925/jawn-core/src/main/java/net/javapla/jawn/core/templates/TemplateEngineHelper.java#L47-L50
141,801
MTDdk/jawn
jawn-core-new/src/main/java/net/javapla/jawn/core/internal/FrameworkBootstrap.java
FrameworkBootstrap.locateAll
private <T, U> T[] locateAll(final ClassLocator locator, final Class<T> clazz, final Consumer<T> bootstrapper) { Set<Class<? extends T>> set = locator.subtypeOf(clazz); if (!set.isEmpty()) { @SuppressWarnings("unchecked") T[] all = (T[]) Array.newInstance(clazz, set.size()); int index = 0; Iterator<Class<? extends T>> iterator = set.iterator(); while (iterator.hasNext()) { Class<? extends T> c = iterator.next(); try { T locatedImplementation = DynamicClassFactory.createInstance(c, clazz); bootstrapper.accept(locatedImplementation); logger.debug("Loaded configuration from: " + c); all[index++] = locatedImplementation; } catch (IllegalArgumentException e) { throw e; } catch (Exception e) { logger.debug("Error reading custom configuration. Going with built in defaults. The error was: " + getCauseMessage(e)); } } return all; } else { logger.debug("Did not find custom configuration for {}. Going with built in defaults ", clazz); } return null; }
java
private <T, U> T[] locateAll(final ClassLocator locator, final Class<T> clazz, final Consumer<T> bootstrapper) { Set<Class<? extends T>> set = locator.subtypeOf(clazz); if (!set.isEmpty()) { @SuppressWarnings("unchecked") T[] all = (T[]) Array.newInstance(clazz, set.size()); int index = 0; Iterator<Class<? extends T>> iterator = set.iterator(); while (iterator.hasNext()) { Class<? extends T> c = iterator.next(); try { T locatedImplementation = DynamicClassFactory.createInstance(c, clazz); bootstrapper.accept(locatedImplementation); logger.debug("Loaded configuration from: " + c); all[index++] = locatedImplementation; } catch (IllegalArgumentException e) { throw e; } catch (Exception e) { logger.debug("Error reading custom configuration. Going with built in defaults. The error was: " + getCauseMessage(e)); } } return all; } else { logger.debug("Did not find custom configuration for {}. Going with built in defaults ", clazz); } return null; }
[ "private", "<", "T", ",", "U", ">", "T", "[", "]", "locateAll", "(", "final", "ClassLocator", "locator", ",", "final", "Class", "<", "T", ">", "clazz", ",", "final", "Consumer", "<", "T", ">", "bootstrapper", ")", "{", "Set", "<", "Class", "<", "?", "extends", "T", ">", ">", "set", "=", "locator", ".", "subtypeOf", "(", "clazz", ")", ";", "if", "(", "!", "set", ".", "isEmpty", "(", ")", ")", "{", "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "T", "[", "]", "all", "=", "(", "T", "[", "]", ")", "Array", ".", "newInstance", "(", "clazz", ",", "set", ".", "size", "(", ")", ")", ";", "int", "index", "=", "0", ";", "Iterator", "<", "Class", "<", "?", "extends", "T", ">", ">", "iterator", "=", "set", ".", "iterator", "(", ")", ";", "while", "(", "iterator", ".", "hasNext", "(", ")", ")", "{", "Class", "<", "?", "extends", "T", ">", "c", "=", "iterator", ".", "next", "(", ")", ";", "try", "{", "T", "locatedImplementation", "=", "DynamicClassFactory", ".", "createInstance", "(", "c", ",", "clazz", ")", ";", "bootstrapper", ".", "accept", "(", "locatedImplementation", ")", ";", "logger", ".", "debug", "(", "\"Loaded configuration from: \"", "+", "c", ")", ";", "all", "[", "index", "++", "]", "=", "locatedImplementation", ";", "}", "catch", "(", "IllegalArgumentException", "e", ")", "{", "throw", "e", ";", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "debug", "(", "\"Error reading custom configuration. Going with built in defaults. The error was: \"", "+", "getCauseMessage", "(", "e", ")", ")", ";", "}", "}", "return", "all", ";", "}", "else", "{", "logger", ".", "debug", "(", "\"Did not find custom configuration for {}. Going with built in defaults \"", ",", "clazz", ")", ";", "}", "return", "null", ";", "}" ]
Locates an implementation of the given type, and executes the consumer if a class of the given type is found @param reflections @param clazz @param bootstrapper @return
[ "Locates", "an", "implementation", "of", "the", "given", "type", "and", "executes", "the", "consumer", "if", "a", "class", "of", "the", "given", "type", "is", "found" ]
4ec2d09b97d413efdead7487e6075e5bfd13b925
https://github.com/MTDdk/jawn/blob/4ec2d09b97d413efdead7487e6075e5bfd13b925/jawn-core-new/src/main/java/net/javapla/jawn/core/internal/FrameworkBootstrap.java#L230-L259
141,802
MTDdk/jawn
jawn-server/src/main/java/net/javapla/jawn/server/JawnServletContext.java
JawnServletContext.parseRequestMultiPartItems
public Optional<List<FormItem>> parseRequestMultiPartItems(String encoding) { DiskFileItemFactory factory = new DiskFileItemFactory(); factory.setSizeThreshold(properties.getInt(Constants.PROPERTY_UPLOADS_MAX_SIZE/*Constants.Params.maxUploadSize.name()*/));//Configuration.getMaxUploadSize()); factory.setRepository(new File(System.getProperty("java.io.tmpdir"))); //Configuration.getTmpDir()); //README the file for tmpdir *MIGHT* need to go into Properties ServletFileUpload upload = new ServletFileUpload(factory); if(encoding != null) upload.setHeaderEncoding(encoding); upload.setFileSizeMax(properties.getInt(Constants.PROPERTY_UPLOADS_MAX_SIZE)); try { List<FormItem> items = upload.parseRequest(request) .stream() .map(item -> new ApacheFileItemFormItem(item)) .collect(Collectors.toList()); return Optional.of(items); } catch (FileUploadException e) { //"Error while trying to process mulitpart file upload" //README: perhaps some logging } return Optional.empty(); }
java
public Optional<List<FormItem>> parseRequestMultiPartItems(String encoding) { DiskFileItemFactory factory = new DiskFileItemFactory(); factory.setSizeThreshold(properties.getInt(Constants.PROPERTY_UPLOADS_MAX_SIZE/*Constants.Params.maxUploadSize.name()*/));//Configuration.getMaxUploadSize()); factory.setRepository(new File(System.getProperty("java.io.tmpdir"))); //Configuration.getTmpDir()); //README the file for tmpdir *MIGHT* need to go into Properties ServletFileUpload upload = new ServletFileUpload(factory); if(encoding != null) upload.setHeaderEncoding(encoding); upload.setFileSizeMax(properties.getInt(Constants.PROPERTY_UPLOADS_MAX_SIZE)); try { List<FormItem> items = upload.parseRequest(request) .stream() .map(item -> new ApacheFileItemFormItem(item)) .collect(Collectors.toList()); return Optional.of(items); } catch (FileUploadException e) { //"Error while trying to process mulitpart file upload" //README: perhaps some logging } return Optional.empty(); }
[ "public", "Optional", "<", "List", "<", "FormItem", ">", ">", "parseRequestMultiPartItems", "(", "String", "encoding", ")", "{", "DiskFileItemFactory", "factory", "=", "new", "DiskFileItemFactory", "(", ")", ";", "factory", ".", "setSizeThreshold", "(", "properties", ".", "getInt", "(", "Constants", ".", "PROPERTY_UPLOADS_MAX_SIZE", "/*Constants.Params.maxUploadSize.name()*/", ")", ")", ";", "//Configuration.getMaxUploadSize());", "factory", ".", "setRepository", "(", "new", "File", "(", "System", ".", "getProperty", "(", "\"java.io.tmpdir\"", ")", ")", ")", ";", "//Configuration.getTmpDir());", "//README the file for tmpdir *MIGHT* need to go into Properties", "ServletFileUpload", "upload", "=", "new", "ServletFileUpload", "(", "factory", ")", ";", "if", "(", "encoding", "!=", "null", ")", "upload", ".", "setHeaderEncoding", "(", "encoding", ")", ";", "upload", ".", "setFileSizeMax", "(", "properties", ".", "getInt", "(", "Constants", ".", "PROPERTY_UPLOADS_MAX_SIZE", ")", ")", ";", "try", "{", "List", "<", "FormItem", ">", "items", "=", "upload", ".", "parseRequest", "(", "request", ")", ".", "stream", "(", ")", ".", "map", "(", "item", "->", "new", "ApacheFileItemFormItem", "(", "item", ")", ")", ".", "collect", "(", "Collectors", ".", "toList", "(", ")", ")", ";", "return", "Optional", ".", "of", "(", "items", ")", ";", "}", "catch", "(", "FileUploadException", "e", ")", "{", "//\"Error while trying to process mulitpart file upload\"", "//README: perhaps some logging", "}", "return", "Optional", ".", "empty", "(", ")", ";", "}" ]
Gets the FileItemIterator of the input. Can be used to process uploads in a streaming fashion. Check out: http://commons.apache.org/fileupload/streaming.html @return the FileItemIterator of the request or null if there was an error.
[ "Gets", "the", "FileItemIterator", "of", "the", "input", "." ]
4ec2d09b97d413efdead7487e6075e5bfd13b925
https://github.com/MTDdk/jawn/blob/4ec2d09b97d413efdead7487e6075e5bfd13b925/jawn-server/src/main/java/net/javapla/jawn/server/JawnServletContext.java#L518-L541
141,803
buschmais/jqa-core-framework
rule/src/main/java/com/buschmais/jqassistant/core/rule/api/RuleHelper.java
RuleHelper.printRuleSet
public void printRuleSet(RuleSet ruleSet) throws RuleException { RuleSelection ruleSelection = RuleSelection.builder() .conceptIds(ruleSet.getConceptBucket().getIds()) .constraintIds(ruleSet.getConstraintBucket().getIds()) .groupIds(ruleSet.getGroupsBucket().getIds()).build(); printRuleSet(ruleSet, ruleSelection); }
java
public void printRuleSet(RuleSet ruleSet) throws RuleException { RuleSelection ruleSelection = RuleSelection.builder() .conceptIds(ruleSet.getConceptBucket().getIds()) .constraintIds(ruleSet.getConstraintBucket().getIds()) .groupIds(ruleSet.getGroupsBucket().getIds()).build(); printRuleSet(ruleSet, ruleSelection); }
[ "public", "void", "printRuleSet", "(", "RuleSet", "ruleSet", ")", "throws", "RuleException", "{", "RuleSelection", "ruleSelection", "=", "RuleSelection", ".", "builder", "(", ")", ".", "conceptIds", "(", "ruleSet", ".", "getConceptBucket", "(", ")", ".", "getIds", "(", ")", ")", ".", "constraintIds", "(", "ruleSet", ".", "getConstraintBucket", "(", ")", ".", "getIds", "(", ")", ")", ".", "groupIds", "(", "ruleSet", ".", "getGroupsBucket", "(", ")", ".", "getIds", "(", ")", ")", ".", "build", "(", ")", ";", "printRuleSet", "(", "ruleSet", ",", "ruleSelection", ")", ";", "}" ]
Logs the given rule set on level info. @param ruleSet The rule set.
[ "Logs", "the", "given", "rule", "set", "on", "level", "info", "." ]
0e63ff509cfe52f9063539a23d5f9f183b2ea4a5
https://github.com/buschmais/jqa-core-framework/blob/0e63ff509cfe52f9063539a23d5f9f183b2ea4a5/rule/src/main/java/com/buschmais/jqassistant/core/rule/api/RuleHelper.java#L36-L42
141,804
buschmais/jqa-core-framework
rule/src/main/java/com/buschmais/jqassistant/core/rule/api/RuleHelper.java
RuleHelper.printValidRules
private void printValidRules(CollectRulesVisitor visitor) { logger.info("Groups [" + visitor.getGroups().size() + "]"); for (Group group : visitor.getGroups()) { logger.info(LOG_LINE_PREFIX + group.getId() + "\""); } logger.info("Constraints [" + visitor.getConstraints().size() + "]"); for (Constraint constraint : visitor.getConstraints().keySet()) { logger.info(LOG_LINE_PREFIX + constraint.getId() + "\" - " + constraint.getDescription()); } logger.info("Concepts [" + visitor.getConcepts().size() + "]"); for (Concept concept : visitor.getConcepts().keySet()) { logger.info(LOG_LINE_PREFIX + concept.getId() + "\" - " + concept.getDescription()); } }
java
private void printValidRules(CollectRulesVisitor visitor) { logger.info("Groups [" + visitor.getGroups().size() + "]"); for (Group group : visitor.getGroups()) { logger.info(LOG_LINE_PREFIX + group.getId() + "\""); } logger.info("Constraints [" + visitor.getConstraints().size() + "]"); for (Constraint constraint : visitor.getConstraints().keySet()) { logger.info(LOG_LINE_PREFIX + constraint.getId() + "\" - " + constraint.getDescription()); } logger.info("Concepts [" + visitor.getConcepts().size() + "]"); for (Concept concept : visitor.getConcepts().keySet()) { logger.info(LOG_LINE_PREFIX + concept.getId() + "\" - " + concept.getDescription()); } }
[ "private", "void", "printValidRules", "(", "CollectRulesVisitor", "visitor", ")", "{", "logger", ".", "info", "(", "\"Groups [\"", "+", "visitor", ".", "getGroups", "(", ")", ".", "size", "(", ")", "+", "\"]\"", ")", ";", "for", "(", "Group", "group", ":", "visitor", ".", "getGroups", "(", ")", ")", "{", "logger", ".", "info", "(", "LOG_LINE_PREFIX", "+", "group", ".", "getId", "(", ")", "+", "\"\\\"\"", ")", ";", "}", "logger", ".", "info", "(", "\"Constraints [\"", "+", "visitor", ".", "getConstraints", "(", ")", ".", "size", "(", ")", "+", "\"]\"", ")", ";", "for", "(", "Constraint", "constraint", ":", "visitor", ".", "getConstraints", "(", ")", ".", "keySet", "(", ")", ")", "{", "logger", ".", "info", "(", "LOG_LINE_PREFIX", "+", "constraint", ".", "getId", "(", ")", "+", "\"\\\" - \"", "+", "constraint", ".", "getDescription", "(", ")", ")", ";", "}", "logger", ".", "info", "(", "\"Concepts [\"", "+", "visitor", ".", "getConcepts", "(", ")", ".", "size", "(", ")", "+", "\"]\"", ")", ";", "for", "(", "Concept", "concept", ":", "visitor", ".", "getConcepts", "(", ")", ".", "keySet", "(", ")", ")", "{", "logger", ".", "info", "(", "LOG_LINE_PREFIX", "+", "concept", ".", "getId", "(", ")", "+", "\"\\\" - \"", "+", "concept", ".", "getDescription", "(", ")", ")", ";", "}", "}" ]
Prints all valid rules. @param visitor The visitor.
[ "Prints", "all", "valid", "rules", "." ]
0e63ff509cfe52f9063539a23d5f9f183b2ea4a5
https://github.com/buschmais/jqa-core-framework/blob/0e63ff509cfe52f9063539a23d5f9f183b2ea4a5/rule/src/main/java/com/buschmais/jqassistant/core/rule/api/RuleHelper.java#L62-L75
141,805
buschmais/jqa-core-framework
rule/src/main/java/com/buschmais/jqassistant/core/rule/api/RuleHelper.java
RuleHelper.getAllRules
private CollectRulesVisitor getAllRules(RuleSet ruleSet, RuleSelection ruleSelection) throws RuleException { CollectRulesVisitor visitor = new CollectRulesVisitor(); RuleSetExecutor executor = new RuleSetExecutor(visitor, new RuleSetExecutorConfiguration()); executor.execute(ruleSet, ruleSelection); return visitor; }
java
private CollectRulesVisitor getAllRules(RuleSet ruleSet, RuleSelection ruleSelection) throws RuleException { CollectRulesVisitor visitor = new CollectRulesVisitor(); RuleSetExecutor executor = new RuleSetExecutor(visitor, new RuleSetExecutorConfiguration()); executor.execute(ruleSet, ruleSelection); return visitor; }
[ "private", "CollectRulesVisitor", "getAllRules", "(", "RuleSet", "ruleSet", ",", "RuleSelection", "ruleSelection", ")", "throws", "RuleException", "{", "CollectRulesVisitor", "visitor", "=", "new", "CollectRulesVisitor", "(", ")", ";", "RuleSetExecutor", "executor", "=", "new", "RuleSetExecutor", "(", "visitor", ",", "new", "RuleSetExecutorConfiguration", "(", ")", ")", ";", "executor", ".", "execute", "(", "ruleSet", ",", "ruleSelection", ")", ";", "return", "visitor", ";", "}" ]
Determines all rules. @param ruleSet The rule set. @return The visitor with all valid and missing rules. @throws RuleException If the rules cannot be evaluated.
[ "Determines", "all", "rules", "." ]
0e63ff509cfe52f9063539a23d5f9f183b2ea4a5
https://github.com/buschmais/jqa-core-framework/blob/0e63ff509cfe52f9063539a23d5f9f183b2ea4a5/rule/src/main/java/com/buschmais/jqassistant/core/rule/api/RuleHelper.java#L86-L91
141,806
buschmais/jqa-core-framework
rule/src/main/java/com/buschmais/jqassistant/core/rule/api/RuleHelper.java
RuleHelper.printMissingRules
private boolean printMissingRules(CollectRulesVisitor visitor) { Set<String> missingConcepts = visitor.getMissingConcepts(); if (!missingConcepts.isEmpty()) { logger.info("Missing concepts [" + missingConcepts.size() + "]"); for (String missingConcept : missingConcepts) { logger.warn(LOG_LINE_PREFIX + missingConcept); } } Set<String> missingConstraints = visitor.getMissingConstraints(); if (!missingConstraints.isEmpty()) { logger.info("Missing constraints [" + missingConstraints.size() + "]"); for (String missingConstraint : missingConstraints) { logger.warn(LOG_LINE_PREFIX + missingConstraint); } } Set<String> missingGroups = visitor.getMissingGroups(); if (!missingGroups.isEmpty()) { logger.info("Missing groups [" + missingGroups.size() + "]"); for (String missingGroup : missingGroups) { logger.warn(LOG_LINE_PREFIX + missingGroup); } } return missingConcepts.isEmpty() && missingConstraints.isEmpty() && missingGroups.isEmpty(); }
java
private boolean printMissingRules(CollectRulesVisitor visitor) { Set<String> missingConcepts = visitor.getMissingConcepts(); if (!missingConcepts.isEmpty()) { logger.info("Missing concepts [" + missingConcepts.size() + "]"); for (String missingConcept : missingConcepts) { logger.warn(LOG_LINE_PREFIX + missingConcept); } } Set<String> missingConstraints = visitor.getMissingConstraints(); if (!missingConstraints.isEmpty()) { logger.info("Missing constraints [" + missingConstraints.size() + "]"); for (String missingConstraint : missingConstraints) { logger.warn(LOG_LINE_PREFIX + missingConstraint); } } Set<String> missingGroups = visitor.getMissingGroups(); if (!missingGroups.isEmpty()) { logger.info("Missing groups [" + missingGroups.size() + "]"); for (String missingGroup : missingGroups) { logger.warn(LOG_LINE_PREFIX + missingGroup); } } return missingConcepts.isEmpty() && missingConstraints.isEmpty() && missingGroups.isEmpty(); }
[ "private", "boolean", "printMissingRules", "(", "CollectRulesVisitor", "visitor", ")", "{", "Set", "<", "String", ">", "missingConcepts", "=", "visitor", ".", "getMissingConcepts", "(", ")", ";", "if", "(", "!", "missingConcepts", ".", "isEmpty", "(", ")", ")", "{", "logger", ".", "info", "(", "\"Missing concepts [\"", "+", "missingConcepts", ".", "size", "(", ")", "+", "\"]\"", ")", ";", "for", "(", "String", "missingConcept", ":", "missingConcepts", ")", "{", "logger", ".", "warn", "(", "LOG_LINE_PREFIX", "+", "missingConcept", ")", ";", "}", "}", "Set", "<", "String", ">", "missingConstraints", "=", "visitor", ".", "getMissingConstraints", "(", ")", ";", "if", "(", "!", "missingConstraints", ".", "isEmpty", "(", ")", ")", "{", "logger", ".", "info", "(", "\"Missing constraints [\"", "+", "missingConstraints", ".", "size", "(", ")", "+", "\"]\"", ")", ";", "for", "(", "String", "missingConstraint", ":", "missingConstraints", ")", "{", "logger", ".", "warn", "(", "LOG_LINE_PREFIX", "+", "missingConstraint", ")", ";", "}", "}", "Set", "<", "String", ">", "missingGroups", "=", "visitor", ".", "getMissingGroups", "(", ")", ";", "if", "(", "!", "missingGroups", ".", "isEmpty", "(", ")", ")", "{", "logger", ".", "info", "(", "\"Missing groups [\"", "+", "missingGroups", ".", "size", "(", ")", "+", "\"]\"", ")", ";", "for", "(", "String", "missingGroup", ":", "missingGroups", ")", "{", "logger", ".", "warn", "(", "LOG_LINE_PREFIX", "+", "missingGroup", ")", ";", "}", "}", "return", "missingConcepts", ".", "isEmpty", "(", ")", "&&", "missingConstraints", ".", "isEmpty", "(", ")", "&&", "missingGroups", ".", "isEmpty", "(", ")", ";", "}" ]
Prints all missing rule ids. @param visitor The visitor.
[ "Prints", "all", "missing", "rule", "ids", "." ]
0e63ff509cfe52f9063539a23d5f9f183b2ea4a5
https://github.com/buschmais/jqa-core-framework/blob/0e63ff509cfe52f9063539a23d5f9f183b2ea4a5/rule/src/main/java/com/buschmais/jqassistant/core/rule/api/RuleHelper.java#L99-L122
141,807
MTDdk/jawn
jawn-core/src/main/java/net/javapla/jawn/core/templates/ContentTemplateLoader.java
ContentTemplateLoader.getTemplateNameForResult
public String getTemplateNameForResult(Route route, Result response) { String template = response.template(); if (template == null) { if (route != null) { String controllerPath = RouterHelper.getReverseRouteFast(route.getController()); // Look for a controller named template first if (new File(realPath + controllerPath + templateSuffix).exists()) { return controllerPath; } //TODO Route(r).reverseRoute return controllerPath + "/" + route.getActionName(); } else { return null; } } else { if (template.endsWith(templateSuffix)) { return template.substring(0, template.length() - templateSuffixLengthToRemove); } return template; } }
java
public String getTemplateNameForResult(Route route, Result response) { String template = response.template(); if (template == null) { if (route != null) { String controllerPath = RouterHelper.getReverseRouteFast(route.getController()); // Look for a controller named template first if (new File(realPath + controllerPath + templateSuffix).exists()) { return controllerPath; } //TODO Route(r).reverseRoute return controllerPath + "/" + route.getActionName(); } else { return null; } } else { if (template.endsWith(templateSuffix)) { return template.substring(0, template.length() - templateSuffixLengthToRemove); } return template; } }
[ "public", "String", "getTemplateNameForResult", "(", "Route", "route", ",", "Result", "response", ")", "{", "String", "template", "=", "response", ".", "template", "(", ")", ";", "if", "(", "template", "==", "null", ")", "{", "if", "(", "route", "!=", "null", ")", "{", "String", "controllerPath", "=", "RouterHelper", ".", "getReverseRouteFast", "(", "route", ".", "getController", "(", ")", ")", ";", "// Look for a controller named template first", "if", "(", "new", "File", "(", "realPath", "+", "controllerPath", "+", "templateSuffix", ")", ".", "exists", "(", ")", ")", "{", "return", "controllerPath", ";", "}", "//TODO Route(r).reverseRoute", "return", "controllerPath", "+", "\"/\"", "+", "route", ".", "getActionName", "(", ")", ";", "}", "else", "{", "return", "null", ";", "}", "}", "else", "{", "if", "(", "template", ".", "endsWith", "(", "templateSuffix", ")", ")", "{", "return", "template", ".", "substring", "(", "0", ",", "template", ".", "length", "(", ")", "-", "templateSuffixLengthToRemove", ")", ";", "}", "return", "template", ";", "}", "}" ]
If the template is specified by the user with a suffix corresponding to the template engine suffix, then this is removed before returning the template. Suffixes such as .st or .ftl.html @param route @param response @return
[ "If", "the", "template", "is", "specified", "by", "the", "user", "with", "a", "suffix", "corresponding", "to", "the", "template", "engine", "suffix", "then", "this", "is", "removed", "before", "returning", "the", "template", ".", "Suffixes", "such", "as", ".", "st", "or", ".", "ftl", ".", "html" ]
4ec2d09b97d413efdead7487e6075e5bfd13b925
https://github.com/MTDdk/jawn/blob/4ec2d09b97d413efdead7487e6075e5bfd13b925/jawn-core/src/main/java/net/javapla/jawn/core/templates/ContentTemplateLoader.java#L59-L82
141,808
MTDdk/jawn
jawn-core/src/main/java/net/javapla/jawn/core/templates/ContentTemplateLoader.java
ContentTemplateLoader.locateLayoutTemplate
public T locateLayoutTemplate(String controller, final String layout, final boolean useCache) throws ViewException { // first see if we have already looked for the template final String controllerLayoutCombined = controller + '/' + layout; if (useCache && cachedTemplates.containsKey(controllerLayoutCombined)) return engine.clone(cachedTemplates.get(controllerLayoutCombined)); // README: computeIfAbsent does not save the result if null - which it actually might need to do to minimise disk reads T template; if ((template = lookupLayoutWithNonDefaultName(controllerLayoutCombined)) != null) return cacheTemplate(controllerLayoutCombined, template, useCache); // going for defaults if ((template = lookupDefaultLayoutInControllerPathChain(controller)) != null) return cacheTemplate(controllerLayoutCombined, template, useCache); if ((template = lookupDefaultLayout()) != null) return cacheTemplate(controllerLayoutCombined, template, useCache); throw new ViewException(TemplateEngine.LAYOUT_DEFAULT + engine.getSuffixOfTemplatingEngine() + " is not to be found anywhere"); }
java
public T locateLayoutTemplate(String controller, final String layout, final boolean useCache) throws ViewException { // first see if we have already looked for the template final String controllerLayoutCombined = controller + '/' + layout; if (useCache && cachedTemplates.containsKey(controllerLayoutCombined)) return engine.clone(cachedTemplates.get(controllerLayoutCombined)); // README: computeIfAbsent does not save the result if null - which it actually might need to do to minimise disk reads T template; if ((template = lookupLayoutWithNonDefaultName(controllerLayoutCombined)) != null) return cacheTemplate(controllerLayoutCombined, template, useCache); // going for defaults if ((template = lookupDefaultLayoutInControllerPathChain(controller)) != null) return cacheTemplate(controllerLayoutCombined, template, useCache); if ((template = lookupDefaultLayout()) != null) return cacheTemplate(controllerLayoutCombined, template, useCache); throw new ViewException(TemplateEngine.LAYOUT_DEFAULT + engine.getSuffixOfTemplatingEngine() + " is not to be found anywhere"); }
[ "public", "T", "locateLayoutTemplate", "(", "String", "controller", ",", "final", "String", "layout", ",", "final", "boolean", "useCache", ")", "throws", "ViewException", "{", "// first see if we have already looked for the template", "final", "String", "controllerLayoutCombined", "=", "controller", "+", "'", "'", "+", "layout", ";", "if", "(", "useCache", "&&", "cachedTemplates", ".", "containsKey", "(", "controllerLayoutCombined", ")", ")", "return", "engine", ".", "clone", "(", "cachedTemplates", ".", "get", "(", "controllerLayoutCombined", ")", ")", ";", "// README: computeIfAbsent does not save the result if null - which it actually might need to do to minimise disk reads", "T", "template", ";", "if", "(", "(", "template", "=", "lookupLayoutWithNonDefaultName", "(", "controllerLayoutCombined", ")", ")", "!=", "null", ")", "return", "cacheTemplate", "(", "controllerLayoutCombined", ",", "template", ",", "useCache", ")", ";", "// going for defaults", "if", "(", "(", "template", "=", "lookupDefaultLayoutInControllerPathChain", "(", "controller", ")", ")", "!=", "null", ")", "return", "cacheTemplate", "(", "controllerLayoutCombined", ",", "template", ",", "useCache", ")", ";", "if", "(", "(", "template", "=", "lookupDefaultLayout", "(", ")", ")", "!=", "null", ")", "return", "cacheTemplate", "(", "controllerLayoutCombined", ",", "template", ",", "useCache", ")", ";", "throw", "new", "ViewException", "(", "TemplateEngine", ".", "LAYOUT_DEFAULT", "+", "engine", ".", "getSuffixOfTemplatingEngine", "(", ")", "+", "\" is not to be found anywhere\"", ")", ";", "}" ]
If found, uses the provided layout within the controller folder. If not found, it looks for the default template within the controller folder then use this to override the root default template
[ "If", "found", "uses", "the", "provided", "layout", "within", "the", "controller", "folder", ".", "If", "not", "found", "it", "looks", "for", "the", "default", "template", "within", "the", "controller", "folder", "then", "use", "this", "to", "override", "the", "root", "default", "template" ]
4ec2d09b97d413efdead7487e6075e5bfd13b925
https://github.com/MTDdk/jawn/blob/4ec2d09b97d413efdead7487e6075e5bfd13b925/jawn-core/src/main/java/net/javapla/jawn/core/templates/ContentTemplateLoader.java#L103-L122
141,809
MTDdk/jawn
jawn-core/src/main/java/net/javapla/jawn/core/Controller.java
Controller.flash
protected void flash(Map<String, String> values){ for(Object key:values.keySet() ){ flash(key.toString(), values.get(key)); } }
java
protected void flash(Map<String, String> values){ for(Object key:values.keySet() ){ flash(key.toString(), values.get(key)); } }
[ "protected", "void", "flash", "(", "Map", "<", "String", ",", "String", ">", "values", ")", "{", "for", "(", "Object", "key", ":", "values", ".", "keySet", "(", ")", ")", "{", "flash", "(", "key", ".", "toString", "(", ")", ",", "values", ".", "get", "(", "key", ")", ")", ";", "}", "}" ]
Convenience method, takes in a map of values to flash. @see #flash(String, String) @param values values to flash.
[ "Convenience", "method", "takes", "in", "a", "map", "of", "values", "to", "flash", "." ]
4ec2d09b97d413efdead7487e6075e5bfd13b925
https://github.com/MTDdk/jawn/blob/4ec2d09b97d413efdead7487e6075e5bfd13b925/jawn-core/src/main/java/net/javapla/jawn/core/Controller.java#L344-L348
141,810
MTDdk/jawn
jawn-core/src/main/java/net/javapla/jawn/core/Controller.java
Controller.flash
protected void flash(String name, String value) { /*if (session().get(Context.FLASH_SESSION_KEYWORD) == null) { session().put(Context.FLASH_SESSION_KEYWORD, new HashMap<String, Object>()); } ((Map<String, Object>) session().get(Context.FLASH_SESSION_KEYWORD)).put(name, value);*/ //context.setFlash(name, value); context.getFlash().put(name, value); }
java
protected void flash(String name, String value) { /*if (session().get(Context.FLASH_SESSION_KEYWORD) == null) { session().put(Context.FLASH_SESSION_KEYWORD, new HashMap<String, Object>()); } ((Map<String, Object>) session().get(Context.FLASH_SESSION_KEYWORD)).put(name, value);*/ //context.setFlash(name, value); context.getFlash().put(name, value); }
[ "protected", "void", "flash", "(", "String", "name", ",", "String", "value", ")", "{", "/*if (session().get(Context.FLASH_SESSION_KEYWORD) == null) {\n session().put(Context.FLASH_SESSION_KEYWORD, new HashMap<String, Object>());\n }\n ((Map<String, Object>) session().get(Context.FLASH_SESSION_KEYWORD)).put(name, value);*/", "//context.setFlash(name, value);", "context", ".", "getFlash", "(", ")", ".", "put", "(", "name", ",", "value", ")", ";", "}" ]
Sends value to flash. Flash survives one more request. Using flash is typical for POST->REDIRECT->GET pattern, @param name name of value to flash @param value value to live for one more request in current session.
[ "Sends", "value", "to", "flash", ".", "Flash", "survives", "one", "more", "request", ".", "Using", "flash", "is", "typical", "for", "POST", "-", ">", "REDIRECT", "-", ">", "GET", "pattern" ]
4ec2d09b97d413efdead7487e6075e5bfd13b925
https://github.com/MTDdk/jawn/blob/4ec2d09b97d413efdead7487e6075e5bfd13b925/jawn-core/src/main/java/net/javapla/jawn/core/Controller.java#L378-L385
141,811
MTDdk/jawn
jawn-core/src/main/java/net/javapla/jawn/core/Controller.java
Controller.redirectToReferrer
protected void redirectToReferrer() { String referrer = context.requestHeader("Referer"); referrer = referrer == null? context.contextPath()/*injector.getInstance(DeploymentInfo.class).getContextPath()*/ : referrer; redirect(referrer); }
java
protected void redirectToReferrer() { String referrer = context.requestHeader("Referer"); referrer = referrer == null? context.contextPath()/*injector.getInstance(DeploymentInfo.class).getContextPath()*/ : referrer; redirect(referrer); }
[ "protected", "void", "redirectToReferrer", "(", ")", "{", "String", "referrer", "=", "context", ".", "requestHeader", "(", "\"Referer\"", ")", ";", "referrer", "=", "referrer", "==", "null", "?", "context", ".", "contextPath", "(", ")", "/*injector.getInstance(DeploymentInfo.class).getContextPath()*/", ":", "referrer", ";", "redirect", "(", "referrer", ")", ";", "}" ]
Redirects to referrer if one exists. If a referrer does not exist, it will be redirected to the root of the application. @return {@link HttpSupport.HttpBuilder}, to accept additional information.
[ "Redirects", "to", "referrer", "if", "one", "exists", ".", "If", "a", "referrer", "does", "not", "exist", "it", "will", "be", "redirected", "to", "the", "root", "of", "the", "application", "." ]
4ec2d09b97d413efdead7487e6075e5bfd13b925
https://github.com/MTDdk/jawn/blob/4ec2d09b97d413efdead7487e6075e5bfd13b925/jawn-core/src/main/java/net/javapla/jawn/core/Controller.java#L438-L442
141,812
MTDdk/jawn
jawn-core/src/main/java/net/javapla/jawn/core/Controller.java
Controller.cookieValue
protected String cookieValue(String name){ Cookie cookie = cookie(name); return cookie != null ? cookie.getValue() : null; }
java
protected String cookieValue(String name){ Cookie cookie = cookie(name); return cookie != null ? cookie.getValue() : null; }
[ "protected", "String", "cookieValue", "(", "String", "name", ")", "{", "Cookie", "cookie", "=", "cookie", "(", "name", ")", ";", "return", "cookie", "!=", "null", "?", "cookie", ".", "getValue", "(", ")", ":", "null", ";", "}" ]
Convenience method, returns cookie value. @param name name of cookie. @return cookie value.
[ "Convenience", "method", "returns", "cookie", "value", "." ]
4ec2d09b97d413efdead7487e6075e5bfd13b925
https://github.com/MTDdk/jawn/blob/4ec2d09b97d413efdead7487e6075e5bfd13b925/jawn-core/src/main/java/net/javapla/jawn/core/Controller.java#L1253-L1256
141,813
buschmais/jqa-core-framework
shared/src/main/java/com/buschmais/jqassistant/core/shared/reflection/ClassHelper.java
ClassHelper.getType
public <T> Class<T> getType(String typeName) { try { return (Class<T>) classLoader.loadClass(typeName); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Cannot find class " + typeName, e); } }
java
public <T> Class<T> getType(String typeName) { try { return (Class<T>) classLoader.loadClass(typeName); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Cannot find class " + typeName, e); } }
[ "public", "<", "T", ">", "Class", "<", "T", ">", "getType", "(", "String", "typeName", ")", "{", "try", "{", "return", "(", "Class", "<", "T", ">", ")", "classLoader", ".", "loadClass", "(", "typeName", ")", ";", "}", "catch", "(", "ClassNotFoundException", "e", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Cannot find class \"", "+", "typeName", ",", "e", ")", ";", "}", "}" ]
Create and return an instance of the given type name. @param typeName The type name. @param <T> The type. @return The instance.
[ "Create", "and", "return", "an", "instance", "of", "the", "given", "type", "name", "." ]
0e63ff509cfe52f9063539a23d5f9f183b2ea4a5
https://github.com/buschmais/jqa-core-framework/blob/0e63ff509cfe52f9063539a23d5f9f183b2ea4a5/shared/src/main/java/com/buschmais/jqassistant/core/shared/reflection/ClassHelper.java#L26-L32
141,814
buschmais/jqa-core-framework
report/src/main/java/com/buschmais/jqassistant/core/report/impl/CompositeReportPlugin.java
CompositeReportPlugin.selectReportPlugins
private Map<String, ReportPlugin> selectReportPlugins(ExecutableRule rule) throws ReportException { Set<String> selection = rule.getReport().getSelectedTypes(); Map<String, ReportPlugin> reportPlugins = new HashMap<>(); if (selection != null) { for (String type : selection) { ReportPlugin candidate = this.selectableReportPlugins.get(type); if (candidate == null) { throw new ReportException("Unknown report selection '" + type + "' selected for '" + rule + "'"); } reportPlugins.put(type, candidate); } } return reportPlugins; }
java
private Map<String, ReportPlugin> selectReportPlugins(ExecutableRule rule) throws ReportException { Set<String> selection = rule.getReport().getSelectedTypes(); Map<String, ReportPlugin> reportPlugins = new HashMap<>(); if (selection != null) { for (String type : selection) { ReportPlugin candidate = this.selectableReportPlugins.get(type); if (candidate == null) { throw new ReportException("Unknown report selection '" + type + "' selected for '" + rule + "'"); } reportPlugins.put(type, candidate); } } return reportPlugins; }
[ "private", "Map", "<", "String", ",", "ReportPlugin", ">", "selectReportPlugins", "(", "ExecutableRule", "rule", ")", "throws", "ReportException", "{", "Set", "<", "String", ">", "selection", "=", "rule", ".", "getReport", "(", ")", ".", "getSelectedTypes", "(", ")", ";", "Map", "<", "String", ",", "ReportPlugin", ">", "reportPlugins", "=", "new", "HashMap", "<>", "(", ")", ";", "if", "(", "selection", "!=", "null", ")", "{", "for", "(", "String", "type", ":", "selection", ")", "{", "ReportPlugin", "candidate", "=", "this", ".", "selectableReportPlugins", ".", "get", "(", "type", ")", ";", "if", "(", "candidate", "==", "null", ")", "{", "throw", "new", "ReportException", "(", "\"Unknown report selection '\"", "+", "type", "+", "\"' selected for '\"", "+", "rule", "+", "\"'\"", ")", ";", "}", "reportPlugins", ".", "put", "(", "type", ",", "candidate", ")", ";", "}", "}", "return", "reportPlugins", ";", "}" ]
Select the report writers for the given rule. @param rule The rule. @throws ReportException If no writer exists for a specified id.
[ "Select", "the", "report", "writers", "for", "the", "given", "rule", "." ]
0e63ff509cfe52f9063539a23d5f9f183b2ea4a5
https://github.com/buschmais/jqa-core-framework/blob/0e63ff509cfe52f9063539a23d5f9f183b2ea4a5/report/src/main/java/com/buschmais/jqassistant/core/report/impl/CompositeReportPlugin.java#L202-L215
141,815
jinahya/database-metadata-bind
src/main/java/com/github/jinahya/database/metadata/bind/Utils.java
Utils.labels
static Set<String> labels(final ResultSet results) throws SQLException { final ResultSetMetaData metadata = results.getMetaData(); final int count = metadata.getColumnCount(); final Set<String> labels = new HashSet<>(count); for (int i = 1; i <= count; i++) { labels.add(metadata.getColumnLabel(i).toUpperCase()); } return labels; }
java
static Set<String> labels(final ResultSet results) throws SQLException { final ResultSetMetaData metadata = results.getMetaData(); final int count = metadata.getColumnCount(); final Set<String> labels = new HashSet<>(count); for (int i = 1; i <= count; i++) { labels.add(metadata.getColumnLabel(i).toUpperCase()); } return labels; }
[ "static", "Set", "<", "String", ">", "labels", "(", "final", "ResultSet", "results", ")", "throws", "SQLException", "{", "final", "ResultSetMetaData", "metadata", "=", "results", ".", "getMetaData", "(", ")", ";", "final", "int", "count", "=", "metadata", ".", "getColumnCount", "(", ")", ";", "final", "Set", "<", "String", ">", "labels", "=", "new", "HashSet", "<>", "(", "count", ")", ";", "for", "(", "int", "i", "=", "1", ";", "i", "<=", "count", ";", "i", "++", ")", "{", "labels", ".", "add", "(", "metadata", ".", "getColumnLabel", "(", "i", ")", ".", "toUpperCase", "(", ")", ")", ";", "}", "return", "labels", ";", "}" ]
Returns a set of column labels of given result set. @param results the result set from which column labels are read. @return a set of column labels @throws SQLException if a database error occurs. @see ResultSet#getMetaData()
[ "Returns", "a", "set", "of", "column", "labels", "of", "given", "result", "set", "." ]
94fc9f9c85149c30dcfd10434f475d8332eedf76
https://github.com/jinahya/database-metadata-bind/blob/94fc9f9c85149c30dcfd10434f475d8332eedf76/src/main/java/com/github/jinahya/database/metadata/bind/Utils.java#L110-L118
141,816
buschmais/jqa-core-framework
report/src/main/java/com/buschmais/jqassistant/core/report/impl/XmlReportPlugin.java
XmlReportPlugin.writeStatus
private void writeStatus(Result.Status status) throws XMLStreamException { xmlStreamWriter.writeStartElement("status"); xmlStreamWriter.writeCharacters(status.name().toLowerCase()); xmlStreamWriter.writeEndElement(); }
java
private void writeStatus(Result.Status status) throws XMLStreamException { xmlStreamWriter.writeStartElement("status"); xmlStreamWriter.writeCharacters(status.name().toLowerCase()); xmlStreamWriter.writeEndElement(); }
[ "private", "void", "writeStatus", "(", "Result", ".", "Status", "status", ")", "throws", "XMLStreamException", "{", "xmlStreamWriter", ".", "writeStartElement", "(", "\"status\"", ")", ";", "xmlStreamWriter", ".", "writeCharacters", "(", "status", ".", "name", "(", ")", ".", "toLowerCase", "(", ")", ")", ";", "xmlStreamWriter", ".", "writeEndElement", "(", ")", ";", "}" ]
Write the status of the current result. @throws XMLStreamException If a problem occurs.
[ "Write", "the", "status", "of", "the", "current", "result", "." ]
0e63ff509cfe52f9063539a23d5f9f183b2ea4a5
https://github.com/buschmais/jqa-core-framework/blob/0e63ff509cfe52f9063539a23d5f9f183b2ea4a5/report/src/main/java/com/buschmais/jqassistant/core/report/impl/XmlReportPlugin.java#L226-L230
141,817
buschmais/jqa-core-framework
report/src/main/java/com/buschmais/jqassistant/core/report/impl/XmlReportPlugin.java
XmlReportPlugin.writeColumn
private void writeColumn(String columnName, Object value) throws XMLStreamException { xmlStreamWriter.writeStartElement("column"); xmlStreamWriter.writeAttribute("name", columnName); String stringValue = null; if (value instanceof CompositeObject) { CompositeObject descriptor = (CompositeObject) value; LanguageElement elementValue = LanguageHelper.getLanguageElement(descriptor); if (elementValue != null) { xmlStreamWriter.writeStartElement("element"); xmlStreamWriter.writeAttribute("language", elementValue.getLanguage()); xmlStreamWriter.writeCharacters(elementValue.name()); xmlStreamWriter.writeEndElement(); // element SourceProvider sourceProvider = elementValue.getSourceProvider(); stringValue = sourceProvider.getName(descriptor); String sourceFile = sourceProvider.getSourceFile(descriptor); Integer lineNumber = sourceProvider.getLineNumber(descriptor); if (sourceFile != null) { xmlStreamWriter.writeStartElement("source"); xmlStreamWriter.writeAttribute("name", sourceFile); if (lineNumber != null) { xmlStreamWriter.writeAttribute("line", lineNumber.toString()); } xmlStreamWriter.writeEndElement(); // sourceFile } } } else if (value != null) { stringValue = ReportHelper.getLabel(value); } xmlStreamWriter.writeStartElement("value"); xmlStreamWriter.writeCharacters(stringValue); xmlStreamWriter.writeEndElement(); // value xmlStreamWriter.writeEndElement(); // column }
java
private void writeColumn(String columnName, Object value) throws XMLStreamException { xmlStreamWriter.writeStartElement("column"); xmlStreamWriter.writeAttribute("name", columnName); String stringValue = null; if (value instanceof CompositeObject) { CompositeObject descriptor = (CompositeObject) value; LanguageElement elementValue = LanguageHelper.getLanguageElement(descriptor); if (elementValue != null) { xmlStreamWriter.writeStartElement("element"); xmlStreamWriter.writeAttribute("language", elementValue.getLanguage()); xmlStreamWriter.writeCharacters(elementValue.name()); xmlStreamWriter.writeEndElement(); // element SourceProvider sourceProvider = elementValue.getSourceProvider(); stringValue = sourceProvider.getName(descriptor); String sourceFile = sourceProvider.getSourceFile(descriptor); Integer lineNumber = sourceProvider.getLineNumber(descriptor); if (sourceFile != null) { xmlStreamWriter.writeStartElement("source"); xmlStreamWriter.writeAttribute("name", sourceFile); if (lineNumber != null) { xmlStreamWriter.writeAttribute("line", lineNumber.toString()); } xmlStreamWriter.writeEndElement(); // sourceFile } } } else if (value != null) { stringValue = ReportHelper.getLabel(value); } xmlStreamWriter.writeStartElement("value"); xmlStreamWriter.writeCharacters(stringValue); xmlStreamWriter.writeEndElement(); // value xmlStreamWriter.writeEndElement(); // column }
[ "private", "void", "writeColumn", "(", "String", "columnName", ",", "Object", "value", ")", "throws", "XMLStreamException", "{", "xmlStreamWriter", ".", "writeStartElement", "(", "\"column\"", ")", ";", "xmlStreamWriter", ".", "writeAttribute", "(", "\"name\"", ",", "columnName", ")", ";", "String", "stringValue", "=", "null", ";", "if", "(", "value", "instanceof", "CompositeObject", ")", "{", "CompositeObject", "descriptor", "=", "(", "CompositeObject", ")", "value", ";", "LanguageElement", "elementValue", "=", "LanguageHelper", ".", "getLanguageElement", "(", "descriptor", ")", ";", "if", "(", "elementValue", "!=", "null", ")", "{", "xmlStreamWriter", ".", "writeStartElement", "(", "\"element\"", ")", ";", "xmlStreamWriter", ".", "writeAttribute", "(", "\"language\"", ",", "elementValue", ".", "getLanguage", "(", ")", ")", ";", "xmlStreamWriter", ".", "writeCharacters", "(", "elementValue", ".", "name", "(", ")", ")", ";", "xmlStreamWriter", ".", "writeEndElement", "(", ")", ";", "// element", "SourceProvider", "sourceProvider", "=", "elementValue", ".", "getSourceProvider", "(", ")", ";", "stringValue", "=", "sourceProvider", ".", "getName", "(", "descriptor", ")", ";", "String", "sourceFile", "=", "sourceProvider", ".", "getSourceFile", "(", "descriptor", ")", ";", "Integer", "lineNumber", "=", "sourceProvider", ".", "getLineNumber", "(", "descriptor", ")", ";", "if", "(", "sourceFile", "!=", "null", ")", "{", "xmlStreamWriter", ".", "writeStartElement", "(", "\"source\"", ")", ";", "xmlStreamWriter", ".", "writeAttribute", "(", "\"name\"", ",", "sourceFile", ")", ";", "if", "(", "lineNumber", "!=", "null", ")", "{", "xmlStreamWriter", ".", "writeAttribute", "(", "\"line\"", ",", "lineNumber", ".", "toString", "(", ")", ")", ";", "}", "xmlStreamWriter", ".", "writeEndElement", "(", ")", ";", "// sourceFile", "}", "}", "}", "else", "if", "(", "value", "!=", "null", ")", "{", "stringValue", "=", "ReportHelper", ".", "getLabel", "(", "value", ")", ";", "}", "xmlStreamWriter", ".", "writeStartElement", "(", "\"value\"", ")", ";", "xmlStreamWriter", ".", "writeCharacters", "(", "stringValue", ")", ";", "xmlStreamWriter", ".", "writeEndElement", "(", ")", ";", "// value", "xmlStreamWriter", ".", "writeEndElement", "(", ")", ";", "// column", "}" ]
Determines the language and language element of a descriptor from a result column. @param columnName The name of the column. @param value The value. @throws XMLStreamException If a problem occurs.
[ "Determines", "the", "language", "and", "language", "element", "of", "a", "descriptor", "from", "a", "result", "column", "." ]
0e63ff509cfe52f9063539a23d5f9f183b2ea4a5
https://github.com/buschmais/jqa-core-framework/blob/0e63ff509cfe52f9063539a23d5f9f183b2ea4a5/report/src/main/java/com/buschmais/jqassistant/core/report/impl/XmlReportPlugin.java#L243-L275
141,818
buschmais/jqa-core-framework
report/src/main/java/com/buschmais/jqassistant/core/report/impl/XmlReportPlugin.java
XmlReportPlugin.writeDuration
private void writeDuration(long beginTime) throws XMLStreamException { xmlStreamWriter.writeStartElement("duration"); xmlStreamWriter.writeCharacters(Long.toString(System.currentTimeMillis() - beginTime)); xmlStreamWriter.writeEndElement(); // duration }
java
private void writeDuration(long beginTime) throws XMLStreamException { xmlStreamWriter.writeStartElement("duration"); xmlStreamWriter.writeCharacters(Long.toString(System.currentTimeMillis() - beginTime)); xmlStreamWriter.writeEndElement(); // duration }
[ "private", "void", "writeDuration", "(", "long", "beginTime", ")", "throws", "XMLStreamException", "{", "xmlStreamWriter", ".", "writeStartElement", "(", "\"duration\"", ")", ";", "xmlStreamWriter", ".", "writeCharacters", "(", "Long", ".", "toString", "(", "System", ".", "currentTimeMillis", "(", ")", "-", "beginTime", ")", ")", ";", "xmlStreamWriter", ".", "writeEndElement", "(", ")", ";", "// duration", "}" ]
Writes the duration. @param beginTime The begin time. @throws XMLStreamException If writing fails.
[ "Writes", "the", "duration", "." ]
0e63ff509cfe52f9063539a23d5f9f183b2ea4a5
https://github.com/buschmais/jqa-core-framework/blob/0e63ff509cfe52f9063539a23d5f9f183b2ea4a5/report/src/main/java/com/buschmais/jqassistant/core/report/impl/XmlReportPlugin.java#L285-L289
141,819
buschmais/jqa-core-framework
report/src/main/java/com/buschmais/jqassistant/core/report/impl/XmlReportPlugin.java
XmlReportPlugin.writeSeverity
private void writeSeverity(Severity severity) throws XMLStreamException { xmlStreamWriter.writeStartElement("severity"); xmlStreamWriter.writeAttribute("level", severity.getLevel().toString()); xmlStreamWriter.writeCharacters(severity.getValue()); xmlStreamWriter.writeEndElement(); }
java
private void writeSeverity(Severity severity) throws XMLStreamException { xmlStreamWriter.writeStartElement("severity"); xmlStreamWriter.writeAttribute("level", severity.getLevel().toString()); xmlStreamWriter.writeCharacters(severity.getValue()); xmlStreamWriter.writeEndElement(); }
[ "private", "void", "writeSeverity", "(", "Severity", "severity", ")", "throws", "XMLStreamException", "{", "xmlStreamWriter", ".", "writeStartElement", "(", "\"severity\"", ")", ";", "xmlStreamWriter", ".", "writeAttribute", "(", "\"level\"", ",", "severity", ".", "getLevel", "(", ")", ".", "toString", "(", ")", ")", ";", "xmlStreamWriter", ".", "writeCharacters", "(", "severity", ".", "getValue", "(", ")", ")", ";", "xmlStreamWriter", ".", "writeEndElement", "(", ")", ";", "}" ]
Writes the severity of the rule. @param severity The severity the rule has been executed with @throws XMLStreamException If writing fails.
[ "Writes", "the", "severity", "of", "the", "rule", "." ]
0e63ff509cfe52f9063539a23d5f9f183b2ea4a5
https://github.com/buschmais/jqa-core-framework/blob/0e63ff509cfe52f9063539a23d5f9f183b2ea4a5/report/src/main/java/com/buschmais/jqassistant/core/report/impl/XmlReportPlugin.java#L299-L304
141,820
buschmais/jqa-core-framework
report/src/main/java/com/buschmais/jqassistant/core/report/impl/XmlReportPlugin.java
XmlReportPlugin.run
private void run(XmlOperation operation) throws ReportException { try { operation.run(); } catch (XMLStreamException | IOException e) { throw new ReportException("Cannot write to XML report.", e); } }
java
private void run(XmlOperation operation) throws ReportException { try { operation.run(); } catch (XMLStreamException | IOException e) { throw new ReportException("Cannot write to XML report.", e); } }
[ "private", "void", "run", "(", "XmlOperation", "operation", ")", "throws", "ReportException", "{", "try", "{", "operation", ".", "run", "(", ")", ";", "}", "catch", "(", "XMLStreamException", "|", "IOException", "e", ")", "{", "throw", "new", "ReportException", "(", "\"Cannot write to XML report.\"", ",", "e", ")", ";", "}", "}" ]
Defines an operation to write XML elements. @param operation The operation. @throws ReportException If writing fails.
[ "Defines", "an", "operation", "to", "write", "XML", "elements", "." ]
0e63ff509cfe52f9063539a23d5f9f183b2ea4a5
https://github.com/buschmais/jqa-core-framework/blob/0e63ff509cfe52f9063539a23d5f9f183b2ea4a5/report/src/main/java/com/buschmais/jqassistant/core/report/impl/XmlReportPlugin.java#L314-L320
141,821
MTDdk/jawn
jawn-templates-stringtemplate/src/main/java/net/javapla/jawn/templates/stringtemplate/rewrite/STFastGroupDir.java
STFastGroupDir.loadTemplateResource
private final CompiledST loadTemplateResource(String prefix, String unqualifiedFileName) { //if (resourceRoot == null) return null; //return loadTemplate(resourceRoot, prefix, unqualifiedFileName); if (resourceRoots.isEmpty()) return null; CompiledST template = null; for (URL resourceRoot : resourceRoots) { if ((template = loadTemplate(resourceRoot, prefix, unqualifiedFileName)) != null) return template; } return null; }
java
private final CompiledST loadTemplateResource(String prefix, String unqualifiedFileName) { //if (resourceRoot == null) return null; //return loadTemplate(resourceRoot, prefix, unqualifiedFileName); if (resourceRoots.isEmpty()) return null; CompiledST template = null; for (URL resourceRoot : resourceRoots) { if ((template = loadTemplate(resourceRoot, prefix, unqualifiedFileName)) != null) return template; } return null; }
[ "private", "final", "CompiledST", "loadTemplateResource", "(", "String", "prefix", ",", "String", "unqualifiedFileName", ")", "{", "//if (resourceRoot == null) return null;", "//return loadTemplate(resourceRoot, prefix, unqualifiedFileName);", "if", "(", "resourceRoots", ".", "isEmpty", "(", ")", ")", "return", "null", ";", "CompiledST", "template", "=", "null", ";", "for", "(", "URL", "resourceRoot", ":", "resourceRoots", ")", "{", "if", "(", "(", "template", "=", "loadTemplate", "(", "resourceRoot", ",", "prefix", ",", "unqualifiedFileName", ")", ")", "!=", "null", ")", "return", "template", ";", "}", "return", "null", ";", "}" ]
Loads from a jar or similar resource if the template could not be found directly on the filesystem.
[ "Loads", "from", "a", "jar", "or", "similar", "resource", "if", "the", "template", "could", "not", "be", "found", "directly", "on", "the", "filesystem", "." ]
4ec2d09b97d413efdead7487e6075e5bfd13b925
https://github.com/MTDdk/jawn/blob/4ec2d09b97d413efdead7487e6075e5bfd13b925/jawn-templates-stringtemplate/src/main/java/net/javapla/jawn/templates/stringtemplate/rewrite/STFastGroupDir.java#L123-L133
141,822
MTDdk/jawn
jawn-templates-stringtemplate/src/main/java/net/javapla/jawn/templates/stringtemplate/StringTemplateTemplateEngine.java
StringTemplateTemplateEngine.renderContentTemplate
private final void renderContentTemplate(final ST contentTemplate, final Writer writer, final Map<String, Object> values/*, final String language*/, final ErrorBuffer error) { injectTemplateValues(contentTemplate, values); // if (language == null) contentTemplate.write(createSTWriter(writer), error); // else // contentTemplate.write(createSTWriter(writer), new Locale(language), error); }
java
private final void renderContentTemplate(final ST contentTemplate, final Writer writer, final Map<String, Object> values/*, final String language*/, final ErrorBuffer error) { injectTemplateValues(contentTemplate, values); // if (language == null) contentTemplate.write(createSTWriter(writer), error); // else // contentTemplate.write(createSTWriter(writer), new Locale(language), error); }
[ "private", "final", "void", "renderContentTemplate", "(", "final", "ST", "contentTemplate", ",", "final", "Writer", "writer", ",", "final", "Map", "<", "String", ",", "Object", ">", "values", "/*, final String language*/", ",", "final", "ErrorBuffer", "error", ")", "{", "injectTemplateValues", "(", "contentTemplate", ",", "values", ")", ";", "// if (language == null)", "contentTemplate", ".", "write", "(", "createSTWriter", "(", "writer", ")", ",", "error", ")", ";", "// else", "// contentTemplate.write(createSTWriter(writer), new Locale(language), error);", "}" ]
Renders template directly to writer
[ "Renders", "template", "directly", "to", "writer" ]
4ec2d09b97d413efdead7487e6075e5bfd13b925
https://github.com/MTDdk/jawn/blob/4ec2d09b97d413efdead7487e6075e5bfd13b925/jawn-templates-stringtemplate/src/main/java/net/javapla/jawn/templates/stringtemplate/StringTemplateTemplateEngine.java#L203-L209
141,823
MTDdk/jawn
jawn-templates-stringtemplate/src/main/java/net/javapla/jawn/templates/stringtemplate/StringTemplateTemplateEngine.java
StringTemplateTemplateEngine.renderContentTemplate
private final String renderContentTemplate(final ST contentTemplate, final Map<String, Object> values, final ErrorBuffer error, boolean inErrorState) { if (contentTemplate != null) { // it has to be possible to use a layout without defining a template try (Writer sw = new StringBuilderWriter()) { final ErrorBuffer templateErrors = new ErrorBuffer(); renderContentTemplate(contentTemplate, sw, values/*, language*/, templateErrors); // handle potential errors if (!templateErrors.errors.isEmpty() && !inErrorState) { for (STMessage err : templateErrors.errors) { if (err.error == ErrorType.INTERNAL_ERROR) { log.warn("Reloading GroupDir as we have found a problem during rendering of template \"{}\"\n{}",contentTemplate.getName(), templateErrors.errors.toString()); //README when errors occur, try to reload the specified templates and try the whole thing again // this often rectifies the problem reloadGroup(); ST reloadedContentTemplate = readTemplate(contentTemplate.getName()); return renderContentTemplate(reloadedContentTemplate, values, error, true); } } } return sw.toString(); } catch (IOException noMethodsThrowsIOE) { } } return ""; }
java
private final String renderContentTemplate(final ST contentTemplate, final Map<String, Object> values, final ErrorBuffer error, boolean inErrorState) { if (contentTemplate != null) { // it has to be possible to use a layout without defining a template try (Writer sw = new StringBuilderWriter()) { final ErrorBuffer templateErrors = new ErrorBuffer(); renderContentTemplate(contentTemplate, sw, values/*, language*/, templateErrors); // handle potential errors if (!templateErrors.errors.isEmpty() && !inErrorState) { for (STMessage err : templateErrors.errors) { if (err.error == ErrorType.INTERNAL_ERROR) { log.warn("Reloading GroupDir as we have found a problem during rendering of template \"{}\"\n{}",contentTemplate.getName(), templateErrors.errors.toString()); //README when errors occur, try to reload the specified templates and try the whole thing again // this often rectifies the problem reloadGroup(); ST reloadedContentTemplate = readTemplate(contentTemplate.getName()); return renderContentTemplate(reloadedContentTemplate, values, error, true); } } } return sw.toString(); } catch (IOException noMethodsThrowsIOE) { } } return ""; }
[ "private", "final", "String", "renderContentTemplate", "(", "final", "ST", "contentTemplate", ",", "final", "Map", "<", "String", ",", "Object", ">", "values", ",", "final", "ErrorBuffer", "error", ",", "boolean", "inErrorState", ")", "{", "if", "(", "contentTemplate", "!=", "null", ")", "{", "// it has to be possible to use a layout without defining a template", "try", "(", "Writer", "sw", "=", "new", "StringBuilderWriter", "(", ")", ")", "{", "final", "ErrorBuffer", "templateErrors", "=", "new", "ErrorBuffer", "(", ")", ";", "renderContentTemplate", "(", "contentTemplate", ",", "sw", ",", "values", "/*, language*/", ",", "templateErrors", ")", ";", "// handle potential errors", "if", "(", "!", "templateErrors", ".", "errors", ".", "isEmpty", "(", ")", "&&", "!", "inErrorState", ")", "{", "for", "(", "STMessage", "err", ":", "templateErrors", ".", "errors", ")", "{", "if", "(", "err", ".", "error", "==", "ErrorType", ".", "INTERNAL_ERROR", ")", "{", "log", ".", "warn", "(", "\"Reloading GroupDir as we have found a problem during rendering of template \\\"{}\\\"\\n{}\"", ",", "contentTemplate", ".", "getName", "(", ")", ",", "templateErrors", ".", "errors", ".", "toString", "(", ")", ")", ";", "//README when errors occur, try to reload the specified templates and try the whole thing again", "// this often rectifies the problem", "reloadGroup", "(", ")", ";", "ST", "reloadedContentTemplate", "=", "readTemplate", "(", "contentTemplate", ".", "getName", "(", ")", ")", ";", "return", "renderContentTemplate", "(", "reloadedContentTemplate", ",", "values", ",", "error", ",", "true", ")", ";", "}", "}", "}", "return", "sw", ".", "toString", "(", ")", ";", "}", "catch", "(", "IOException", "noMethodsThrowsIOE", ")", "{", "}", "}", "return", "\"\"", ";", "}" ]
Renders template into string @return The rendered template if exists, or empty string
[ "Renders", "template", "into", "string" ]
4ec2d09b97d413efdead7487e6075e5bfd13b925
https://github.com/MTDdk/jawn/blob/4ec2d09b97d413efdead7487e6075e5bfd13b925/jawn-templates-stringtemplate/src/main/java/net/javapla/jawn/templates/stringtemplate/StringTemplateTemplateEngine.java#L213-L238
141,824
MTDdk/jawn
jawn-core-new/src/main/java/net/javapla/jawn/core/util/ConvertUtil.java
ConvertUtil.toInteger
public static Integer toInteger(Object value) throws ConversionException { if (value == null) { return null; } else if (value instanceof Number) { return ((Number)value).intValue(); } else { NumberFormat nf = new DecimalFormat(); try { return nf.parse(value.toString()).intValue(); } catch (ParseException e) { throw new ConversionException("failed to convert: '" + value + "' to Integer", e); } } }
java
public static Integer toInteger(Object value) throws ConversionException { if (value == null) { return null; } else if (value instanceof Number) { return ((Number)value).intValue(); } else { NumberFormat nf = new DecimalFormat(); try { return nf.parse(value.toString()).intValue(); } catch (ParseException e) { throw new ConversionException("failed to convert: '" + value + "' to Integer", e); } } }
[ "public", "static", "Integer", "toInteger", "(", "Object", "value", ")", "throws", "ConversionException", "{", "if", "(", "value", "==", "null", ")", "{", "return", "null", ";", "}", "else", "if", "(", "value", "instanceof", "Number", ")", "{", "return", "(", "(", "Number", ")", "value", ")", ".", "intValue", "(", ")", ";", "}", "else", "{", "NumberFormat", "nf", "=", "new", "DecimalFormat", "(", ")", ";", "try", "{", "return", "nf", ".", "parse", "(", "value", ".", "toString", "(", ")", ")", ".", "intValue", "(", ")", ";", "}", "catch", "(", "ParseException", "e", ")", "{", "throw", "new", "ConversionException", "(", "\"failed to convert: '\"", "+", "value", "+", "\"' to Integer\"", ",", "e", ")", ";", "}", "}", "}" ]
Converts value to Integer if it can. If value is an Integer, it is returned, if it is a Number, it is promoted to Integer and then returned, in all other cases, it converts the value to String, then tries to parse Integer from it. @param value value to be converted to Integer. @return value converted to Integer. @throws ConversionException if failing to do the conversion
[ "Converts", "value", "to", "Integer", "if", "it", "can", ".", "If", "value", "is", "an", "Integer", "it", "is", "returned", "if", "it", "is", "a", "Number", "it", "is", "promoted", "to", "Integer", "and", "then", "returned", "in", "all", "other", "cases", "it", "converts", "the", "value", "to", "String", "then", "tries", "to", "parse", "Integer", "from", "it", "." ]
4ec2d09b97d413efdead7487e6075e5bfd13b925
https://github.com/MTDdk/jawn/blob/4ec2d09b97d413efdead7487e6075e5bfd13b925/jawn-core-new/src/main/java/net/javapla/jawn/core/util/ConvertUtil.java#L31-L44
141,825
MTDdk/jawn
jawn-core-new/src/main/java/net/javapla/jawn/core/util/ConvertUtil.java
ConvertUtil.toBoolean
public static Boolean toBoolean(Object value){ if (value == null) { return false; } else if (value instanceof Boolean) { return (Boolean) value; } else if (value instanceof BigDecimal) { return value.equals(BigDecimal.ONE); } else if (value instanceof Long) { return value.equals(1L); } else if (value instanceof Integer) { return value.equals(1); } else if (value instanceof Character) { return value.equals('y') || value.equals('Y') || value.equals('t') || value.equals('T'); }else return value.toString().equalsIgnoreCase("yes") || value.toString().equalsIgnoreCase("true") || value.toString().equalsIgnoreCase("y") || value.toString().equalsIgnoreCase("t") || Boolean.parseBoolean(value.toString()); }
java
public static Boolean toBoolean(Object value){ if (value == null) { return false; } else if (value instanceof Boolean) { return (Boolean) value; } else if (value instanceof BigDecimal) { return value.equals(BigDecimal.ONE); } else if (value instanceof Long) { return value.equals(1L); } else if (value instanceof Integer) { return value.equals(1); } else if (value instanceof Character) { return value.equals('y') || value.equals('Y') || value.equals('t') || value.equals('T'); }else return value.toString().equalsIgnoreCase("yes") || value.toString().equalsIgnoreCase("true") || value.toString().equalsIgnoreCase("y") || value.toString().equalsIgnoreCase("t") || Boolean.parseBoolean(value.toString()); }
[ "public", "static", "Boolean", "toBoolean", "(", "Object", "value", ")", "{", "if", "(", "value", "==", "null", ")", "{", "return", "false", ";", "}", "else", "if", "(", "value", "instanceof", "Boolean", ")", "{", "return", "(", "Boolean", ")", "value", ";", "}", "else", "if", "(", "value", "instanceof", "BigDecimal", ")", "{", "return", "value", ".", "equals", "(", "BigDecimal", ".", "ONE", ")", ";", "}", "else", "if", "(", "value", "instanceof", "Long", ")", "{", "return", "value", ".", "equals", "(", "1L", ")", ";", "}", "else", "if", "(", "value", "instanceof", "Integer", ")", "{", "return", "value", ".", "equals", "(", "1", ")", ";", "}", "else", "if", "(", "value", "instanceof", "Character", ")", "{", "return", "value", ".", "equals", "(", "'", "'", ")", "||", "value", ".", "equals", "(", "'", "'", ")", "||", "value", ".", "equals", "(", "'", "'", ")", "||", "value", ".", "equals", "(", "'", "'", ")", ";", "}", "else", "return", "value", ".", "toString", "(", ")", ".", "equalsIgnoreCase", "(", "\"yes\"", ")", "||", "value", ".", "toString", "(", ")", ".", "equalsIgnoreCase", "(", "\"true\"", ")", "||", "value", ".", "toString", "(", ")", ".", "equalsIgnoreCase", "(", "\"y\"", ")", "||", "value", ".", "toString", "(", ")", ".", "equalsIgnoreCase", "(", "\"t\"", ")", "||", "Boolean", ".", "parseBoolean", "(", "value", ".", "toString", "(", ")", ")", ";", "}" ]
Returns true if the value is any numeric type and has a value of 1, or if string type has a value of 'y', 't', 'true' or 'yes'. Otherwise, return false. @param value value to convert @return true if the value is any numeric type and has a value of 1, or if string type has a value of 'y', 't', 'true' or 'yes'. Otherwise, return false.
[ "Returns", "true", "if", "the", "value", "is", "any", "numeric", "type", "and", "has", "a", "value", "of", "1", "or", "if", "string", "type", "has", "a", "value", "of", "y", "t", "true", "or", "yes", ".", "Otherwise", "return", "false", "." ]
4ec2d09b97d413efdead7487e6075e5bfd13b925
https://github.com/MTDdk/jawn/blob/4ec2d09b97d413efdead7487e6075e5bfd13b925/jawn-core-new/src/main/java/net/javapla/jawn/core/util/ConvertUtil.java#L69-L89
141,826
MTDdk/jawn
jawn-core-new/src/main/java/net/javapla/jawn/core/util/ConvertUtil.java
ConvertUtil.toLong
public static Long toLong(Object value) throws ConversionException { if (value == null) { return null; } else if (value instanceof Number) { return ((Number)value).longValue(); } else { NumberFormat nf = new DecimalFormat(); try { return nf.parse(value.toString()).longValue(); } catch (ParseException e) { throw new ConversionException("failed to convert: '" + value + "' to Long", e); } } }
java
public static Long toLong(Object value) throws ConversionException { if (value == null) { return null; } else if (value instanceof Number) { return ((Number)value).longValue(); } else { NumberFormat nf = new DecimalFormat(); try { return nf.parse(value.toString()).longValue(); } catch (ParseException e) { throw new ConversionException("failed to convert: '" + value + "' to Long", e); } } }
[ "public", "static", "Long", "toLong", "(", "Object", "value", ")", "throws", "ConversionException", "{", "if", "(", "value", "==", "null", ")", "{", "return", "null", ";", "}", "else", "if", "(", "value", "instanceof", "Number", ")", "{", "return", "(", "(", "Number", ")", "value", ")", ".", "longValue", "(", ")", ";", "}", "else", "{", "NumberFormat", "nf", "=", "new", "DecimalFormat", "(", ")", ";", "try", "{", "return", "nf", ".", "parse", "(", "value", ".", "toString", "(", ")", ")", ".", "longValue", "(", ")", ";", "}", "catch", "(", "ParseException", "e", ")", "{", "throw", "new", "ConversionException", "(", "\"failed to convert: '\"", "+", "value", "+", "\"' to Long\"", ",", "e", ")", ";", "}", "}", "}" ]
Converts value to Long if c it can. If value is a Long, it is returned, if it is a Number, it is promoted to Long and then returned, in all other cases, it converts the value to String, then tries to parse Long from it. @param value value to be converted to Long. @return value converted to Long. @throws ConversionException if the conversion failed
[ "Converts", "value", "to", "Long", "if", "c", "it", "can", ".", "If", "value", "is", "a", "Long", "it", "is", "returned", "if", "it", "is", "a", "Number", "it", "is", "promoted", "to", "Long", "and", "then", "returned", "in", "all", "other", "cases", "it", "converts", "the", "value", "to", "String", "then", "tries", "to", "parse", "Long", "from", "it", "." ]
4ec2d09b97d413efdead7487e6075e5bfd13b925
https://github.com/MTDdk/jawn/blob/4ec2d09b97d413efdead7487e6075e5bfd13b925/jawn-core-new/src/main/java/net/javapla/jawn/core/util/ConvertUtil.java#L122-L135
141,827
buschmais/jqa-core-framework
plugin/src/main/java/com/buschmais/jqassistant/core/plugin/impl/AbstractPluginRepository.java
AbstractPluginRepository.getType
protected <T> Class<T> getType(String typeName) throws PluginRepositoryException { try { return (Class<T>) classLoader.loadClass(typeName.trim()); } catch (ClassNotFoundException | LinkageError e) { // Catching class loader related errors for logging a message which plugin class // actually caused the problem. throw new PluginRepositoryException("Cannot find or load class " + typeName, e); } }
java
protected <T> Class<T> getType(String typeName) throws PluginRepositoryException { try { return (Class<T>) classLoader.loadClass(typeName.trim()); } catch (ClassNotFoundException | LinkageError e) { // Catching class loader related errors for logging a message which plugin class // actually caused the problem. throw new PluginRepositoryException("Cannot find or load class " + typeName, e); } }
[ "protected", "<", "T", ">", "Class", "<", "T", ">", "getType", "(", "String", "typeName", ")", "throws", "PluginRepositoryException", "{", "try", "{", "return", "(", "Class", "<", "T", ">", ")", "classLoader", ".", "loadClass", "(", "typeName", ".", "trim", "(", ")", ")", ";", "}", "catch", "(", "ClassNotFoundException", "|", "LinkageError", "e", ")", "{", "// Catching class loader related errors for logging a message which plugin class", "// actually caused the problem.", "throw", "new", "PluginRepositoryException", "(", "\"Cannot find or load class \"", "+", "typeName", ",", "e", ")", ";", "}", "}" ]
Get the class for the given type name. @param typeName The type name. @param <T> The type name. @return The class. @throws PluginRepositoryException If the type could not be loaded.
[ "Get", "the", "class", "for", "the", "given", "type", "name", "." ]
0e63ff509cfe52f9063539a23d5f9f183b2ea4a5
https://github.com/buschmais/jqa-core-framework/blob/0e63ff509cfe52f9063539a23d5f9f183b2ea4a5/plugin/src/main/java/com/buschmais/jqassistant/core/plugin/impl/AbstractPluginRepository.java#L51-L59
141,828
buschmais/jqa-core-framework
plugin/src/main/java/com/buschmais/jqassistant/core/plugin/impl/AbstractPluginRepository.java
AbstractPluginRepository.createInstance
protected <T> T createInstance(String typeName) throws PluginRepositoryException { Class<T> type = getType(typeName.trim()); try { return type.newInstance(); } catch (InstantiationException e) { throw new PluginRepositoryException("Cannot create instance of class " + type.getName(), e); } catch (IllegalAccessException e) { throw new PluginRepositoryException("Cannot access class " + typeName, e); } catch (LinkageError e) { throw new PluginRepositoryException("Cannot load plugin class " + typeName, e); } }
java
protected <T> T createInstance(String typeName) throws PluginRepositoryException { Class<T> type = getType(typeName.trim()); try { return type.newInstance(); } catch (InstantiationException e) { throw new PluginRepositoryException("Cannot create instance of class " + type.getName(), e); } catch (IllegalAccessException e) { throw new PluginRepositoryException("Cannot access class " + typeName, e); } catch (LinkageError e) { throw new PluginRepositoryException("Cannot load plugin class " + typeName, e); } }
[ "protected", "<", "T", ">", "T", "createInstance", "(", "String", "typeName", ")", "throws", "PluginRepositoryException", "{", "Class", "<", "T", ">", "type", "=", "getType", "(", "typeName", ".", "trim", "(", ")", ")", ";", "try", "{", "return", "type", ".", "newInstance", "(", ")", ";", "}", "catch", "(", "InstantiationException", "e", ")", "{", "throw", "new", "PluginRepositoryException", "(", "\"Cannot create instance of class \"", "+", "type", ".", "getName", "(", ")", ",", "e", ")", ";", "}", "catch", "(", "IllegalAccessException", "e", ")", "{", "throw", "new", "PluginRepositoryException", "(", "\"Cannot access class \"", "+", "typeName", ",", "e", ")", ";", "}", "catch", "(", "LinkageError", "e", ")", "{", "throw", "new", "PluginRepositoryException", "(", "\"Cannot load plugin class \"", "+", "typeName", ",", "e", ")", ";", "}", "}" ]
Create an instance of the given scanner plugin class. @param typeName The type name. @param <T> The type. @return The plugin instance. @throws PluginRepositoryException If the requested instance could not be created.
[ "Create", "an", "instance", "of", "the", "given", "scanner", "plugin", "class", "." ]
0e63ff509cfe52f9063539a23d5f9f183b2ea4a5
https://github.com/buschmais/jqa-core-framework/blob/0e63ff509cfe52f9063539a23d5f9f183b2ea4a5/plugin/src/main/java/com/buschmais/jqassistant/core/plugin/impl/AbstractPluginRepository.java#L72-L83
141,829
MTDdk/jawn
jawn-core/src/main/java/net/javapla/jawn/core/routes/RouterImpl.java
RouterImpl.calculateRoute
private final Route calculateRoute(HttpMethod httpMethod, String requestUri/*, ActionInvoker invoker*//*,Injector injector*/) throws RouteException { if (routes == null) throw new IllegalStateException("Routes have not been compiled. Call #compileRoutes() first"); final Route route = matchCustom(httpMethod, requestUri); if (route != null) return route; // nothing is found - try to deduce a route from controllers //if (isDev) { try { return matchStandard(httpMethod, requestUri, invoker/*injector*/); } catch (ClassLoadException e) { // a route could not be deduced } //} throw new RouteException("Failed to map resource to URI: " + requestUri); }
java
private final Route calculateRoute(HttpMethod httpMethod, String requestUri/*, ActionInvoker invoker*//*,Injector injector*/) throws RouteException { if (routes == null) throw new IllegalStateException("Routes have not been compiled. Call #compileRoutes() first"); final Route route = matchCustom(httpMethod, requestUri); if (route != null) return route; // nothing is found - try to deduce a route from controllers //if (isDev) { try { return matchStandard(httpMethod, requestUri, invoker/*injector*/); } catch (ClassLoadException e) { // a route could not be deduced } //} throw new RouteException("Failed to map resource to URI: " + requestUri); }
[ "private", "final", "Route", "calculateRoute", "(", "HttpMethod", "httpMethod", ",", "String", "requestUri", "/*, ActionInvoker invoker*/", "/*,Injector injector*/", ")", "throws", "RouteException", "{", "if", "(", "routes", "==", "null", ")", "throw", "new", "IllegalStateException", "(", "\"Routes have not been compiled. Call #compileRoutes() first\"", ")", ";", "final", "Route", "route", "=", "matchCustom", "(", "httpMethod", ",", "requestUri", ")", ";", "if", "(", "route", "!=", "null", ")", "return", "route", ";", "// nothing is found - try to deduce a route from controllers", "//if (isDev) {", "try", "{", "return", "matchStandard", "(", "httpMethod", ",", "requestUri", ",", "invoker", "/*injector*/", ")", ";", "}", "catch", "(", "ClassLoadException", "e", ")", "{", "// a route could not be deduced", "}", "//}", "throw", "new", "RouteException", "(", "\"Failed to map resource to URI: \"", "+", "requestUri", ")", ";", "}" ]
It is not consistent that this particular injector handles implementations from both core and server
[ "It", "is", "not", "consistent", "that", "this", "particular", "injector", "handles", "implementations", "from", "both", "core", "and", "server" ]
4ec2d09b97d413efdead7487e6075e5bfd13b925
https://github.com/MTDdk/jawn/blob/4ec2d09b97d413efdead7487e6075e5bfd13b925/jawn-core/src/main/java/net/javapla/jawn/core/routes/RouterImpl.java#L82-L98
141,830
MTDdk/jawn
jawn-core/src/main/java/net/javapla/jawn/core/routes/RouterImpl.java
RouterImpl.matchStandard
private Route matchStandard(HttpMethod httpMethod, String requestUri, ActionInvoker invoker) throws ClassLoadException { // find potential routes for (InternalRoute internalRoute : internalRoutes) { if (internalRoute.matches(requestUri) ) { Route deferred = deduceRoute(internalRoute, httpMethod, requestUri, invoker); if (deferred != null) return deferred; } } throw new ClassLoadException("A route for request " + requestUri + " could not be deduced"); }
java
private Route matchStandard(HttpMethod httpMethod, String requestUri, ActionInvoker invoker) throws ClassLoadException { // find potential routes for (InternalRoute internalRoute : internalRoutes) { if (internalRoute.matches(requestUri) ) { Route deferred = deduceRoute(internalRoute, httpMethod, requestUri, invoker); if (deferred != null) return deferred; } } throw new ClassLoadException("A route for request " + requestUri + " could not be deduced"); }
[ "private", "Route", "matchStandard", "(", "HttpMethod", "httpMethod", ",", "String", "requestUri", ",", "ActionInvoker", "invoker", ")", "throws", "ClassLoadException", "{", "// find potential routes", "for", "(", "InternalRoute", "internalRoute", ":", "internalRoutes", ")", "{", "if", "(", "internalRoute", ".", "matches", "(", "requestUri", ")", ")", "{", "Route", "deferred", "=", "deduceRoute", "(", "internalRoute", ",", "httpMethod", ",", "requestUri", ",", "invoker", ")", ";", "if", "(", "deferred", "!=", "null", ")", "return", "deferred", ";", "}", "}", "throw", "new", "ClassLoadException", "(", "\"A route for request \"", "+", "requestUri", "+", "\" could not be deduced\"", ")", ";", "}" ]
Only to be used in DEV mode @param httpMethod @param requestUri @param injector @return @throws ClassLoadException
[ "Only", "to", "be", "used", "in", "DEV", "mode" ]
4ec2d09b97d413efdead7487e6075e5bfd13b925
https://github.com/MTDdk/jawn/blob/4ec2d09b97d413efdead7487e6075e5bfd13b925/jawn-core/src/main/java/net/javapla/jawn/core/routes/RouterImpl.java#L196-L205
141,831
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/model/JBBPAbstractArrayField.java
JBBPAbstractArrayField.iterator
@SuppressWarnings("NullableProblems") @Override public Iterator<T> iterator() { return new Iterator<T>() { private int index = 0; @Override public boolean hasNext() { return this.index < size(); } @Override public T next() { if (this.index >= size()) { throw new NoSuchElementException(this.index + ">=" + size()); } return getElementAt(this.index++); } @Override public void remove() { throw new UnsupportedOperationException("Removing is unsupported here"); } }; }
java
@SuppressWarnings("NullableProblems") @Override public Iterator<T> iterator() { return new Iterator<T>() { private int index = 0; @Override public boolean hasNext() { return this.index < size(); } @Override public T next() { if (this.index >= size()) { throw new NoSuchElementException(this.index + ">=" + size()); } return getElementAt(this.index++); } @Override public void remove() { throw new UnsupportedOperationException("Removing is unsupported here"); } }; }
[ "@", "SuppressWarnings", "(", "\"NullableProblems\"", ")", "@", "Override", "public", "Iterator", "<", "T", ">", "iterator", "(", ")", "{", "return", "new", "Iterator", "<", "T", ">", "(", ")", "{", "private", "int", "index", "=", "0", ";", "@", "Override", "public", "boolean", "hasNext", "(", ")", "{", "return", "this", ".", "index", "<", "size", "(", ")", ";", "}", "@", "Override", "public", "T", "next", "(", ")", "{", "if", "(", "this", ".", "index", ">=", "size", "(", ")", ")", "{", "throw", "new", "NoSuchElementException", "(", "this", ".", "index", "+", "\">=\"", "+", "size", "(", ")", ")", ";", "}", "return", "getElementAt", "(", "this", ".", "index", "++", ")", ";", "}", "@", "Override", "public", "void", "remove", "(", ")", "{", "throw", "new", "UnsupportedOperationException", "(", "\"Removing is unsupported here\"", ")", ";", "}", "}", ";", "}" ]
Generates an iterator to allow the array processing in loops. @return an iterator for the array
[ "Generates", "an", "iterator", "to", "allow", "the", "array", "processing", "in", "loops", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/model/JBBPAbstractArrayField.java#L70-L95
141,832
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/JBBPParser.java
JBBPParser.assertArrayLength
private static void assertArrayLength(final int length, final JBBPNamedFieldInfo name) { if (length < 0) { throw new JBBPParsingException("Detected negative calculated array length for field '" + (name == null ? "<NO NAME>" : name.getFieldPath()) + "\' [" + JBBPUtils.int2msg(length) + ']'); } }
java
private static void assertArrayLength(final int length, final JBBPNamedFieldInfo name) { if (length < 0) { throw new JBBPParsingException("Detected negative calculated array length for field '" + (name == null ? "<NO NAME>" : name.getFieldPath()) + "\' [" + JBBPUtils.int2msg(length) + ']'); } }
[ "private", "static", "void", "assertArrayLength", "(", "final", "int", "length", ",", "final", "JBBPNamedFieldInfo", "name", ")", "{", "if", "(", "length", "<", "0", ")", "{", "throw", "new", "JBBPParsingException", "(", "\"Detected negative calculated array length for field '\"", "+", "(", "name", "==", "null", "?", "\"<NO NAME>\"", ":", "name", ".", "getFieldPath", "(", ")", ")", "+", "\"\\' [\"", "+", "JBBPUtils", ".", "int2msg", "(", "length", ")", "+", "'", "'", ")", ";", "}", "}" ]
Ensure that an array length is not a negative one. @param length the array length to be checked @param name the name information of a field, it can be null
[ "Ensure", "that", "an", "array", "length", "is", "not", "a", "negative", "one", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/JBBPParser.java#L146-L150
141,833
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/JBBPParser.java
JBBPParser.prepare
public static JBBPParser prepare(final String script, final JBBPBitOrder bitOrder) { return new JBBPParser(script, bitOrder, null, 0); }
java
public static JBBPParser prepare(final String script, final JBBPBitOrder bitOrder) { return new JBBPParser(script, bitOrder, null, 0); }
[ "public", "static", "JBBPParser", "prepare", "(", "final", "String", "script", ",", "final", "JBBPBitOrder", "bitOrder", ")", "{", "return", "new", "JBBPParser", "(", "script", ",", "bitOrder", ",", "null", ",", "0", ")", ";", "}" ]
Prepare a parser for a script and a bit order. @param script a text script contains field order and types reference, it must not be null @param bitOrder the bit order for reading operations, it must not be null @return the prepared parser for the script @see JBBPBitOrder#LSB0 @see JBBPBitOrder#MSB0
[ "Prepare", "a", "parser", "for", "a", "script", "and", "a", "bit", "order", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/JBBPParser.java#L161-L163
141,834
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/JBBPParser.java
JBBPParser.prepare
public static JBBPParser prepare(final String script, final JBBPBitOrder bitOrder, final JBBPCustomFieldTypeProcessor customFieldTypeProcessor, final int flags) { return new JBBPParser(script, bitOrder, customFieldTypeProcessor, flags); }
java
public static JBBPParser prepare(final String script, final JBBPBitOrder bitOrder, final JBBPCustomFieldTypeProcessor customFieldTypeProcessor, final int flags) { return new JBBPParser(script, bitOrder, customFieldTypeProcessor, flags); }
[ "public", "static", "JBBPParser", "prepare", "(", "final", "String", "script", ",", "final", "JBBPBitOrder", "bitOrder", ",", "final", "JBBPCustomFieldTypeProcessor", "customFieldTypeProcessor", ",", "final", "int", "flags", ")", "{", "return", "new", "JBBPParser", "(", "script", ",", "bitOrder", ",", "customFieldTypeProcessor", ",", "flags", ")", ";", "}" ]
Prepare a parser for a script with defined bit order and special flags. @param script a text script contains field order and types reference, it must not be null @param bitOrder the bit order for reading operations, it must not be null @param customFieldTypeProcessor custom field type processor, it can be null @param flags special flags for parsing @return the prepared parser for the script @see JBBPBitOrder#LSB0 @see JBBPBitOrder#MSB0 @see #FLAG_SKIP_REMAINING_FIELDS_IF_EOF @since 1.1.1
[ "Prepare", "a", "parser", "for", "a", "script", "with", "defined", "bit", "order", "and", "special", "flags", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/JBBPParser.java#L196-L198
141,835
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/JBBPParser.java
JBBPParser.parse
public JBBPFieldStruct parse(final InputStream in, final JBBPVarFieldProcessor varFieldProcessor, final JBBPExternalValueProvider externalValueProvider) throws IOException { final JBBPBitInputStream bitInStream = in instanceof JBBPBitInputStream ? (JBBPBitInputStream) in : new JBBPBitInputStream(in, bitOrder); this.finalStreamByteCounter = bitInStream.getCounter(); final JBBPNamedNumericFieldMap fieldMap; if (this.compiledBlock.hasEvaluatedSizeArrays() || this.compiledBlock.hasVarFields()) { fieldMap = new JBBPNamedNumericFieldMap(externalValueProvider); } else { fieldMap = null; } if (this.compiledBlock.hasVarFields()) { JBBPUtils.assertNotNull(varFieldProcessor, "The Script contains VAR fields, a var field processor must be provided"); } try { return new JBBPFieldStruct(new JBBPNamedFieldInfo("", "", -1), parseStruct(bitInStream, new JBBPIntCounter(), varFieldProcessor, fieldMap, new JBBPIntCounter(), new JBBPIntCounter(), false)); } finally { this.finalStreamByteCounter = bitInStream.getCounter(); } }
java
public JBBPFieldStruct parse(final InputStream in, final JBBPVarFieldProcessor varFieldProcessor, final JBBPExternalValueProvider externalValueProvider) throws IOException { final JBBPBitInputStream bitInStream = in instanceof JBBPBitInputStream ? (JBBPBitInputStream) in : new JBBPBitInputStream(in, bitOrder); this.finalStreamByteCounter = bitInStream.getCounter(); final JBBPNamedNumericFieldMap fieldMap; if (this.compiledBlock.hasEvaluatedSizeArrays() || this.compiledBlock.hasVarFields()) { fieldMap = new JBBPNamedNumericFieldMap(externalValueProvider); } else { fieldMap = null; } if (this.compiledBlock.hasVarFields()) { JBBPUtils.assertNotNull(varFieldProcessor, "The Script contains VAR fields, a var field processor must be provided"); } try { return new JBBPFieldStruct(new JBBPNamedFieldInfo("", "", -1), parseStruct(bitInStream, new JBBPIntCounter(), varFieldProcessor, fieldMap, new JBBPIntCounter(), new JBBPIntCounter(), false)); } finally { this.finalStreamByteCounter = bitInStream.getCounter(); } }
[ "public", "JBBPFieldStruct", "parse", "(", "final", "InputStream", "in", ",", "final", "JBBPVarFieldProcessor", "varFieldProcessor", ",", "final", "JBBPExternalValueProvider", "externalValueProvider", ")", "throws", "IOException", "{", "final", "JBBPBitInputStream", "bitInStream", "=", "in", "instanceof", "JBBPBitInputStream", "?", "(", "JBBPBitInputStream", ")", "in", ":", "new", "JBBPBitInputStream", "(", "in", ",", "bitOrder", ")", ";", "this", ".", "finalStreamByteCounter", "=", "bitInStream", ".", "getCounter", "(", ")", ";", "final", "JBBPNamedNumericFieldMap", "fieldMap", ";", "if", "(", "this", ".", "compiledBlock", ".", "hasEvaluatedSizeArrays", "(", ")", "||", "this", ".", "compiledBlock", ".", "hasVarFields", "(", ")", ")", "{", "fieldMap", "=", "new", "JBBPNamedNumericFieldMap", "(", "externalValueProvider", ")", ";", "}", "else", "{", "fieldMap", "=", "null", ";", "}", "if", "(", "this", ".", "compiledBlock", ".", "hasVarFields", "(", ")", ")", "{", "JBBPUtils", ".", "assertNotNull", "(", "varFieldProcessor", ",", "\"The Script contains VAR fields, a var field processor must be provided\"", ")", ";", "}", "try", "{", "return", "new", "JBBPFieldStruct", "(", "new", "JBBPNamedFieldInfo", "(", "\"\"", ",", "\"\"", ",", "-", "1", ")", ",", "parseStruct", "(", "bitInStream", ",", "new", "JBBPIntCounter", "(", ")", ",", "varFieldProcessor", ",", "fieldMap", ",", "new", "JBBPIntCounter", "(", ")", ",", "new", "JBBPIntCounter", "(", ")", ",", "false", ")", ")", ";", "}", "finally", "{", "this", ".", "finalStreamByteCounter", "=", "bitInStream", ".", "getCounter", "(", ")", ";", "}", "}" ]
Parse am input stream with defined external value provider. @param in an input stream which content will be parsed, it must not be null @param varFieldProcessor a var field processor, it may be null if there is not any var field in a script, otherwise NPE will be thrown during parsing @param externalValueProvider an external value provider, it can be null but only if the script doesn't have fields desired the provider @return the parsed content as the root structure @throws IOException it will be thrown for transport errors
[ "Parse", "am", "input", "stream", "with", "defined", "external", "value", "provider", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/JBBPParser.java#L626-L645
141,836
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/JBBPParser.java
JBBPParser.convertToSrc
public List<ResultSrcItem> convertToSrc(final TargetSources target, final String name) { JBBPUtils.assertNotNull(name, "Name must not be null"); if (target == TargetSources.JAVA_1_6) { final Properties metadata = new Properties(); metadata.setProperty("script", this.compiledBlock.getSource()); metadata.setProperty("name", name); metadata.setProperty("target", target.name()); metadata.setProperty("converter", JBBPToJava6Converter.class.getCanonicalName()); final int nameStart = name.lastIndexOf('.'); final String packageName; final String className; if (nameStart < 0) { packageName = ""; className = name; } else { packageName = name.substring(0, nameStart); className = name.substring(nameStart + 1); } final String resultSources = JBBPToJava6Converter.makeBuilder(this).setMainClassPackage(packageName).setMainClassName(className).build().convert(); final Map<String, String> resultMap = Collections.singletonMap(name.replace('.', '/') + ".java", resultSources); return Collections.singletonList(new ResultSrcItem() { @Override public Properties getMetadata() { return metadata; } @Override public Map<String, String> getResult() { return resultMap; } }); } throw new IllegalArgumentException("Unsupported target : " + target); }
java
public List<ResultSrcItem> convertToSrc(final TargetSources target, final String name) { JBBPUtils.assertNotNull(name, "Name must not be null"); if (target == TargetSources.JAVA_1_6) { final Properties metadata = new Properties(); metadata.setProperty("script", this.compiledBlock.getSource()); metadata.setProperty("name", name); metadata.setProperty("target", target.name()); metadata.setProperty("converter", JBBPToJava6Converter.class.getCanonicalName()); final int nameStart = name.lastIndexOf('.'); final String packageName; final String className; if (nameStart < 0) { packageName = ""; className = name; } else { packageName = name.substring(0, nameStart); className = name.substring(nameStart + 1); } final String resultSources = JBBPToJava6Converter.makeBuilder(this).setMainClassPackage(packageName).setMainClassName(className).build().convert(); final Map<String, String> resultMap = Collections.singletonMap(name.replace('.', '/') + ".java", resultSources); return Collections.singletonList(new ResultSrcItem() { @Override public Properties getMetadata() { return metadata; } @Override public Map<String, String> getResult() { return resultMap; } }); } throw new IllegalArgumentException("Unsupported target : " + target); }
[ "public", "List", "<", "ResultSrcItem", ">", "convertToSrc", "(", "final", "TargetSources", "target", ",", "final", "String", "name", ")", "{", "JBBPUtils", ".", "assertNotNull", "(", "name", ",", "\"Name must not be null\"", ")", ";", "if", "(", "target", "==", "TargetSources", ".", "JAVA_1_6", ")", "{", "final", "Properties", "metadata", "=", "new", "Properties", "(", ")", ";", "metadata", ".", "setProperty", "(", "\"script\"", ",", "this", ".", "compiledBlock", ".", "getSource", "(", ")", ")", ";", "metadata", ".", "setProperty", "(", "\"name\"", ",", "name", ")", ";", "metadata", ".", "setProperty", "(", "\"target\"", ",", "target", ".", "name", "(", ")", ")", ";", "metadata", ".", "setProperty", "(", "\"converter\"", ",", "JBBPToJava6Converter", ".", "class", ".", "getCanonicalName", "(", ")", ")", ";", "final", "int", "nameStart", "=", "name", ".", "lastIndexOf", "(", "'", "'", ")", ";", "final", "String", "packageName", ";", "final", "String", "className", ";", "if", "(", "nameStart", "<", "0", ")", "{", "packageName", "=", "\"\"", ";", "className", "=", "name", ";", "}", "else", "{", "packageName", "=", "name", ".", "substring", "(", "0", ",", "nameStart", ")", ";", "className", "=", "name", ".", "substring", "(", "nameStart", "+", "1", ")", ";", "}", "final", "String", "resultSources", "=", "JBBPToJava6Converter", ".", "makeBuilder", "(", "this", ")", ".", "setMainClassPackage", "(", "packageName", ")", ".", "setMainClassName", "(", "className", ")", ".", "build", "(", ")", ".", "convert", "(", ")", ";", "final", "Map", "<", "String", ",", "String", ">", "resultMap", "=", "Collections", ".", "singletonMap", "(", "name", ".", "replace", "(", "'", "'", ",", "'", "'", ")", "+", "\".java\"", ",", "resultSources", ")", ";", "return", "Collections", ".", "singletonList", "(", "new", "ResultSrcItem", "(", ")", "{", "@", "Override", "public", "Properties", "getMetadata", "(", ")", "{", "return", "metadata", ";", "}", "@", "Override", "public", "Map", "<", "String", ",", "String", ">", "getResult", "(", ")", "{", "return", "resultMap", ";", "}", "}", ")", ";", "}", "throw", "new", "IllegalArgumentException", "(", "\"Unsupported target : \"", "+", "target", ")", ";", "}" ]
Convert the prepared parser into sources. It doesn't provide way to define different flag for conversion, it uses default flags for converters and provided for short fast way. @param target target to generate sources, must not be null @param name name of result, depends on target, must not be null, for instance class name (example 'com.test.jbbp.Parser') @return list of source items generated during operation, must not be null and must not be empty @throws IllegalArgumentException if target is unsupported @see JBBPToJava6Converter @see JBBPToJava6Converter.Builder @since 1.3.0
[ "Convert", "the", "prepared", "parser", "into", "sources", ".", "It", "doesn", "t", "provide", "way", "to", "define", "different", "flag", "for", "conversion", "it", "uses", "default", "flags", "for", "converters", "and", "provided", "for", "short", "fast", "way", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/JBBPParser.java#L720-L757
141,837
raydac/java-binary-block-parser
jbbp-plugins/jbbp-plugin-common/src/main/java/com/igormaznitsa/jbbp/plugin/common/utils/CommonUtils.java
CommonUtils.ensureEncodingName
@Nonnull public static String ensureEncodingName(@Nullable final String charsetName) { final Charset defaultCharset = Charset.defaultCharset(); try { return (charsetName == null) ? defaultCharset.name() : Charset.forName(charsetName.trim()).name(); } catch (IllegalCharsetNameException ex) { throw new IllegalArgumentException("Can't recognize charset for name '" + charsetName + '\''); } }
java
@Nonnull public static String ensureEncodingName(@Nullable final String charsetName) { final Charset defaultCharset = Charset.defaultCharset(); try { return (charsetName == null) ? defaultCharset.name() : Charset.forName(charsetName.trim()).name(); } catch (IllegalCharsetNameException ex) { throw new IllegalArgumentException("Can't recognize charset for name '" + charsetName + '\''); } }
[ "@", "Nonnull", "public", "static", "String", "ensureEncodingName", "(", "@", "Nullable", "final", "String", "charsetName", ")", "{", "final", "Charset", "defaultCharset", "=", "Charset", ".", "defaultCharset", "(", ")", ";", "try", "{", "return", "(", "charsetName", "==", "null", ")", "?", "defaultCharset", ".", "name", "(", ")", ":", "Charset", ".", "forName", "(", "charsetName", ".", "trim", "(", ")", ")", ".", "name", "(", ")", ";", "}", "catch", "(", "IllegalCharsetNameException", "ex", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Can't recognize charset for name '\"", "+", "charsetName", "+", "'", "'", ")", ";", "}", "}" ]
Get charset name. If name is null then default charset name provided. @param charsetName name of charset, can be null @return charset name, must not be null @throws IllegalArgumentException if charset name can't be recognized
[ "Get", "charset", "name", ".", "If", "name", "is", "null", "then", "default", "charset", "name", "provided", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp-plugins/jbbp-plugin-common/src/main/java/com/igormaznitsa/jbbp/plugin/common/utils/CommonUtils.java#L43-L51
141,838
raydac/java-binary-block-parser
jbbp-plugins/jbbp-plugin-common/src/main/java/com/igormaznitsa/jbbp/plugin/common/utils/CommonUtils.java
CommonUtils.extractClassName
@Nonnull public static String extractClassName(@Nonnull final String canonicalJavaClassName) { final int lastDot = canonicalJavaClassName.lastIndexOf('.'); if (lastDot < 0) { return canonicalJavaClassName.trim(); } return canonicalJavaClassName.substring(lastDot + 1).trim(); }
java
@Nonnull public static String extractClassName(@Nonnull final String canonicalJavaClassName) { final int lastDot = canonicalJavaClassName.lastIndexOf('.'); if (lastDot < 0) { return canonicalJavaClassName.trim(); } return canonicalJavaClassName.substring(lastDot + 1).trim(); }
[ "@", "Nonnull", "public", "static", "String", "extractClassName", "(", "@", "Nonnull", "final", "String", "canonicalJavaClassName", ")", "{", "final", "int", "lastDot", "=", "canonicalJavaClassName", ".", "lastIndexOf", "(", "'", "'", ")", ";", "if", "(", "lastDot", "<", "0", ")", "{", "return", "canonicalJavaClassName", ".", "trim", "(", ")", ";", "}", "return", "canonicalJavaClassName", ".", "substring", "(", "lastDot", "+", "1", ")", ".", "trim", "(", ")", ";", "}" ]
Extract class name from canonical Java class name @param canonicalJavaClassName canonical class name (like 'a.b.c.SomeClassName'), must not be null @return extracted class name, must not be null but can be empty for case "a.b.c.d."
[ "Extract", "class", "name", "from", "canonical", "Java", "class", "name" ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp-plugins/jbbp-plugin-common/src/main/java/com/igormaznitsa/jbbp/plugin/common/utils/CommonUtils.java#L59-L66
141,839
raydac/java-binary-block-parser
jbbp-plugins/jbbp-plugin-common/src/main/java/com/igormaznitsa/jbbp/plugin/common/utils/CommonUtils.java
CommonUtils.extractPackageName
@Nonnull public static String extractPackageName(@Nonnull final String fileNameWithoutExtension) { final int lastDot = fileNameWithoutExtension.lastIndexOf('.'); if (lastDot < 0) { return ""; } return fileNameWithoutExtension.substring(0, lastDot).trim(); }
java
@Nonnull public static String extractPackageName(@Nonnull final String fileNameWithoutExtension) { final int lastDot = fileNameWithoutExtension.lastIndexOf('.'); if (lastDot < 0) { return ""; } return fileNameWithoutExtension.substring(0, lastDot).trim(); }
[ "@", "Nonnull", "public", "static", "String", "extractPackageName", "(", "@", "Nonnull", "final", "String", "fileNameWithoutExtension", ")", "{", "final", "int", "lastDot", "=", "fileNameWithoutExtension", ".", "lastIndexOf", "(", "'", "'", ")", ";", "if", "(", "lastDot", "<", "0", ")", "{", "return", "\"\"", ";", "}", "return", "fileNameWithoutExtension", ".", "substring", "(", "0", ",", "lastDot", ")", ".", "trim", "(", ")", ";", "}" ]
Extract package name from canonical Java class name @param fileNameWithoutExtension canonical class name (like 'a.b.c.SomeClassName'), must not be null @return extracted package name, must not be null but can be empty
[ "Extract", "package", "name", "from", "canonical", "Java", "class", "name" ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp-plugins/jbbp-plugin-common/src/main/java/com/igormaznitsa/jbbp/plugin/common/utils/CommonUtils.java#L74-L81
141,840
raydac/java-binary-block-parser
jbbp-plugins/jbbp-plugin-common/src/main/java/com/igormaznitsa/jbbp/plugin/common/utils/CommonUtils.java
CommonUtils.scriptFileToJavaFile
@Nonnull public static File scriptFileToJavaFile(@Nullable final File targetDir, @Nullable final String classPackage, @Nonnull final File scriptFile) { final String rawFileName = FilenameUtils.getBaseName(scriptFile.getName()); final String className = CommonUtils.extractClassName(rawFileName); final String packageName = classPackage == null ? CommonUtils.extractPackageName(rawFileName) : classPackage; String fullClassName = packageName.isEmpty() ? className : packageName + '.' + className; fullClassName = fullClassName.replace('.', File.separatorChar) + ".java"; return new File(targetDir, fullClassName); }
java
@Nonnull public static File scriptFileToJavaFile(@Nullable final File targetDir, @Nullable final String classPackage, @Nonnull final File scriptFile) { final String rawFileName = FilenameUtils.getBaseName(scriptFile.getName()); final String className = CommonUtils.extractClassName(rawFileName); final String packageName = classPackage == null ? CommonUtils.extractPackageName(rawFileName) : classPackage; String fullClassName = packageName.isEmpty() ? className : packageName + '.' + className; fullClassName = fullClassName.replace('.', File.separatorChar) + ".java"; return new File(targetDir, fullClassName); }
[ "@", "Nonnull", "public", "static", "File", "scriptFileToJavaFile", "(", "@", "Nullable", "final", "File", "targetDir", ",", "@", "Nullable", "final", "String", "classPackage", ",", "@", "Nonnull", "final", "File", "scriptFile", ")", "{", "final", "String", "rawFileName", "=", "FilenameUtils", ".", "getBaseName", "(", "scriptFile", ".", "getName", "(", ")", ")", ";", "final", "String", "className", "=", "CommonUtils", ".", "extractClassName", "(", "rawFileName", ")", ";", "final", "String", "packageName", "=", "classPackage", "==", "null", "?", "CommonUtils", ".", "extractPackageName", "(", "rawFileName", ")", ":", "classPackage", ";", "String", "fullClassName", "=", "packageName", ".", "isEmpty", "(", ")", "?", "className", ":", "packageName", "+", "'", "'", "+", "className", ";", "fullClassName", "=", "fullClassName", ".", "replace", "(", "'", "'", ",", "File", ".", "separatorChar", ")", "+", "\".java\"", ";", "return", "new", "File", "(", "targetDir", ",", "fullClassName", ")", ";", "}" ]
Convert script file into path to Java class file. @param targetDir the target dir for generated sources, it can be null @param classPackage class package to override extracted one from script name, it can be null @param scriptFile the script file, must not be null @return java source file for the script file
[ "Convert", "script", "file", "into", "path", "to", "Java", "class", "file", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp-plugins/jbbp-plugin-common/src/main/java/com/igormaznitsa/jbbp/plugin/common/utils/CommonUtils.java#L91-L101
141,841
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java
JBBPUtils.strToUtf8
public static byte[] strToUtf8(final String str) { final ByteBuffer buffer = CHARSET_UTF8.encode(str); final byte[] bytesArray = new byte[buffer.remaining()]; buffer.get(bytesArray, 0, bytesArray.length); return bytesArray; }
java
public static byte[] strToUtf8(final String str) { final ByteBuffer buffer = CHARSET_UTF8.encode(str); final byte[] bytesArray = new byte[buffer.remaining()]; buffer.get(bytesArray, 0, bytesArray.length); return bytesArray; }
[ "public", "static", "byte", "[", "]", "strToUtf8", "(", "final", "String", "str", ")", "{", "final", "ByteBuffer", "buffer", "=", "CHARSET_UTF8", ".", "encode", "(", "str", ")", ";", "final", "byte", "[", "]", "bytesArray", "=", "new", "byte", "[", "buffer", ".", "remaining", "(", ")", "]", ";", "buffer", ".", "get", "(", "bytesArray", ",", "0", ",", "bytesArray", ".", "length", ")", ";", "return", "bytesArray", ";", "}" ]
Convert a string into its UTF8 representation. @param str string to be converted, must not be null @return array of chars from the string in utf8 format, must not be null @since 1.4.0
[ "Convert", "a", "string", "into", "its", "UTF8", "representation", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java#L56-L61
141,842
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java
JBBPUtils.isNumber
public static boolean isNumber(final String num) { if (num == null || num.length() == 0) { return false; } final boolean firstIsDigit = Character.isDigit(num.charAt(0)); if (!firstIsDigit && num.charAt(0) != '-') { return false; } boolean dig = firstIsDigit; for (int i = 1; i < num.length(); i++) { if (!Character.isDigit(num.charAt(i))) { return false; } dig = true; } return dig; }
java
public static boolean isNumber(final String num) { if (num == null || num.length() == 0) { return false; } final boolean firstIsDigit = Character.isDigit(num.charAt(0)); if (!firstIsDigit && num.charAt(0) != '-') { return false; } boolean dig = firstIsDigit; for (int i = 1; i < num.length(); i++) { if (!Character.isDigit(num.charAt(i))) { return false; } dig = true; } return dig; }
[ "public", "static", "boolean", "isNumber", "(", "final", "String", "num", ")", "{", "if", "(", "num", "==", "null", "||", "num", ".", "length", "(", ")", "==", "0", ")", "{", "return", "false", ";", "}", "final", "boolean", "firstIsDigit", "=", "Character", ".", "isDigit", "(", "num", ".", "charAt", "(", "0", ")", ")", ";", "if", "(", "!", "firstIsDigit", "&&", "num", ".", "charAt", "(", "0", ")", "!=", "'", "'", ")", "{", "return", "false", ";", "}", "boolean", "dig", "=", "firstIsDigit", ";", "for", "(", "int", "i", "=", "1", ";", "i", "<", "num", ".", "length", "(", ")", ";", "i", "++", ")", "{", "if", "(", "!", "Character", ".", "isDigit", "(", "num", ".", "charAt", "(", "i", ")", ")", ")", "{", "return", "false", ";", "}", "dig", "=", "true", ";", "}", "return", "dig", ";", "}" ]
Check that a string is a number. @param num a string to be checked, it can be null @return true if the string represents a number, false if it is not number or it is null
[ "Check", "that", "a", "string", "is", "a", "number", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java#L81-L97
141,843
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java
JBBPUtils.packInt
public static byte[] packInt(final int value) { if ((value & 0xFFFFFF80) == 0) { return new byte[] {(byte) value}; } else if ((value & 0xFFFF0000) == 0) { return new byte[] {(byte) 0x80, (byte) (value >>> 8), (byte) value}; } else { return new byte[] {(byte) 0x81, (byte) (value >>> 24), (byte) (value >>> 16), (byte) (value >>> 8), (byte) value}; } }
java
public static byte[] packInt(final int value) { if ((value & 0xFFFFFF80) == 0) { return new byte[] {(byte) value}; } else if ((value & 0xFFFF0000) == 0) { return new byte[] {(byte) 0x80, (byte) (value >>> 8), (byte) value}; } else { return new byte[] {(byte) 0x81, (byte) (value >>> 24), (byte) (value >>> 16), (byte) (value >>> 8), (byte) value}; } }
[ "public", "static", "byte", "[", "]", "packInt", "(", "final", "int", "value", ")", "{", "if", "(", "(", "value", "&", "0xFFFFFF80", ")", "==", "0", ")", "{", "return", "new", "byte", "[", "]", "{", "(", "byte", ")", "value", "}", ";", "}", "else", "if", "(", "(", "value", "&", "0xFFFF0000", ")", "==", "0", ")", "{", "return", "new", "byte", "[", "]", "{", "(", "byte", ")", "0x80", ",", "(", "byte", ")", "(", "value", ">>>", "8", ")", ",", "(", "byte", ")", "value", "}", ";", "}", "else", "{", "return", "new", "byte", "[", "]", "{", "(", "byte", ")", "0x81", ",", "(", "byte", ")", "(", "value", ">>>", "24", ")", ",", "(", "byte", ")", "(", "value", ">>>", "16", ")", ",", "(", "byte", ")", "(", "value", ">>>", "8", ")", ",", "(", "byte", ")", "value", "}", ";", "}", "}" ]
Pack an integer value as a byte array. @param value a code to be packed @return a byte array contains the packed code
[ "Pack", "an", "integer", "value", "as", "a", "byte", "array", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java#L105-L113
141,844
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java
JBBPUtils.packInt
public static int packInt(final byte[] array, final JBBPIntCounter position, final int value) { if ((value & 0xFFFFFF80) == 0) { array[position.getAndIncrement()] = (byte) value; return 1; } else if ((value & 0xFFFF0000) == 0) { array[position.getAndIncrement()] = (byte) 0x80; array[position.getAndIncrement()] = (byte) (value >>> 8); array[position.getAndIncrement()] = (byte) value; return 3; } array[position.getAndIncrement()] = (byte) 0x81; array[position.getAndIncrement()] = (byte) (value >>> 24); array[position.getAndIncrement()] = (byte) (value >>> 16); array[position.getAndIncrement()] = (byte) (value >>> 8); array[position.getAndIncrement()] = (byte) value; return 5; }
java
public static int packInt(final byte[] array, final JBBPIntCounter position, final int value) { if ((value & 0xFFFFFF80) == 0) { array[position.getAndIncrement()] = (byte) value; return 1; } else if ((value & 0xFFFF0000) == 0) { array[position.getAndIncrement()] = (byte) 0x80; array[position.getAndIncrement()] = (byte) (value >>> 8); array[position.getAndIncrement()] = (byte) value; return 3; } array[position.getAndIncrement()] = (byte) 0x81; array[position.getAndIncrement()] = (byte) (value >>> 24); array[position.getAndIncrement()] = (byte) (value >>> 16); array[position.getAndIncrement()] = (byte) (value >>> 8); array[position.getAndIncrement()] = (byte) value; return 5; }
[ "public", "static", "int", "packInt", "(", "final", "byte", "[", "]", "array", ",", "final", "JBBPIntCounter", "position", ",", "final", "int", "value", ")", "{", "if", "(", "(", "value", "&", "0xFFFFFF80", ")", "==", "0", ")", "{", "array", "[", "position", ".", "getAndIncrement", "(", ")", "]", "=", "(", "byte", ")", "value", ";", "return", "1", ";", "}", "else", "if", "(", "(", "value", "&", "0xFFFF0000", ")", "==", "0", ")", "{", "array", "[", "position", ".", "getAndIncrement", "(", ")", "]", "=", "(", "byte", ")", "0x80", ";", "array", "[", "position", ".", "getAndIncrement", "(", ")", "]", "=", "(", "byte", ")", "(", "value", ">>>", "8", ")", ";", "array", "[", "position", ".", "getAndIncrement", "(", ")", "]", "=", "(", "byte", ")", "value", ";", "return", "3", ";", "}", "array", "[", "position", ".", "getAndIncrement", "(", ")", "]", "=", "(", "byte", ")", "0x81", ";", "array", "[", "position", ".", "getAndIncrement", "(", ")", "]", "=", "(", "byte", ")", "(", "value", ">>>", "24", ")", ";", "array", "[", "position", ".", "getAndIncrement", "(", ")", "]", "=", "(", "byte", ")", "(", "value", ">>>", "16", ")", ";", "array", "[", "position", ".", "getAndIncrement", "(", ")", "]", "=", "(", "byte", ")", "(", "value", ">>>", "8", ")", ";", "array", "[", "position", ".", "getAndIncrement", "(", ")", "]", "=", "(", "byte", ")", "value", ";", "return", "5", ";", "}" ]
Pack an integer value and save that into a byte array since defined position. @param array a byte array where to write the packed data, it must not be null @param position the position of the first byte of the packed value, it must not be null @param value the value to be packed @return number of bytes written into the array, the position will be increased
[ "Pack", "an", "integer", "value", "and", "save", "that", "into", "a", "byte", "array", "since", "defined", "position", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java#L127-L143
141,845
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java
JBBPUtils.unpackInt
public static int unpackInt(final byte[] array, final JBBPIntCounter position) { final int code = array[position.getAndIncrement()] & 0xFF; if (code < 0x80) { return code; } final int result; switch (code) { case 0x80: { result = ((array[position.getAndIncrement()] & 0xFF) << 8) | (array[position.getAndIncrement()] & 0xFF); } break; case 0x81: { result = ((array[position.getAndIncrement()] & 0xFF) << 24) | ((array[position.getAndIncrement()] & 0xFF) << 16) | ((array[position.getAndIncrement()] & 0xFF) << 8) | (array[position.getAndIncrement()] & 0xFF); } break; default: throw new IllegalArgumentException("Unsupported packed integer prefix [0x" + Integer.toHexString(code).toUpperCase(Locale.ENGLISH) + ']'); } return result; }
java
public static int unpackInt(final byte[] array, final JBBPIntCounter position) { final int code = array[position.getAndIncrement()] & 0xFF; if (code < 0x80) { return code; } final int result; switch (code) { case 0x80: { result = ((array[position.getAndIncrement()] & 0xFF) << 8) | (array[position.getAndIncrement()] & 0xFF); } break; case 0x81: { result = ((array[position.getAndIncrement()] & 0xFF) << 24) | ((array[position.getAndIncrement()] & 0xFF) << 16) | ((array[position.getAndIncrement()] & 0xFF) << 8) | (array[position.getAndIncrement()] & 0xFF); } break; default: throw new IllegalArgumentException("Unsupported packed integer prefix [0x" + Integer.toHexString(code).toUpperCase(Locale.ENGLISH) + ']'); } return result; }
[ "public", "static", "int", "unpackInt", "(", "final", "byte", "[", "]", "array", ",", "final", "JBBPIntCounter", "position", ")", "{", "final", "int", "code", "=", "array", "[", "position", ".", "getAndIncrement", "(", ")", "]", "&", "0xFF", ";", "if", "(", "code", "<", "0x80", ")", "{", "return", "code", ";", "}", "final", "int", "result", ";", "switch", "(", "code", ")", "{", "case", "0x80", ":", "{", "result", "=", "(", "(", "array", "[", "position", ".", "getAndIncrement", "(", ")", "]", "&", "0xFF", ")", "<<", "8", ")", "|", "(", "array", "[", "position", ".", "getAndIncrement", "(", ")", "]", "&", "0xFF", ")", ";", "}", "break", ";", "case", "0x81", ":", "{", "result", "=", "(", "(", "array", "[", "position", ".", "getAndIncrement", "(", ")", "]", "&", "0xFF", ")", "<<", "24", ")", "|", "(", "(", "array", "[", "position", ".", "getAndIncrement", "(", ")", "]", "&", "0xFF", ")", "<<", "16", ")", "|", "(", "(", "array", "[", "position", ".", "getAndIncrement", "(", ")", "]", "&", "0xFF", ")", "<<", "8", ")", "|", "(", "array", "[", "position", ".", "getAndIncrement", "(", ")", "]", "&", "0xFF", ")", ";", "}", "break", ";", "default", ":", "throw", "new", "IllegalArgumentException", "(", "\"Unsupported packed integer prefix [0x\"", "+", "Integer", ".", "toHexString", "(", "code", ")", ".", "toUpperCase", "(", "Locale", ".", "ENGLISH", ")", "+", "'", "'", ")", ";", "}", "return", "result", ";", "}" ]
Unpack an integer value from defined position in a byte array. @param array the source byte array @param position the position of the first byte of packed value @return the unpacked value, the position will be increased
[ "Unpack", "an", "integer", "value", "from", "defined", "position", "in", "a", "byte", "array", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java#L152-L175
141,846
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java
JBBPUtils.byteArray2String
public static String byteArray2String(final byte[] array, final String prefix, final String delimiter, final boolean brackets, final int radix) { if (array == null) { return null; } final int maxlen = Integer.toString(0xFF, radix).length(); final String zero = "00000000"; final String normDelim = delimiter == null ? " " : delimiter; final String normPrefix = prefix == null ? "" : prefix; final StringBuilder result = new StringBuilder(array.length * 4); if (brackets) { result.append('['); } boolean nofirst = false; for (final byte b : array) { if (nofirst) { result.append(normDelim); } else { nofirst = true; } result.append(normPrefix); final String v = Integer.toString(b & 0xFF, radix); if (v.length() < maxlen) { result.append(zero, 0, maxlen - v.length()); } result.append(v.toUpperCase(Locale.ENGLISH)); } if (brackets) { result.append(']'); } return result.toString(); }
java
public static String byteArray2String(final byte[] array, final String prefix, final String delimiter, final boolean brackets, final int radix) { if (array == null) { return null; } final int maxlen = Integer.toString(0xFF, radix).length(); final String zero = "00000000"; final String normDelim = delimiter == null ? " " : delimiter; final String normPrefix = prefix == null ? "" : prefix; final StringBuilder result = new StringBuilder(array.length * 4); if (brackets) { result.append('['); } boolean nofirst = false; for (final byte b : array) { if (nofirst) { result.append(normDelim); } else { nofirst = true; } result.append(normPrefix); final String v = Integer.toString(b & 0xFF, radix); if (v.length() < maxlen) { result.append(zero, 0, maxlen - v.length()); } result.append(v.toUpperCase(Locale.ENGLISH)); } if (brackets) { result.append(']'); } return result.toString(); }
[ "public", "static", "String", "byteArray2String", "(", "final", "byte", "[", "]", "array", ",", "final", "String", "prefix", ",", "final", "String", "delimiter", ",", "final", "boolean", "brackets", ",", "final", "int", "radix", ")", "{", "if", "(", "array", "==", "null", ")", "{", "return", "null", ";", "}", "final", "int", "maxlen", "=", "Integer", ".", "toString", "(", "0xFF", ",", "radix", ")", ".", "length", "(", ")", ";", "final", "String", "zero", "=", "\"00000000\"", ";", "final", "String", "normDelim", "=", "delimiter", "==", "null", "?", "\" \"", ":", "delimiter", ";", "final", "String", "normPrefix", "=", "prefix", "==", "null", "?", "\"\"", ":", "prefix", ";", "final", "StringBuilder", "result", "=", "new", "StringBuilder", "(", "array", ".", "length", "*", "4", ")", ";", "if", "(", "brackets", ")", "{", "result", ".", "append", "(", "'", "'", ")", ";", "}", "boolean", "nofirst", "=", "false", ";", "for", "(", "final", "byte", "b", ":", "array", ")", "{", "if", "(", "nofirst", ")", "{", "result", ".", "append", "(", "normDelim", ")", ";", "}", "else", "{", "nofirst", "=", "true", ";", "}", "result", ".", "append", "(", "normPrefix", ")", ";", "final", "String", "v", "=", "Integer", ".", "toString", "(", "b", "&", "0xFF", ",", "radix", ")", ";", "if", "(", "v", ".", "length", "(", ")", "<", "maxlen", ")", "{", "result", ".", "append", "(", "zero", ",", "0", ",", "maxlen", "-", "v", ".", "length", "(", ")", ")", ";", "}", "result", ".", "append", "(", "v", ".", "toUpperCase", "(", "Locale", ".", "ENGLISH", ")", ")", ";", "}", "if", "(", "brackets", ")", "{", "result", ".", "append", "(", "'", "'", ")", ";", "}", "return", "result", ".", "toString", "(", ")", ";", "}" ]
Convert a byte array into string representation @param array the array to be converted, it must not be null @param prefix the prefix for each converted value, it can be null @param delimiter the delimeter for string representations @param brackets if true then place the result into square brackets @param radix the base for conversion @return the string representation of the byte array
[ "Convert", "a", "byte", "array", "into", "string", "representation" ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java#L217-L257
141,847
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java
JBBPUtils.reverseBitsInByte
public static byte reverseBitsInByte(final JBBPBitNumber bitNumber, final byte value) { final byte reversed = reverseBitsInByte(value); return (byte) ((reversed >>> (8 - bitNumber.getBitNumber())) & bitNumber.getMask()); }
java
public static byte reverseBitsInByte(final JBBPBitNumber bitNumber, final byte value) { final byte reversed = reverseBitsInByte(value); return (byte) ((reversed >>> (8 - bitNumber.getBitNumber())) & bitNumber.getMask()); }
[ "public", "static", "byte", "reverseBitsInByte", "(", "final", "JBBPBitNumber", "bitNumber", ",", "final", "byte", "value", ")", "{", "final", "byte", "reversed", "=", "reverseBitsInByte", "(", "value", ")", ";", "return", "(", "byte", ")", "(", "(", "reversed", ">>>", "(", "8", "-", "bitNumber", ".", "getBitNumber", "(", ")", ")", ")", "&", "bitNumber", ".", "getMask", "(", ")", ")", ";", "}" ]
Reverse lower part of a byte defined by bits number constant. @param bitNumber number of lowest bits to be reversed, must not be null @param value a byte to be processed @return value contains reversed number of lowest bits of the byte
[ "Reverse", "lower", "part", "of", "a", "byte", "defined", "by", "bits", "number", "constant", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java#L278-L281
141,848
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java
JBBPUtils.bin2str
public static String bin2str(final byte[] values, final JBBPBitOrder bitOrder, final boolean separateBytes) { if (values == null) { return null; } final StringBuilder result = new StringBuilder(values.length * (separateBytes ? 9 : 8)); boolean nofirst = false; for (final byte b : values) { if (separateBytes) { if (nofirst) { result.append(' '); } else { nofirst = true; } } int a = b; if (bitOrder == JBBPBitOrder.MSB0) { for (int i = 0; i < 8; i++) { result.append((a & 0x1) == 0 ? '0' : '1'); a >>= 1; } } else { for (int i = 0; i < 8; i++) { result.append((a & 0x80) == 0 ? '0' : '1'); a <<= 1; } } } return result.toString(); }
java
public static String bin2str(final byte[] values, final JBBPBitOrder bitOrder, final boolean separateBytes) { if (values == null) { return null; } final StringBuilder result = new StringBuilder(values.length * (separateBytes ? 9 : 8)); boolean nofirst = false; for (final byte b : values) { if (separateBytes) { if (nofirst) { result.append(' '); } else { nofirst = true; } } int a = b; if (bitOrder == JBBPBitOrder.MSB0) { for (int i = 0; i < 8; i++) { result.append((a & 0x1) == 0 ? '0' : '1'); a >>= 1; } } else { for (int i = 0; i < 8; i++) { result.append((a & 0x80) == 0 ? '0' : '1'); a <<= 1; } } } return result.toString(); }
[ "public", "static", "String", "bin2str", "(", "final", "byte", "[", "]", "values", ",", "final", "JBBPBitOrder", "bitOrder", ",", "final", "boolean", "separateBytes", ")", "{", "if", "(", "values", "==", "null", ")", "{", "return", "null", ";", "}", "final", "StringBuilder", "result", "=", "new", "StringBuilder", "(", "values", ".", "length", "*", "(", "separateBytes", "?", "9", ":", "8", ")", ")", ";", "boolean", "nofirst", "=", "false", ";", "for", "(", "final", "byte", "b", ":", "values", ")", "{", "if", "(", "separateBytes", ")", "{", "if", "(", "nofirst", ")", "{", "result", ".", "append", "(", "'", "'", ")", ";", "}", "else", "{", "nofirst", "=", "true", ";", "}", "}", "int", "a", "=", "b", ";", "if", "(", "bitOrder", "==", "JBBPBitOrder", ".", "MSB0", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "8", ";", "i", "++", ")", "{", "result", ".", "append", "(", "(", "a", "&", "0x1", ")", "==", "0", "?", "'", "'", ":", "'", "'", ")", ";", "a", ">>=", "1", ";", "}", "}", "else", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "8", ";", "i", "++", ")", "{", "result", ".", "append", "(", "(", "a", "&", "0x80", ")", "==", "0", "?", "'", "'", ":", "'", "'", ")", ";", "a", "<<=", "1", ";", "}", "}", "}", "return", "result", ".", "toString", "(", ")", ";", "}" ]
Convert a byte array into string binary representation with defined bit order and possibility to separate bytes. @param values a byte array to be converted @param bitOrder the bit order for byte decoding @param separateBytes if true then bytes will be separated by spaces @return the string representation of the array
[ "Convert", "a", "byte", "array", "into", "string", "binary", "representation", "with", "defined", "bit", "order", "and", "possibility", "to", "separate", "bytes", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java#L314-L347
141,849
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java
JBBPUtils.fieldsAsList
public static List<JBBPAbstractField> fieldsAsList(final JBBPAbstractField... fields) { final List<JBBPAbstractField> result = new ArrayList<>(); Collections.addAll(result, fields); return result; }
java
public static List<JBBPAbstractField> fieldsAsList(final JBBPAbstractField... fields) { final List<JBBPAbstractField> result = new ArrayList<>(); Collections.addAll(result, fields); return result; }
[ "public", "static", "List", "<", "JBBPAbstractField", ">", "fieldsAsList", "(", "final", "JBBPAbstractField", "...", "fields", ")", "{", "final", "List", "<", "JBBPAbstractField", ">", "result", "=", "new", "ArrayList", "<>", "(", ")", ";", "Collections", ".", "addAll", "(", "result", ",", "fields", ")", ";", "return", "result", ";", "}" ]
Convert array of JBBP fields into a list. @param fields an array of fields, must not be null @return a list of JBBP fields
[ "Convert", "array", "of", "JBBP", "fields", "into", "a", "list", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java#L355-L359
141,850
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java
JBBPUtils.splitString
public static String[] splitString(final String str, final char splitChar) { final int length = str.length(); final StringBuilder bulder = new StringBuilder(Math.max(8, length)); int counter = 1; for (int i = 0; i < length; i++) { if (str.charAt(i) == splitChar) { counter++; } } final String[] result = new String[counter]; int position = 0; for (int i = 0; i < length; i++) { final char chr = str.charAt(i); if (chr == splitChar) { result[position++] = bulder.toString(); bulder.setLength(0); } else { bulder.append(chr); } } if (position < result.length) { result[position] = bulder.toString(); } return result; }
java
public static String[] splitString(final String str, final char splitChar) { final int length = str.length(); final StringBuilder bulder = new StringBuilder(Math.max(8, length)); int counter = 1; for (int i = 0; i < length; i++) { if (str.charAt(i) == splitChar) { counter++; } } final String[] result = new String[counter]; int position = 0; for (int i = 0; i < length; i++) { final char chr = str.charAt(i); if (chr == splitChar) { result[position++] = bulder.toString(); bulder.setLength(0); } else { bulder.append(chr); } } if (position < result.length) { result[position] = bulder.toString(); } return result; }
[ "public", "static", "String", "[", "]", "splitString", "(", "final", "String", "str", ",", "final", "char", "splitChar", ")", "{", "final", "int", "length", "=", "str", ".", "length", "(", ")", ";", "final", "StringBuilder", "bulder", "=", "new", "StringBuilder", "(", "Math", ".", "max", "(", "8", ",", "length", ")", ")", ";", "int", "counter", "=", "1", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "length", ";", "i", "++", ")", "{", "if", "(", "str", ".", "charAt", "(", "i", ")", "==", "splitChar", ")", "{", "counter", "++", ";", "}", "}", "final", "String", "[", "]", "result", "=", "new", "String", "[", "counter", "]", ";", "int", "position", "=", "0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "length", ";", "i", "++", ")", "{", "final", "char", "chr", "=", "str", ".", "charAt", "(", "i", ")", ";", "if", "(", "chr", "==", "splitChar", ")", "{", "result", "[", "position", "++", "]", "=", "bulder", ".", "toString", "(", ")", ";", "bulder", ".", "setLength", "(", "0", ")", ";", "}", "else", "{", "bulder", ".", "append", "(", "chr", ")", ";", "}", "}", "if", "(", "position", "<", "result", ".", "length", ")", "{", "result", "[", "position", "]", "=", "bulder", ".", "toString", "(", ")", ";", "}", "return", "result", ";", "}" ]
Split a string for a char used as the delimeter. @param str a string to be split @param splitChar a char to be used as delimeter @return array contains split string parts without delimeter chars
[ "Split", "a", "string", "for", "a", "char", "used", "as", "the", "delimeter", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java#L441-L469
141,851
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java
JBBPUtils.assertNotNull
public static void assertNotNull(final Object object, final String message) { if (object == null) { throw new NullPointerException(message == null ? "Object is null" : message); } }
java
public static void assertNotNull(final Object object, final String message) { if (object == null) { throw new NullPointerException(message == null ? "Object is null" : message); } }
[ "public", "static", "void", "assertNotNull", "(", "final", "Object", "object", ",", "final", "String", "message", ")", "{", "if", "(", "object", "==", "null", ")", "{", "throw", "new", "NullPointerException", "(", "message", "==", "null", "?", "\"Object is null\"", ":", "message", ")", ";", "}", "}" ]
Check that an object is null and throw NullPointerException in the case. @param object an object to be checked @param message message to be used as the exception message @throws NullPointerException it will be thrown if the object is null
[ "Check", "that", "an", "object", "is", "null", "and", "throw", "NullPointerException", "in", "the", "case", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java#L478-L482
141,852
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java
JBBPUtils.int2msg
public static String int2msg(final int number) { return number + " (0x" + Long.toHexString((long) number & 0xFFFFFFFFL).toUpperCase(Locale.ENGLISH) + ')'; }
java
public static String int2msg(final int number) { return number + " (0x" + Long.toHexString((long) number & 0xFFFFFFFFL).toUpperCase(Locale.ENGLISH) + ')'; }
[ "public", "static", "String", "int2msg", "(", "final", "int", "number", ")", "{", "return", "number", "+", "\" (0x\"", "+", "Long", ".", "toHexString", "(", "(", "long", ")", "number", "&", "0xFFFFFFFF", "L", ")", ".", "toUpperCase", "(", "Locale", ".", "ENGLISH", ")", "+", "'", "'", ";", "}" ]
Convert an integer number into human readable hexadecimal format. @param number a number to be converted @return a string with human readable hexadecimal number representation
[ "Convert", "an", "integer", "number", "into", "human", "readable", "hexadecimal", "format", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java#L490-L492
141,853
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java
JBBPUtils.normalizeFieldNameOrPath
public static String normalizeFieldNameOrPath(final String nameOrPath) { assertNotNull(nameOrPath, "Name of path must not be null"); return nameOrPath.trim().toLowerCase(Locale.ENGLISH); }
java
public static String normalizeFieldNameOrPath(final String nameOrPath) { assertNotNull(nameOrPath, "Name of path must not be null"); return nameOrPath.trim().toLowerCase(Locale.ENGLISH); }
[ "public", "static", "String", "normalizeFieldNameOrPath", "(", "final", "String", "nameOrPath", ")", "{", "assertNotNull", "(", "nameOrPath", ",", "\"Name of path must not be null\"", ")", ";", "return", "nameOrPath", ".", "trim", "(", ")", ".", "toLowerCase", "(", "Locale", ".", "ENGLISH", ")", ";", "}" ]
Normalize field name or path. @param nameOrPath a field name or a path to be normalized, must not be null @return the normalized version of the name or path
[ "Normalize", "field", "name", "or", "path", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java#L500-L503
141,854
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java
JBBPUtils.str2UnicodeByteArray
public static byte[] str2UnicodeByteArray(final JBBPByteOrder byteOrder, final String str) { final byte[] result = new byte[str.length() << 1]; int index = 0; for (int i = 0; i < str.length(); i++) { final int val = str.charAt(i); switch (byteOrder) { case BIG_ENDIAN: { result[index++] = (byte) (val >> 8); result[index++] = (byte) val; } break; case LITTLE_ENDIAN: { result[index++] = (byte) val; result[index++] = (byte) (val >> 8); } break; default: throw new Error("Unexpected byte order [" + byteOrder + ']'); } } return result; }
java
public static byte[] str2UnicodeByteArray(final JBBPByteOrder byteOrder, final String str) { final byte[] result = new byte[str.length() << 1]; int index = 0; for (int i = 0; i < str.length(); i++) { final int val = str.charAt(i); switch (byteOrder) { case BIG_ENDIAN: { result[index++] = (byte) (val >> 8); result[index++] = (byte) val; } break; case LITTLE_ENDIAN: { result[index++] = (byte) val; result[index++] = (byte) (val >> 8); } break; default: throw new Error("Unexpected byte order [" + byteOrder + ']'); } } return result; }
[ "public", "static", "byte", "[", "]", "str2UnicodeByteArray", "(", "final", "JBBPByteOrder", "byteOrder", ",", "final", "String", "str", ")", "{", "final", "byte", "[", "]", "result", "=", "new", "byte", "[", "str", ".", "length", "(", ")", "<<", "1", "]", ";", "int", "index", "=", "0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "str", ".", "length", "(", ")", ";", "i", "++", ")", "{", "final", "int", "val", "=", "str", ".", "charAt", "(", "i", ")", ";", "switch", "(", "byteOrder", ")", "{", "case", "BIG_ENDIAN", ":", "{", "result", "[", "index", "++", "]", "=", "(", "byte", ")", "(", "val", ">>", "8", ")", ";", "result", "[", "index", "++", "]", "=", "(", "byte", ")", "val", ";", "}", "break", ";", "case", "LITTLE_ENDIAN", ":", "{", "result", "[", "index", "++", "]", "=", "(", "byte", ")", "val", ";", "result", "[", "index", "++", "]", "=", "(", "byte", ")", "(", "val", ">>", "8", ")", ";", "}", "break", ";", "default", ":", "throw", "new", "Error", "(", "\"Unexpected byte order [\"", "+", "byteOrder", "+", "'", "'", ")", ";", "}", "}", "return", "result", ";", "}" ]
Convert chars of a string into a byte array contains the unicode codes. @param byteOrder the byte order for the operation, must not be null @param str the string which chars should be written, must not be null @return the byte array contains unicodes of the string written as byte pairs @since 1.1
[ "Convert", "chars", "of", "a", "string", "into", "a", "byte", "array", "contains", "the", "unicode", "codes", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java#L529-L550
141,855
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java
JBBPUtils.reverseArray
public static byte[] reverseArray(final byte[] nullableArrayToBeInverted) { if (nullableArrayToBeInverted != null && nullableArrayToBeInverted.length > 0) { int indexStart = 0; int indexEnd = nullableArrayToBeInverted.length - 1; while (indexStart < indexEnd) { final byte a = nullableArrayToBeInverted[indexStart]; nullableArrayToBeInverted[indexStart] = nullableArrayToBeInverted[indexEnd]; nullableArrayToBeInverted[indexEnd] = a; indexStart++; indexEnd--; } } return nullableArrayToBeInverted; }
java
public static byte[] reverseArray(final byte[] nullableArrayToBeInverted) { if (nullableArrayToBeInverted != null && nullableArrayToBeInverted.length > 0) { int indexStart = 0; int indexEnd = nullableArrayToBeInverted.length - 1; while (indexStart < indexEnd) { final byte a = nullableArrayToBeInverted[indexStart]; nullableArrayToBeInverted[indexStart] = nullableArrayToBeInverted[indexEnd]; nullableArrayToBeInverted[indexEnd] = a; indexStart++; indexEnd--; } } return nullableArrayToBeInverted; }
[ "public", "static", "byte", "[", "]", "reverseArray", "(", "final", "byte", "[", "]", "nullableArrayToBeInverted", ")", "{", "if", "(", "nullableArrayToBeInverted", "!=", "null", "&&", "nullableArrayToBeInverted", ".", "length", ">", "0", ")", "{", "int", "indexStart", "=", "0", ";", "int", "indexEnd", "=", "nullableArrayToBeInverted", ".", "length", "-", "1", ";", "while", "(", "indexStart", "<", "indexEnd", ")", "{", "final", "byte", "a", "=", "nullableArrayToBeInverted", "[", "indexStart", "]", ";", "nullableArrayToBeInverted", "[", "indexStart", "]", "=", "nullableArrayToBeInverted", "[", "indexEnd", "]", ";", "nullableArrayToBeInverted", "[", "indexEnd", "]", "=", "a", ";", "indexStart", "++", ";", "indexEnd", "--", ";", "}", "}", "return", "nullableArrayToBeInverted", ";", "}" ]
Reverse order of bytes in a byte array. @param nullableArrayToBeInverted a byte array which order must be reversed, it can be null @return the same array instance but with reversed byte order, null if the source array is null @since 1.1
[ "Reverse", "order", "of", "bytes", "in", "a", "byte", "array", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java#L561-L574
141,856
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java
JBBPUtils.splitInteger
public static byte[] splitInteger(final int value, final boolean valueInLittleEndian, final byte[] buffer) { final byte[] result; if (buffer == null || buffer.length < 4) { result = new byte[4]; } else { result = buffer; } int tmpvalue = value; if (valueInLittleEndian) { for (int i = 0; i < 4; i++) { result[i] = (byte) tmpvalue; tmpvalue >>>= 8; } } else { for (int i = 3; i >= 0; i--) { result[i] = (byte) tmpvalue; tmpvalue >>>= 8; } } return result; }
java
public static byte[] splitInteger(final int value, final boolean valueInLittleEndian, final byte[] buffer) { final byte[] result; if (buffer == null || buffer.length < 4) { result = new byte[4]; } else { result = buffer; } int tmpvalue = value; if (valueInLittleEndian) { for (int i = 0; i < 4; i++) { result[i] = (byte) tmpvalue; tmpvalue >>>= 8; } } else { for (int i = 3; i >= 0; i--) { result[i] = (byte) tmpvalue; tmpvalue >>>= 8; } } return result; }
[ "public", "static", "byte", "[", "]", "splitInteger", "(", "final", "int", "value", ",", "final", "boolean", "valueInLittleEndian", ",", "final", "byte", "[", "]", "buffer", ")", "{", "final", "byte", "[", "]", "result", ";", "if", "(", "buffer", "==", "null", "||", "buffer", ".", "length", "<", "4", ")", "{", "result", "=", "new", "byte", "[", "4", "]", ";", "}", "else", "{", "result", "=", "buffer", ";", "}", "int", "tmpvalue", "=", "value", ";", "if", "(", "valueInLittleEndian", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "4", ";", "i", "++", ")", "{", "result", "[", "i", "]", "=", "(", "byte", ")", "tmpvalue", ";", "tmpvalue", ">>>=", "8", ";", "}", "}", "else", "{", "for", "(", "int", "i", "=", "3", ";", "i", ">=", "0", ";", "i", "--", ")", "{", "result", "[", "i", "]", "=", "(", "byte", ")", "tmpvalue", ";", "tmpvalue", ">>>=", "8", ";", "}", "}", "return", "result", ";", "}" ]
Split an integer value to bytes and returns as a byte array. @param value a value to be split @param valueInLittleEndian the flag shows that the integer is presented in the little endian form @param buffer a buffer array to be used as a storage, if the array is null or its length is less than 4 then new array will be created @return the same array filled by parts of the integer value or new array if the provided buffer is null or has not enough size @since 1.1
[ "Split", "an", "integer", "value", "to", "bytes", "and", "returns", "as", "a", "byte", "array", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java#L588-L608
141,857
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java
JBBPUtils.concat
public static byte[] concat(final byte[]... arrays) { int len = 0; for (final byte[] arr : arrays) { len += arr.length; } final byte[] result = new byte[len]; int pos = 0; for (final byte[] arr : arrays) { System.arraycopy(arr, 0, result, pos, arr.length); pos += arr.length; } return result; }
java
public static byte[] concat(final byte[]... arrays) { int len = 0; for (final byte[] arr : arrays) { len += arr.length; } final byte[] result = new byte[len]; int pos = 0; for (final byte[] arr : arrays) { System.arraycopy(arr, 0, result, pos, arr.length); pos += arr.length; } return result; }
[ "public", "static", "byte", "[", "]", "concat", "(", "final", "byte", "[", "]", "...", "arrays", ")", "{", "int", "len", "=", "0", ";", "for", "(", "final", "byte", "[", "]", "arr", ":", "arrays", ")", "{", "len", "+=", "arr", ".", "length", ";", "}", "final", "byte", "[", "]", "result", "=", "new", "byte", "[", "len", "]", ";", "int", "pos", "=", "0", ";", "for", "(", "final", "byte", "[", "]", "arr", ":", "arrays", ")", "{", "System", ".", "arraycopy", "(", "arr", ",", "0", ",", "result", ",", "pos", ",", "arr", ".", "length", ")", ";", "pos", "+=", "arr", ".", "length", ";", "}", "return", "result", ";", "}" ]
Concatenate byte arrays into one byte array sequentially. @param arrays arrays to be concatenated @return the result byte array contains concatenated source arrays @since 1.1
[ "Concatenate", "byte", "arrays", "into", "one", "byte", "array", "sequentially", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java#L651-L664
141,858
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java
JBBPUtils.reverseByteOrder
public static long reverseByteOrder(long value, int numOfLowerBytesToInvert) { if (numOfLowerBytesToInvert < 1 || numOfLowerBytesToInvert > 8) { throw new IllegalArgumentException("Wrong number of bytes [" + numOfLowerBytesToInvert + ']'); } long result = 0; int offsetInResult = (numOfLowerBytesToInvert - 1) * 8; while (numOfLowerBytesToInvert-- > 0) { final long thebyte = value & 0xFF; value >>>= 8; result |= (thebyte << offsetInResult); offsetInResult -= 8; } return result; }
java
public static long reverseByteOrder(long value, int numOfLowerBytesToInvert) { if (numOfLowerBytesToInvert < 1 || numOfLowerBytesToInvert > 8) { throw new IllegalArgumentException("Wrong number of bytes [" + numOfLowerBytesToInvert + ']'); } long result = 0; int offsetInResult = (numOfLowerBytesToInvert - 1) * 8; while (numOfLowerBytesToInvert-- > 0) { final long thebyte = value & 0xFF; value >>>= 8; result |= (thebyte << offsetInResult); offsetInResult -= 8; } return result; }
[ "public", "static", "long", "reverseByteOrder", "(", "long", "value", ",", "int", "numOfLowerBytesToInvert", ")", "{", "if", "(", "numOfLowerBytesToInvert", "<", "1", "||", "numOfLowerBytesToInvert", ">", "8", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Wrong number of bytes [\"", "+", "numOfLowerBytesToInvert", "+", "'", "'", ")", ";", "}", "long", "result", "=", "0", ";", "int", "offsetInResult", "=", "(", "numOfLowerBytesToInvert", "-", "1", ")", "*", "8", ";", "while", "(", "numOfLowerBytesToInvert", "--", ">", "0", ")", "{", "final", "long", "thebyte", "=", "value", "&", "0xFF", ";", "value", ">>>=", "8", ";", "result", "|=", "(", "thebyte", "<<", "offsetInResult", ")", ";", "offsetInResult", "-=", "8", ";", "}", "return", "result", ";", "}" ]
Revert order for defined number of bytes in a value. @param value the value which bytes should be reordered @param numOfLowerBytesToInvert number of lower bytes to be reverted in their order, must be 1..8 @return new value which has reverted order for defined number of lower bytes @since 1.1
[ "Revert", "order", "for", "defined", "number", "of", "bytes", "in", "a", "value", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java#L676-L693
141,859
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java
JBBPUtils.double2str
public static String double2str(final double doubleValue, final int radix) { if (radix != 10 && radix != 16) { throw new IllegalArgumentException("Illegal radix [" + radix + ']'); } final String result; if (radix == 16) { String converted = Double.toHexString(doubleValue); boolean minus = converted.startsWith("-"); if (minus) { converted = converted.substring(1); } if (converted.startsWith("0x")) { converted = converted.substring(2); } result = (minus ? '-' + converted : converted).toUpperCase(Locale.ENGLISH); } else { result = Double.toString(doubleValue); } return result; }
java
public static String double2str(final double doubleValue, final int radix) { if (radix != 10 && radix != 16) { throw new IllegalArgumentException("Illegal radix [" + radix + ']'); } final String result; if (radix == 16) { String converted = Double.toHexString(doubleValue); boolean minus = converted.startsWith("-"); if (minus) { converted = converted.substring(1); } if (converted.startsWith("0x")) { converted = converted.substring(2); } result = (minus ? '-' + converted : converted).toUpperCase(Locale.ENGLISH); } else { result = Double.toString(doubleValue); } return result; }
[ "public", "static", "String", "double2str", "(", "final", "double", "doubleValue", ",", "final", "int", "radix", ")", "{", "if", "(", "radix", "!=", "10", "&&", "radix", "!=", "16", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Illegal radix [\"", "+", "radix", "+", "'", "'", ")", ";", "}", "final", "String", "result", ";", "if", "(", "radix", "==", "16", ")", "{", "String", "converted", "=", "Double", ".", "toHexString", "(", "doubleValue", ")", ";", "boolean", "minus", "=", "converted", ".", "startsWith", "(", "\"-\"", ")", ";", "if", "(", "minus", ")", "{", "converted", "=", "converted", ".", "substring", "(", "1", ")", ";", "}", "if", "(", "converted", ".", "startsWith", "(", "\"0x\"", ")", ")", "{", "converted", "=", "converted", ".", "substring", "(", "2", ")", ";", "}", "result", "=", "(", "minus", "?", "'", "'", "+", "converted", ":", "converted", ")", ".", "toUpperCase", "(", "Locale", ".", "ENGLISH", ")", ";", "}", "else", "{", "result", "=", "Double", ".", "toString", "(", "doubleValue", ")", ";", "}", "return", "result", ";", "}" ]
Convert double value into string representation with defined radix base. @param doubleValue value to be converted in string @param radix radix base to be used for conversion, must be 10 or 16 @return converted value as upper case string @throws IllegalArgumentException for wrong radix base @since 1.4.0
[ "Convert", "double", "value", "into", "string", "representation", "with", "defined", "radix", "base", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java#L706-L726
141,860
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java
JBBPUtils.float2str
public static String float2str(final float floatValue, final int radix) { if (radix != 10 && radix != 16) { throw new IllegalArgumentException("Illegal radix [" + radix + ']'); } final String result; if (radix == 16) { String converted = Double.toHexString(floatValue); boolean minus = converted.startsWith("-"); if (minus) { converted = converted.substring(1); } if (converted.startsWith("0x")) { converted = converted.substring(2); } result = (minus ? '-' + converted : converted).toUpperCase(Locale.ENGLISH); } else { result = Double.toString(floatValue); } return result; }
java
public static String float2str(final float floatValue, final int radix) { if (radix != 10 && radix != 16) { throw new IllegalArgumentException("Illegal radix [" + radix + ']'); } final String result; if (radix == 16) { String converted = Double.toHexString(floatValue); boolean minus = converted.startsWith("-"); if (minus) { converted = converted.substring(1); } if (converted.startsWith("0x")) { converted = converted.substring(2); } result = (minus ? '-' + converted : converted).toUpperCase(Locale.ENGLISH); } else { result = Double.toString(floatValue); } return result; }
[ "public", "static", "String", "float2str", "(", "final", "float", "floatValue", ",", "final", "int", "radix", ")", "{", "if", "(", "radix", "!=", "10", "&&", "radix", "!=", "16", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Illegal radix [\"", "+", "radix", "+", "'", "'", ")", ";", "}", "final", "String", "result", ";", "if", "(", "radix", "==", "16", ")", "{", "String", "converted", "=", "Double", ".", "toHexString", "(", "floatValue", ")", ";", "boolean", "minus", "=", "converted", ".", "startsWith", "(", "\"-\"", ")", ";", "if", "(", "minus", ")", "{", "converted", "=", "converted", ".", "substring", "(", "1", ")", ";", "}", "if", "(", "converted", ".", "startsWith", "(", "\"0x\"", ")", ")", "{", "converted", "=", "converted", ".", "substring", "(", "2", ")", ";", "}", "result", "=", "(", "minus", "?", "'", "'", "+", "converted", ":", "converted", ")", ".", "toUpperCase", "(", "Locale", ".", "ENGLISH", ")", ";", "}", "else", "{", "result", "=", "Double", ".", "toString", "(", "floatValue", ")", ";", "}", "return", "result", ";", "}" ]
Convert float value into string representation with defined radix base. @param floatValue value to be converted in string @param radix radix base to be used for conversion, must be 10 or 16 @return converted value as upper case string @throws IllegalArgumentException for wrong radix base @since 1.4.0
[ "Convert", "float", "value", "into", "string", "representation", "with", "defined", "radix", "base", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java#L738-L757
141,861
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java
JBBPUtils.ulong2str
public static String ulong2str(final long ulongValue, final int radix, final char[] charBuffer) { if (radix < 2 || radix > 36) { throw new IllegalArgumentException("Illegal radix [" + radix + ']'); } if (ulongValue == 0) { return "0"; } else { final String result; if (ulongValue > 0) { result = Long.toString(ulongValue, radix).toUpperCase(Locale.ENGLISH); } else { final char[] buffer = charBuffer == null || charBuffer.length < 64 ? new char[64] : charBuffer; int pos = buffer.length; long topPart = ulongValue >>> 32; long bottomPart = (ulongValue & 0xFFFFFFFFL) + ((topPart % radix) << 32); topPart /= radix; while ((bottomPart | topPart) > 0) { final int val = (int) (bottomPart % radix); buffer[--pos] = (char) (val < 10 ? '0' + val : 'A' + val - 10); bottomPart = (bottomPart / radix) + ((topPart % radix) << 32); topPart /= radix; } result = new String(buffer, pos, buffer.length - pos); } return result; } }
java
public static String ulong2str(final long ulongValue, final int radix, final char[] charBuffer) { if (radix < 2 || radix > 36) { throw new IllegalArgumentException("Illegal radix [" + radix + ']'); } if (ulongValue == 0) { return "0"; } else { final String result; if (ulongValue > 0) { result = Long.toString(ulongValue, radix).toUpperCase(Locale.ENGLISH); } else { final char[] buffer = charBuffer == null || charBuffer.length < 64 ? new char[64] : charBuffer; int pos = buffer.length; long topPart = ulongValue >>> 32; long bottomPart = (ulongValue & 0xFFFFFFFFL) + ((topPart % radix) << 32); topPart /= radix; while ((bottomPart | topPart) > 0) { final int val = (int) (bottomPart % radix); buffer[--pos] = (char) (val < 10 ? '0' + val : 'A' + val - 10); bottomPart = (bottomPart / radix) + ((topPart % radix) << 32); topPart /= radix; } result = new String(buffer, pos, buffer.length - pos); } return result; } }
[ "public", "static", "String", "ulong2str", "(", "final", "long", "ulongValue", ",", "final", "int", "radix", ",", "final", "char", "[", "]", "charBuffer", ")", "{", "if", "(", "radix", "<", "2", "||", "radix", ">", "36", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Illegal radix [\"", "+", "radix", "+", "'", "'", ")", ";", "}", "if", "(", "ulongValue", "==", "0", ")", "{", "return", "\"0\"", ";", "}", "else", "{", "final", "String", "result", ";", "if", "(", "ulongValue", ">", "0", ")", "{", "result", "=", "Long", ".", "toString", "(", "ulongValue", ",", "radix", ")", ".", "toUpperCase", "(", "Locale", ".", "ENGLISH", ")", ";", "}", "else", "{", "final", "char", "[", "]", "buffer", "=", "charBuffer", "==", "null", "||", "charBuffer", ".", "length", "<", "64", "?", "new", "char", "[", "64", "]", ":", "charBuffer", ";", "int", "pos", "=", "buffer", ".", "length", ";", "long", "topPart", "=", "ulongValue", ">>>", "32", ";", "long", "bottomPart", "=", "(", "ulongValue", "&", "0xFFFFFFFF", "L", ")", "+", "(", "(", "topPart", "%", "radix", ")", "<<", "32", ")", ";", "topPart", "/=", "radix", ";", "while", "(", "(", "bottomPart", "|", "topPart", ")", ">", "0", ")", "{", "final", "int", "val", "=", "(", "int", ")", "(", "bottomPart", "%", "radix", ")", ";", "buffer", "[", "--", "pos", "]", "=", "(", "char", ")", "(", "val", "<", "10", "?", "'", "'", "+", "val", ":", "'", "'", "+", "val", "-", "10", ")", ";", "bottomPart", "=", "(", "bottomPart", "/", "radix", ")", "+", "(", "(", "topPart", "%", "radix", ")", "<<", "32", ")", ";", "topPart", "/=", "radix", ";", "}", "result", "=", "new", "String", "(", "buffer", ",", "pos", ",", "buffer", ".", "length", "-", "pos", ")", ";", "}", "return", "result", ";", "}", "}" ]
Convert unsigned long value into string representation with defined radix base. @param ulongValue value to be converted in string @param radix radix base to be used for conversion, must be 2..36 @param charBuffer char buffer to be used for conversion operations, should be not less than 64 char length, if length is less than 64 or null then new one will be created @return converted value as upper case string @throws IllegalArgumentException for wrong radix base @since 1.1
[ "Convert", "unsigned", "long", "value", "into", "string", "representation", "with", "defined", "radix", "base", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java#L773-L800
141,862
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java
JBBPUtils.ensureMinTextLength
public static String ensureMinTextLength(final String text, final int neededLen, final char ch, final int mode) { final int number = neededLen - text.length(); if (number <= 0) { return text; } final StringBuilder result = new StringBuilder(neededLen); switch (mode) { case 0: { for (int i = 0; i < number; i++) { result.append(ch); } result.append(text); } break; case 1: { result.append(text); for (int i = 0; i < number; i++) { result.append(ch); } } break; default: { int leftField = number / 2; int rightField = number - leftField; while (leftField-- > 0) { result.append(ch); } result.append(text); while (rightField-- > 0) { result.append(ch); } } break; } return result.toString(); }
java
public static String ensureMinTextLength(final String text, final int neededLen, final char ch, final int mode) { final int number = neededLen - text.length(); if (number <= 0) { return text; } final StringBuilder result = new StringBuilder(neededLen); switch (mode) { case 0: { for (int i = 0; i < number; i++) { result.append(ch); } result.append(text); } break; case 1: { result.append(text); for (int i = 0; i < number; i++) { result.append(ch); } } break; default: { int leftField = number / 2; int rightField = number - leftField; while (leftField-- > 0) { result.append(ch); } result.append(text); while (rightField-- > 0) { result.append(ch); } } break; } return result.toString(); }
[ "public", "static", "String", "ensureMinTextLength", "(", "final", "String", "text", ",", "final", "int", "neededLen", ",", "final", "char", "ch", ",", "final", "int", "mode", ")", "{", "final", "int", "number", "=", "neededLen", "-", "text", ".", "length", "(", ")", ";", "if", "(", "number", "<=", "0", ")", "{", "return", "text", ";", "}", "final", "StringBuilder", "result", "=", "new", "StringBuilder", "(", "neededLen", ")", ";", "switch", "(", "mode", ")", "{", "case", "0", ":", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "number", ";", "i", "++", ")", "{", "result", ".", "append", "(", "ch", ")", ";", "}", "result", ".", "append", "(", "text", ")", ";", "}", "break", ";", "case", "1", ":", "{", "result", ".", "append", "(", "text", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "number", ";", "i", "++", ")", "{", "result", ".", "append", "(", "ch", ")", ";", "}", "}", "break", ";", "default", ":", "{", "int", "leftField", "=", "number", "/", "2", ";", "int", "rightField", "=", "number", "-", "leftField", ";", "while", "(", "leftField", "--", ">", "0", ")", "{", "result", ".", "append", "(", "ch", ")", ";", "}", "result", ".", "append", "(", "text", ")", ";", "while", "(", "rightField", "--", ">", "0", ")", "{", "result", ".", "append", "(", "ch", ")", ";", "}", "}", "break", ";", "}", "return", "result", ".", "toString", "(", ")", ";", "}" ]
Extend text by chars to needed length. @param text text to be extended, must not be null. @param neededLen needed length for text @param ch char to be used for extending @param mode 0 to extend left, 1 to extend right, otherwise extends both sides @return text extended by chars up to needed length, or non-changed if the text has equals or greater length. @since 1.1
[ "Extend", "text", "by", "chars", "to", "needed", "length", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java#L814-L850
141,863
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java
JBBPUtils.removeLeadingZeros
public static String removeLeadingZeros(final String str) { String result = str; if (str != null && str.length() != 0) { int startIndex = 0; while (startIndex < str.length() - 1) { final char ch = str.charAt(startIndex); if (ch != '0') { break; } startIndex++; } if (startIndex > 0) { result = str.substring(startIndex); } } return result; }
java
public static String removeLeadingZeros(final String str) { String result = str; if (str != null && str.length() != 0) { int startIndex = 0; while (startIndex < str.length() - 1) { final char ch = str.charAt(startIndex); if (ch != '0') { break; } startIndex++; } if (startIndex > 0) { result = str.substring(startIndex); } } return result; }
[ "public", "static", "String", "removeLeadingZeros", "(", "final", "String", "str", ")", "{", "String", "result", "=", "str", ";", "if", "(", "str", "!=", "null", "&&", "str", ".", "length", "(", ")", "!=", "0", ")", "{", "int", "startIndex", "=", "0", ";", "while", "(", "startIndex", "<", "str", ".", "length", "(", ")", "-", "1", ")", "{", "final", "char", "ch", "=", "str", ".", "charAt", "(", "startIndex", ")", ";", "if", "(", "ch", "!=", "'", "'", ")", "{", "break", ";", "}", "startIndex", "++", ";", "}", "if", "(", "startIndex", ">", "0", ")", "{", "result", "=", "str", ".", "substring", "(", "startIndex", ")", ";", "}", "}", "return", "result", ";", "}" ]
Remove leading zeros from string. @param str the string to be trimmed @return the result string without left extra zeros, or null if argument is null @since 1.1
[ "Remove", "leading", "zeros", "from", "string", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java#L860-L876
141,864
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java
JBBPUtils.removeTrailingZeros
public static String removeTrailingZeros(final String str) { String result = str; if (str != null && str.length() != 0) { int endIndex = str.length(); while (endIndex > 1) { final char ch = str.charAt(endIndex - 1); if (ch != '0') { break; } endIndex--; } if (endIndex < str.length()) { result = str.substring(0, endIndex); } } return result; }
java
public static String removeTrailingZeros(final String str) { String result = str; if (str != null && str.length() != 0) { int endIndex = str.length(); while (endIndex > 1) { final char ch = str.charAt(endIndex - 1); if (ch != '0') { break; } endIndex--; } if (endIndex < str.length()) { result = str.substring(0, endIndex); } } return result; }
[ "public", "static", "String", "removeTrailingZeros", "(", "final", "String", "str", ")", "{", "String", "result", "=", "str", ";", "if", "(", "str", "!=", "null", "&&", "str", ".", "length", "(", ")", "!=", "0", ")", "{", "int", "endIndex", "=", "str", ".", "length", "(", ")", ";", "while", "(", "endIndex", ">", "1", ")", "{", "final", "char", "ch", "=", "str", ".", "charAt", "(", "endIndex", "-", "1", ")", ";", "if", "(", "ch", "!=", "'", "'", ")", "{", "break", ";", "}", "endIndex", "--", ";", "}", "if", "(", "endIndex", "<", "str", ".", "length", "(", ")", ")", "{", "result", "=", "str", ".", "substring", "(", "0", ",", "endIndex", ")", ";", "}", "}", "return", "result", ";", "}" ]
Remove trailing zeros from string. @param str the string to be trimmed @return the result string without left extra zeros, or null if argument is null @since 1.1
[ "Remove", "trailing", "zeros", "from", "string", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java#L886-L902
141,865
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java
JBBPUtils.arrayStartsWith
public static boolean arrayStartsWith(final byte[] array, final byte[] str) { boolean result = false; if (array.length >= str.length) { result = true; int index = str.length; while (--index >= 0) { if (array[index] != str[index]) { result = false; break; } } } return result; }
java
public static boolean arrayStartsWith(final byte[] array, final byte[] str) { boolean result = false; if (array.length >= str.length) { result = true; int index = str.length; while (--index >= 0) { if (array[index] != str[index]) { result = false; break; } } } return result; }
[ "public", "static", "boolean", "arrayStartsWith", "(", "final", "byte", "[", "]", "array", ",", "final", "byte", "[", "]", "str", ")", "{", "boolean", "result", "=", "false", ";", "if", "(", "array", ".", "length", ">=", "str", ".", "length", ")", "{", "result", "=", "true", ";", "int", "index", "=", "str", ".", "length", ";", "while", "(", "--", "index", ">=", "0", ")", "{", "if", "(", "array", "[", "index", "]", "!=", "str", "[", "index", "]", ")", "{", "result", "=", "false", ";", "break", ";", "}", "}", "}", "return", "result", ";", "}" ]
Check that a byte array starts with some byte values. @param array array to be checked, must not be null @param str a byte string which will be checked as the start sequence of the array, must not be null @return true if the string is the start sequence of the array, false otherwise @throws NullPointerException if any argument is null @since 1.1
[ "Check", "that", "a", "byte", "array", "starts", "with", "some", "byte", "values", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java#L915-L928
141,866
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java
JBBPUtils.arrayEndsWith
public static boolean arrayEndsWith(final byte[] array, final byte[] str) { boolean result = false; if (array.length >= str.length) { result = true; int index = str.length; int arrindex = array.length; while (--index >= 0) { if (array[--arrindex] != str[index]) { result = false; break; } } } return result; }
java
public static boolean arrayEndsWith(final byte[] array, final byte[] str) { boolean result = false; if (array.length >= str.length) { result = true; int index = str.length; int arrindex = array.length; while (--index >= 0) { if (array[--arrindex] != str[index]) { result = false; break; } } } return result; }
[ "public", "static", "boolean", "arrayEndsWith", "(", "final", "byte", "[", "]", "array", ",", "final", "byte", "[", "]", "str", ")", "{", "boolean", "result", "=", "false", ";", "if", "(", "array", ".", "length", ">=", "str", ".", "length", ")", "{", "result", "=", "true", ";", "int", "index", "=", "str", ".", "length", ";", "int", "arrindex", "=", "array", ".", "length", ";", "while", "(", "--", "index", ">=", "0", ")", "{", "if", "(", "array", "[", "--", "arrindex", "]", "!=", "str", "[", "index", "]", ")", "{", "result", "=", "false", ";", "break", ";", "}", "}", "}", "return", "result", ";", "}" ]
Check that a byte array ends with some byte values. @param array array to be checked, must not be null @param str a byte string which will be checked as the end sequence of the array, must not be null @return true if the string is the end sequence of the array, false otherwise @throws NullPointerException if any argument is null @since 1.1
[ "Check", "that", "a", "byte", "array", "ends", "with", "some", "byte", "values", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPUtils.java#L941-L955
141,867
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/compiler/tokenizer/JBBPTokenizer.java
JBBPTokenizer.checkFieldName
private JBBPTokenizerException checkFieldName(final String name, final int position) { if (name != null) { final String normalized = JBBPUtils.normalizeFieldNameOrPath(name); if (normalized.indexOf('.') >= 0) { return new JBBPTokenizerException("Field name must not contain '.' char", position); } if (normalized.length() > 0) { if (normalized.equals("_") || normalized.equals("$$") || normalized.startsWith("$") || Character.isDigit(normalized.charAt(0)) ) { return new JBBPTokenizerException("'" + name + "' can't be field name", position); } for (int i = 1; i < normalized.length(); i++) { final char chr = normalized.charAt(i); if (chr != '_' && !Character.isLetterOrDigit(chr)) { return new JBBPTokenizerException("Char '" + chr + "' not allowed in name", position); } } } } return null; }
java
private JBBPTokenizerException checkFieldName(final String name, final int position) { if (name != null) { final String normalized = JBBPUtils.normalizeFieldNameOrPath(name); if (normalized.indexOf('.') >= 0) { return new JBBPTokenizerException("Field name must not contain '.' char", position); } if (normalized.length() > 0) { if (normalized.equals("_") || normalized.equals("$$") || normalized.startsWith("$") || Character.isDigit(normalized.charAt(0)) ) { return new JBBPTokenizerException("'" + name + "' can't be field name", position); } for (int i = 1; i < normalized.length(); i++) { final char chr = normalized.charAt(i); if (chr != '_' && !Character.isLetterOrDigit(chr)) { return new JBBPTokenizerException("Char '" + chr + "' not allowed in name", position); } } } } return null; }
[ "private", "JBBPTokenizerException", "checkFieldName", "(", "final", "String", "name", ",", "final", "int", "position", ")", "{", "if", "(", "name", "!=", "null", ")", "{", "final", "String", "normalized", "=", "JBBPUtils", ".", "normalizeFieldNameOrPath", "(", "name", ")", ";", "if", "(", "normalized", ".", "indexOf", "(", "'", "'", ")", ">=", "0", ")", "{", "return", "new", "JBBPTokenizerException", "(", "\"Field name must not contain '.' char\"", ",", "position", ")", ";", "}", "if", "(", "normalized", ".", "length", "(", ")", ">", "0", ")", "{", "if", "(", "normalized", ".", "equals", "(", "\"_\"", ")", "||", "normalized", ".", "equals", "(", "\"$$\"", ")", "||", "normalized", ".", "startsWith", "(", "\"$\"", ")", "||", "Character", ".", "isDigit", "(", "normalized", ".", "charAt", "(", "0", ")", ")", ")", "{", "return", "new", "JBBPTokenizerException", "(", "\"'\"", "+", "name", "+", "\"' can't be field name\"", ",", "position", ")", ";", "}", "for", "(", "int", "i", "=", "1", ";", "i", "<", "normalized", ".", "length", "(", ")", ";", "i", "++", ")", "{", "final", "char", "chr", "=", "normalized", ".", "charAt", "(", "i", ")", ";", "if", "(", "chr", "!=", "'", "'", "&&", "!", "Character", ".", "isLetterOrDigit", "(", "chr", ")", ")", "{", "return", "new", "JBBPTokenizerException", "(", "\"Char '\"", "+", "chr", "+", "\"' not allowed in name\"", ",", "position", ")", ";", "}", "}", "}", "}", "return", "null", ";", "}" ]
Check a field name @param name the name to be checked. @param position the token position in the string. @return JBBPTokenizerException if the field name has wrong chars or presented in disabled name set, null otherwise
[ "Check", "a", "field", "name" ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/compiler/tokenizer/JBBPTokenizer.java#L255-L280
141,868
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/compiler/JBBPCompilerUtils.java
JBBPCompilerUtils.findIndexForFieldPath
public static int findIndexForFieldPath(final String fieldPath, final List<JBBPNamedFieldInfo> namedFields) { final String normalized = JBBPUtils.normalizeFieldNameOrPath(fieldPath); int result = -1; for (int i = namedFields.size() - 1; i >= 0; i--) { final JBBPNamedFieldInfo f = namedFields.get(i); if (normalized.equals(f.getFieldPath())) { result = i; break; } } return result; }
java
public static int findIndexForFieldPath(final String fieldPath, final List<JBBPNamedFieldInfo> namedFields) { final String normalized = JBBPUtils.normalizeFieldNameOrPath(fieldPath); int result = -1; for (int i = namedFields.size() - 1; i >= 0; i--) { final JBBPNamedFieldInfo f = namedFields.get(i); if (normalized.equals(f.getFieldPath())) { result = i; break; } } return result; }
[ "public", "static", "int", "findIndexForFieldPath", "(", "final", "String", "fieldPath", ",", "final", "List", "<", "JBBPNamedFieldInfo", ">", "namedFields", ")", "{", "final", "String", "normalized", "=", "JBBPUtils", ".", "normalizeFieldNameOrPath", "(", "fieldPath", ")", ";", "int", "result", "=", "-", "1", ";", "for", "(", "int", "i", "=", "namedFields", ".", "size", "(", ")", "-", "1", ";", "i", ">=", "0", ";", "i", "--", ")", "{", "final", "JBBPNamedFieldInfo", "f", "=", "namedFields", ".", "get", "(", "i", ")", ";", "if", "(", "normalized", ".", "equals", "(", "f", ".", "getFieldPath", "(", ")", ")", ")", "{", "result", "=", "i", ";", "break", ";", "}", "}", "return", "result", ";", "}" ]
Find a named field info index in a list for its path. @param fieldPath a field path, it must not be null. @param namedFields a list contains named field info items. @return the index of a field for the path if found one, -1 otherwise
[ "Find", "a", "named", "field", "info", "index", "in", "a", "list", "for", "its", "path", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/compiler/JBBPCompilerUtils.java#L42-L53
141,869
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/compiler/JBBPCompilerUtils.java
JBBPCompilerUtils.assertFieldIsNotArrayOrInArray
public static void assertFieldIsNotArrayOrInArray(final JBBPNamedFieldInfo fieldToCheck, final List<JBBPNamedFieldInfo> namedFieldList, final byte[] compiledScript) { // check that the field is not array if ((compiledScript[fieldToCheck.getFieldOffsetInCompiledBlock()] & FLAG_ARRAY) != 0) { throw new JBBPCompilationException("An Array field can't be used as array size [" + fieldToCheck.getFieldPath() + ']'); } if (fieldToCheck.getFieldPath().indexOf('.') >= 0) { // the field in structure, check that the structure is not an array or not in an array final String[] splittedFieldPath = JBBPUtils.splitString(fieldToCheck.getFieldPath(), '.'); final StringBuilder fieldPath = new StringBuilder(); // process till the field name because we have already checked the field for (int i = 0; i < splittedFieldPath.length - 1; i++) { if (fieldPath.length() != 0) { fieldPath.append('.'); } fieldPath.append(splittedFieldPath[i]); final JBBPNamedFieldInfo structureEnd = JBBPCompilerUtils.findForFieldPath(fieldPath.toString(), namedFieldList); if ((compiledScript[structureEnd.getFieldOffsetInCompiledBlock()] & FLAG_ARRAY) != 0) { throw new JBBPCompilationException("Field from structure array can't be use as array size [" + fieldToCheck.getFieldPath() + ';' + structureEnd.getFieldPath() + ']'); } } } }
java
public static void assertFieldIsNotArrayOrInArray(final JBBPNamedFieldInfo fieldToCheck, final List<JBBPNamedFieldInfo> namedFieldList, final byte[] compiledScript) { // check that the field is not array if ((compiledScript[fieldToCheck.getFieldOffsetInCompiledBlock()] & FLAG_ARRAY) != 0) { throw new JBBPCompilationException("An Array field can't be used as array size [" + fieldToCheck.getFieldPath() + ']'); } if (fieldToCheck.getFieldPath().indexOf('.') >= 0) { // the field in structure, check that the structure is not an array or not in an array final String[] splittedFieldPath = JBBPUtils.splitString(fieldToCheck.getFieldPath(), '.'); final StringBuilder fieldPath = new StringBuilder(); // process till the field name because we have already checked the field for (int i = 0; i < splittedFieldPath.length - 1; i++) { if (fieldPath.length() != 0) { fieldPath.append('.'); } fieldPath.append(splittedFieldPath[i]); final JBBPNamedFieldInfo structureEnd = JBBPCompilerUtils.findForFieldPath(fieldPath.toString(), namedFieldList); if ((compiledScript[structureEnd.getFieldOffsetInCompiledBlock()] & FLAG_ARRAY) != 0) { throw new JBBPCompilationException("Field from structure array can't be use as array size [" + fieldToCheck.getFieldPath() + ';' + structureEnd.getFieldPath() + ']'); } } } }
[ "public", "static", "void", "assertFieldIsNotArrayOrInArray", "(", "final", "JBBPNamedFieldInfo", "fieldToCheck", ",", "final", "List", "<", "JBBPNamedFieldInfo", ">", "namedFieldList", ",", "final", "byte", "[", "]", "compiledScript", ")", "{", "// check that the field is not array", "if", "(", "(", "compiledScript", "[", "fieldToCheck", ".", "getFieldOffsetInCompiledBlock", "(", ")", "]", "&", "FLAG_ARRAY", ")", "!=", "0", ")", "{", "throw", "new", "JBBPCompilationException", "(", "\"An Array field can't be used as array size [\"", "+", "fieldToCheck", ".", "getFieldPath", "(", ")", "+", "'", "'", ")", ";", "}", "if", "(", "fieldToCheck", ".", "getFieldPath", "(", ")", ".", "indexOf", "(", "'", "'", ")", ">=", "0", ")", "{", "// the field in structure, check that the structure is not an array or not in an array", "final", "String", "[", "]", "splittedFieldPath", "=", "JBBPUtils", ".", "splitString", "(", "fieldToCheck", ".", "getFieldPath", "(", ")", ",", "'", "'", ")", ";", "final", "StringBuilder", "fieldPath", "=", "new", "StringBuilder", "(", ")", ";", "// process till the field name because we have already checked the field", "for", "(", "int", "i", "=", "0", ";", "i", "<", "splittedFieldPath", ".", "length", "-", "1", ";", "i", "++", ")", "{", "if", "(", "fieldPath", ".", "length", "(", ")", "!=", "0", ")", "{", "fieldPath", ".", "append", "(", "'", "'", ")", ";", "}", "fieldPath", ".", "append", "(", "splittedFieldPath", "[", "i", "]", ")", ";", "final", "JBBPNamedFieldInfo", "structureEnd", "=", "JBBPCompilerUtils", ".", "findForFieldPath", "(", "fieldPath", ".", "toString", "(", ")", ",", "namedFieldList", ")", ";", "if", "(", "(", "compiledScript", "[", "structureEnd", ".", "getFieldOffsetInCompiledBlock", "(", ")", "]", "&", "FLAG_ARRAY", ")", "!=", "0", ")", "{", "throw", "new", "JBBPCompilationException", "(", "\"Field from structure array can't be use as array size [\"", "+", "fieldToCheck", ".", "getFieldPath", "(", ")", "+", "'", "'", "+", "structureEnd", ".", "getFieldPath", "(", ")", "+", "'", "'", ")", ";", "}", "}", "}", "}" ]
Check a field in a compiled list defined by its named field info, that the field is not an array and it is not inside a structure array. @param fieldToCheck a named field info to be checked, must not be null @param namedFieldList a named field info list, must not be null. @param compiledScript a compiled script body
[ "Check", "a", "field", "in", "a", "compiled", "list", "defined", "by", "its", "named", "field", "info", "that", "the", "field", "is", "not", "an", "array", "and", "it", "is", "not", "inside", "a", "structure", "array", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/compiler/JBBPCompilerUtils.java#L82-L103
141,870
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/compiler/varlen/JBBPExpressionEvaluator.java
JBBPExpressionEvaluator.codeToUnary
private static int codeToUnary(final int code) { final int result; switch (code) { case CODE_MINUS: result = CODE_UNARYMINUS; break; case CODE_ADD: result = CODE_UNARYPLUS; break; default: result = code; break; } return result; }
java
private static int codeToUnary(final int code) { final int result; switch (code) { case CODE_MINUS: result = CODE_UNARYMINUS; break; case CODE_ADD: result = CODE_UNARYPLUS; break; default: result = code; break; } return result; }
[ "private", "static", "int", "codeToUnary", "(", "final", "int", "code", ")", "{", "final", "int", "result", ";", "switch", "(", "code", ")", "{", "case", "CODE_MINUS", ":", "result", "=", "CODE_UNARYMINUS", ";", "break", ";", "case", "CODE_ADD", ":", "result", "=", "CODE_UNARYPLUS", ";", "break", ";", "default", ":", "result", "=", "code", ";", "break", ";", "}", "return", "result", ";", "}" ]
Encode code of an operator to code of similar unary operator. @param code a code of operator. @return code of an unary similar operator if it exists, the same code otherwise
[ "Encode", "code", "of", "an", "operator", "to", "code", "of", "similar", "unary", "operator", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/compiler/varlen/JBBPExpressionEvaluator.java#L428-L443
141,871
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/compiler/varlen/JBBPExpressionEvaluator.java
JBBPExpressionEvaluator.hasExpressionOperators
public static boolean hasExpressionOperators(final String str) { boolean result = false; for (final char chr : OPERATOR_FIRST_CHARS) { if (str.indexOf(chr) >= 0) { result = true; break; } } return result; }
java
public static boolean hasExpressionOperators(final String str) { boolean result = false; for (final char chr : OPERATOR_FIRST_CHARS) { if (str.indexOf(chr) >= 0) { result = true; break; } } return result; }
[ "public", "static", "boolean", "hasExpressionOperators", "(", "final", "String", "str", ")", "{", "boolean", "result", "=", "false", ";", "for", "(", "final", "char", "chr", ":", "OPERATOR_FIRST_CHARS", ")", "{", "if", "(", "str", ".", "indexOf", "(", "chr", ")", ">=", "0", ")", "{", "result", "=", "true", ";", "break", ";", "}", "}", "return", "result", ";", "}" ]
Check that a string has a char of operators. @param str a string to be checked, must not be null @return true if the string contains a char of an operator, false otherwise
[ "Check", "that", "a", "string", "has", "a", "char", "of", "operators", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/compiler/varlen/JBBPExpressionEvaluator.java#L496-L507
141,872
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/compiler/varlen/JBBPExpressionEvaluator.java
JBBPExpressionEvaluator.assertUnaryOperator
private void assertUnaryOperator(final String operator) { if (!("+".equals(operator) || "-".equals(operator) || "~".equals(operator))) { throw new JBBPCompilationException("Wrong unary operator '" + operator + "' [" + this.expressionSource + ']'); } }
java
private void assertUnaryOperator(final String operator) { if (!("+".equals(operator) || "-".equals(operator) || "~".equals(operator))) { throw new JBBPCompilationException("Wrong unary operator '" + operator + "' [" + this.expressionSource + ']'); } }
[ "private", "void", "assertUnaryOperator", "(", "final", "String", "operator", ")", "{", "if", "(", "!", "(", "\"+\"", ".", "equals", "(", "operator", ")", "||", "\"-\"", ".", "equals", "(", "operator", ")", "||", "\"~\"", ".", "equals", "(", "operator", ")", ")", ")", "{", "throw", "new", "JBBPCompilationException", "(", "\"Wrong unary operator '\"", "+", "operator", "+", "\"' [\"", "+", "this", ".", "expressionSource", "+", "'", "'", ")", ";", "}", "}" ]
Check that a string represents a unary operator. @param operator an operator to be checked, must not be null. @throws JBBPCompilationException if the operator is not supported unary operator.
[ "Check", "that", "a", "string", "represents", "a", "unary", "operator", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/compiler/varlen/JBBPExpressionEvaluator.java#L515-L519
141,873
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JavaSrcTextBuffer.java
JavaSrcTextBuffer.printf
public JavaSrcTextBuffer printf(final String text, final Object... args) { this.buffer.append(String.format(text, args)); return this; }
java
public JavaSrcTextBuffer printf(final String text, final Object... args) { this.buffer.append(String.format(text, args)); return this; }
[ "public", "JavaSrcTextBuffer", "printf", "(", "final", "String", "text", ",", "final", "Object", "...", "args", ")", "{", "this", ".", "buffer", ".", "append", "(", "String", ".", "format", "(", "text", ",", "args", ")", ")", ";", "return", "this", ";", "}" ]
Formatted print. @param text format string @param args arguments for formatted string @return this instance @see String#format(String, Object...)
[ "Formatted", "print", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JavaSrcTextBuffer.java#L98-L101
141,874
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JavaSrcTextBuffer.java
JavaSrcTextBuffer.printLinesWithIndent
public JavaSrcTextBuffer printLinesWithIndent(final String text) { final String[] splitted = text.split("\n", -1); for (final String aSplitted : splitted) { this.indent().println(aSplitted); } return this; }
java
public JavaSrcTextBuffer printLinesWithIndent(final String text) { final String[] splitted = text.split("\n", -1); for (final String aSplitted : splitted) { this.indent().println(aSplitted); } return this; }
[ "public", "JavaSrcTextBuffer", "printLinesWithIndent", "(", "final", "String", "text", ")", "{", "final", "String", "[", "]", "splitted", "=", "text", ".", "split", "(", "\"\\n\"", ",", "-", "1", ")", ";", "for", "(", "final", "String", "aSplitted", ":", "splitted", ")", "{", "this", ".", "indent", "(", ")", ".", "println", "(", "aSplitted", ")", ";", "}", "return", "this", ";", "}" ]
Parse string to lines and print each line with current indent @param text the text to be printed @return this instance
[ "Parse", "string", "to", "lines", "and", "print", "each", "line", "with", "current", "indent" ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JavaSrcTextBuffer.java#L182-L190
141,875
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/compiler/tokenizer/JBBPToken.java
JBBPToken.getArraySizeAsInt
public Integer getArraySizeAsInt() { if (this.arraySize == null) { throw new NullPointerException("Array size is not defined"); } try { return Integer.valueOf(this.arraySize.trim()); } catch (NumberFormatException ex) { return null; } }
java
public Integer getArraySizeAsInt() { if (this.arraySize == null) { throw new NullPointerException("Array size is not defined"); } try { return Integer.valueOf(this.arraySize.trim()); } catch (NumberFormatException ex) { return null; } }
[ "public", "Integer", "getArraySizeAsInt", "(", ")", "{", "if", "(", "this", ".", "arraySize", "==", "null", ")", "{", "throw", "new", "NullPointerException", "(", "\"Array size is not defined\"", ")", ";", "}", "try", "{", "return", "Integer", ".", "valueOf", "(", "this", ".", "arraySize", ".", "trim", "(", ")", ")", ";", "}", "catch", "(", "NumberFormatException", "ex", ")", "{", "return", "null", ";", "}", "}" ]
Get numeric representation of the array size. @return the parsed numeric representation of the array size value or null if it can't be parsed @throws NullPointerException will be thrown if the array size value is null
[ "Get", "numeric", "representation", "of", "the", "array", "size", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/compiler/tokenizer/JBBPToken.java#L150-L159
141,876
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPTextWriterExtraAdapter.java
JBBPTextWriterExtraAdapter.extractFieldValue
public Object extractFieldValue(final Object instance, final Field field) { JBBPUtils.assertNotNull(field, "Field must not be null"); try { return ReflectUtils.makeAccessible(field).get(instance); } catch (Exception ex) { throw new JBBPException("Can't extract value from field for exception", ex); } }
java
public Object extractFieldValue(final Object instance, final Field field) { JBBPUtils.assertNotNull(field, "Field must not be null"); try { return ReflectUtils.makeAccessible(field).get(instance); } catch (Exception ex) { throw new JBBPException("Can't extract value from field for exception", ex); } }
[ "public", "Object", "extractFieldValue", "(", "final", "Object", "instance", ",", "final", "Field", "field", ")", "{", "JBBPUtils", ".", "assertNotNull", "(", "field", ",", "\"Field must not be null\"", ")", ";", "try", "{", "return", "ReflectUtils", ".", "makeAccessible", "(", "field", ")", ".", "get", "(", "instance", ")", ";", "}", "catch", "(", "Exception", "ex", ")", "{", "throw", "new", "JBBPException", "(", "\"Can't extract value from field for exception\"", ",", "ex", ")", ";", "}", "}" ]
Auxiliary method to extract field value. @param instance object instance, can be null @param field the filed which value should be extracted, must not be null @return the field value
[ "Auxiliary", "method", "to", "extract", "field", "value", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPTextWriterExtraAdapter.java#L97-L104
141,877
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/mapper/instantiators/JBBPClassInstantiatorFactory.java
JBBPClassInstantiatorFactory.make
public JBBPClassInstantiator make(final JBBPClassInstantiatorType type) { JBBPUtils.assertNotNull(type, "Type must not be null"); String className = "com.igormaznitsa.jbbp.mapper.instantiators.JBBPSafeInstantiator"; switch (type) { case AUTO: { final String customClassName = JBBPSystemProperty.PROPERTY_INSTANTIATOR_CLASS.getAsString(null); if (customClassName == null) { try { final Class<?> unsafeclazz = Class.forName("sun.misc.Unsafe"); unsafeclazz.getDeclaredField("theUnsafe"); className = "com.igormaznitsa.jbbp.mapper.instantiators.JBBPUnsafeInstantiator"; } catch (ClassNotFoundException | NoSuchFieldException | SecurityException ex) { // do nothing } } else { className = customClassName; } } break; case SAFE: { className = "com.igormaznitsa.jbbp.mapper.instantiators.JBBPSafeInstantiator"; } break; case UNSAFE: { className = "com.igormaznitsa.jbbp.mapper.instantiators.JBBPUnsafeInstantiator"; } break; default: throw new Error("Unexpected type, contact developer! [" + type + ']'); } return (JBBPClassInstantiator) ReflectUtils.newInstanceForClassName(className); }
java
public JBBPClassInstantiator make(final JBBPClassInstantiatorType type) { JBBPUtils.assertNotNull(type, "Type must not be null"); String className = "com.igormaznitsa.jbbp.mapper.instantiators.JBBPSafeInstantiator"; switch (type) { case AUTO: { final String customClassName = JBBPSystemProperty.PROPERTY_INSTANTIATOR_CLASS.getAsString(null); if (customClassName == null) { try { final Class<?> unsafeclazz = Class.forName("sun.misc.Unsafe"); unsafeclazz.getDeclaredField("theUnsafe"); className = "com.igormaznitsa.jbbp.mapper.instantiators.JBBPUnsafeInstantiator"; } catch (ClassNotFoundException | NoSuchFieldException | SecurityException ex) { // do nothing } } else { className = customClassName; } } break; case SAFE: { className = "com.igormaznitsa.jbbp.mapper.instantiators.JBBPSafeInstantiator"; } break; case UNSAFE: { className = "com.igormaznitsa.jbbp.mapper.instantiators.JBBPUnsafeInstantiator"; } break; default: throw new Error("Unexpected type, contact developer! [" + type + ']'); } return (JBBPClassInstantiator) ReflectUtils.newInstanceForClassName(className); }
[ "public", "JBBPClassInstantiator", "make", "(", "final", "JBBPClassInstantiatorType", "type", ")", "{", "JBBPUtils", ".", "assertNotNull", "(", "type", ",", "\"Type must not be null\"", ")", ";", "String", "className", "=", "\"com.igormaznitsa.jbbp.mapper.instantiators.JBBPSafeInstantiator\"", ";", "switch", "(", "type", ")", "{", "case", "AUTO", ":", "{", "final", "String", "customClassName", "=", "JBBPSystemProperty", ".", "PROPERTY_INSTANTIATOR_CLASS", ".", "getAsString", "(", "null", ")", ";", "if", "(", "customClassName", "==", "null", ")", "{", "try", "{", "final", "Class", "<", "?", ">", "unsafeclazz", "=", "Class", ".", "forName", "(", "\"sun.misc.Unsafe\"", ")", ";", "unsafeclazz", ".", "getDeclaredField", "(", "\"theUnsafe\"", ")", ";", "className", "=", "\"com.igormaznitsa.jbbp.mapper.instantiators.JBBPUnsafeInstantiator\"", ";", "}", "catch", "(", "ClassNotFoundException", "|", "NoSuchFieldException", "|", "SecurityException", "ex", ")", "{", "// do nothing", "}", "}", "else", "{", "className", "=", "customClassName", ";", "}", "}", "break", ";", "case", "SAFE", ":", "{", "className", "=", "\"com.igormaznitsa.jbbp.mapper.instantiators.JBBPSafeInstantiator\"", ";", "}", "break", ";", "case", "UNSAFE", ":", "{", "className", "=", "\"com.igormaznitsa.jbbp.mapper.instantiators.JBBPUnsafeInstantiator\"", ";", "}", "break", ";", "default", ":", "throw", "new", "Error", "(", "\"Unexpected type, contact developer! [\"", "+", "type", "+", "'", "'", ")", ";", "}", "return", "(", "JBBPClassInstantiator", ")", "ReflectUtils", ".", "newInstanceForClassName", "(", "className", ")", ";", "}" ]
Make an instantiator for defined type. @param type the type of needed instantiator, must not be null @return the class instantiator INSTANCE which is compatible with the current platform
[ "Make", "an", "instantiator", "for", "defined", "type", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/mapper/instantiators/JBBPClassInstantiatorFactory.java#L71-L105
141,878
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/io/JBBPBitOutputStream.java
JBBPBitOutputStream.writeShort
public void writeShort(final int value, final JBBPByteOrder byteOrder) throws IOException { if (byteOrder == JBBPByteOrder.BIG_ENDIAN) { this.write(value >>> 8); this.write(value); } else { this.write(value); this.write(value >>> 8); } }
java
public void writeShort(final int value, final JBBPByteOrder byteOrder) throws IOException { if (byteOrder == JBBPByteOrder.BIG_ENDIAN) { this.write(value >>> 8); this.write(value); } else { this.write(value); this.write(value >>> 8); } }
[ "public", "void", "writeShort", "(", "final", "int", "value", ",", "final", "JBBPByteOrder", "byteOrder", ")", "throws", "IOException", "{", "if", "(", "byteOrder", "==", "JBBPByteOrder", ".", "BIG_ENDIAN", ")", "{", "this", ".", "write", "(", "value", ">>>", "8", ")", ";", "this", ".", "write", "(", "value", ")", ";", "}", "else", "{", "this", ".", "write", "(", "value", ")", ";", "this", ".", "write", "(", "value", ">>>", "8", ")", ";", "}", "}" ]
Write a signed short value into the output stream. @param value a value to be written. Only two bytes will be written. @param byteOrder the byte order of the value bytes to be used for writing. @throws IOException it will be thrown for transport errors @see JBBPByteOrder#BIG_ENDIAN @see JBBPByteOrder#LITTLE_ENDIAN
[ "Write", "a", "signed", "short", "value", "into", "the", "output", "stream", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/io/JBBPBitOutputStream.java#L92-L100
141,879
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/io/JBBPBitOutputStream.java
JBBPBitOutputStream.writeInt
public void writeInt(final int value, final JBBPByteOrder byteOrder) throws IOException { if (byteOrder == JBBPByteOrder.BIG_ENDIAN) { this.writeShort(value >>> 16, byteOrder); this.writeShort(value, byteOrder); } else { this.writeShort(value, byteOrder); this.writeShort(value >>> 16, byteOrder); } }
java
public void writeInt(final int value, final JBBPByteOrder byteOrder) throws IOException { if (byteOrder == JBBPByteOrder.BIG_ENDIAN) { this.writeShort(value >>> 16, byteOrder); this.writeShort(value, byteOrder); } else { this.writeShort(value, byteOrder); this.writeShort(value >>> 16, byteOrder); } }
[ "public", "void", "writeInt", "(", "final", "int", "value", ",", "final", "JBBPByteOrder", "byteOrder", ")", "throws", "IOException", "{", "if", "(", "byteOrder", "==", "JBBPByteOrder", ".", "BIG_ENDIAN", ")", "{", "this", ".", "writeShort", "(", "value", ">>>", "16", ",", "byteOrder", ")", ";", "this", ".", "writeShort", "(", "value", ",", "byteOrder", ")", ";", "}", "else", "{", "this", ".", "writeShort", "(", "value", ",", "byteOrder", ")", ";", "this", ".", "writeShort", "(", "value", ">>>", "16", ",", "byteOrder", ")", ";", "}", "}" ]
Write an integer value into the output stream. @param value a value to be written into the output stream. @param byteOrder the byte order of the value bytes to be used for writing. @throws IOException it will be thrown for transport errors @see JBBPByteOrder#BIG_ENDIAN @see JBBPByteOrder#LITTLE_ENDIAN
[ "Write", "an", "integer", "value", "into", "the", "output", "stream", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/io/JBBPBitOutputStream.java#L111-L119
141,880
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/io/JBBPBitOutputStream.java
JBBPBitOutputStream.writeFloat
public void writeFloat(final float value, final JBBPByteOrder byteOrder) throws IOException { final int intValue = Float.floatToIntBits(value); if (byteOrder == JBBPByteOrder.BIG_ENDIAN) { this.writeShort(intValue >>> 16, byteOrder); this.writeShort(intValue, byteOrder); } else { this.writeShort(intValue, byteOrder); this.writeShort(intValue >>> 16, byteOrder); } }
java
public void writeFloat(final float value, final JBBPByteOrder byteOrder) throws IOException { final int intValue = Float.floatToIntBits(value); if (byteOrder == JBBPByteOrder.BIG_ENDIAN) { this.writeShort(intValue >>> 16, byteOrder); this.writeShort(intValue, byteOrder); } else { this.writeShort(intValue, byteOrder); this.writeShort(intValue >>> 16, byteOrder); } }
[ "public", "void", "writeFloat", "(", "final", "float", "value", ",", "final", "JBBPByteOrder", "byteOrder", ")", "throws", "IOException", "{", "final", "int", "intValue", "=", "Float", ".", "floatToIntBits", "(", "value", ")", ";", "if", "(", "byteOrder", "==", "JBBPByteOrder", ".", "BIG_ENDIAN", ")", "{", "this", ".", "writeShort", "(", "intValue", ">>>", "16", ",", "byteOrder", ")", ";", "this", ".", "writeShort", "(", "intValue", ",", "byteOrder", ")", ";", "}", "else", "{", "this", ".", "writeShort", "(", "intValue", ",", "byteOrder", ")", ";", "this", ".", "writeShort", "(", "intValue", ">>>", "16", ",", "byteOrder", ")", ";", "}", "}" ]
Write an float value into the output stream. @param value a value to be written into the output stream. @param byteOrder the byte order of the value bytes to be used for writing. @throws IOException it will be thrown for transport errors @see JBBPByteOrder#BIG_ENDIAN @see JBBPByteOrder#LITTLE_ENDIAN @since 1.4.0
[ "Write", "an", "float", "value", "into", "the", "output", "stream", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/io/JBBPBitOutputStream.java#L131-L140
141,881
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/io/JBBPBitOutputStream.java
JBBPBitOutputStream.writeLong
public void writeLong(final long value, final JBBPByteOrder byteOrder) throws IOException { if (byteOrder == JBBPByteOrder.BIG_ENDIAN) { this.writeInt((int) (value >>> 32), byteOrder); this.writeInt((int) value, byteOrder); } else { this.writeInt((int) value, byteOrder); this.writeInt((int) (value >>> 32), byteOrder); } }
java
public void writeLong(final long value, final JBBPByteOrder byteOrder) throws IOException { if (byteOrder == JBBPByteOrder.BIG_ENDIAN) { this.writeInt((int) (value >>> 32), byteOrder); this.writeInt((int) value, byteOrder); } else { this.writeInt((int) value, byteOrder); this.writeInt((int) (value >>> 32), byteOrder); } }
[ "public", "void", "writeLong", "(", "final", "long", "value", ",", "final", "JBBPByteOrder", "byteOrder", ")", "throws", "IOException", "{", "if", "(", "byteOrder", "==", "JBBPByteOrder", ".", "BIG_ENDIAN", ")", "{", "this", ".", "writeInt", "(", "(", "int", ")", "(", "value", ">>>", "32", ")", ",", "byteOrder", ")", ";", "this", ".", "writeInt", "(", "(", "int", ")", "value", ",", "byteOrder", ")", ";", "}", "else", "{", "this", ".", "writeInt", "(", "(", "int", ")", "value", ",", "byteOrder", ")", ";", "this", ".", "writeInt", "(", "(", "int", ")", "(", "value", ">>>", "32", ")", ",", "byteOrder", ")", ";", "}", "}" ]
Write a long value into the output stream. @param value a value to be written into the output stream. @param byteOrder the byte order of the value bytes to be used for writing. @throws IOException it will be thrown for transport errors @see JBBPByteOrder#BIG_ENDIAN @see JBBPByteOrder#LITTLE_ENDIAN
[ "Write", "a", "long", "value", "into", "the", "output", "stream", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/io/JBBPBitOutputStream.java#L151-L159
141,882
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/io/JBBPBitOutputStream.java
JBBPBitOutputStream.writeDouble
public void writeDouble(final double value, final JBBPByteOrder byteOrder) throws IOException { final long longValue = Double.doubleToLongBits(value); if (byteOrder == JBBPByteOrder.BIG_ENDIAN) { this.writeInt((int) (longValue >>> 32), byteOrder); this.writeInt((int) longValue, byteOrder); } else { this.writeInt((int) longValue, byteOrder); this.writeInt((int) (longValue >>> 32), byteOrder); } }
java
public void writeDouble(final double value, final JBBPByteOrder byteOrder) throws IOException { final long longValue = Double.doubleToLongBits(value); if (byteOrder == JBBPByteOrder.BIG_ENDIAN) { this.writeInt((int) (longValue >>> 32), byteOrder); this.writeInt((int) longValue, byteOrder); } else { this.writeInt((int) longValue, byteOrder); this.writeInt((int) (longValue >>> 32), byteOrder); } }
[ "public", "void", "writeDouble", "(", "final", "double", "value", ",", "final", "JBBPByteOrder", "byteOrder", ")", "throws", "IOException", "{", "final", "long", "longValue", "=", "Double", ".", "doubleToLongBits", "(", "value", ")", ";", "if", "(", "byteOrder", "==", "JBBPByteOrder", ".", "BIG_ENDIAN", ")", "{", "this", ".", "writeInt", "(", "(", "int", ")", "(", "longValue", ">>>", "32", ")", ",", "byteOrder", ")", ";", "this", ".", "writeInt", "(", "(", "int", ")", "longValue", ",", "byteOrder", ")", ";", "}", "else", "{", "this", ".", "writeInt", "(", "(", "int", ")", "longValue", ",", "byteOrder", ")", ";", "this", ".", "writeInt", "(", "(", "int", ")", "(", "longValue", ">>>", "32", ")", ",", "byteOrder", ")", ";", "}", "}" ]
Write a double value into the output stream. @param value a value to be written into the output stream. @param byteOrder the byte order of the value bytes to be used for writing. @throws IOException it will be thrown for transport errors @see JBBPByteOrder#BIG_ENDIAN @see JBBPByteOrder#LITTLE_ENDIAN @since 1.4.0
[ "Write", "a", "double", "value", "into", "the", "output", "stream", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/io/JBBPBitOutputStream.java#L171-L180
141,883
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/io/JBBPBitOutputStream.java
JBBPBitOutputStream.writeBits
public void writeBits(final int value, final JBBPBitNumber bitNumber) throws IOException { if (this.bitBufferCount == 0 && bitNumber == JBBPBitNumber.BITS_8) { write(value); } else { final int initialMask; int mask; initialMask = 1; mask = initialMask << this.bitBufferCount; int accum = value; int i = bitNumber.getBitNumber(); while (i > 0) { this.bitBuffer = this.bitBuffer | ((accum & 1) == 0 ? 0 : mask); accum >>= 1; mask = mask << 1; i--; this.bitBufferCount++; if (this.bitBufferCount == 8) { this.bitBufferCount = 0; writeByte(this.bitBuffer); mask = initialMask; this.bitBuffer = 0; } } } }
java
public void writeBits(final int value, final JBBPBitNumber bitNumber) throws IOException { if (this.bitBufferCount == 0 && bitNumber == JBBPBitNumber.BITS_8) { write(value); } else { final int initialMask; int mask; initialMask = 1; mask = initialMask << this.bitBufferCount; int accum = value; int i = bitNumber.getBitNumber(); while (i > 0) { this.bitBuffer = this.bitBuffer | ((accum & 1) == 0 ? 0 : mask); accum >>= 1; mask = mask << 1; i--; this.bitBufferCount++; if (this.bitBufferCount == 8) { this.bitBufferCount = 0; writeByte(this.bitBuffer); mask = initialMask; this.bitBuffer = 0; } } } }
[ "public", "void", "writeBits", "(", "final", "int", "value", ",", "final", "JBBPBitNumber", "bitNumber", ")", "throws", "IOException", "{", "if", "(", "this", ".", "bitBufferCount", "==", "0", "&&", "bitNumber", "==", "JBBPBitNumber", ".", "BITS_8", ")", "{", "write", "(", "value", ")", ";", "}", "else", "{", "final", "int", "initialMask", ";", "int", "mask", ";", "initialMask", "=", "1", ";", "mask", "=", "initialMask", "<<", "this", ".", "bitBufferCount", ";", "int", "accum", "=", "value", ";", "int", "i", "=", "bitNumber", ".", "getBitNumber", "(", ")", ";", "while", "(", "i", ">", "0", ")", "{", "this", ".", "bitBuffer", "=", "this", ".", "bitBuffer", "|", "(", "(", "accum", "&", "1", ")", "==", "0", "?", "0", ":", "mask", ")", ";", "accum", ">>=", "1", ";", "mask", "=", "mask", "<<", "1", ";", "i", "--", ";", "this", ".", "bitBufferCount", "++", ";", "if", "(", "this", ".", "bitBufferCount", "==", "8", ")", "{", "this", ".", "bitBufferCount", "=", "0", ";", "writeByte", "(", "this", ".", "bitBuffer", ")", ";", "mask", "=", "initialMask", ";", "this", ".", "bitBuffer", "=", "0", ";", "}", "}", "}", "}" ]
Write bits into the output stream. @param value the value which bits will be written in the output stream @param bitNumber number of bits from the value to be written, must be in 1..8 @throws IOException it will be thrown for transport errors @throws IllegalArgumentException it will be thrown for wrong bit number
[ "Write", "bits", "into", "the", "output", "stream", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/io/JBBPBitOutputStream.java#L260-L288
141,884
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/io/JBBPBitOutputStream.java
JBBPBitOutputStream.align
public void align(final long alignByteNumber) throws IOException { if (this.bitBufferCount > 0) { this.writeBits(0, JBBPBitNumber.decode(8 - this.bitBufferCount)); } if (alignByteNumber > 0) { long padding = (alignByteNumber - (this.byteCounter % alignByteNumber)) % alignByteNumber; while (padding > 0) { this.out.write(0); this.byteCounter++; padding--; } } }
java
public void align(final long alignByteNumber) throws IOException { if (this.bitBufferCount > 0) { this.writeBits(0, JBBPBitNumber.decode(8 - this.bitBufferCount)); } if (alignByteNumber > 0) { long padding = (alignByteNumber - (this.byteCounter % alignByteNumber)) % alignByteNumber; while (padding > 0) { this.out.write(0); this.byteCounter++; padding--; } } }
[ "public", "void", "align", "(", "final", "long", "alignByteNumber", ")", "throws", "IOException", "{", "if", "(", "this", ".", "bitBufferCount", ">", "0", ")", "{", "this", ".", "writeBits", "(", "0", ",", "JBBPBitNumber", ".", "decode", "(", "8", "-", "this", ".", "bitBufferCount", ")", ")", ";", "}", "if", "(", "alignByteNumber", ">", "0", ")", "{", "long", "padding", "=", "(", "alignByteNumber", "-", "(", "this", ".", "byteCounter", "%", "alignByteNumber", ")", ")", "%", "alignByteNumber", ";", "while", "(", "padding", ">", "0", ")", "{", "this", ".", "out", ".", "write", "(", "0", ")", ";", "this", ".", "byteCounter", "++", ";", "padding", "--", ";", "}", "}", "}" ]
Write padding bytes to align the stream counter for the border. @param alignByteNumber the alignment border @throws IOException it will be thrown for transport errors
[ "Write", "padding", "bytes", "to", "align", "the", "stream", "counter", "for", "the", "border", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/io/JBBPBitOutputStream.java#L296-L309
141,885
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/io/JBBPBitOutputStream.java
JBBPBitOutputStream.writeByte
private void writeByte(int value) throws IOException { if (this.msb0) { value = JBBPUtils.reverseBitsInByte((byte) value) & 0xFF; } this.out.write(value); this.byteCounter++; }
java
private void writeByte(int value) throws IOException { if (this.msb0) { value = JBBPUtils.reverseBitsInByte((byte) value) & 0xFF; } this.out.write(value); this.byteCounter++; }
[ "private", "void", "writeByte", "(", "int", "value", ")", "throws", "IOException", "{", "if", "(", "this", ".", "msb0", ")", "{", "value", "=", "JBBPUtils", ".", "reverseBitsInByte", "(", "(", "byte", ")", "value", ")", "&", "0xFF", ";", "}", "this", ".", "out", ".", "write", "(", "value", ")", ";", "this", ".", "byteCounter", "++", ";", "}" ]
Inside method to write a byte into wrapped stream. @param value a byte value to be written @throws IOException it will be thrown for transport problems
[ "Inside", "method", "to", "write", "a", "byte", "into", "wrapped", "stream", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/io/JBBPBitOutputStream.java#L317-L323
141,886
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/io/JBBPBitOutputStream.java
JBBPBitOutputStream.writeBytes
public void writeBytes(final byte[] array, final int length, final JBBPByteOrder byteOrder) throws IOException { if (byteOrder == JBBPByteOrder.LITTLE_ENDIAN) { int i = length < 0 ? array.length - 1 : length - 1; while (i >= 0) { this.write(array[i--]); } } else { this.write(array, 0, length < 0 ? array.length : length); } }
java
public void writeBytes(final byte[] array, final int length, final JBBPByteOrder byteOrder) throws IOException { if (byteOrder == JBBPByteOrder.LITTLE_ENDIAN) { int i = length < 0 ? array.length - 1 : length - 1; while (i >= 0) { this.write(array[i--]); } } else { this.write(array, 0, length < 0 ? array.length : length); } }
[ "public", "void", "writeBytes", "(", "final", "byte", "[", "]", "array", ",", "final", "int", "length", ",", "final", "JBBPByteOrder", "byteOrder", ")", "throws", "IOException", "{", "if", "(", "byteOrder", "==", "JBBPByteOrder", ".", "LITTLE_ENDIAN", ")", "{", "int", "i", "=", "length", "<", "0", "?", "array", ".", "length", "-", "1", ":", "length", "-", "1", ";", "while", "(", "i", ">=", "0", ")", "{", "this", ".", "write", "(", "array", "[", "i", "--", "]", ")", ";", "}", "}", "else", "{", "this", ".", "write", "(", "array", ",", "0", ",", "length", "<", "0", "?", "array", ".", "length", ":", "length", ")", ";", "}", "}" ]
Write number of items from byte array into stream @param array array, must not be null @param length number of items to be written, if -1 then whole array @param byteOrder order of bytes, if LITTLE_ENDIAN then array will be reversed @throws IOException it will be thrown if any transport error @see JBBPByteOrder#LITTLE_ENDIAN @since 1.3.0
[ "Write", "number", "of", "items", "from", "byte", "array", "into", "stream" ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/io/JBBPBitOutputStream.java#L350-L359
141,887
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/model/JBBPFieldStruct.java
JBBPFieldStruct.mapTo
public Object mapTo(final Object objectToMap, final JBBPMapperCustomFieldProcessor customFieldProcessor) { return JBBPMapper.map(this, objectToMap, customFieldProcessor); }
java
public Object mapTo(final Object objectToMap, final JBBPMapperCustomFieldProcessor customFieldProcessor) { return JBBPMapper.map(this, objectToMap, customFieldProcessor); }
[ "public", "Object", "mapTo", "(", "final", "Object", "objectToMap", ",", "final", "JBBPMapperCustomFieldProcessor", "customFieldProcessor", ")", "{", "return", "JBBPMapper", ".", "map", "(", "this", ",", "objectToMap", ",", "customFieldProcessor", ")", ";", "}" ]
Map the structure fields to object fields. @param objectToMap an object to map fields of the structure, must not be null @param customFieldProcessor a custom field processor to provide values for custom mapping fields, it can be null if there is not any custom field @return the same object from the arguments but with filled fields by values of the structure
[ "Map", "the", "structure", "fields", "to", "object", "fields", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/model/JBBPFieldStruct.java#L378-L380
141,888
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/compiler/tokenizer/JBBPFieldTypeParameterContainer.java
JBBPFieldTypeParameterContainer.getExtraDataExpression
public String getExtraDataExpression() { String result = null; if (hasExpressionAsExtraData()) { result = this.extraData.substring(1, this.extraData.length() - 1); } return result; }
java
public String getExtraDataExpression() { String result = null; if (hasExpressionAsExtraData()) { result = this.extraData.substring(1, this.extraData.length() - 1); } return result; }
[ "public", "String", "getExtraDataExpression", "(", ")", "{", "String", "result", "=", "null", ";", "if", "(", "hasExpressionAsExtraData", "(", ")", ")", "{", "result", "=", "this", ".", "extraData", ".", "substring", "(", "1", ",", "this", ".", "extraData", ".", "length", "(", ")", "-", "1", ")", ";", "}", "return", "result", ";", "}" ]
Extract expression for extra data. @return extracted expression from extra data, null if it is not extra data
[ "Extract", "expression", "for", "extra", "data", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/compiler/tokenizer/JBBPFieldTypeParameterContainer.java#L93-L99
141,889
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/JBBPNamedNumericFieldMap.java
JBBPNamedNumericFieldMap.putField
public void putField(final JBBPNumericField field) { JBBPUtils.assertNotNull(field, "Field must not be null"); final JBBPNamedFieldInfo fieldName = field.getNameInfo(); JBBPUtils.assertNotNull(fieldName, "Field name info must not be null"); this.fieldMap.put(fieldName, field); }
java
public void putField(final JBBPNumericField field) { JBBPUtils.assertNotNull(field, "Field must not be null"); final JBBPNamedFieldInfo fieldName = field.getNameInfo(); JBBPUtils.assertNotNull(fieldName, "Field name info must not be null"); this.fieldMap.put(fieldName, field); }
[ "public", "void", "putField", "(", "final", "JBBPNumericField", "field", ")", "{", "JBBPUtils", ".", "assertNotNull", "(", "field", ",", "\"Field must not be null\"", ")", ";", "final", "JBBPNamedFieldInfo", "fieldName", "=", "field", ".", "getNameInfo", "(", ")", ";", "JBBPUtils", ".", "assertNotNull", "(", "fieldName", ",", "\"Field name info must not be null\"", ")", ";", "this", ".", "fieldMap", ".", "put", "(", "fieldName", ",", "field", ")", ";", "}" ]
Put a numeric field into map. @param field a field to be added into map or replace already exists one, it must not be null @throws NullPointerException if the field is null or if it is an anonymous field
[ "Put", "a", "numeric", "field", "into", "map", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/JBBPNamedNumericFieldMap.java#L93-L98
141,890
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/JBBPNamedNumericFieldMap.java
JBBPNamedNumericFieldMap.remove
public JBBPNumericField remove(final JBBPNamedFieldInfo nameInfo) { JBBPUtils.assertNotNull(nameInfo, "Name info must not be null"); return this.fieldMap.remove(nameInfo); }
java
public JBBPNumericField remove(final JBBPNamedFieldInfo nameInfo) { JBBPUtils.assertNotNull(nameInfo, "Name info must not be null"); return this.fieldMap.remove(nameInfo); }
[ "public", "JBBPNumericField", "remove", "(", "final", "JBBPNamedFieldInfo", "nameInfo", ")", "{", "JBBPUtils", ".", "assertNotNull", "(", "nameInfo", ",", "\"Name info must not be null\"", ")", ";", "return", "this", ".", "fieldMap", ".", "remove", "(", "nameInfo", ")", ";", "}" ]
Remove a field for its field name info descriptor. @param nameInfo the field name info, it must not be null @return removed numeric field or null if there was not any field for the info
[ "Remove", "a", "field", "for", "its", "field", "name", "info", "descriptor", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/JBBPNamedNumericFieldMap.java#L106-L109
141,891
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/JBBPNamedNumericFieldMap.java
JBBPNamedNumericFieldMap.findForFieldOffset
public JBBPNumericField findForFieldOffset(final int offset) { JBBPNumericField result = null; for (final Map.Entry<JBBPNamedFieldInfo, JBBPNumericField> f : fieldMap.entrySet()) { if (f.getKey().getFieldOffsetInCompiledBlock() == offset) { result = f.getValue(); break; } } return result; }
java
public JBBPNumericField findForFieldOffset(final int offset) { JBBPNumericField result = null; for (final Map.Entry<JBBPNamedFieldInfo, JBBPNumericField> f : fieldMap.entrySet()) { if (f.getKey().getFieldOffsetInCompiledBlock() == offset) { result = f.getValue(); break; } } return result; }
[ "public", "JBBPNumericField", "findForFieldOffset", "(", "final", "int", "offset", ")", "{", "JBBPNumericField", "result", "=", "null", ";", "for", "(", "final", "Map", ".", "Entry", "<", "JBBPNamedFieldInfo", ",", "JBBPNumericField", ">", "f", ":", "fieldMap", ".", "entrySet", "(", ")", ")", "{", "if", "(", "f", ".", "getKey", "(", ")", ".", "getFieldOffsetInCompiledBlock", "(", ")", "==", "offset", ")", "{", "result", "=", "f", ".", "getValue", "(", ")", ";", "break", ";", "}", "}", "return", "result", ";", "}" ]
Find a registered field for its field offset in compiled script. @param offset the field offset @return found field or null if there is not any found for the offset
[ "Find", "a", "registered", "field", "for", "its", "field", "offset", "in", "compiled", "script", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/JBBPNamedNumericFieldMap.java#L117-L126
141,892
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/JBBPNamedNumericFieldMap.java
JBBPNamedNumericFieldMap.getExternalFieldValue
public int getExternalFieldValue(final String externalFieldName, final JBBPCompiledBlock compiledBlock, final JBBPIntegerValueEvaluator evaluator) { final String normalizedName = JBBPUtils.normalizeFieldNameOrPath(externalFieldName); if (this.externalValueProvider == null) { throw new JBBPEvalException("Request for '" + externalFieldName + "' but there is not any value provider", evaluator); } else { return this.externalValueProvider.provideArraySize(normalizedName, this, compiledBlock); } }
java
public int getExternalFieldValue(final String externalFieldName, final JBBPCompiledBlock compiledBlock, final JBBPIntegerValueEvaluator evaluator) { final String normalizedName = JBBPUtils.normalizeFieldNameOrPath(externalFieldName); if (this.externalValueProvider == null) { throw new JBBPEvalException("Request for '" + externalFieldName + "' but there is not any value provider", evaluator); } else { return this.externalValueProvider.provideArraySize(normalizedName, this, compiledBlock); } }
[ "public", "int", "getExternalFieldValue", "(", "final", "String", "externalFieldName", ",", "final", "JBBPCompiledBlock", "compiledBlock", ",", "final", "JBBPIntegerValueEvaluator", "evaluator", ")", "{", "final", "String", "normalizedName", "=", "JBBPUtils", ".", "normalizeFieldNameOrPath", "(", "externalFieldName", ")", ";", "if", "(", "this", ".", "externalValueProvider", "==", "null", ")", "{", "throw", "new", "JBBPEvalException", "(", "\"Request for '\"", "+", "externalFieldName", "+", "\"' but there is not any value provider\"", ",", "evaluator", ")", ";", "}", "else", "{", "return", "this", ".", "externalValueProvider", ".", "provideArraySize", "(", "normalizedName", ",", "this", ",", "compiledBlock", ")", ";", "}", "}" ]
Ask the registered external value provider for a field value. @param externalFieldName the name of a field, it must not be null @param compiledBlock the compiled block, it must not be null @param evaluator an evaluator which is calling the method, it can be null @return integer value for the field @throws JBBPException if there is not any external value provider
[ "Ask", "the", "registered", "external", "value", "provider", "for", "a", "field", "value", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/JBBPNamedNumericFieldMap.java#L296-L303
141,893
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/io/AbstractMappedClassFieldObserver.java
AbstractMappedClassFieldObserver.readFieldValue
private static Object readFieldValue(final Object obj, final Field field) { try { return field.get(obj); } catch (Exception ex) { throw new JBBPException("Can't get value from field [" + field + ']', ex); } }
java
private static Object readFieldValue(final Object obj, final Field field) { try { return field.get(obj); } catch (Exception ex) { throw new JBBPException("Can't get value from field [" + field + ']', ex); } }
[ "private", "static", "Object", "readFieldValue", "(", "final", "Object", "obj", ",", "final", "Field", "field", ")", "{", "try", "{", "return", "field", ".", "get", "(", "obj", ")", ";", "}", "catch", "(", "Exception", "ex", ")", "{", "throw", "new", "JBBPException", "(", "\"Can't get value from field [\"", "+", "field", "+", "'", "'", ",", "ex", ")", ";", "}", "}" ]
Inside auxiliary method to read object field value. @param obj an object which field is read @param field a field to be read @return a value from the field of the object @throws JBBPException if the field can't be read @since 1.1
[ "Inside", "auxiliary", "method", "to", "read", "object", "field", "value", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/io/AbstractMappedClassFieldObserver.java#L61-L67
141,894
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/io/AbstractMappedClassFieldObserver.java
AbstractMappedClassFieldObserver.onFieldCustom
protected void onFieldCustom(final Object obj, final Field field, final Bin annotation, final Object customFieldProcessor, final Object value) { }
java
protected void onFieldCustom(final Object obj, final Field field, final Bin annotation, final Object customFieldProcessor, final Object value) { }
[ "protected", "void", "onFieldCustom", "(", "final", "Object", "obj", ",", "final", "Field", "field", ",", "final", "Bin", "annotation", ",", "final", "Object", "customFieldProcessor", ",", "final", "Object", "value", ")", "{", "}" ]
Notification about custom field. @param obj the object instance, must not be null @param field the custom field, must not be null @param annotation the annotation for the field, must not be null @param customFieldProcessor processor for custom fields, must not be null @param value the value of the custom field
[ "Notification", "about", "custom", "field", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/io/AbstractMappedClassFieldObserver.java#L527-L529
141,895
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/io/AbstractMappedClassFieldObserver.java
AbstractMappedClassFieldObserver.onFieldBits
protected void onFieldBits(final Object obj, final Field field, final Bin annotation, final JBBPBitNumber bitNumber, final int value) { }
java
protected void onFieldBits(final Object obj, final Field field, final Bin annotation, final JBBPBitNumber bitNumber, final int value) { }
[ "protected", "void", "onFieldBits", "(", "final", "Object", "obj", ",", "final", "Field", "field", ",", "final", "Bin", "annotation", ",", "final", "JBBPBitNumber", "bitNumber", ",", "final", "int", "value", ")", "{", "}" ]
Notification about bit field. @param obj the object instance, must not be null @param field the field, must not be null @param annotation the annotation for field, must not be null @param bitNumber number of bits for the field, must not be null @param value the value of the field
[ "Notification", "about", "bit", "field", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/io/AbstractMappedClassFieldObserver.java#L540-L542
141,896
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/io/AbstractMappedClassFieldObserver.java
AbstractMappedClassFieldObserver.resetInsideClassCache
public void resetInsideClassCache() { final Map<Class<?>, Field[]> fieldz = cachedClasses; if (fieldz != null) { synchronized (fieldz) { fieldz.clear(); } } }
java
public void resetInsideClassCache() { final Map<Class<?>, Field[]> fieldz = cachedClasses; if (fieldz != null) { synchronized (fieldz) { fieldz.clear(); } } }
[ "public", "void", "resetInsideClassCache", "(", ")", "{", "final", "Map", "<", "Class", "<", "?", ">", ",", "Field", "[", "]", ">", "fieldz", "=", "cachedClasses", ";", "if", "(", "fieldz", "!=", "null", ")", "{", "synchronized", "(", "fieldz", ")", "{", "fieldz", ".", "clear", "(", ")", ";", "}", "}", "}" ]
Inside JBBPOut.Bin command creates cached list of fields of a saved class, the method allows to reset the inside cache.
[ "Inside", "JBBPOut", ".", "Bin", "command", "creates", "cached", "list", "of", "fields", "of", "a", "saved", "class", "the", "method", "allows", "to", "reset", "the", "inside", "cache", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/io/AbstractMappedClassFieldObserver.java#L694-L701
141,897
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPTextWriter.java
JBBPTextWriter.makeStrWriter
public static JBBPTextWriter makeStrWriter() { final String lineSeparator = System.setProperty("line.separator", "\n"); return new JBBPTextWriter(new StringWriter(), JBBPByteOrder.BIG_ENDIAN, lineSeparator, 16, "0x", ".", ";", "~", ","); }
java
public static JBBPTextWriter makeStrWriter() { final String lineSeparator = System.setProperty("line.separator", "\n"); return new JBBPTextWriter(new StringWriter(), JBBPByteOrder.BIG_ENDIAN, lineSeparator, 16, "0x", ".", ";", "~", ","); }
[ "public", "static", "JBBPTextWriter", "makeStrWriter", "(", ")", "{", "final", "String", "lineSeparator", "=", "System", ".", "setProperty", "(", "\"line.separator\"", ",", "\"\\n\"", ")", ";", "return", "new", "JBBPTextWriter", "(", "new", "StringWriter", "(", ")", ",", "JBBPByteOrder", ".", "BIG_ENDIAN", ",", "lineSeparator", ",", "16", ",", "\"0x\"", ",", "\".\"", ",", "\";\"", ",", "\"~\"", ",", "\",\"", ")", ";", "}" ]
Auxiliary method allows to build writer over StringWriter with system-depended next line and hex radix. The Method allows fast instance create. @since 1.4.0
[ "Auxiliary", "method", "allows", "to", "build", "writer", "over", "StringWriter", "with", "system", "-", "depended", "next", "line", "and", "hex", "radix", ".", "The", "Method", "allows", "fast", "instance", "create", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPTextWriter.java#L331-L334
141,898
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPTextWriter.java
JBBPTextWriter.ensureValueMode
private void ensureValueMode() throws IOException { switch (this.mode) { case MODE_START_LINE: { changeMode(MODE_VALUES); for (final Extra e : extras) { e.onBeforeFirstValue(this); } writeIndent(); this.write(this.prefixFirtValueAtLine); } break; case MODE_COMMENTS: { this.BR(); writeIndent(); changeMode(MODE_VALUES); for (final Extra e : extras) { e.onBeforeFirstValue(this); } this.write(this.prefixFirtValueAtLine); } break; case MODE_VALUES: break; default: throw new Error("Unexpected state"); } }
java
private void ensureValueMode() throws IOException { switch (this.mode) { case MODE_START_LINE: { changeMode(MODE_VALUES); for (final Extra e : extras) { e.onBeforeFirstValue(this); } writeIndent(); this.write(this.prefixFirtValueAtLine); } break; case MODE_COMMENTS: { this.BR(); writeIndent(); changeMode(MODE_VALUES); for (final Extra e : extras) { e.onBeforeFirstValue(this); } this.write(this.prefixFirtValueAtLine); } break; case MODE_VALUES: break; default: throw new Error("Unexpected state"); } }
[ "private", "void", "ensureValueMode", "(", ")", "throws", "IOException", "{", "switch", "(", "this", ".", "mode", ")", "{", "case", "MODE_START_LINE", ":", "{", "changeMode", "(", "MODE_VALUES", ")", ";", "for", "(", "final", "Extra", "e", ":", "extras", ")", "{", "e", ".", "onBeforeFirstValue", "(", "this", ")", ";", "}", "writeIndent", "(", ")", ";", "this", ".", "write", "(", "this", ".", "prefixFirtValueAtLine", ")", ";", "}", "break", ";", "case", "MODE_COMMENTS", ":", "{", "this", ".", "BR", "(", ")", ";", "writeIndent", "(", ")", ";", "changeMode", "(", "MODE_VALUES", ")", ";", "for", "(", "final", "Extra", "e", ":", "extras", ")", "{", "e", ".", "onBeforeFirstValue", "(", "this", ")", ";", "}", "this", ".", "write", "(", "this", ".", "prefixFirtValueAtLine", ")", ";", "}", "break", ";", "case", "MODE_VALUES", ":", "break", ";", "default", ":", "throw", "new", "Error", "(", "\"Unexpected state\"", ")", ";", "}", "}" ]
Ensure the value mode. @throws IOException it will be thrown for transport errors
[ "Ensure", "the", "value", "mode", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPTextWriter.java#L399-L425
141,899
raydac/java-binary-block-parser
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPTextWriter.java
JBBPTextWriter.ensureCommentMode
private void ensureCommentMode() throws IOException { switch (this.mode) { case MODE_START_LINE: writeIndent(); this.prevLineCommentsStartPosition = this.linePosition; this.write(this.prefixComment); changeMode(MODE_COMMENTS); break; case MODE_VALUES: { this.prevLineCommentsStartPosition = this.linePosition; this.write(this.prefixComment); changeMode(MODE_COMMENTS); } break; case MODE_COMMENTS: { BR(); writeIndent(); while (this.linePosition < this.prevLineCommentsStartPosition) { this.write(' '); } this.write(this.prefixComment); } break; default: throw new Error("Unexpected state"); } }
java
private void ensureCommentMode() throws IOException { switch (this.mode) { case MODE_START_LINE: writeIndent(); this.prevLineCommentsStartPosition = this.linePosition; this.write(this.prefixComment); changeMode(MODE_COMMENTS); break; case MODE_VALUES: { this.prevLineCommentsStartPosition = this.linePosition; this.write(this.prefixComment); changeMode(MODE_COMMENTS); } break; case MODE_COMMENTS: { BR(); writeIndent(); while (this.linePosition < this.prevLineCommentsStartPosition) { this.write(' '); } this.write(this.prefixComment); } break; default: throw new Error("Unexpected state"); } }
[ "private", "void", "ensureCommentMode", "(", ")", "throws", "IOException", "{", "switch", "(", "this", ".", "mode", ")", "{", "case", "MODE_START_LINE", ":", "writeIndent", "(", ")", ";", "this", ".", "prevLineCommentsStartPosition", "=", "this", ".", "linePosition", ";", "this", ".", "write", "(", "this", ".", "prefixComment", ")", ";", "changeMode", "(", "MODE_COMMENTS", ")", ";", "break", ";", "case", "MODE_VALUES", ":", "{", "this", ".", "prevLineCommentsStartPosition", "=", "this", ".", "linePosition", ";", "this", ".", "write", "(", "this", ".", "prefixComment", ")", ";", "changeMode", "(", "MODE_COMMENTS", ")", ";", "}", "break", ";", "case", "MODE_COMMENTS", ":", "{", "BR", "(", ")", ";", "writeIndent", "(", ")", ";", "while", "(", "this", ".", "linePosition", "<", "this", ".", "prevLineCommentsStartPosition", ")", "{", "this", ".", "write", "(", "'", "'", ")", ";", "}", "this", ".", "write", "(", "this", ".", "prefixComment", ")", ";", "}", "break", ";", "default", ":", "throw", "new", "Error", "(", "\"Unexpected state\"", ")", ";", "}", "}" ]
Ensure the comment mode. @throws IOException it will be thrown for transport errors
[ "Ensure", "the", "comment", "mode", "." ]
6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b
https://github.com/raydac/java-binary-block-parser/blob/6d98abcab01e0c72d525ebcc9e7b694f9ce49f5b/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPTextWriter.java#L447-L473