List of usage examples for java.lang Long longValue
@HotSpotIntrinsicCandidate public long longValue()
From source file:org.matsim.analysis.IterationStopWatch.java
/** * Writes the gathered data as graph into a png file. * * @param filename The name of a file where to write the gathered data. *//*ww w.j a v a2 s . co m*/ public void writeGraphFile(String filename) { int iterations = this.iterations.entrySet().size(); Map<String, double[]> arrayMap = new HashMap<String, double[]>(); for (String identifier : this.operations) arrayMap.put(identifier, new double[iterations]); int iter = 0; for (Entry<Integer, Map<String, Long>> entry : this.iterations.entrySet()) { Map<String, Long> data = entry.getValue(); // children map of current iteration Map<String, List<String>> childrenMap = this.children.get(entry.getKey()); // durations of operations for (String identifier : this.operations) { Long startTime = data.get("BEGIN " + identifier); Long endTime = data.get("END " + identifier); if (startTime != null && endTime != null) { double diff = (endTime.longValue() - startTime.longValue()); /* * If the operation has children, subtract their durations since they are * also included in the plot. Otherwise their duration would be counted twice. */ for (String child : childrenMap.get(identifier)) { Long childStartTime = data.get("BEGIN " + child); Long childEndTime = data.get("END " + child); diff -= (childEndTime.longValue() - childStartTime.longValue()); } arrayMap.get(identifier)[iter] = diff / 1000.0; } else arrayMap.get(identifier)[iter] = 0.0; } iter++; } String title = "Computation time distribution per iteration"; String xAxisLabel = "iteration"; String yAxisLabel = "seconds"; String[] categories = new String[this.iterations.size()]; int index = 0; for (int iteration : this.iterations.keySet()) { categories[index] = String.valueOf(iteration); index++; } StackedBarChart chart = new StackedBarChart(title, xAxisLabel, yAxisLabel, categories); chart.addMatsimLogo(); /* * Rotate x-axis labels by 90 which should allow more of them to be plotted before overlapping. * However, a more general solution that also is able to skip labels would be nice. * cdobler nov'13 */ chart.getChart().getCategoryPlot().getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_90); double[] iterationData = null; // double[] sumData = new double[iterations]; for (String operation : this.operations) { double[] data = arrayMap.get(operation); if (operation.equals(AbstractController.OPERATION_ITERATION)) { iterationData = data; continue; } else { chart.addSeries(operation, data); // for (int i = 0; i < iterations; i++) { // sumData[i] += data[i]; // } } } if (iterationData != null) { double[] otherData = new double[iterations]; System.arraycopy(iterationData, 0, otherData, 0, iterations); chart.addSeries(OPERATION_OTHER, otherData); } chart.saveAsPng(filename + ".png", 1024, 768); }
From source file:de.codesourcery.jasm16.emulator.Breakpoint.java
private long calculateConditionValue(IEmulator emulator) throws ParseException { final StringBuilder trimmed = new StringBuilder(); for (char c : condition.toCharArray()) { if (!Character.isWhitespace(c)) { trimmed.append(c);/* w w w . j a v a 2s . c om*/ } } final String expanded = substitutePlaceholders(emulator, trimmed.toString()); final TermNode expression = parseCondition(expanded); final Long value = expression.calculate(new SymbolTable("calculateConditionValue(IEmulator)")); if (value == null) { throw new ParseException("Failed to evaluate condition '" + expanded + "'", 0, expanded.length()); } return value.longValue(); }
From source file:com.opensymphony.module.propertyset.database.JDBCPropertySet.java
private void setValues(PreparedStatement ps, int type, String key, Object value) throws SQLException, PropertyException { // Patched by Edson Richter for MS SQL Server JDBC Support! String driverName;/*w w w . j a v a2 s . c o m*/ try { driverName = ps.getConnection().getMetaData().getDriverName().toUpperCase(); } catch (Exception e) { driverName = ""; } ps.setNull(1, Types.VARCHAR); ps.setNull(2, Types.TIMESTAMP); // Patched by Edson Richter for MS SQL Server JDBC Support! // Oracle support suggestion also Michael G. Slack if ((driverName.indexOf("SQLSERVER") >= 0) || (driverName.indexOf("ORACLE") >= 0)) { ps.setNull(3, Types.BINARY); } else { ps.setNull(3, Types.BLOB); } ps.setNull(4, Types.FLOAT); ps.setNull(5, Types.NUMERIC); ps.setInt(6, type); ps.setString(7, globalKey); ps.setString(8, key); switch (type) { case PropertySet.BOOLEAN: Boolean boolVal = (Boolean) value; ps.setInt(5, boolVal.booleanValue() ? 1 : 0); break; case PropertySet.DATA: Data data = (Data) value; ps.setBytes(3, data.getBytes()); break; case PropertySet.DATE: Date date = (Date) value; ps.setTimestamp(2, new Timestamp(date.getTime())); break; case PropertySet.DOUBLE: Double d = (Double) value; ps.setDouble(4, d.doubleValue()); break; case PropertySet.INT: Integer i = (Integer) value; ps.setInt(5, i.intValue()); break; case PropertySet.LONG: Long l = (Long) value; ps.setLong(5, l.longValue()); break; case PropertySet.STRING: ps.setString(1, (String) value); break; default: throw new PropertyException("This type isn't supported!"); } }
From source file:org.sakaiproject.gradebookng.tool.panels.AssignmentStatisticsPanel.java
@Override public void onInitialize() { super.onInitialize(); final Long assignmentId = ((Model<Long>) getDefaultModel()).getObject(); final Assignment assignment = this.businessService.getAssignment(assignmentId.longValue()); AssignmentStatisticsPanel.this.window.setTitle( (new StringResourceModel("label.statistics.title", null, new Object[] { assignment.getName() }) .getString()));/*from w w w .ja v a 2 s. c o m*/ final List<GbStudentGradeInfo> gradeInfo = this.businessService.buildGradeMatrix(Arrays.asList(assignment)); final List<Double> allGrades = new ArrayList<>(); for (int i = 0; i < gradeInfo.size(); i++) { final GbStudentGradeInfo studentGradeInfo = gradeInfo.get(i); final Map<Long, GbGradeInfo> studentGrades = studentGradeInfo.getGrades(); final GbGradeInfo grade = studentGrades.get(assignmentId); if (grade == null || grade.getGrade() == null) { // this is not the grade you are looking for } else { allGrades.add(Double.valueOf(grade.getGrade())); } } Collections.sort(allGrades); final DefaultCategoryDataset data = new DefaultCategoryDataset(); final Map<String, Integer> counts = new TreeMap<>(); Integer extraCredits = 0; // Start off with a 0-50% range counts.put(String.format("%d-%d", 0, 50), 0); final int range = 10; for (int start = 50; start < 100; start = start + range) { final String key = String.format("%d-%d", start, start + range); counts.put(key, 0); } for (final Double grade : allGrades) { if (isExtraCredit(grade, assignment)) { extraCredits = extraCredits + 1; continue; } final double percentage; if (GradingType.PERCENTAGE.equals(this.gradingType)) { percentage = grade; } else { percentage = grade / assignment.getPoints() * 100; } final int total = Double.valueOf(Math.ceil(percentage) / range).intValue(); int start = total * range; if (start == 100) { start = start - range; } String key = String.format("%d-%d", start, start + range); if (start < 50) { key = String.format("%d-%d", 0, 50); } counts.put(key, counts.get(key) + 1); } for (final String label : counts.keySet()) { data.addValue(counts.get(label), "count", label); } if (extraCredits > 0) { data.addValue(extraCredits, "count", getString("label.statistics.chart.extracredit")); } final JFreeChart chart = ChartFactory.createBarChart(null, // the chart title getString("label.statistics.chart.xaxis"), // the label for the category axis getString("label.statistics.chart.yaxis"), // the label for the value axis data, // the dataset for the chart PlotOrientation.VERTICAL, // the plot orientation false, // show legend true, // show tooltips false); // show urls chart.setBorderVisible(false); chart.setAntiAlias(false); final CategoryPlot categoryPlot = chart.getCategoryPlot(); final BarRenderer br = (BarRenderer) categoryPlot.getRenderer(); br.setItemMargin(0); br.setMinimumBarLength(0.05); br.setMaximumBarWidth(0.1); br.setSeriesPaint(0, new Color(51, 122, 183)); br.setBarPainter(new StandardBarPainter()); br.setShadowPaint(new Color(220, 220, 220)); BarRenderer.setDefaultShadowsVisible(true); br.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator(getString("label.statistics.chart.tooltip"), NumberFormat.getInstance())); categoryPlot.setRenderer(br); // show only integers in the count axis categoryPlot.getRangeAxis().setStandardTickUnits(new NumberTickUnitSource(true)); categoryPlot.setBackgroundPaint(Color.white); add(new JFreeChartImageWithToolTip("chart", Model.of(chart), "tooltip", 540, 300)); add(new Label("graded", String.valueOf(allGrades.size()))); if (allGrades.size() > 0) { add(new Label("average", constructAverageLabel(allGrades, assignment))); add(new Label("median", constructMedianLabel(allGrades, assignment))); add(new Label("lowest", constructLowestLabel(allGrades, assignment))); add(new Label("highest", constructHighestLabel(allGrades, assignment))); add(new Label("deviation", constructStandardDeviationLabel(allGrades))); } else { add(new Label("average", "-")); add(new Label("median", "-")); add(new Label("lowest", "-")); add(new Label("highest", "-")); add(new Label("deviation", "-")); } add(new GbAjaxLink("done") { private static final long serialVersionUID = 1L; @Override public void onClick(final AjaxRequestTarget target) { AssignmentStatisticsPanel.this.window.close(target); } }); }
From source file:net.sf.sze.frontend.zeugnis.AvSvBewertungController.java
/** * Zeigt die AG-Bewertungen an.//from w w w . jav a2 s .co m * @param halbjahrId die Id des Schulhalbjahres * @param klassenId die Id der Klasse * @param schuelerId die Id des Schuelers * @param model das Model * @return die logische View */ @RequestMapping(value = URL.ZeugnisPath.ZEUGNIS_EDIT_AV_SV, method = RequestMethod.GET) public String editArbeitsgruppen(@PathVariable(URL.Session.P_HALBJAHR_ID) Long halbjahrId, @PathVariable(URL.Session.P_KLASSEN_ID) Long klassenId, @PathVariable(URL.Session.P_SCHUELER_ID) Long schuelerId, Model model) { final Zeugnis zeugnis = zeugnisErfassungsService.getZeugnis(halbjahrId, schuelerId); final SchuelerList schuelerList = schuelerService.getSchuelerWithZeugnis(halbjahrId.longValue(), klassenId.longValue(), schuelerId); final AvSvForm avSvForm = new AvSvForm(zeugnis.getAvSvBewertungen(), zeugnis.getSchueler(), zeugnis.getFormular()); Collections.sort(avSvForm.getAvSvBewertungen()); fillModel(model, avSvForm, halbjahrId, klassenId, schuelerId, schuelerList.getPrevSchuelerId(), schuelerList.getNextSchuelerId()); return EDIT_ZEUGNIS_AV_SV_VIEW; }
From source file:org.matsim.analysis.IterationStopWatch.java
/** * Writes the gathered data tab-separated into a text file. * * @param filename The name of a file where to write the gathered data. *//*from w ww . j a v a 2 s .c om*/ public void writeTextFile(final String filename) { try { BufferedWriter writer = IOUtils.getBufferedWriter(filename + ".txt"); // print header writer.write("Iteration"); for (String identifier : this.identifiers) { writer.write('\t'); writer.write(identifier); } writer.write('\t'); for (String identifier : this.operations) { writer.write('\t'); writer.write(identifier); } writer.newLine(); // print data for (Map.Entry<Integer, Map<String, Long>> entry : this.iterations.entrySet()) { Integer iteration = entry.getKey(); Map<String, Long> data = entry.getValue(); // iteration writer.write(iteration.toString()); // identifiers for (String identifier : this.identifiers) { Long time = data.get(identifier); writer.write('\t'); writer.write(formatMilliTime(time)); } // blank separator writer.write('\t'); // durations of operations for (String identifier : this.operations) { Long startTime = data.get("BEGIN " + identifier); Long endTime = data.get("END " + identifier); writer.write('\t'); if (startTime != null && endTime != null) { double diff = (endTime.longValue() - startTime.longValue()) / 1000.0; writer.write(Time.writeTime(diff)); } } // finish writer.newLine(); } writer.flush(); writer.close(); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.demo.rest.front.DriverRestService.java
/** * ?//from w w w . ja v a 2 s . c om * * @param cell * @param name * @param password * @param sfzA * @param sfzB * @param jszA * @param alias * @param captcha * @param licensePlate * @param xszA * @param response * @param request * @return */ @POST @Path("/signup") @Produces(MediaType.APPLICATION_JSON) public RestResult validSignupDriver(@FormParam("cell") final String cell, @FormParam("name") final String name, @FormParam("password") final String password, @FormParam("sfza") final String sfzA, @FormParam("sfzb") final String sfzB, @FormParam("jsza") final String jszA, @FormParam("alias") final String alias, @FormParam("captcha") final String captcha, @FormParam("license") final String licensePlate, @FormParam("xsza") final String xszA, @Context HttpServletResponse response, @Context HttpServletRequest request) { RestResult restResult = new RestResult(); // this.enabledCrossDomain(response); if (StringUtils.isBlank(cell)) { restResult.setCode(DriverLoginResultTypeEnum.CELL_IS_BLANK.getCode()); restResult.setMsg(DriverLoginResultTypeEnum.CELL_IS_BLANK.getMsg()); logger.error("{}", restResult); return restResult; } if (StringUtils.isBlank(name)) { restResult.setCode(DriverLoginResultTypeEnum.NAME_IS_BLANK.getCode()); restResult.setMsg(DriverLoginResultTypeEnum.NAME_IS_BLANK.getMsg()); logger.error("{}", restResult); return restResult; } if (StringUtils.isBlank(password)) { restResult.setCode(DriverLoginResultTypeEnum.PASSWORD_IS_BLANK.getCode()); restResult.setMsg(DriverLoginResultTypeEnum.PASSWORD_IS_BLANK.getMsg()); logger.error("{}", restResult); return restResult; } if (StringUtils.isBlank(sfzA)) { restResult.setCode(DriverLoginResultTypeEnum.SFZ_A_IS_BLANK.getCode()); restResult.setMsg(DriverLoginResultTypeEnum.SFZ_A_IS_BLANK.getMsg()); logger.error("{}", restResult); return restResult; } if (StringUtils.isBlank(sfzB)) { restResult.setCode(DriverLoginResultTypeEnum.SFZ_B_IS_BLANK.getCode()); restResult.setMsg(DriverLoginResultTypeEnum.SFZ_B_IS_BLANK.getMsg()); logger.error("{}", restResult); return restResult; } if (StringUtils.isBlank(jszA)) { restResult.setCode(DriverLoginResultTypeEnum.JSZ_A_IS_BLANK.getCode()); restResult.setMsg(DriverLoginResultTypeEnum.JSZ_A_IS_BLANK.getMsg()); logger.error("{}", restResult); return restResult; } if (StringUtils.isBlank(xszA)) { restResult.setCode(DriverLoginResultTypeEnum.XSZ_A_IS_BLANK.getCode()); restResult.setMsg(DriverLoginResultTypeEnum.XSZ_A_IS_BLANK.getMsg()); logger.error("{}", restResult); return restResult; } if (StringUtils.isBlank(licensePlate)) { restResult.setCode(DriverLoginResultTypeEnum.LICENSE_PLATE_IS_BLANK.getCode()); restResult.setMsg(DriverLoginResultTypeEnum.LICENSE_PLATE_IS_BLANK.getMsg()); logger.error("{}", restResult); return restResult; } Driver user = driverService.get(cell); if (null != user) { restResult.setCode(DriverLoginResultTypeEnum.CELL_IS_EXIST.getCode()); restResult.setMsg(DriverLoginResultTypeEnum.CELL_IS_EXIST.getMsg()); logger.error("{}{}", restResult, cell); return restResult; } if (StringUtils.isBlank(alias) || StringUtils.isBlank(captcha)) { resultWrapper(restResult, DriverLoginResultTypeEnum.CAPTCHA_IS_BLANK); // restResult.setCode(DriverLoginResultTypeEnum.CAPTCHA_IS_BLANK.getCode()); // restResult.setMsg(DriverLoginResultTypeEnum.CAPTCHA_IS_BLANK.getMsg()); logger.error("{}", restResult); return restResult; } final String redisToken = RedisUtils.get(alias); if (StringUtils.isBlank(redisToken)) { resultWrapper(restResult, DriverLoginResultTypeEnum.CAPTCHA_IS_EXPIRED); logger.error("{}", restResult); return restResult; } if (!StringUtils.equalsIgnoreCase(redisToken, captcha)) { resultWrapper(restResult, DriverLoginResultTypeEnum.CAPTCHA_IS_WRONG); logger.error("{}", restResult); return restResult; } logger.info("strEmail={}strPassword={}strDrivername={}", cell, password, name); Driver driverSignup = new Driver(); driverSignup.setCell(cell); driverSignup.setPassword(password); driverSignup.setName(name); driverSignup.setSfzA(sfzA); driverSignup.setSfzB(sfzB); driverSignup.setJszA(jszA); driverSignup.setXszA(xszA); driverSignup.setLicensePlate(licensePlate.toUpperCase()); logger.info("userSignup={}", driverSignup); Driver driverSaved = driverService.signup(driverSignup); Long sDriverId = driverSaved.getId(); if (sDriverId.longValue() > 0) { logger.info("??id={}", sDriverId); // UserSignupEmail signupEmail = new UserSignupEmail(); // try { // final String strTime = String.valueOf(Calendar.getInstance().getTime()); // final String strToken = DigestUtils.md5Hex(strTime + ":" + cell + ":" + name); // signupEmail.setToken(strToken); // signupEmail.setUserId(sUserId); // signupEmailService.insert(signupEmail); // } catch (Exception e) { // logger.error("??signupEmail={}={}", signupEmail, e); // } } else { logger.error("?{}{}", driverSignup, driverSaved); restResult.setCode(RestResultTypeEnum.ERROR.getCode()); restResult.setMsg(RestResultTypeEnum.ERROR.getMsg()); } return restResult; }
From source file:cherry.spring.common.foundation.impl.MessageStoreImpl.java
private long createMailLog(final String launcherId, final LocalDateTime launchedAt, final String messageName, final LocalDateTime scheduledAt, final String from, final String subject, final String body) { final QMailLog a = new QMailLog("a"); SqlInsertWithKeyCallback<Long> callback = new SqlInsertWithKeyCallback<Long>() { @Override/*w w w.ja v a 2 s .c o m*/ public Long doInSqlInsertWithKeyClause(SQLInsertClause insert) { insert.set(a.launchedBy, launcherId); insert.set(a.launchedAt, launchedAt); insert.set(a.mailStatus, FlagCode.FALSE.code()); insert.set(a.messageName, messageName); insert.set(a.scheduledAt, scheduledAt); insert.set(a.fromAddr, from); insert.set(a.subject, subject); insert.set(a.body, body); return insert.executeWithKey(Long.class); } }; Long id = queryDslJdbcOperations.insertWithKey(a, callback); checkState(id != null, "failed to create QMailLog: launchedBy={0}, launchedAt={1}, mailStatus={2}, messageName={3}, scheduledAt={4}, fromAddr={5}, subject={6}, body={7}", launcherId, launchedAt, FlagCode.FALSE.code(), messageName, scheduledAt, from, subject, body); return id.longValue(); }
From source file:gate.corpora.DocumentContentImpl.java
/** Contruction from URL and offsets. */ public DocumentContentImpl(URL u, String encoding, Long start, Long end) throws IOException { int readLength = 0; char[] readBuffer = new char[INTERNAL_BUFFER_SIZE]; BufferedReader uReader = null; InputStream uStream = null;/* www. j ava2 s .c om*/ StringBuffer buf = new StringBuffer(); long s = 0, e = Long.MAX_VALUE; if (start != null && end != null) { s = start.longValue(); e = end.longValue(); } try { URLConnection conn = u.openConnection(); uStream = conn.getInputStream(); if ("gzip".equals(conn.getContentEncoding())) { uStream = new GZIPInputStream(uStream); } if (encoding != null && !encoding.equalsIgnoreCase("")) { uReader = new BomStrippingInputStreamReader(uStream, encoding, INTERNAL_BUFFER_SIZE); } else { uReader = new BomStrippingInputStreamReader(uStream, INTERNAL_BUFFER_SIZE); } ; // 1. skip S characters uReader.skip(s); // 2. how many character shall I read? long toRead = e - s; // 3. read gtom source into buffer while (toRead > 0 && (readLength = uReader.read(readBuffer, 0, INTERNAL_BUFFER_SIZE)) != -1) { if (toRead < readLength) { //well, if toRead(long) is less than readLenght(int) //then there can be no overflow, so the cast is safe readLength = (int) toRead; } buf.append(readBuffer, 0, readLength); toRead -= readLength; } } finally { // 4.close reader IOUtils.closeQuietly(uReader); IOUtils.closeQuietly(uStream); } content = new String(buf); originalContent = content; }
From source file:com.dsf.dbxtract.cdc.journal.JournalExecutor.java
/** * Memorizes the last imported window_id from journal table * //www . jav a 2 s . co m * @param rows */ private void markLastLoaded(CuratorFramework client, List<Map<String, Object>> rows) { if (rows == null || rows.isEmpty()) return; Long lastWindowId = 0L; for (Map<String, Object> row : rows) { Number windowId = (Number) row.get("window_id"); if (windowId.longValue() > lastWindowId.longValue()) { lastWindowId = windowId.longValue(); } } String k = getPrefix() + "/lastWindowId"; String s = lastWindowId.toString(); try { if (client.checkExists().forPath(k) == null) client.create().withMode(CreateMode.PERSISTENT).forPath(k); client.setData().forPath(k, s.getBytes()); } catch (Exception e) { logger.error("failed to update last window_id", e); } }