List of usage examples for java.math BigInteger compareTo
public int compareTo(BigInteger val)
From source file:org.jasig.cas.web.support.ThrottledSubmissionByIpAddressHandlerInterceptorAdapter.java
public void postHandle(final HttpServletRequest request, final HttpServletResponse response, final Object handler, final ModelAndView modelAndView) throws Exception { if (!request.getMethod().equals("GET") || !"casLoginView".equals(modelAndView.getViewName())) { return;//from w w w . j av a 2 s. c o m } final String remoteAddr = request.getRemoteAddr(); // workaround for the IPv6 bug in the original adapter. See CAS-639 try { final String lastQuad = remoteAddr.substring(remoteAddr.lastIndexOf(".") + 1); final int intVersionOfLastQuad = Integer.parseInt(lastQuad); final Map<String, BigInteger> quadMap = this.restrictedIpAddressMaps[intVersionOfLastQuad - 1]; synchronized (quadMap) { final BigInteger original = quadMap.get(lastQuad); BigInteger integer = ONE; if (original != null) { integer = original.add(ONE); } quadMap.put(lastQuad, integer); if (integer.compareTo(this.failureThreshhold) == 1) { log.warn("Possible hacking attack from " + remoteAddr + ". More than " + this.failureThreshhold + " failed login attempts within " + this.failureTimeout + " seconds."); modelAndView.setViewName("casFailureAuthenticationThreshhold"); } } } catch (NumberFormatException e) { log.warn( "Skipping ip-address blocking. Possible reason: IPv6 Address not supported: " + e.getMessage()); } catch (Exception ex) { log.error(ex.getMessage()); } }
From source file:com.offbynull.peernetic.common.identification.Id.java
/** * Constructs a {@link Id} from {@link BigInteger}s. * @param data id value/*w ww . ja v a2 s . c o m*/ * @param limit limit value * @throws NullPointerException if any argument is {@code null} * @throws IllegalArgumentException if {@code data > limit}, or if either argument is {@code < 0} */ private Id(BigInteger data, BigInteger limit) { Validate.notNull(data); Validate.notNull(limit); Validate.isTrue(data.compareTo(limit) <= 0 && data.signum() >= 0 && limit.signum() >= 0); this.data = data; this.limit = limit; }
From source file:org.openspotlight.graph.internal.NodeAndLinkSupport.java
private static void fixTypeData(final StorageSession session, final Class<? extends Node> clazz, final StorageNode node) { final String numericTypeAsString = node.getPropertyValueAsString(session, NUMERIC_TYPE); final BigInteger numericTypeFromTargetNodeType = findNumericType(clazz); if (numericTypeAsString != null) { final BigInteger numericTypeAsBigInteger = new BigInteger(numericTypeAsString); if (numericTypeFromTargetNodeType.compareTo(numericTypeAsBigInteger) > 0) { setWeigthAndTypeOnNode(session, node, clazz, numericTypeFromTargetNodeType); }// ww w . j av a 2 s .co m } else { setWeigthAndTypeOnNode(session, node, clazz, numericTypeFromTargetNodeType); } }
From source file:org.geowebcache.diskquota.ConfigLoader.java
private void validateQuota(Quota quota) throws ConfigurationException { if (quota == null) { throw new IllegalArgumentException("No quota defined"); }/* w ww.j a v a2 s . c om*/ BigInteger limit = quota.getBytes(); if (limit.compareTo(BigInteger.ZERO) < 0) { throw new ConfigurationException("Limit shall be >= 0: " + limit + ". " + quota); } log.debug("Quota validated: " + quota); }
From source file:org.apache.streams.data.moreover.MoreoverResult.java
public BigInteger process() { try {/* w ww . j a va 2 s . co m*/ this.resultObject = xmlMapper.readValue(xmlString, ArticlesResponse.class); } catch (JsonMappingException e) { // theory is this may not be fatal this.resultObject = (ArticlesResponse) e.getPath().get(0).getFrom(); } catch (Exception e) { e.printStackTrace(); logger.warn("Unable to process document:"); logger.warn(xmlString); } if (this.resultObject.getStatus().equals("FAILURE")) { logger.warn(this.resultObject.getStatus()); logger.warn(this.resultObject.getMessageCode()); logger.warn(this.resultObject.getUserMessage()); logger.warn(this.resultObject.getDeveloperMessage()); } else { this.articles = resultObject.getArticles(); this.articleArray = articles.getArticle(); for (Article article : articleArray) { BigInteger sequenceid = new BigInteger(article.getSequenceId()); list.add(new StreamsDatum(article, sequenceid)); logger.trace("Prior max sequence Id {} current candidate {}", this.maxSequencedId, sequenceid); if (sequenceid.compareTo(this.maxSequencedId) > 0) { this.maxSequencedId = sequenceid; } } } return this.maxSequencedId; }
From source file:org.owasp.jbrofuzz.core.FuzzerBigInteger.java
/** * <p>Return the next element of the fuzzer during iteration.</p> * /* w w w .j av a 2 s . c o m*/ * <p>This method should be used to access fuzzing payloads, after * construction of the fuzzer object.</p> * * @return String The next fuzzer payload, during the iteration * process * * @author subere@uncon.org * @version 2.4 * @since 1.2 */ public String next() { final StringBuffer output = new StringBuffer(""); // Replacive Prototype if (maxValue.compareTo(BigInteger.valueOf(payloads.size())) == 0) { output.append(payloads.get(cValue.intValue())); cValue = cValue.add(BigInteger.ONE); } // Recursive Prototype else { BigInteger val = cValue; // Perform division on a stack final Stack<BigInteger> stack = new Stack<BigInteger>(); while (val.compareTo(BigInteger.valueOf(payloads.size())) >= 0) { stack.push(val.mod(BigInteger.valueOf(payloads.size()))); val = val.divide(BigInteger.valueOf(payloads.size())); } // Append the relevant empty positions with the first element // identified output.append(StringUtils.leftPad(payloads.get(val.intValue()), len - stack.size(), payloads.get(0))); while (!stack.isEmpty()) { output.append(payloads.get(stack.pop().intValue())); } cValue = cValue.add(BigInteger.ONE); } return output.toString(); }
From source file:org.openremote.controller.protocol.http.HttpGetCommand.java
private int resolveRangeMinimum(String min) { if (min == null || min.equals("")) { return Integer.MIN_VALUE; }/*from ww w . ja v a 2 s . co m*/ try { BigInteger minimum = new BigInteger(min); BigInteger integerMin = new BigInteger(Integer.toString(Integer.MIN_VALUE)); if (minimum.compareTo(integerMin) < 0) { return Integer.MIN_VALUE; } else { return minimum.intValue(); } } catch (NumberFormatException e) { // TODO : log return Integer.MIN_VALUE; } }
From source file:org.openremote.controller.protocol.http.HttpGetCommand.java
private int resolveRangeMaximum(String max) { if (max == null || max.equals("")) { return Integer.MAX_VALUE; }/*from w w w. ja v a 2s . c o m*/ try { BigInteger maximum = new BigInteger(max); BigInteger integerMax = new BigInteger(Integer.toString(Integer.MAX_VALUE)); if (maximum.compareTo(integerMax) > 0) { return Integer.MAX_VALUE; } else { return maximum.intValue(); } } catch (NumberFormatException e) { // TODO : log return Integer.MAX_VALUE; } }
From source file:de.jfachwert.math.Bruch.java
/** * Vergleicht den anderen Bruch mit dem aktuellen Bruch. * * @param other der andere Bruch, der verglichen wird. * @return negtive Zahl, falls this < other, 0 bei Gleichheit, ansonsten * positive Zahl./*ww w.j av a2 s .co m*/ */ @Override public int compareTo(Bruch other) { BigInteger thisZaehlerErweitert = this.zaehler.multiply(other.nenner); BigInteger otherZaehlerErweitert = other.zaehler.multiply(this.nenner); return thisZaehlerErweitert.compareTo(otherZaehlerErweitert); }