List of usage examples for java.lang Double intValue
public int intValue()
From source file:org.ambraproject.migration.BootstrapMigratorServiceImpl.java
/** * Get the current version of the binaries * <p/>/* w ww. j a v a2 s . c om*/ * Assumptions about the version number: * Only contains single-digit integers between dots (e.g., 2.2.1.6.9.3) * * @return binary version * @throws IOException when the class loader fails */ private void setBinaryVersion() throws IOException { InputStream is = BootstrapMigratorServiceImpl.class.getResourceAsStream("version.properties"); Properties prop = new Properties(); prop.load(is); String sVersion = (String) prop.get("version"); if (sVersion.indexOf("-SNAPSHOT") > 0) { sVersion = sVersion.substring(0, sVersion.indexOf("-SNAPSHOT")); this.isSnapshot = true; } Double dVersion; // If the version has multiple dots, then it cannot be directly parsed as a Double. String[] versionArray = sVersion.split("\\."); if (versionArray.length < 3) { // example version numbers: 2 and 2.2 and 2.46 and 3.65 dVersion = Double.parseDouble(sVersion) * 100; // 200 220 246 365 } else { // example version numbers: 2.1.1 and 2.2.5.3 and dVersion = Double.parseDouble(versionArray[0] + "." + versionArray[1]) * 100; for (int i = 2; i < versionArray.length; i++) { dVersion = dVersion + Math.pow((new Double(versionArray[i])).doubleValue(), (new Double(1 - i)).doubleValue()); } } this.binaryVersion = dVersion.intValue(); }
From source file:classes.MyVisitor.java
@Override public T visitExpr(MyLanguageParser.ExprContext ctx) { // Multipliacin/divisin if (ctx.expr(0) != null && ctx.MULOP() != null && ctx.expr(1) != null) { T visit1 = posicionArray(visitExpr(ctx.expr(0))); T visit2 = posicionArray(visitExpr(ctx.expr(1))); Double a = Double.valueOf(visit1.toString()); Double b = Double.valueOf(visit2.toString()); if (ctx.MULOP().toString().equals("*")) { Double c; c = a * b;/*from ww w . jav a2 s . c o m*/ if (isInt(c)) { Integer d = c.intValue(); return (T) d; } return (T) c; } else if (ctx.MULOP().toString().equals("/")) { Double c; c = a * b; if (isInt(c)) { Integer d = c.intValue(); return (T) d; } return (T) c; } } // NO.token else if (ctx.NO_ID() != null && ctx.ID() != null) { Objeto obj = buscar(ctx.ID().toString()); String bool; if (getTipo(obj) != 4) { // SEMANTICO error = "Negacion se usa para cambiar el estado de variables logicas"; error(); } else if (obj.getObjeto().equals("verdadero")) { bool = "falso"; return (T) bool; } else if (obj.getObjeto().equals("falso")) { bool = "verdadero"; return (T) bool; } } // +/- expr else if (ctx.SUMOP() != null && ctx.expr(0) != null && ctx.expr(1) == null) { T tipo1 = visitExpr(ctx.expr(0)); T tipo = posicionArray(visitExpr(ctx.expr(0))); boolean isNumber = NumberUtils.isNumber(tipo.toString()); if (isNumber) { if (ctx.SUMOP().toString().equals("+")) { Double tipe = Double.valueOf(tipo.toString()); return (T) tipe; } else { Double tipe = -Double.valueOf(tipo.toString()); return (T) tipe; } } } // b[a][][] etc REVCISASUDJWQ else if (ctx.ID() != null && ctx.COR_IZQ() != null && ctx.expr(0) != null && ctx.COR_DER() != null) { T tipo = visitExpr(ctx.expr(0)); String lista = tipo.toString(); lista = lista.replace("[", ""); lista = lista.replace("]", ""); lista = lista.replace(" ", ""); ArrayList<String> list = new ArrayList<String>(Arrays.asList(lista.split(","))); for (String string : list) { if (!isNum(string)) { error = "<linea:col> Error en tiempo de ejecucion: se accedio a una posicion no valida del arreglo: " + string; error(); } } ArrayList<String> idList = new ArrayList<>(); idList.add(ctx.ID().toString()); for (String string : list) { idList.add(string); } return (T) idList; } // [expr] else if (ctx.COR_IZQ() != null && ctx.expr(0) != null && ctx.COR_DER() != null) { T tipo = visitExpr(ctx.expr(0)); String s = tipo + ""; return (T) s; } // SUMA else if (ctx.expr(0) != null && ctx.SUMOP() != null && ctx.expr(1) != null) { T visit1 = posicionArray(visitExpr(ctx.expr(0))); T visit2 = posicionArray(visitExpr(ctx.expr(1))); Double a = Double.valueOf(visit1.toString()); Double b = Double.valueOf(visit2.toString()); if (ctx.SUMOP().toString().equals("+")) { Double c; c = a + b; if (isInt(c)) { Integer d = c.intValue(); return (T) d; } return (T) c; } else if (ctx.SUMOP().toString().equals("-")) { Double c; c = a - b; if (isInt(c)) { Integer d = c.intValue(); return (T) d; } return (T) c; } } // pow else if (ctx.expr(0) != null && ctx.POTENCIA() != null && ctx.expr(1) != null) { T visit1 = posicionArray(visitExpr(ctx.expr(0))); T visit2 = posicionArray(visitExpr(ctx.expr(1))); Double a = Double.valueOf(visit1.toString()); Double b = Double.valueOf(visit2.toString()); Double c = Math.pow(a, b); return (T) c; } // modulo % else if (ctx.expr(0) != null && ctx.MODOP() != null && ctx.expr(1) != null) { T visit1 = posicionArray(visitExpr(ctx.expr(0))); T visit2 = posicionArray(visitExpr(ctx.expr(1))); Double a = Double.valueOf(visit1.toString()); Double b = Double.valueOf(visit2.toString()); Double c = a % b; return (T) c; } // modulo mod else if (ctx.expr(0) != null && ctx.MODULO() != null && ctx.expr(1) != null) { T visit1 = posicionArray(visitExpr(ctx.expr(0))); T visit2 = posicionArray(visitExpr(ctx.expr(1))); Double a = Double.valueOf(visit1.toString()); Double b = Double.valueOf(visit2.toString()); Double c = a % b; return (T) c; } // Case Y/O else if (ctx.expr(0) != null && (ctx.AND_OP() != null || ctx.OR_OP() != null) && ctx.expr(1) != null) { T visit1 = posicionArray(visitExpr(ctx.expr(0))); T visit2 = posicionArray(visitExpr(ctx.expr(1))); String a = visit1.toString(); String b = visit2.toString(); if (!(a.equals("verdadero") || a.equals("falso"))) { error = "Se esperaba un valor logico, en cambio llego" + a; error(); } if (!(b.equals("verdadero") || b.equals("falso"))) { error = "Se esperaba un valor logico, en cambio llego" + b; error(); } String valor; if (ctx.AND_OP() != null) { if (a.equals("verdadero") && b.equals("verdadero")) { valor = "verdadero"; } else { valor = "falso"; } return (T) valor; } else if (ctx.OR_OP() != null) { if (a.equals("verdadero") || b.equals("verdadero")) { valor = "verdadero"; } else { valor = "falso"; } return (T) valor; } } // real else if (ctx.REAL() != null) { Double a = Double.valueOf(ctx.REAL().toString()); if (isInt(a)) { Integer d = a.intValue(); return (T) d; } return (T) a; } // entero else if (ctx.ENTERO() != null) { Integer a = Integer.valueOf(ctx.ENTERO().toString()); return (T) a; } // logico verdadero else if (ctx.VERDADERO() != null) { String bool = "verdadero"; return (T) bool; } // logico falso else if (ctx.FALSO() != null) { String bool = "falso"; return (T) bool; } // ROP else if (ctx.ROP() != null) { String rop = ctx.ROP().toString(); return (T) rop; } // ID, expr else if (ctx.ID() != null && ctx.COMMA() != null && ctx.expr(0) != null) { Objeto obj = isDefined(ctx.ID().toString()); // T visit1 = posicionArray(visitExpr(ctx.expr(0))); String s = obj.getObjeto() + ", " + visitExpr(ctx.expr(0)).toString(); return (T) s; } // ID else if (ctx.ID() != null) { Objeto obj = isDefined(ctx.ID().toString()); String valor = isInicialized(obj); return (T) valor; } // (expr) else if (ctx.PAR_DER() != null && ctx.expr(0) != null && ctx.PAR_DER() != null) { return posicionArray(visitExpr(ctx.expr(0))); } // function f(expr)?? else if (ctx.ID() != null && ctx.PAR_DER() != null && ctx.expr(0) != null && ctx.PAR_DER() != null) { System.out.println("definir Caso funcion(expr)"); } // expr, expr else if (ctx.expr(0) != null && ctx.COMMA() != null && ctx.expr(1) != null) { ArrayList<T> a = new ArrayList<T>(); T visit1 = visitExpr(ctx.expr(0)); T visit2 = visitExpr(ctx.expr(1)); String izq = visit1.toString(); String der = visit2.toString(); a.add((T) izq); a.add((T) der); return (T) a; } // f()?? else if (ctx.ID() != null && ctx.PAR_IZQ() != null && ctx.PAR_DER() != null) { System.out.println("definir Caso f()"); } // negacion else if (ctx.NEGACION() != null && ctx.expr(0) != null) { T visit1 = posicionArray(visitExpr(ctx.expr(0))); String bool; if (visit1.toString() != "verdadero" || visit1.toString() != "falso") { // SEMANTICO error = "Negacion se usa para cambiar el estado de variables logicas"; error(); } else if (visit1.toString().equals("verdadero")) { bool = "falso"; return (T) bool; } else if (visit1.toString().equals("falso")) { bool = "verdadero"; return (T) bool; } } System.out.println("Estado no definido"); return null; }
From source file:com.odoo.core.rpc.wrapper.OdooWrapper.java
private OUser parseUserObject(OUser user, OdooResult result) { // Odoo 10.0+ returns array of object in read method if (result.containsKey("result") && result.get("result") instanceof ArrayList) { List<LinkedTreeMap> items = (List<LinkedTreeMap>) result.get("result"); result = new OdooResult(); result.putAll(items.get(0));//from w w w .jav a 2 s .com } user.setName(result.getString("name")); user.setAvatar(result.getString("image_medium")); user.setTimezone(result.getString("tz")); Double partner_id = (Double) result.getArray("partner_id").get(0); Double company_id = (Double) result.getArray("company_id").get(0); user.setPartnerId(partner_id.intValue()); user.setCompanyId(company_id.intValue()); if (mVersion.getVersionNumber() == 7) { //FIX: Odoo 7 Not returning company id with user login details odooSession.setCompanyId(company_id.intValue()); } return user; }
From source file:org.sakaiproject.contentreview.urkund.UrkundReviewServiceImpl.java
/** * find the next time this item should be tried * /*w w w . j a v a 2 s . co m*/ * @param retryCount * @return */ private Date getNextRetryTime(long retryCount) { Double offset = 5.; if (retryCount > 0) { offset = 15 * Math.pow(2, retryCount - 1); } if (offset > 480) { offset = 480.; } Calendar cal = Calendar.getInstance(); cal.add(Calendar.MINUTE, offset.intValue()); return cal.getTime(); }
From source file:io.hops.hopsworks.api.zeppelin.rest.NotebookRestApi.java
/** * Insert paragraph REST API/* w w w . j a va 2 s.c o m*/ * * @param message - JSON containing paragraph's information * @return JSON with status.OK * @throws IOException */ @POST @Path("{noteId}/paragraph") public Response insertParagraph(@PathParam("noteId") String noteId, String message) throws IOException { String user = SecurityUtils.getPrincipal(); LOG.info("insert paragraph {} {}", noteId, message); Note note = notebook.getNote(noteId); checkIfNoteIsNotNull(note); checkIfUserCanWrite(noteId, "Insufficient privileges you cannot add paragraph to this note"); NewParagraphRequest request = NewParagraphRequest.fromJson(message); AuthenticationInfo subject = new AuthenticationInfo(user); Paragraph p; Double indexDouble = request.getIndex(); if (indexDouble == null) { p = note.addNewParagraph(subject); } else { p = note.insertNewParagraph(indexDouble.intValue(), subject); } initParagraph(p, request, user); note.persist(subject); notebookServer.broadcastNote(note); return new JsonResponse<>(Status.OK, "", p.getId()).build(); }
From source file:me.Wundero.Ray.utils.TextUtils.java
/** * Darken or replace characters from the original text based off of the * percentages provided.//from ww w. ja va 2 s. c o m */ public static Text obfuscate(Text original, Double percentObfuscation, Double percentDiscoloration) { if (original == null) { return Text.of(); } List<Text> children = original.getChildren(); original = original.toBuilder().removeAll().build(); Text.Builder out = Text.builder().color(original.getColor()); char[] chars = getContent(original).toCharArray(); Integer obC = percentDiscoloration.intValue(); Integer obS = percentObfuscation.intValue(); List<Text> cs = Utils.al(); Random rng = new Random(); TextColor co = original.getColor(); for (Character c : chars) { if (rng.nextInt(100) < obS) { cs.add(Text.of(co, " ")); } else { cs.add(Text.of(co, c)); } } List<Text> toBuild = Utils.al(); for (Text t : cs) { if (rng.nextInt(100) < obC) { toBuild.add(t.toBuilder().color(TextColors.DARK_GRAY).build()); } else { toBuild.add(t); } } out.append(toBuild); for (Text t : children) { out.append(obfuscate(t, percentObfuscation, percentDiscoloration)); } return out.build(); }
From source file:fr.mael.jiwigo.dao.impl.ImageDaoImpl.java
/** * Creation of an image<br/>//from w ww . java 2 s .c o m * Sequence : <br/> * <li> * <ul>sending of the thumbnail in base64, thanks to the method addchunk.</ul> * <ul>sending of the image in base64, thanks to the method addchunk</ul> * <ul>using of the add method to add the image to the database<ul> * </li> * Finally, the response of the webservice is checked * * @param image the image to create * @return true if the creation of the image was the successful * @throws IOException * @throws NoSuchAlgorithmException * @throws WrongChunkSizeException * @throws JiwigoException * @throws Exception */ //TODO ne pas continuer si une des reponses precedentes est negative public boolean create(Image image, Double chunkSize) throws FileAlreadyExistsException, IOException, ProxyAuthenticationException, NoSuchAlgorithmException, WrongChunkSizeException, JiwigoException { if (exists(image)) { throw new FileAlreadyExistsException("Photo already exists"); } //thumbnail converted to base64 BASE64Encoder base64 = new BASE64Encoder(); String thumbnailBase64 = base64.encode(Tools.getBytesFromFile(image.getThumbnail())); //sends the thumbnail and gets the result Document reponseThumb = (sessionManager.executeReturnDocument(MethodsEnum.ADD_CHUNK.getLabel(), "data", thumbnailBase64, "type", "thumb", "position", "1", "original_sum", Tools.getMD5Checksum(image.getOriginale().getAbsolutePath()))); //begin feature:0001827 int chunk = chunkSize.intValue(); if (chunk == 0) { throw new WrongChunkSizeException("Error : the chunk size cannot be 0"); } filesToSend = Tools.splitFile(image.getOriginale(), chunk); boolean echec = false; for (int i = 0; i < filesToSend.size(); i++) { File fichierAEnvoyer = filesToSend.get(i); String originaleBase64 = base64.encode(Tools.getBytesFromFile(fichierAEnvoyer)); Document reponseOriginale = (sessionManager.executeReturnDocument(MethodsEnum.ADD_CHUNK.getLabel(), "data", originaleBase64, "type", "file", "position", String.valueOf(i), "original_sum", Tools.getMD5Checksum(image.getOriginale().getAbsolutePath()))); if (!Tools.checkOk(reponseOriginale)) { echec = true; break; } } //end //add the image in the database and get the result of the webservice Document reponseAjout = (sessionManager.executeReturnDocument(MethodsEnum.ADD_IMAGE.getLabel(), "file_sum", Tools.getMD5Checksum(image.getOriginale().getAbsolutePath()), "thumbnail_sum", Tools.getMD5Checksum(image.getThumbnail().getCanonicalPath()), "position", "1", "original_sum", Tools.getMD5Checksum(image.getOriginale().getAbsolutePath()), "categories", String.valueOf(image.getIdCategory()), "name", image.getName(), "author", sessionManager.getLogin(), "level", image.getPrivacyLevel())); if (LOG.isDebugEnabled()) { LOG.debug("Response add : " + Tools.documentToString(reponseAjout)); } // System.out.println(Main.sessionManager.executerReturnString("pwg.images.add", "file_sum", Outil // .getMD5Checksum(image.getOriginale().getAbsolutePath()), "thumbnail_sum", Outil.getMD5Checksum(image // .getThumbnail().getCanonicalPath()), "position", "1", "original_sum", Outil.getMD5Checksum(image // .getOriginale().getAbsolutePath()), "categories", String.valueOf(image.getIdCategory()), "name", image // .getName(), "author", Main.sessionManager.getLogin())); // Document reponsePrivacy = null; // if (Outil.checkOk(reponseAjout)) { // reponsePrivacy = Main.sessionManager.executerReturnDocument(MethodsEnum.SET_PRIVACY_LEVEL.getLabel()); // } boolean reussite = true; if (!Tools.checkOk(reponseThumb) || echec || !Tools.checkOk(reponseAjout)) { reussite = false; } deleteTempFiles(); return reussite; }
From source file:org.sonar.plugins.cxx.xunit.XunitReportParser.java
private TestCase parseTestCaseTag(SMInputCursor testCaseCursor, String tsName, String tsFilename) throws XMLStreamException { String classname = testCaseCursor.getAttrValue("classname"); String name = parseTestCaseName(testCaseCursor); Double time = parseTime(testCaseCursor); String status = "ok"; String stack = ""; String msg = ""; // Googletest-reports mark the skipped tests with status="notrun" String statusattr = testCaseCursor.getAttrValue("status"); if ("notrun".equals(statusattr)) { status = "skipped"; } else {/*w w w. j a va 2 s .com*/ SMInputCursor childCursor = testCaseCursor.childElementCursor(); if (childCursor.getNext() != null) { String elementName = childCursor.getLocalName(); if (elementName.equals("skipped")) { status = "skipped"; } else if (elementName.equals("failure")) { status = "failure"; msg = childCursor.getAttrValue("message"); stack = childCursor.collectDescendantText(); } else if (elementName.equals("error")) { status = "error"; msg = childCursor.getAttrValue("message"); stack = childCursor.collectDescendantText(); } } } return new TestCase(name, time.intValue(), status, stack, msg, classname, tsName, tsFilename); }
From source file:org.sonar.plugins.cxx.tests.xunit.XunitReportParser.java
private TestCase parseTestCaseTag(SMInputCursor testCaseCursor, String tsName, String tsFilename) throws XMLStreamException { String classname = testCaseCursor.getAttrValue("classname"); String tcFilename = testCaseCursor.getAttrValue("filename"); String name = parseTestCaseName(testCaseCursor); Double time = parseTime(testCaseCursor); String status = "ok"; String stack = ""; String msg = ""; // Googletest-reports mark the skipped tests with status="notrun" String statusattr = testCaseCursor.getAttrValue("status"); if ("notrun".equals(statusattr)) { status = "skipped"; } else {//from w ww . j av a 2s . c o m SMInputCursor childCursor = testCaseCursor.childElementCursor(); if (childCursor.getNext() != null) { String elementName = childCursor.getLocalName(); if ("skipped".equals(elementName)) { status = "skipped"; } else if ("failure".equals(elementName)) { status = "failure"; msg = childCursor.getAttrValue("message"); stack = childCursor.collectDescendantText(); } else if ("error".equals(elementName)) { status = "error"; msg = childCursor.getAttrValue("message"); stack = childCursor.collectDescendantText(); } } } return new TestCase(name, time.intValue(), status, stack, msg, classname, tcFilename, tsName, tsFilename); }