List of usage examples for java.lang Short parseShort
public static short parseShort(String s) throws NumberFormatException
From source file:net.sf.jasperreports.engine.xml.TextLineBreakOffsetsRule.java
@Override public void body(String namespace, String name, String text) throws Exception { if (text != null) { StringTokenizer tokenizer = new StringTokenizer(text, JRXmlConstants.LINE_BREAK_OFFSET_SEPARATOR); int tokenCount = tokenizer.countTokens(); short[] offsets; if (tokenCount == 0) { //use the zero length array singleton offsets = JRPrintText.ZERO_LINE_BREAK_OFFSETS; } else {/*from www .java2s . c o m*/ offsets = new short[tokenCount]; for (int i = 0; i < offsets.length; i++) { String token = tokenizer.nextToken(); offsets[i] = Short.parseShort(token); } } JRPrintText printText = (JRPrintText) getDigester().peek(); printText.setLineBreakOffsets(offsets); } }
From source file:de.Keyle.MyPet.api.Util.java
public static boolean isShort(String number) { try {//w w w . j ava2 s. co m Short.parseShort(number); return true; } catch (NumberFormatException nFE) { return false; } }
From source file:com.sms.server.service.parser.NFOParser.java
public MediaElement parse(MediaElement mediaElement) { // Get XML file File nfoFile = getNFOFile(mediaElement.getParentPath()); if (nfoFile != null) { LogService.getInstance().addLogEntry(LogService.Level.DEBUG, CLASS_NAME, "Parsing NFO file " + nfoFile.getPath(), null); try {/*from w w w . j a v a2s . c o m*/ DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = dbFactory.newDocumentBuilder(); Document document = builder.parse(nfoFile); // Optimise XML before proceeding to minimise errors document.getDocumentElement().normalize(); if (document.getElementsByTagName("title").getLength() > 0) { if (!document.getElementsByTagName("title").item(0).getTextContent().equals("")) { mediaElement.setTitle(document.getElementsByTagName("title").item(0).getTextContent()); } } if (document.getElementsByTagName("rating").getLength() > 0) { if (!document.getElementsByTagName("rating").item(0).getTextContent().equals("")) { Float rating = Float .valueOf(document.getElementsByTagName("rating").item(0).getTextContent()); mediaElement.setRating(rating); } } if (document.getElementsByTagName("year").getLength() > 0) { if (!document.getElementsByTagName("year").item(0).getTextContent().equals("")) { Short year = Short .parseShort(document.getElementsByTagName("year").item(0).getTextContent()); mediaElement.setYear(year); } } if (document.getElementsByTagName("genre").getLength() > 0) { if (!document.getElementsByTagName("genre").item(0).getTextContent().equals("")) { mediaElement.setGenre(document.getElementsByTagName("genre").item(0).getTextContent()); } } if (document.getElementsByTagName("outline").getLength() > 0) { if (!document.getElementsByTagName("outline").item(0).getTextContent().equals("")) { mediaElement .setDescription(document.getElementsByTagName("outline").item(0).getTextContent()); } } if (document.getElementsByTagName("tagline").getLength() > 0) { if (!document.getElementsByTagName("tagline").item(0).getTextContent().equals("")) { mediaElement.setTagline(document.getElementsByTagName("tagline").item(0).getTextContent()); } } if (document.getElementsByTagName("mpaa").getLength() > 0) { if (!document.getElementsByTagName("mpaa").item(0).getTextContent().equals("")) { mediaElement.setCertificate(document.getElementsByTagName("mpaa").item(0).getTextContent()); } } if (document.getElementsByTagName("set").getLength() > 0) { if (!document.getElementsByTagName("set").item(0).getTextContent().equals("")) { mediaElement.setCollection(document.getElementsByTagName("set").item(0).getTextContent()); } } } catch (ParserConfigurationException | SAXException | IOException e) { LogService.getInstance().addLogEntry(LogService.Level.ERROR, CLASS_NAME, "Unable to parse NFO file " + nfoFile.getPath(), e); } } return mediaElement; }
From source file:dev.maisentito.suca.commands.AdminCommandHandler.java
@Override public void handleCommand(MessageEvent event, String[] args) throws Throwable { if ((!Main.config.verifyOwner || event.getUser().isVerified()) && event.getUser().getNick().equals(getStringGlobal(Main.GLOBAL_OWNER, ""))) { if (args.length < 2) { if (args.length == 1) { if (getGlobals().has(args[0], Object.class)) { event.respond(/*from w w w .j a va 2 s . c o m*/ String.format("!admin: %s = %s", args[0], getGlobals().get(args[0]).toString())); } else { event.respond(String.format("!admin: %s = null", args[0])); } return; } else { event.respond("!admin: not enough arguments"); return; } } else if (args[1].length() < 3) { event.respond("!admin: invalid value"); return; } String key = args[0]; String full = StringUtils.join(Arrays.copyOfRange(args, 1, args.length), ' '); Object value; switch (args[1].charAt(0)) { case 'c': value = args[1].charAt(2); break; case 'b': value = Byte.parseByte(args[1].substring(2)); break; case 's': value = Short.parseShort(args[1].substring(2)); break; case 'i': value = Integer.parseInt(args[1].substring(2)); break; case 'l': value = Long.parseLong(args[1].substring(2)); break; case 'f': value = Float.parseFloat(args[1].substring(2)); break; case 'd': value = Double.parseDouble(args[1].substring(2)); break; case 'z': value = Boolean.parseBoolean(args[1].substring(2)); break; case 'a': value = full.substring(2); break; default: event.respond("!admin: invalid type"); return; } getGlobals().put(key, value); event.respond("success"); } else { event.respond("nope"); } }
From source file:com.linkedin.databus2.schemas.FileSystemVersionedSchemaSetProvider.java
static VersionedSchemaId parseSchemaVersion(String fileName) throws IOException { Matcher matcher = FILE_NAME_PATTERN.matcher(fileName); if (matcher.matches()) { String baseName = matcher.group(1); short version = Short.parseShort(matcher.group(2)); return new VersionedSchemaId(baseName, version); } else {/* w w w . ja v a 2 s . c o m*/ logger.warn("Invalid file name: " + fileName); return null; } }
From source file:gr.abiss.calipso.domain.FieldGroup.java
public FieldGroup(Element e) { this(); setId(e.attributeValue(GROUP_ID)); setName(e.attributeValue(NAME)); setPriority(Short.parseShort(e.attributeValue(PRIORITY))); }
From source file:hu.bme.mit.sette.common.model.runner.xml.ParameterElement.java
@Override protected void validate2(final GeneralValidator validator) { switch (getType()) { case BYTE:/* w ww . j av a 2s. co m*/ // TODO validator exception Byte.parseByte(value); break; case SHORT: // TODO validator exception Short.parseShort(value); break; case INT: // TODO validator exception Integer.parseInt(value); break; case LONG: // TODO validator exception Long.parseLong(value); break; case FLOAT: // TODO validator exception Float.parseFloat(value); break; case DOUBLE: // TODO validator exception Double.parseDouble(value); break; case BOOLEAN: if (!value.equals("true") && !value.equals("false")) { // TODO error handling throw new RuntimeException("Bad boolean: " + value); } break; case CHAR: if (value.length() != 1) { // TODO error handling throw new RuntimeException("Bad char: " + value); } break; case EXPRESSION: if (StringUtils.isBlank(value)) { // TODO error handling throw new RuntimeException("Blank expression"); } break; default: // TODO error handling throw new RuntimeException("Unhandled parameter type: " + getType()); } }
From source file:com.srotya.tau.ui.rules.RulesManager.java
public short createNewRule(UserBean ub, Tenant tenant) throws Exception { CloseableHttpClient client = Utils.buildClient(am.getBaseUrl(), am.getConnectTimeout(), am.getRequestTimeout());//from w w w.j a v a2 s . co m HttpPost post = new HttpPost(am.getBaseUrl() + RULES_URL + "/" + tenant.getTenantId()); if (am.isEnableAuth()) { post.addHeader(BapiLoginDAO.X_SUBJECT_TOKEN, ub.getToken()); post.addHeader(BapiLoginDAO.HMAC, ub.getHmac()); } CloseableHttpResponse resp = client.execute(post); String result = EntityUtils.toString(resp.getEntity()); return Short.parseShort(result); }
From source file:org.fcrepo.it.SparqlRecipesIT.java
@BeforeClass public static void startFuseki() throws InterruptedException, IOException { //Determine the snapshot used for testing and its REST api, //make it default for snapshot 4 for the current version final String fcrepoSnapshot = System.getProperty("fcrepo.version"); if (fcrepoSnapshot != null && fcrepoSnapshot.indexOf("-") > 0 && fcrepoSnapshot.indexOf("4.0.0-beta") >= 0) { final String[] verTokens = fcrepoSnapshot.split("-"); if (verTokens.length >= 3) { try { FCREPO_SNAPSHOT_NUMBER = Short.parseShort(verTokens[2]); } catch (final NumberFormatException ne) { FCREPO_SNAPSHOT_NUMBER = 4; }/* w ww . j a v a 2 s .c om*/ } } if (FCREPO_SNAPSHOT_NUMBER < 4) { DATASTREAM_URL_SUFIX = ""; DATASTREAM_CONTENT_URL_SUFIX = "/fcr:content"; DATASTREAM_MIXIN_TYPE = "fedora:datastream"; DATASTREAM_RELATION = "fcrepo:hasContent"; } final File commandFile = new File("target/jena-fuseki-1.0.1/fuseki-server"); final ProcessBuilder b = new ProcessBuilder().inheritIO().directory(commandFile.getParentFile()).command( "./fuseki-server", "--update", "--mem", "--port=" + FUSEKI_PORT, "--mgtPort=" + MGT_PORT, "/test"); fuseki = b.start(); // It might take a while to startup and be ready to receive messages... Thread.sleep(10000); setUpTestObjects(); }
From source file:com.srotya.tau.ui.rules.TemplateManager.java
public short createTemplate(UserBean ub, Tenant tenant) throws Exception { if (tenant == null) { throw new NullPointerException("Template can't be empty"); }/*from www . j a v a 2s . c om*/ try { CloseableHttpClient client = Utils.buildClient(am.getBaseUrl(), am.getConnectTimeout(), am.getRequestTimeout()); HttpPost post = new HttpPost(am.getBaseUrl() + TEMPLATE_URL + "/" + tenant.getTenantId()); if (am.isEnableAuth()) { post.addHeader(BapiLoginDAO.X_SUBJECT_TOKEN, ub.getToken()); post.addHeader(BapiLoginDAO.HMAC, ub.getHmac()); } CloseableHttpResponse resp = client.execute(post); if (!Utils.validateStatus(resp)) { throw new Exception("status code:" + resp.getStatusLine().getStatusCode()); } return Short.parseShort(EntityUtils.toString(resp.getEntity())); } catch (Exception e) { logger.log(Level.SEVERE, "Failed to create template:" + tenant + "\t" + e.getMessage()); throw e; } }