List of usage examples for java.lang Math ceil
public static double ceil(double a)
From source file:etymology.util.EtyMath.java
public static double lnGamma(double value) { if (value < 0) { throw new RuntimeException("Value for lnGamma must be > 0."); }/*ww w . jav a 2 s . com*/ if (value == 0) { return 0; } if (value == 1.0) { return 0; } if (value > 100000) { return avgLnGamma(value); } int arrayIndex = (int) Math.ceil((value * GAMMA_CACHE_DIVIDER)); if (logGammaValues.size() > arrayIndex) { return logGammaValues.get(arrayIndex); } int size = (logGammaValues.isEmpty()) ? 1 : logGammaValues.size(); double val = 0.0; for (int i = size; i <= arrayIndex; i++) { val = Gamma.logGamma((i / GAMMA_CACHE_DIVIDER)); logGammaValues.add(val); } return val; }
From source file:com.canyapan.randompasswordgenerator.PasswordMeter.java
/** * Meters strength of a given password./*from w w w . j a v a2 s . c o m*/ * * @param password A password to meter. * @return Strength in percent. */ public static Result check(final String password) throws PasswordMeterException { int score, uniqueCharacters, length, requirements = 0, alphaUC = 0, alphaLC = 0, number = 0, symbol = 0, midChar = 0, alphasOnly = 0, numbersOnly = 0, repChar = 0, consecutiveAlphaUC = 0, consecutiveAlphaLC = 0, consecutiveNumber = 0, consecutiveSymbol = 0, consecutiveCharType = 0, sequentialAlpha = 0, sequentialNumber = 0, sequentialSymbol = 0, sequentialChar = 0; double repInc = 0d; if (org.apache.commons.lang.StringUtils.isBlank(password)) { throw new PasswordMeterException("Password cannot be blank"); } final String alphas = "abcdefghijklmnopqrstuvwxyz"; final String numerics = "01234567890"; final String symbols = ")!@#$%^&*()"; length = password.length(); String[] arrPwd = password.replaceAll("\\s+", "").split("\\s*"); int arrPwdLen = arrPwd.length; int tmpAlphaUC = -1, tmpAlphaLC = -1, tmpNumber = -1, tmpSymbol = -1; /* Loop through password to check for Symbol, Numeric, Lowercase and Uppercase pattern matches */ for (int a = 0; a < arrPwdLen; a++) { if (arrPwd[a].matches("[A-Z]")) { if (tmpAlphaUC != -1 && (tmpAlphaUC + 1) == a) { consecutiveAlphaUC++; consecutiveCharType++; } tmpAlphaUC = a; alphaUC++; } else if (arrPwd[a].matches("[a-z]")) { if (tmpAlphaLC != -1 && (tmpAlphaLC + 1) == a) { consecutiveAlphaLC++; consecutiveCharType++; } tmpAlphaLC = a; alphaLC++; } else if (arrPwd[a].matches("[0-9]")) { if (a > 0 && a < (arrPwdLen - 1)) { midChar++; } if (tmpNumber != -1 && (tmpNumber + 1) == a) { consecutiveNumber++; consecutiveCharType++; } tmpNumber = a; number++; } else if (arrPwd[a].matches("[^a-zA-Z0-9_]")) { if (a > 0 && a < (arrPwdLen - 1)) { midChar++; } if (tmpSymbol != -1 && (tmpSymbol + 1) == a) { consecutiveSymbol++; consecutiveCharType++; } tmpSymbol = a; symbol++; } /* Internal loop through password to check for repeat characters */ boolean charExists = false; for (int b = 0; b < arrPwdLen; b++) { if (arrPwd[a].equals(arrPwd[b]) && a != b) { /* repeat character exists */ charExists = true; /* Calculate increment deduction based on proximity to identical characters Deduction is incremented each time a new match is discovered Deduction amount is based on total password length divided by the difference of distance between currently selected match */ repInc += Math.abs(arrPwdLen / (b - a)); } } if (charExists) { repChar++; uniqueCharacters = arrPwdLen - repChar; repInc = uniqueCharacters > 0 ? Math.ceil(repInc / uniqueCharacters) : Math.ceil(repInc); } } /* Check for sequential alpha string patterns (forward and reverse) */ for (int s = 0; s < 23; s++) { String fwd = alphas.substring(s, s + 3); String rev = new StringBuilder(fwd).reverse().toString(); if (password.toLowerCase().contains(fwd) || password.toLowerCase().contains(rev)) { sequentialAlpha++; sequentialChar++; } } /* Check for sequential numeric string patterns (forward and reverse) */ for (int s = 0; s < 8; s++) { String fwd = numerics.substring(s, s + 3); String rev = new StringBuilder(fwd).reverse().toString(); if (password.toLowerCase().contains(fwd) || password.toLowerCase().contains(rev)) { sequentialNumber++; sequentialChar++; } } /* Check for sequential symbol string patterns (forward and reverse) */ for (int s = 0; s < 8; s++) { String fwd = symbols.substring(s, s + 3); String rev = new StringBuilder(fwd).reverse().toString(); if (password.toLowerCase().contains(fwd) || password.toLowerCase().contains(rev)) { sequentialSymbol++; sequentialChar++; } } final int multiplierMidChar = 2, multiplierConsecutiveAlphaUC = 2, multiplierConsecutiveAlphaLC = 2, multiplierConsecutiveNumber = 2, multiplierSequentialAlpha = 3, multiplierSequentialNumber = 3, multiplierSequentialSymbol = 3, multiplierLength = 4, multiplierNumber = 4, multiplierSymbol = 6; score = length * multiplierLength; /* Modify overall score value based on usage vs requirements */ /* General point assignment */ if (alphaUC > 0 && alphaUC < length) { score += (length - alphaUC) * 2; } if (alphaLC > 0 && alphaLC < length) { score += (length - alphaLC) * 2; } if (number > 0 && number < length) { score += number * multiplierNumber; } if (symbol > 0) { score += symbol * multiplierSymbol; } if (midChar > 0) { score += midChar * multiplierMidChar; } /* Point deductions for poor practices */ if ((alphaLC > 0 || alphaUC > 0) && symbol == 0 && number == 0) { // Only Letters score -= length; alphasOnly = length; } if (alphaLC == 0 && alphaUC == 0 && symbol == 0 && number > 0) { // Only Numbers score -= length; numbersOnly = length; } if (repChar > 0) { // Same character exists more than once score -= repInc; } if (consecutiveAlphaUC > 0) { // Consecutive Uppercase Letters exist score -= consecutiveAlphaUC * multiplierConsecutiveAlphaUC; } if (consecutiveAlphaLC > 0) { // Consecutive Lowercase Letters exist score -= consecutiveAlphaLC * multiplierConsecutiveAlphaLC; } if (consecutiveNumber > 0) { // Consecutive Numbers exist score -= consecutiveNumber * multiplierConsecutiveNumber; } if (sequentialAlpha > 0) { // Sequential alpha strings exist (3 characters or more) score -= sequentialAlpha * multiplierSequentialAlpha; } if (sequentialNumber > 0) { // Sequential numeric strings exist (3 characters or more) score -= sequentialNumber * multiplierSequentialNumber; } if (sequentialSymbol > 0) { // Sequential symbol strings exist (3 characters or more) score -= sequentialSymbol * multiplierSequentialSymbol; } /* Determine if mandatory requirements have been met and set image indicators accordingly */ int minPwdLen = 8; if (length == minPwdLen) { requirements++; } else if (length > minPwdLen) { requirements++; } if (alphaUC == 1) { requirements++; } else if (alphaUC > 1) { requirements++; } if (alphaLC >= 1) { requirements++; } if (number >= 1) { requirements++; } if (symbol >= 1) { requirements++; } int minimumRequirementsChars = password.length() >= minPwdLen ? 3 : 4; if (requirements > minimumRequirementsChars) { // One or more required characters exist score += requirements * 2; } /* Determine complexity based on overall score */ if (score > 100) { score = 100; } else if (score < 0) { score = 0; } return new Result(score); }
From source file:gdsc.smlm.ij.results.IJImagePeakResults.java
private int ceil(float f) { return (int) Math.ceil(f); }
From source file:com.sixrr.metrics.ui.charts.DiffHistogramDialog.java
private static boolean isIntegral(double v) { if (Math.abs(Math.ceil(v) - v) < EPSILON) { return true; }//from w ww . ja v a 2 s .c om return Math.abs(v - Math.floor(v)) < EPSILON; }
From source file:signalviewer.SignalViewer.java
/** * Array with values in an interval and step size * * @param start of the interval/* w w w.j a v a2s.c o m*/ * @param end of the interval * @param step size between the values * @return int array with size (start - end) / step */ public static int[] range(int start, int end, int step) { int size = (int) Math.ceil(((double) (end - start)) / step); if (size < 1) { return new int[0]; } int[] arr = new int[size]; int index = 0; for (int i = start; i < end; i += step) { arr[index] = i; index++; } return arr; }
From source file:com.esd.ps.RegListController.java
/** * ?/* w w w . j a va2 s .com*/ * * @param session * @param page * @param beginDateate * @param endDateate * @return */ @RequestMapping(value = "/regList", method = RequestMethod.POST) @ResponseBody public Map<String, Object> regListPost(HttpSession session, int page, String beginDate, String endDate) { logger.debug("beginDateate:{},endDateate:{}", beginDate, endDate); Map<String, Object> map = new HashMap<String, Object>(); int districtId = Integer.parseInt(session.getAttribute(Constants.ID).toString()); List<RegistrationTrans> list = new ArrayList<RegistrationTrans>(); if (endDate.trim().length() > 0 || !endDate.isEmpty()) { try { SimpleDateFormat sdf1 = new SimpleDateFormat(Constants.DATE_FORMAT); SimpleDateFormat formatter = new SimpleDateFormat(Constants.DATE_FORMAT_HAVE_LINE); Date myDate = formatter.parse(endDate); Calendar c = Calendar.getInstance(); c.setTime(myDate); c.add(Calendar.DATE, 1); myDate = c.getTime(); endDate = sdf1.format(myDate); } catch (ParseException e) { e.printStackTrace(); } } int totle = registrationService.getCountByTimeAndDistrictId(districtId, beginDate, endDate); if (totle == 0) { map.clear(); map.put(Constants.TOTLE, totle); map.put(Constants.TOTLE_PAGE, Math.ceil((double) totle / (double) Constants.ROW)); map.put(Constants.LIST, list); return map; } List<Registration> regList = registrationService.getByTimeAndDistrictId(districtId, beginDate, endDate, page, Constants.ROW); SimpleDateFormat sdf = new SimpleDateFormat(Constants.DATETIME_FORMAT); for (Iterator<Registration> iterator = regList.iterator(); iterator.hasNext();) { Registration registration = (Registration) iterator.next(); RegistrationTrans rt = new RegistrationTrans(); rt.setAddress(registration.getAddress()); rt.setCard(registration.getCard()); rt.setCreateTime(sdf.format(registration.getCreateTime())); rt.setDes(registration.getDes()); rt.setName(registration.getName()); rt.setPhone(registration.getPhone()); rt.setQq(registration.getQq()); list.add(rt); } map.clear(); map.put(Constants.TOTLE, totle); map.put(Constants.TOTLE_PAGE, Math.ceil((double) totle / (double) Constants.ROW)); map.put(Constants.LIST, list); return map; }
From source file:bide.hpd.TraceDistribution.java
public static double statQuantile(double q, double[] x, int[] indices) { if (q < 0.0 || q > 1.0) throw new IllegalArgumentException("Quantile out of range"); if (q == 0.0) { // for q==0 we have to "invent" an entry smaller than the smallest x return x[indices[0]] - 1.0; }/*from w w w. j av a 2 s . co m*/ return x[indices[(int) Math.ceil(q * indices.length) - 1]]; }
From source file:com.sketchy.utils.image.SketchyImage.java
public int getHeightInMillimeters() { return (int) Math.ceil(image.getHeight() / getDotsPerMillimeterHeight()); }
From source file:ldbc.snb.datagen.generator.CommentGenerator.java
public long createComments(RandomGeneratorFarm randomFarm, final Forum forum, final Post post, long numComments, long startId, PersonActivityExporter exporter) throws IOException { long nextId = startId; ArrayList<Message> replyCandidates = new ArrayList<Message>(); replyCandidates.add(post);//w ww . jav a2 s . c o m Properties prop = new Properties(); prop.setProperty("type", "comment"); for (int i = 0; i < numComments; ++i) { int replyIndex = randomFarm.get(RandomGeneratorFarm.Aspect.REPLY_TO).nextInt(replyCandidates.size()); Message replyTo = replyCandidates.get(replyIndex); ArrayList<ForumMembership> validMemberships = new ArrayList<ForumMembership>(); for (ForumMembership fM : forum.memberships()) { if (fM.creationDate() + DatagenParams.deltaTime <= replyTo.creationDate()) { validMemberships.add(fM); } } if (validMemberships.size() == 0) { return nextId; } ForumMembership member = validMemberships.get( randomFarm.get(RandomGeneratorFarm.Aspect.MEMBERSHIP_INDEX).nextInt(validMemberships.size())); TreeSet<Integer> tags = new TreeSet<Integer>(); String content = ""; String gif = ""; boolean isShort = false; if (randomFarm.get(RandomGeneratorFarm.Aspect.REDUCED_TEXT).nextDouble() > 0.6666) { ArrayList<Integer> currentTags = new ArrayList<Integer>(); Iterator<Integer> it = replyTo.tags().iterator(); while (it.hasNext()) { Integer tag = it.next(); if (randomFarm.get(RandomGeneratorFarm.Aspect.TAG).nextDouble() > 0.5) { tags.add(tag); } currentTags.add(tag); } for (int j = 0; j < (int) Math.ceil(replyTo.tags().size() / 2.0); ++j) { int randomTag = currentTags .get(randomFarm.get(RandomGeneratorFarm.Aspect.TAG).nextInt(currentTags.size())); tags.add(Dictionaries.tagMatrix .getRandomRelated(randomFarm.get(RandomGeneratorFarm.Aspect.TOPIC), randomTag)); } content = this.generator.generateText(member.person(), tags, prop); } else { isShort = true; if (!richRdf || randomFarm.get(RandomGeneratorFarm.Aspect.COMMENT_ISGIF).nextDouble() > 0.8) { int index = randomFarm.get(RandomGeneratorFarm.Aspect.TEXT_SIZE).nextInt(shortComments_.length); content = shortComments_[index]; } else { int index = randomFarm.get(RandomGeneratorFarm.Aspect.COMMENT_GIF).nextInt(gifs_.length); gif = gifs_[index]; } } long creationDate = Dictionaries.dates.powerlawCommDateDay( randomFarm.get(RandomGeneratorFarm.Aspect.DATE), replyTo.creationDate() + DatagenParams.deltaTime); /*if( creationDate <= Dictionaries.dates.getEndDateTime() )*/ { Comment comment = new Comment(SN.formId(SN.composeId(nextId++, creationDate)), creationDate, member.person(), forum.id(), content, tags, Dictionaries.ips.getIP(randomFarm.get(RandomGeneratorFarm.Aspect.IP), randomFarm.get(RandomGeneratorFarm.Aspect.DIFF_IP), randomFarm.get(RandomGeneratorFarm.Aspect.DIFF_IP_FOR_TRAVELER), member.person().ipAddress(), creationDate), Dictionaries.browsers.getPostBrowserId( randomFarm.get(RandomGeneratorFarm.Aspect.DIFF_BROWSER), randomFarm.get(RandomGeneratorFarm.Aspect.BROWSER), member.person().browserId()), post.messageId(), replyTo.messageId(), gif); if (richRdf) { comment.richRdf(true); if (randomFarm.get(RandomGeneratorFarm.Aspect.COMMENT_MENTIONED).nextDouble() > 0.6) { TreeSet<Long> t = new TreeSet<Long>(); // The user mentions one or more (up to 4) members of the forum t.add(validMemberships .get(randomFarm.get(RandomGeneratorFarm.Aspect.MEMBERSHIP_INDEX_COMMENT_MENTIONED) .nextInt(validMemberships.size())) .person().accountId()); double probabilityForNumberOfMentions = randomFarm .get(RandomGeneratorFarm.Aspect.COMMENT_MENTIONED_NUM).nextDouble(); if (probabilityForNumberOfMentions > 0.5) t.add(validMemberships.get( randomFarm.get(RandomGeneratorFarm.Aspect.MEMBERSHIP_INDEX_COMMENT_MENTIONED) .nextInt(validMemberships.size())) .person().accountId()); if (probabilityForNumberOfMentions > 0.75) t.add(validMemberships.get( randomFarm.get(RandomGeneratorFarm.Aspect.MEMBERSHIP_INDEX_COMMENT_MENTIONED) .nextInt(validMemberships.size())) .person().accountId()); if (probabilityForNumberOfMentions > 0.95) t.add(validMemberships.get( randomFarm.get(RandomGeneratorFarm.Aspect.MEMBERSHIP_INDEX_COMMENT_MENTIONED) .nextInt(validMemberships.size())) .person().accountId()); comment.mentioned(t); } if (randomFarm.get(RandomGeneratorFarm.Aspect.COMMENT_VISIBILITY).nextDouble() > 0.95) { if (comment.mentioned() == null || randomFarm .get(RandomGeneratorFarm.Aspect.COMMENT_VISIBILITY_TF).nextDouble() > 0.5) comment.setPublic(true); else comment.setPublic(false); } if (randomFarm.get(RandomGeneratorFarm.Aspect.COMMENT_LINK).nextDouble() > 0.57) { comment.link("http://ld.bc/" + RandomStringUtils.random(6, true, false)); } } if (richRdf && randomFarm.get(RandomGeneratorFarm.Aspect.COMMENT_COUNTRY).nextDouble() > 0.02) comment.countryKnown(false); if (!isShort) replyCandidates.add(new Comment(comment)); exporter.export(comment); if (comment.content().length() > 10 && randomFarm.get(RandomGeneratorFarm.Aspect.NUM_LIKE).nextDouble() <= 0.1) { likeGenerator_.generateLikes(randomFarm.get(RandomGeneratorFarm.Aspect.NUM_LIKE), forum, comment, Like.LikeType.COMMENT, exporter); } } } replyCandidates.clear(); return nextId; }
From source file:com.app.inventario.logica.ProveedorLogicaImpl.java
@Transactional(readOnly = true) public String obtenerListaTodosXML(int numeroPagina, int numeroFilas, String ordenarPor, String ordenarAsc) throws Exception { XStream xstream = new XStream(); xstream.alias("root", jqGridModel.class); xstream.alias("proveedor", Proveedor.class); modelo = new jqGridModel<Proveedor>(); int primerResultado = numeroFilas * (numeroPagina - 1); List<Proveedor> proveedores = null; try {/*from w w w. java 2s. c o m*/ proveedores = proveedorDAO.obtenerTodosAGrid(ordenarPor, ordenarAsc); modelo.setPage(numeroPagina); modelo.setTotal((int) Math.ceil((double) proveedores.size() / (double) numeroFilas)); modelo.setRecords(proveedores.size()); modelo.setRows(proveedores.subList(primerResultado, numeroFilas > proveedores.size() ? proveedores.size() : numeroFilas)); return xstream.toXML(modelo); } catch (HibernateException he) { Logger.getLogger(ProveedorLogicaImpl.class.getName()).log(Level.SEVERE, null, he); throw he; } //return map; }