/** * <p>Multiplies the value of this fraction by another, returning the * result in reduced form.</p> * * @param fraction the fraction to multiply by, must not be {@code null} * @return a {@code Fraction} instance with the resulting values * @throws NullArgumentException if the fraction is {@code null} * @throws MathArithmeticException if the resulting numerator or denominator exceeds * {@code Integer.MAX_VALUE} */ public Fraction multiply(Fraction fraction) { if (fraction == null) { throw new NullArgumentException(LocalizedFormats.FRACTION); } if (numerator == 0 || fraction.numerator == 0) { return ZERO; } // knuth 4.5.1 // make sure we don't overflow unless the result *must* overflow. int d1 = ArithmeticUtils.gcd(numerator, fraction.denominator); int d2 = ArithmeticUtils.gcd(fraction.numerator, denominator); return getReducedFraction (ArithmeticUtils.mulAndCheck(numerator/d1, fraction.numerator/d2), ArithmeticUtils.mulAndCheck(denominator/d2, fraction.denominator/d1)); }
final int d = ArithmeticUtils.gcd(num, den); if (d > 1) { num /= d;
private synchronized void configureSinks() { sinkConfigs = config.getInstanceConfigs(SINK_KEY); long confPeriodMillis = 0; for (Entry<String, MetricsConfig> entry : sinkConfigs.entrySet()) { MetricsConfig conf = entry.getValue(); int sinkPeriod = conf.getInt(PERIOD_KEY, PERIOD_DEFAULT); // Support configuring periodMillis for testing. long sinkPeriodMillis = conf.getLong(PERIOD_MILLIS_KEY, sinkPeriod * 1000); confPeriodMillis = confPeriodMillis == 0 ? sinkPeriodMillis : ArithmeticUtils.gcd(confPeriodMillis, sinkPeriodMillis); String clsName = conf.getClassName(""); if (clsName == null) continue; // sink can be registered later on String sinkName = entry.getKey(); try { MetricsSinkAdapter sa = newSink(sinkName, conf.getString(DESC_KEY, sinkName), conf); sa.start(); sinks.put(sinkName, sa); } catch (Exception e) { LOG.warn("Error creating sink '"+ sinkName +"'", e); } } long periodSec = config.getInt(PERIOD_KEY, PERIOD_DEFAULT); period = confPeriodMillis > 0 ? confPeriodMillis : config.getLong(PERIOD_MILLIS_KEY, periodSec * 1000); }
return 0; long lcm = FastMath.abs(ArithmeticUtils.mulAndCheck(a / gcd(a, b), b)); if (lcm == Long.MIN_VALUE){ throw new MathArithmeticException(LocalizedFormats.LCM_OVERFLOW_64_BITS,
return 0; int lcm = FastMath.abs(ArithmeticUtils.mulAndCheck(a / gcd(a, b), b)); if (lcm == Integer.MIN_VALUE) { throw new MathArithmeticException(LocalizedFormats.LCM_OVERFLOW_32_BITS,
int gcd = ArithmeticUtils.gcd(numerator, denominator); numerator /= gcd; denominator /= gcd;
protected SlidingWindowAssigner(long size, long slide, long offset, boolean isEventTime) { if (offset < 0 || offset >= slide || size <= 0) { throw new IllegalArgumentException( "SlidingWindowAssigner parameters must satisfy 0 <= offset < slide and size > 0"); } this.size = size; this.slide = slide; this.offset = offset; this.isEventTime = isEventTime; this.paneSize = ArithmeticUtils.gcd(size, slide); this.numPanesPerWindow = MathUtils.checkedDownCast(size / paneSize); }
final long paneSlide = ArithmeticUtils.gcd(windowLength, windowSlide); if (paneSlide < MIN_SLIDE_TIME) { throw new IllegalArgumentException(String.format(
return 0; long lcm = Math.abs(ArithmeticUtils.mulAndCheck(a / gcd(a, b), b)); if (lcm == Long.MIN_VALUE){ throw new MathArithmeticException(LocalizedFormats.LCM_OVERFLOW_64_BITS,
return 0; int lcm = Math.abs(ArithmeticUtils.mulAndCheck(a / gcd(a, b), b)); if (lcm == Integer.MIN_VALUE) { throw new MathArithmeticException(LocalizedFormats.LCM_OVERFLOW_32_BITS,
/** * <p>Multiplies the value of this fraction by another, returning the * result in reduced form.</p> * * @param fraction the fraction to multiply by, must not be {@code null} * @return a {@code Fraction} instance with the resulting values * @throws NullArgumentException if the fraction is {@code null} * @throws MathArithmeticException if the resulting numerator or denominator exceeds * {@code Integer.MAX_VALUE} */ public Fraction multiply(Fraction fraction) { if (fraction == null) { throw new NullArgumentException(LocalizedFormats.FRACTION); } if (numerator == 0 || fraction.numerator == 0) { return ZERO; } // knuth 4.5.1 // make sure we don't overflow unless the result *must* overflow. int d1 = ArithmeticUtils.gcd(numerator, fraction.denominator); int d2 = ArithmeticUtils.gcd(fraction.numerator, denominator); return getReducedFraction (ArithmeticUtils.mulAndCheck(numerator/d1, fraction.numerator/d2), ArithmeticUtils.mulAndCheck(denominator/d2, fraction.denominator/d1)); }
/** * <p>Multiplies the value of this fraction by another, returning the * result in reduced form.</p> * * @param fraction the fraction to multiply by, must not be {@code null} * @return a {@code Fraction} instance with the resulting values * @throws NullArgumentException if the fraction is {@code null} * @throws MathArithmeticException if the resulting numerator or denominator exceeds * {@code Integer.MAX_VALUE} */ public Fraction multiply(Fraction fraction) { if (fraction == null) { throw new NullArgumentException(LocalizedFormats.FRACTION); } if (numerator == 0 || fraction.numerator == 0) { return ZERO; } // knuth 4.5.1 // make sure we don't overflow unless the result *must* overflow. int d1 = ArithmeticUtils.gcd(numerator, fraction.denominator); int d2 = ArithmeticUtils.gcd(fraction.numerator, denominator); return getReducedFraction (ArithmeticUtils.mulAndCheck(numerator/d1, fraction.numerator/d2), ArithmeticUtils.mulAndCheck(denominator/d2, fraction.denominator/d1)); }
final int d = ArithmeticUtils.gcd(num, den); if (d > 1) { num /= d;
private synchronized void configureSinks() { sinkConfigs = config.getInstanceConfigs(SINK_KEY); int confPeriod = 0; for (Entry<String, MetricsConfig> entry : sinkConfigs.entrySet()) { MetricsConfig conf = entry.getValue(); int sinkPeriod = conf.getInt(PERIOD_KEY, PERIOD_DEFAULT); confPeriod = confPeriod == 0 ? sinkPeriod : ArithmeticUtils.gcd(confPeriod, sinkPeriod); String clsName = conf.getClassName(""); if (clsName == null) continue; // sink can be registered later on String sinkName = entry.getKey(); try { MetricsSinkAdapter sa = newSink(sinkName, conf.getString(DESC_KEY, sinkName), conf); sa.start(); sinks.put(sinkName, sa); } catch (Exception e) { LOG.warn("Error creating sink '"+ sinkName +"'", e); } } period = confPeriod > 0 ? confPeriod : config.getInt(PERIOD_KEY, PERIOD_DEFAULT); }
private synchronized void configureSinks() { sinkConfigs = config.getInstanceConfigs(SINK_KEY); int confPeriod = 0; for (Entry<String, MetricsConfig> entry : sinkConfigs.entrySet()) { MetricsConfig conf = entry.getValue(); int sinkPeriod = conf.getInt(PERIOD_KEY, PERIOD_DEFAULT); confPeriod = confPeriod == 0 ? sinkPeriod : ArithmeticUtils.gcd(confPeriod, sinkPeriod); String clsName = conf.getClassName(""); if (clsName == null) continue; // sink can be registered later on String sinkName = entry.getKey(); try { MetricsSinkAdapter sa = newSink(sinkName, conf.getString(DESC_KEY, sinkName), conf); sa.start(); sinks.put(sinkName, sa); } catch (Exception e) { LOG.warn("Error creating sink '"+ sinkName +"'", e); } } period = confPeriod > 0 ? confPeriod : config.getInt(PERIOD_KEY, PERIOD_DEFAULT); }
private long getPaneSize() { Preconditions.checkArgument( legacyWindowOperatorType == LegacyWindowOperatorType.FAST_ACCUMULATING || legacyWindowOperatorType == LegacyWindowOperatorType.FAST_AGGREGATING); final long paneSlide; if (windowAssigner instanceof SlidingProcessingTimeWindows) { SlidingProcessingTimeWindows timeWindows = (SlidingProcessingTimeWindows) windowAssigner; paneSlide = ArithmeticUtils.gcd(timeWindows.getSize(), timeWindows.getSlide()); } else { TumblingProcessingTimeWindows timeWindows = (TumblingProcessingTimeWindows) windowAssigner; paneSlide = timeWindows.getSize(); // this is valid as windowLength == windowSlide == timeWindows.getSize } return paneSlide; }
return 0; long lcm = FastMath.abs(ArithmeticUtils.mulAndCheck(a / gcd(a, b), b)); if (lcm == Long.MIN_VALUE){ throw new MathArithmeticException(LocalizedFormats.LCM_OVERFLOW_64_BITS,
private synchronized void configureSinks() { sinkConfigs = config.getInstanceConfigs(SINK_KEY); long confPeriodMillis = 0; for (Entry<String, MetricsConfig> entry : sinkConfigs.entrySet()) { MetricsConfig conf = entry.getValue(); int sinkPeriod = conf.getInt(PERIOD_KEY, PERIOD_DEFAULT); // Support configuring periodMillis for testing. long sinkPeriodMillis = conf.getLong(PERIOD_MILLIS_KEY, sinkPeriod * 1000); confPeriodMillis = confPeriodMillis == 0 ? sinkPeriodMillis : ArithmeticUtils.gcd(confPeriodMillis, sinkPeriodMillis); String clsName = conf.getClassName(""); if (clsName == null) continue; // sink can be registered later on String sinkName = entry.getKey(); try { MetricsSinkAdapter sa = newSink(sinkName, conf.getString(DESC_KEY, sinkName), conf); sa.start(); sinks.put(sinkName, sa); } catch (Exception e) { LOG.warn("Error creating sink '"+ sinkName +"'", e); } } long periodSec = config.getInt(PERIOD_KEY, PERIOD_DEFAULT); period = confPeriodMillis > 0 ? confPeriodMillis : config.getLong(PERIOD_MILLIS_KEY, periodSec * 1000); }