List of usage examples for java.lang Number intValue
public abstract int intValue();
From source file:com.prowidesoftware.swift.model.field.Field14S.java
/** * Set the component2 from a Number object. * <br />/*from w w w . j a va2 s . com*/ * <em>If the component being set is a fixed length number, the argument will not be * padded.</em> It is recommended for these cases to use the setComponent2(String) * method. * * @see #setComponent2(String) * * @param component2 the Number with the component2 content to set */ public Field14S setComponent2(java.lang.Number component2) { if (component2 != null) { setComponent(2, "" + component2.intValue()); } return this; }
From source file:de.egore911.opengate.services.PilotService.java
@POST @Path("/register") @Produces("application/json") @Documentation("Register a new pilot. This will at first verify the login and email are " + "unique and the email is valid. After this it will register the pilot and send " + "and email to him to verify the address. The 'verify' will finalize the registration. " + "This method returns a JSON object containing a status field, i.e. {status: 'failed', " + "details: '...'} in case of an error and {status: 'ok', id: ...}. If an internal " + "error occured an HTTP 500 will be sent.") public Response performRegister(@FormParam("login") String login, @FormParam("email") String email, @FormParam("faction_id") @Documentation("ID of the faction this pilot will be working for") long factionId) { JSONObject jsonObject = new JSONObject(); EntityManager em = EntityManagerFilter.getEntityManager(); Number n = (Number) em .createQuery("select count(pilot.key) from Pilot pilot " + "where pilot.login = (:login)") .setParameter("login", login).getSingleResult(); if (n.intValue() > 0) { try {/*from w w w .jav a2 s. c o m*/ StatusHelper.failed(jsonObject, "Duplicate login"); return Response.ok(jsonObject.toString()).build(); } catch (JSONException e) { LOG.log(Level.SEVERE, e.getMessage(), e); return Response.status(Status.INTERNAL_SERVER_ERROR).build(); } } n = (Number) em.createQuery("select count(pilot.key) from Pilot pilot " + "where pilot.email = (:email)") .setParameter("email", email).getSingleResult(); if (n.intValue() > 0) { try { StatusHelper.failed(jsonObject, "Duplicate email"); return Response.ok(jsonObject.toString()).build(); } catch (JSONException e) { LOG.log(Level.SEVERE, e.getMessage(), e); return Response.status(Status.INTERNAL_SERVER_ERROR).build(); } } InternetAddress recipient; try { recipient = new InternetAddress(email, login); } catch (UnsupportedEncodingException e1) { try { StatusHelper.failed(jsonObject, "Invalid email"); return Response.ok(jsonObject.toString()).build(); } catch (JSONException e) { LOG.log(Level.SEVERE, e.getMessage(), e); return Response.status(Status.INTERNAL_SERVER_ERROR).build(); } } Faction faction; try { faction = em.find(Faction.class, factionId); } catch (NoResultException e) { try { StatusHelper.failed(jsonObject, "Invalid faction"); return Response.ok(jsonObject.toString()).build(); } catch (JSONException e1) { LOG.log(Level.SEVERE, e.getMessage(), e1); return Response.status(Status.INTERNAL_SERVER_ERROR).build(); } } Vessel vessel; try { vessel = (Vessel) em .createQuery("select vessel from Vessel vessel " + "where vessel.faction = :faction " + "order by vessel.techLevel asc") .setParameter("faction", faction).setMaxResults(1).getSingleResult(); // TODO assign initical equipment as well } catch (NoResultException e) { try { StatusHelper.failed(jsonObject, "Faction has no vessel"); return Response.ok(jsonObject.toString()).build(); } catch (JSONException e1) { LOG.log(Level.SEVERE, e.getMessage(), e1); return Response.status(Status.INTERNAL_SERVER_ERROR).build(); } } String passwordHash; String password = randomText(); try { passwordHash = hashPassword(password); } catch (NoSuchAlgorithmException e) { LOG.log(Level.SEVERE, e.getMessage(), e); return Response.status(Status.INTERNAL_SERVER_ERROR).build(); } em.getTransaction().begin(); try { Pilot pilot = new Pilot(); pilot.setLogin(login); pilot.setCreated(new Date()); pilot.setPasswordHash(passwordHash); pilot.setEmail(email); pilot.setFaction(faction); pilot.setVessel(vessel); pilot.setVerificationCode(randomText()); em.persist(pilot); em.getTransaction().commit(); try { // send e-mail to registered user containing the new password Properties props = new Properties(); Session session = Session.getDefaultInstance(props, null); String msgBody = "Welcome to opengate!\n\nSomeone, propably you, registered the user " + pilot.getLogin() + " with your e-mail adress. The following credentials can be used for your account:\n" + " login : " + pilot.getLogin() + "\n" + " password : " + password + "\n\n" + "To log into the game you need to verify your account using the following link: http://opengate-meta.appspot.com/services/pilot/verify/" + pilot.getLogin() + "?verification=" + pilot.getVerificationCode(); try { Message msg = new MimeMessage(session); msg.setFrom(new InternetAddress("egore911@gmail.com", "Opengate administration")); msg.addRecipient(Message.RecipientType.TO, recipient); msg.setSubject("Your Example.com account has been activated"); msg.setText(msgBody); Transport.send(msg); } catch (AddressException e) { LOG.log(Level.SEVERE, e.getMessage(), e); return Response.status(Status.INTERNAL_SERVER_ERROR).build(); } catch (MessagingException e) { LOG.log(Level.SEVERE, e.getMessage(), e); return Response.status(Status.INTERNAL_SERVER_ERROR).build(); } catch (UnsupportedEncodingException e) { LOG.log(Level.SEVERE, e.getMessage(), e); return Response.status(Status.INTERNAL_SERVER_ERROR).build(); } StatusHelper.ok(jsonObject); jsonObject.put("id", pilot.getKey().getId()); jsonObject.put("vessel_id", pilot.getVessel().getKey().getId()); // TODO properly wrap the vessel and its equipment/cargo return Response.ok(jsonObject.toString()).build(); } catch (JSONException e) { LOG.log(Level.SEVERE, e.getMessage(), e); return Response.status(Status.INTERNAL_SERVER_ERROR).build(); } } catch (NoResultException e) { return Response.status(Status.FORBIDDEN).build(); } finally { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } } }
From source file:com.rogchen.common.xml.UtilDateTime.java
public static Timestamp getYearStart(Timestamp stamp, Number daysLater, Number monthsLater, Number yearsLater, TimeZone timeZone, Locale locale) { return getYearStart(stamp, (daysLater == null ? 0 : daysLater.intValue()), (monthsLater == null ? 0 : monthsLater.intValue()), (yearsLater == null ? 0 : yearsLater.intValue()), timeZone, locale); }
From source file:com.hello2morrow.sonarplugin.SonargraphSensor.java
private void analyse(IProject project, XsdAttributeRoot xsdBuildUnit, String buildUnitName, ReportContext report) {//from w ww. j ava 2 s. c om LOG.info("Adding measures for " + project.getName()); readAttributes(xsdBuildUnit); Number internalPackages = getBuildUnitMetric(INTERNAL_PACKAGES); if (internalPackages.intValue() == 0) { LOG.warn("No packages found in project " + project.getName()); return; } saveMeasure(ACD, SonargraphMetrics.ACD, 1); saveMeasure(NCCD, SonargraphMetrics.NCCD, 1); saveMeasure(INSTRUCTIONS, SonargraphMetrics.INSTRUCTIONS, 0); saveMeasure(JAVA_FILES, SonargraphMetrics.JAVA_FILES, 0); saveMeasure(TYPE_DEPENDENCIES, SonargraphMetrics.TYPE_DEPENDENCIES, 0); saveMeasure(EROSION_REFS, SonargraphMetrics.EROSION_REFS, 0); saveMeasure(EROSION_TYPES, SonargraphMetrics.EROSION_TYPES, 0); Number structuralDebtIndex = saveMeasure(STUCTURAL_DEBT_INDEX, SonargraphMetrics.EROSION_INDEX, 0) .getValue(); if (indexCost > 0) { double structuralDebtCost = structuralDebtIndex.doubleValue() * indexCost; saveMeasure(SonargraphMetrics.EROSION_COST, structuralDebtCost, 0); } analyseCycleGroups(report, internalPackages, buildUnitName); if (hasBuildUnitMetric(UNASSIGNED_TYPES)) { LOG.info("Adding architecture measures for " + project.getName()); addArchitectureMeasures(report, buildUnitName); } AlertDecorator.setAlertLevels(new SensorProjectContext(sensorContext)); }
From source file:mml.handler.get.MMLGetMMLHandler.java
private void addAbsoluteOffsets(JSONArray arr) { int offset = 0; for (int i = 0; i < arr.size(); i++) { JSONObject jObj = (JSONObject) arr.get(i); Number reloff = (Number) jObj.get(JSONKeys.RELOFF); offset += reloff.intValue(); jObj.put(JSONKeys.OFFSET, offset); }/*from ww w . j av a2 s .co m*/ }
From source file:eu.dasish.annotation.backend.dao.impl.JdbcAnnotationDaoTest.java
/** * * Test of getAnnotationID method, of class JdbcAnnotationDao. Integer * getAnnotationID(UUID externalID)//w w w . j a v a2 s.c o m */ @Test public void getInternalID() throws NotInDataBaseException { System.out.println("test getInternalID"); final Number annotaionId = jdbcAnnotationDao .getInternalID(UUID.fromString("00000000-0000-0000-0000-000000000021")); assertEquals(1, annotaionId.intValue()); try { final Number annotaionIdNE = jdbcAnnotationDao .getInternalID(UUID.fromString("00000000-0000-0000-0000-0000000000cc")); } catch (NotInDataBaseException e) { System.out.println(e); } }
From source file:com.hello2morrow.sonarplugin.SonarJSensor.java
private void analyse(IProject project, XsdAttributeRoot xsdBuildUnit, String buildUnitName, ReportContext report, boolean isMultiModuleProject) { LOG.info("Adding measures for " + project.getName()); projectMetrics = readAttributes(xsdBuildUnit); Number internalPackages = projectMetrics.get(INTERNAL_PACKAGES); if (internalPackages.intValue() == 0) { LOG.warn("No classes found in project " + project.getName()); return;//from ww w . j a v a2 s . c o m } double acd = projectMetrics.get(ACD).doubleValue(); double nccd = projectMetrics.get(NCCD).doubleValue(); saveMeasure(ACD, SonarJMetrics.ACD, 1); saveMeasure(NCCD, SonarJMetrics.NCCD, 1); saveMeasure(INSTRUCTIONS, SonarJMetrics.INSTRUCTIONS, 0); saveMeasure(JAVA_FILES, SonarJMetrics.JAVA_FILES, 0); saveMeasure(TYPE_DEPENDENCIES, SonarJMetrics.TYPE_DEPENDENCIES, 0); saveMeasure(EROSION_REFS, SonarJMetrics.EROSION_REFS, 0); saveMeasure(EROSION_TYPES, SonarJMetrics.EROSION_TYPES, 0); Number structuralDebtIndex = saveMeasure(STUCTURAL_DEBT_INDEX, SonarJMetrics.EROSION_INDEX, 0).getValue(); if (indexCost > 0) { double structuralDebtCost = structuralDebtIndex.doubleValue() * indexCost; saveMeasure(SonarJMetrics.EROSION_COST, structuralDebtCost, 0); } analyseCycleGroups(report, internalPackages, buildUnitName); if (projectMetrics.get(UNASSIGNED_TYPES) != null) { LOG.info("Adding architecture measures for " + project.getName()); addArchitectureMeasures(report, buildUnitName); } AlertDecorator.setAlertLevels(new SensorProjectContext(sensorContext)); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLCollection.java
/** * Private helper that retrieves the item or items corresponding to the specified * index or key.//from w w w.ja v a 2 s.c o m * @param o the index or key corresponding to the element or elements to return * @return the element or elements corresponding to the specified index or key */ private Object getIt(final Object o) { if (o instanceof Number) { final Number n = (Number) o; final int i = n.intValue(); return get(i, this); } final String key = String.valueOf(o); return get(key, this); }