id
int64
1
889
project_id
stringclasses
17 values
bug_id
stringclasses
163 values
class_file
stringlengths
28
111
method
stringlengths
3
47
source
stringlengths
66
21.2k
target
stringlengths
25
29k
801
Math
81
src/main/java/org/apache/commons/math/linear/EigenDecompositionImpl.java
computeShiftIncrement
public class EigenDecompositionImpl implements EigenDecomposition { private static final double TOLERANCE = 100 * MathUtils.EPSILON; private static final double TOLERANCE_2 = TOLERANCE * TOLERANCE; private double splitTolerance; private double[] main; private double[] secondary; private double[...
final double cnst1 = 0.563; final double cnst2 = 1.010; final double cnst3 = 1.05; // a negative dMin forces the shift to take that absolute value // tType records the type of shift. if (dMin <= 0.0) { tau = -dMin; tType = -1; return; ...
802
Math
81
src/main/java/org/apache/commons/math/linear/EigenDecompositionImpl.java
processGeneralBlock
public class EigenDecompositionImpl implements EigenDecomposition { private static final double TOLERANCE = 100 * MathUtils.EPSILON; private static final double TOLERANCE_2 = TOLERANCE * TOLERANCE; private double splitTolerance; private double[] main; private double[] secondary; private double[...
// check decomposed matrix data range double sumOffDiag = 0; for (int i = 0; i < n - 1; ++i) { final int fourI = 4 * i; final double ei = work[fourI + 2]; sumOffDiag += ei; } if (sumOffDiag == 0) { // matrix is already diagonal ...
803
Math
82
src/main/java/org/apache/commons/math/optimization/linear/SimplexSolver.java
getPivotRow
public class SimplexSolver extends AbstractLinearOptimizer { private static final double DEFAULT_EPSILON = 1.0e-6; protected final double epsilon; private Integer getPivotRow(final int col, final SimplexTableau tableau) {
double minRatio = Double.MAX_VALUE; Integer minRatioPos = null; for (int i = tableau.getNumObjectiveFunctions(); i < tableau.getHeight(); i++) { final double rhs = tableau.getEntry(i, tableau.getWidth() - 1); final double entry = tableau.getEntry(i, col); if (...
804
Math
84
src/main/java/org/apache/commons/math/optimization/direct/MultiDirectional.java
iterateSimplex
public class MultiDirectional extends DirectSearchOptimizer { private final double khi; private final double gamma; @Override protected void iterateSimplex(final Comparator<RealPointValuePair> comparator) throws FunctionEvaluationException, OptimizationException, IllegalArgumentException {
final RealConvergenceChecker checker = getConvergenceChecker(); while (true) { incrementIterationsCounter(); // save the original vertex final RealPointValuePair[] original = simplex; final RealPointValuePair best = original[0]; // perform a...
805
Math
85
src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java
bracket
public class UnivariateRealSolverUtils { public static double[] bracket(UnivariateRealFunction function, double initial, double lowerBound, double upperBound, int maximumIterations) throws ConvergenceException, FunctionEvaluationException {
if (function == null) { throw MathRuntimeException.createIllegalArgumentException("function is null"); } if (maximumIterations <= 0) { throw MathRuntimeException.createIllegalArgumentException( "bad value for maximum iterations number: {0}", ma...
806
Math
89
src/java/org/apache/commons/math/stat/Frequency.java
addValue
public class Frequency implements Serializable { private static final long serialVersionUID = -3845586908418844111L; private final TreeMap freqTable; @Deprecated public void addValue(Object v) {
if (v instanceof Comparable<?>){ addValue((Comparable<?>) v); } else { throw new IllegalArgumentException("Object must implement Comparable"); } } }
807
Math
90
src/java/org/apache/commons/math/stat/Frequency.java
addValue
public class Frequency implements Serializable { private static final long serialVersionUID = -3845586908418844111L; private final TreeMap freqTable; @Deprecated public void addValue(Object v); public void addValue(Comparable<?>v) {
Object obj = v; if (v instanceof Integer) { obj = Long.valueOf(((Integer) v).longValue()); } try { Long count = (Long) freqTable.get(obj); if (count == null) { freqTable.put(obj, Long.valueOf(1)); } else { fre...
808
Math
90
src/java/org/apache/commons/math/stat/Frequency.java
addValue
public class Frequency implements Serializable { private static final long serialVersionUID = -3845586908418844111L; private final TreeMap freqTable; public void addValue(Comparable<?>v); @Deprecated public void addValue(Object v) {
addValue((Comparable<?>) v); } }
809
Math
91
src/java/org/apache/commons/math/fraction/Fraction.java
compareTo
public class Fraction extends Number implements Comparable<Fraction> { public static final Fraction TWO = new Fraction(2, 1); public static final Fraction ONE = new Fraction(1, 1); public static final Fraction ZERO = new Fraction(0, 1); public static final Fraction MINUS_ONE = new Fraction(-1, 1); ...
long nOd = ((long) numerator) * object.denominator; long dOn = ((long) denominator) * object.numerator; return (nOd < dOn) ? -1 : ((nOd > dOn) ? +1 : 0); } }
810
Math
92
src/java/org/apache/commons/math/util/MathUtils.java
binomialCoefficient
public class MathUtils { public static final double EPSILON = 0x1.0p-53; public static final double SAFE_MIN = 0x1.0p-1022; private static final byte NB = (byte)-1; private static final short NS = (short)-1; private static final byte PB = (byte)1; private static final short PS = (short)1; ...
if (n < k) { throw new IllegalArgumentException( "must have n >= k for binomial coefficient (n,k)"); } if (n < 0) { throw new IllegalArgumentException( "must have n >= 0 for binomial coefficient (n,k)"); } if ((n == k) || (k...
811
Math
92
src/java/org/apache/commons/math/util/MathUtils.java
binomialCoefficientDouble
public class MathUtils { public static final double EPSILON = 0x1.0p-53; public static final double SAFE_MIN = 0x1.0p-1022; private static final byte NB = (byte)-1; private static final short NS = (short)-1; private static final byte PB = (byte)1; private static final short PS = (short)1; ...
if (n < k) { throw new IllegalArgumentException( "must have n >= k for binomial coefficient (n,k)"); } if (n < 0) { throw new IllegalArgumentException( "must have n >= 0 for binomial coefficient (n,k)"); } if ((n == k) || (k...
812
Math
92
src/java/org/apache/commons/math/util/MathUtils.java
binomialCoefficientLog
public class MathUtils { public static final double EPSILON = 0x1.0p-53; public static final double SAFE_MIN = 0x1.0p-1022; private static final byte NB = (byte)-1; private static final short NS = (short)-1; private static final byte PB = (byte)1; private static final short PS = (short)1; ...
if (n < k) { throw new IllegalArgumentException( "must have n >= k for binomial coefficient (n,k)"); } if (n < 0) { throw new IllegalArgumentException( "must have n >= 0 for binomial coefficient (n,k)"); } if ((n == k) || (k...
813
Math
93
src/java/org/apache/commons/math/util/MathUtils.java
factorial
public class MathUtils { public static final double EPSILON = 0x1.0p-53; public static final double SAFE_MIN = 0x1.0p-1022; private static final byte NB = (byte)-1; private static final short NS = (short)-1; private static final byte PB = (byte)1; private static final short PS = (short)1; ...
if (n < 0) { throw new IllegalArgumentException("must have n >= 0 for n!"); } if (n > 20) { throw new ArithmeticException( "factorial value is too large to fit in a long"); } return factorials[n]; } }
814
Math
93
src/java/org/apache/commons/math/util/MathUtils.java
factorialDouble
public class MathUtils { public static final double EPSILON = 0x1.0p-53; public static final double SAFE_MIN = 0x1.0p-1022; private static final byte NB = (byte)-1; private static final short NS = (short)-1; private static final byte PB = (byte)1; private static final short PS = (short)1; ...
if (n < 0) { throw new IllegalArgumentException("must have n >= 0 for n!"); } if (n < 21) { return factorial(n); } return Math.floor(Math.exp(factorialLog(n)) + 0.5); } }
815
Math
93
src/java/org/apache/commons/math/util/MathUtils.java
factorialLog
public class MathUtils { public static final double EPSILON = 0x1.0p-53; public static final double SAFE_MIN = 0x1.0p-1022; private static final byte NB = (byte)-1; private static final short NS = (short)-1; private static final byte PB = (byte)1; private static final short PS = (short)1; ...
if (n < 0) { throw new IllegalArgumentException("must have n > 0 for n!"); } if (n < 21) { return Math.log(factorial(n)); } double logSum = 0; for (int i = 2; i <= n; i++) { logSum += Math.log((double)i); } return logSum...
816
Math
94
src/java/org/apache/commons/math/util/MathUtils.java
gcd
public class MathUtils { public static final double EPSILON = 0x1.0p-53; public static final double SAFE_MIN = 0x1.0p-1022; private static final byte NB = (byte)-1; private static final short NS = (short)-1; private static final byte PB = (byte)1; private static final short PS = (short)1; ...
if ((u == 0) || (v == 0)) { return (Math.abs(u) + Math.abs(v)); } // keep u and v negative, as negative integers range down to // -2^31, while positive numbers can only be as large as 2^31-1 // (i.e. we can't necessarily negate a negative number without // ove...
817
Math
95
src/java/org/apache/commons/math/distribution/FDistributionImpl.java
getInitialDomain
public class FDistributionImpl extends AbstractContinuousDistribution implements FDistribution, Serializable { private static final long serialVersionUID = -8516354193418641566L; private double numeratorDegreesOfFreedom; private double denominatorDegreesOfFreedom; protected double getInitialDomain(dou...
double ret = 1.0; double d = getDenominatorDegreesOfFreedom(); if (d > 2.0) { // use mean ret = d / (d - 2.0); } return ret; } }
818
Math
96
src/java/org/apache/commons/math/complex/Complex.java
equals
public class Complex implements Serializable { private static final long serialVersionUID = -6530173849413811929L; public static final Complex I = new Complex(0.0, 1.0); public static final Complex NaN = new Complex(Double.NaN, Double.NaN); public static final Complex INF = new Complex(Double.POSITIVE_...
boolean ret; if (this == other) { ret = true; } else if (other == null) { ret = false; } else { try { Complex rhs = (Complex)other; if (rhs.isNaN()) { ret = this.isNaN(); } ...
819
Math
97
src/java/org/apache/commons/math/analysis/BrentSolver.java
solve
public class BrentSolver extends UnivariateRealSolverImpl { private static final long serialVersionUID = -2136672307739067002L; public double solve(double min, double max) throws MaxIterationsExceededException, FunctionEvaluationException {
clearResult(); verifyInterval(min, max); double ret = Double.NaN; double yMin = f.value(min); double yMax = f.value(max); // Verify bracketing double sign = yMin * yMax; if (sign > 0) { // check if either val...
820
Math
98
src/java/org/apache/commons/math/linear/BigMatrixImpl.java
operate
public class BigMatrixImpl implements BigMatrix, Serializable { private static final long serialVersionUID = -1011428905656140431L; protected BigDecimal data[][] = null; protected BigDecimal lu[][] = null; protected int[] permutation = null; protected int parity = 1; private int roundingMode = ...
if (v.length != this.getColumnDimension()) { throw new IllegalArgumentException("vector has wrong length"); } final int nRows = this.getRowDimension(); final int nCols = this.getColumnDimension(); final BigDecimal[] out = new BigDecimal[nRows]; for (int row = ...
821
Math
98
src/java/org/apache/commons/math/linear/RealMatrixImpl.java
operate
public class RealMatrixImpl implements RealMatrix, Serializable { private static final long serialVersionUID = -4828886979278117018L; protected double data[][] = null; protected double lu[][] = null; protected int[] permutation = null; protected int parity = 1; private static final double TOO_S...
final int nRows = this.getRowDimension(); final int nCols = this.getColumnDimension(); if (v.length != nCols) { throw new IllegalArgumentException("vector has wrong length"); } final double[] out = new double[nRows]; for (int row = 0; row < nRows; row++) { ...
822
Math
99
src/java/org/apache/commons/math/util/MathUtils.java
gcd
public class MathUtils { public static final double EPSILON = 0x1.0p-53; public static final double SAFE_MIN = 0x1.0p-1022; private static final byte NB = (byte)-1; private static final short NS = (short)-1; private static final byte PB = (byte)1; private static final short PS = (short)1; ...
int u = p; int v = q; if ((u == 0) || (v == 0)) { if ((u == Integer.MIN_VALUE) || (v == Integer.MIN_VALUE)) { throw MathRuntimeException.createArithmeticException( "overflow: gcd({0}, {1}) is 2^31", new Object[] { p, q }...
823
Math
99
src/java/org/apache/commons/math/util/MathUtils.java
lcm
public class MathUtils { public static final double EPSILON = 0x1.0p-53; public static final double SAFE_MIN = 0x1.0p-1022; private static final byte NB = (byte)-1; private static final short NS = (short)-1; private static final byte PB = (byte)1; private static final short PS = (short)1; ...
if (a==0 || b==0){ return 0; } int lcm = Math.abs(mulAndCheck(a / gcd(a, b), b)); if (lcm == Integer.MIN_VALUE){ throw new ArithmeticException("overflow: lcm is 2^31"); } return lcm; } }
824
Math
100
src/java/org/apache/commons/math/estimation/AbstractEstimator.java
getCovariances
public class AbstractEstimator implements Estimator { protected WeightedMeasurement[] measurements; protected EstimatedParameter[] parameters; protected double[] jacobian; protected int cols; protected int rows; protected double[] residuals; protected double cost; private int maxCostEva...
// set up the jacobian updateJacobian(); // compute transpose(J).J, avoiding building big intermediate matrices final int rows = problem.getMeasurements().length; final int cols = problem.getUnboundParameters().length; final int max = cols * rows; double[][] j...
825
Math
101
src/java/org/apache/commons/math/complex/ComplexFormat.java
parse
public class ComplexFormat extends Format implements Serializable { private static final long serialVersionUID = -6337346779577272306L; private static final String DEFAULT_IMAGINARY_CHARACTER = "i"; private String imaginaryCharacter; private NumberFormat imaginaryFormat; private NumberFormat realFo...
int initialIndex = pos.getIndex(); // parse whitespace parseAndIgnoreWhitespace(source, pos); // parse real Number re = parseNumber(source, getRealFormat(), pos); if (re == null) { // invalid real number // set index back to initial, error index ...
826
Math
103
src/java/org/apache/commons/math/distribution/NormalDistributionImpl.java
cumulativeProbability
public class NormalDistributionImpl extends AbstractContinuousDistribution implements NormalDistribution, Serializable { private static final long serialVersionUID = 8589540077390120676L; private double mean = 0; private double standardDeviation = 1; public double cumulativeProbability(double x) throw...
try { return 0.5 * (1.0 + Erf.erf((x - mean) / (standardDeviation * Math.sqrt(2.0)))); } catch (MaxIterationsExceededException ex) { if (x < (mean - 20 * standardDeviation)) { // JDK 1.5 blows at 38 return 0.0d; } else if (x > (mean...
827
Math
105
src/java/org/apache/commons/math/stat/regression/SimpleRegression.java
getSumSquaredErrors
public class SimpleRegression implements Serializable { private static final long serialVersionUID = -3004689053607543335L; private double sumX = 0d; private double sumXX = 0d; private double sumY = 0d; private double sumYY = 0d; private double sumXY = 0d; private long n = 0; private do...
return Math.max(0d, sumYY - sumXY * sumXY / sumXX); } }
828
Math
106
src/java/org/apache/commons/math/fraction/ProperFractionFormat.java
parse
public class ProperFractionFormat extends FractionFormat { private static final long serialVersionUID = -6337346779577272307L; private NumberFormat wholeFormat; public Fraction parse(String source, ParsePosition pos) {
// try to parse improper fraction Fraction ret = super.parse(source, pos); if (ret != null) { return ret; } int initialIndex = pos.getIndex(); // parse whitespace parseAndIgnoreWhitespace(source, pos); // parse whole Number w...
829
Mockito
12
src/org/mockito/internal/util/reflection/GenericMaster.java
getGenericType
public class GenericMaster { public Class getGenericType(Field field) {
Type generic = field.getGenericType(); if (generic != null && generic instanceof ParameterizedType) { Type actual = ((ParameterizedType) generic).getActualTypeArguments()[0]; if (actual instanceof Class) { return (Class) actual; } else if (act...
830
Mockito
13
src/org/mockito/internal/MockHandler.java
handle
public class MockHandler implements MockitoInvocationHandler, MockHandlerInterface<T> { private static final long serialVersionUID = -2917871070982574165L; InvocationContainerImpl invocationContainerImpl; MatchersBinder matchersBinder = new MatchersBinder(); MockingProgress mockingProgress = new Thread...
if (invocationContainerImpl.hasAnswersForStubbing()) { // stubbing voids with stubVoid() or doAnswer() style InvocationMatcher invocationMatcher = matchersBinder.bindMatchers(mockingProgress .getArgumentMatcherStorage(), invocation); invocationCont...
831
Mockito
14
src/org/mockito/internal/MockHandler.java
handle
public class MockHandler implements MockitoInvocationHandler, MockHandlerInterface<T> { private static final long serialVersionUID = -2917871070982574165L; InvocationContainerImpl invocationContainerImpl; MatchersBinder matchersBinder = new MatchersBinder(); MockingProgress mockingProgress = new Thread...
if (invocationContainerImpl.hasAnswersForStubbing()) { // stubbing voids with stubVoid() or doAnswer() style InvocationMatcher invocationMatcher = matchersBinder.bindMatchers(mockingProgress .getArgumentMatcherStorage(), invocation); invocationCont...
832
Mockito
14
src/org/mockito/internal/MockitoCore.java
verify
public class MockitoCore { private final Reporter reporter = new Reporter(); private final MockUtil mockUtil = new MockUtil(); private final MockingProgress mockingProgress = new ThreadSafeMockingProgress(); public <T> T verify(T mock, VerificationMode mode) {
if (mock == null) { reporter.nullPassedToVerify(); } else if (!mockUtil.isMock(mock)) { reporter.notAMockPassedToVerify(); } mockingProgress.verificationStarted(new MockAwareVerificationMode(mock, mode)); return mock; } }
833
Mockito
15
src/org/mockito/internal/configuration/injection/FinalMockCandidateFilter.java
filterCandidate
public class FinalMockCandidateFilter implements MockCandidateFilter { public OngoingInjecter filterCandidate(final Collection<Object> mocks, final Field field, final Object fieldInstance) {
if(mocks.size() == 1) { final Object matchingMock = mocks.iterator().next(); return new OngoingInjecter() { public boolean thenInject() { try { if (!new BeanPropertySetter(fieldInstance, field).set(matchingMock)) { ...
834
Mockito
16
src/org/mockito/Mockito.java
mock
public class Mockito extends Matchers { private static final MockitoCore MOCKITO_CORE = new MockitoCore(); public static final Answer<Object> RETURNS_DEFAULTS = new GloballyConfiguredAnswer(); public static final Answer<Object> RETURNS_SMART_NULLS = new ReturnsSmartNulls(); public static final Answer<O...
return MOCKITO_CORE.mock(classToMock, mockSettings, true); } }
835
Mockito
16
src/org/mockito/internal/MockitoCore.java
mock
public class MockitoCore { private final Reporter reporter = new Reporter(); private final MockUtil mockUtil = new MockUtil(); private final MockingProgress mockingProgress = new ThreadSafeMockingProgress(); public <T> T mock(Class<T> classToMock, MockSettings mockSettings, boolean shouldResetOngoingS...
mockingProgress.validateState(); if (shouldResetOngoingStubbing) { mockingProgress.resetOngoingStubbing(); } return mockUtil.createMock(classToMock, (MockSettingsImpl) mockSettings); } }
836
Mockito
17
src/org/mockito/internal/creation/MockSettingsImpl.java
serializable
public class MockSettingsImpl implements MockSettings { private static final long serialVersionUID = 4475297236197939568L; private Class<?>[] extraInterfaces; private String name; private Object spiedInstance; private Answer<Object> defaultAnswer; private MockName mockName; private boolean ...
this.serializable = true; return this; } }
837
Mockito
17
src/org/mockito/internal/util/MockUtil.java
createMock
public class MockUtil { private final CreationValidator creationValidator; public <T> T createMock(Class<T> classToMock, MockSettingsImpl settings) {
creationValidator.validateType(classToMock); creationValidator.validateExtraInterfaces(classToMock, settings.getExtraInterfaces()); creationValidator.validateMockedType(classToMock, settings.getSpiedInstance()); settings.initiateMockName(classToMock); MockHandler<T> mockHandler...
838
Mockito
22
src/org/mockito/internal/matchers/Equality.java
areEqual
public class Equality { public static boolean areEqual(Object o1, Object o2) {
if (o1 == o2 ) { return true; } else if (o1 == null || o2 == null) { return o1 == null && o2 == null; } else if (isArray(o1)) { return isArray(o2) && areArraysEqual(o1, o2); } else { return o1.equals(o2); } } }
839
Mockito
23
src/org/mockito/internal/stubbing/defaultanswers/ReturnsDeepStubs.java
answer
public class ReturnsDeepStubs implements Answer<Object>, Serializable { private static final long serialVersionUID = -7105341425736035847L; private transient MockitoCore mockitoCore; private transient ReturnsEmptyValues delegate; private MockSettings withSettingsUsing(GenericMetadataSupport returnType...
return mock; } }
840
Mockito
23
src/org/mockito/internal/stubbing/defaultanswers/ReturnsDeepStubs.java
answer
public class ReturnsDeepStubs implements Answer<Object>, Serializable { private static final long serialVersionUID = -7105341425736035847L; private transient MockitoCore mockitoCore; private transient ReturnsEmptyValues delegate; private MockSettings withSettingsUsing(GenericMetadataSupport returnType...
GenericMetadataSupport returnTypeGenericMetadata = actualParameterizedType(invocation.getMock()).resolveGenericReturnType(invocation.getMethod()); Class<?> rawType = returnTypeGenericMetadata.rawType(); instantiateMockitoCoreIfNeeded(); instantiateDelegateIfNeeded(); ...
841
Mockito
23
src/org/mockito/internal/stubbing/defaultanswers/ReturnsDeepStubs.java
recordDeepStubMock
public class ReturnsDeepStubs implements Answer<Object>, Serializable { private static final long serialVersionUID = -7105341425736035847L; private transient MockitoCore mockitoCore; private transient ReturnsEmptyValues delegate; private MockSettings withSettingsUsing(GenericMetadataSupport returnType...
container.addAnswer(new SerializableAnswer() { public Object answer(InvocationOnMock invocation) throws Throwable { return mock; } }, false); return mock; } }
842
Mockito
23
src/org/mockito/internal/stubbing/defaultanswers/ReturnsDeepStubs.java
withSettingsUsing
public class ReturnsDeepStubs implements Answer<Object>, Serializable { private static final long serialVersionUID = -7105341425736035847L; private transient MockitoCore mockitoCore; private transient ReturnsEmptyValues delegate; private Object recordDeepStubMock(final Object mock, InvocationContainer...
MockSettings mockSettings = returnTypeGenericMetadata.rawExtraInterfaces().length > 0 ? withSettings().extraInterfaces(returnTypeGenericMetadata.rawExtraInterfaces()) : withSettings(); return mockSettings .serializable() .default...
843
Mockito
24
src/org/mockito/internal/stubbing/defaultanswers/ReturnsEmptyValues.java
answer
public class ReturnsEmptyValues implements Answer<Object>, Serializable { private static final long serialVersionUID = 1998191268711234347L; ObjectMethodsGuru methodsGuru = new ObjectMethodsGuru(); MockUtil mockUtil = new MockUtil(); public Object answer(InvocationOnMock invocation) {
if (methodsGuru.isToString(invocation.getMethod())) { Object mock = invocation.getMock(); MockName name = mockUtil.getMockName(mock); if (name.isDefault()) { return "Mock for " + mockUtil.getMockSettings(mock).getTypeToMock().getSimpleName() + ", hashCode: " +...
844
Mockito
25
src/org/mockito/internal/stubbing/defaultanswers/ReturnsDeepStubs.java
actualParameterizedType
public class ReturnsDeepStubs implements Answer<Object>, Serializable { private static final long serialVersionUID = -7105341425736035847L; private ReturnsEmptyValues delegate = new ReturnsEmptyValues(); private Object getMock(InvocationOnMock invocation, GenericMetadataSupport returnTypeGenericMetadata) ...
return returnTypeGenericMetadata; } }
845
Mockito
25
src/org/mockito/internal/stubbing/defaultanswers/ReturnsDeepStubs.java
answer
public class ReturnsDeepStubs implements Answer<Object>, Serializable { private static final long serialVersionUID = -7105341425736035847L; private ReturnsEmptyValues delegate = new ReturnsEmptyValues(); @Override protected GenericMetadataSupport actualParameterizedType(Object mock); private Object ge...
GenericMetadataSupport returnTypeGenericMetadata = actualParameterizedType(invocation.getMock()).resolveGenericReturnType(invocation.getMethod()); Class<?> rawType = returnTypeGenericMetadata.rawType(); if (!new MockCreationValidator().isTypeMockable(rawType)) { retu...
846
Mockito
25
src/org/mockito/internal/stubbing/defaultanswers/ReturnsDeepStubs.java
getMock
public class ReturnsDeepStubs implements Answer<Object>, Serializable { private static final long serialVersionUID = -7105341425736035847L; private ReturnsEmptyValues delegate = new ReturnsEmptyValues(); @Override protected GenericMetadataSupport actualParameterizedType(Object mock); private Object re...
InternalMockHandler<Object> handler = new MockUtil().getMockHandler(invocation.getMock()); InvocationContainerImpl container = (InvocationContainerImpl) handler.getInvocationContainer(); // matches invocation for verification for (StubbedInvocationMatcher stubbedInvocationMatcher : container....
847
Mockito
25
src/org/mockito/internal/stubbing/defaultanswers/ReturnsDeepStubs.java
recordDeepStubMock
public class ReturnsDeepStubs implements Answer<Object>, Serializable { private static final long serialVersionUID = -7105341425736035847L; private ReturnsEmptyValues delegate = new ReturnsEmptyValues(); @Override protected GenericMetadataSupport actualParameterizedType(Object mock); private Object ge...
container.addAnswer(new Answer<Object>() { public Object answer(InvocationOnMock invocation) throws Throwable { return mock; } }, false); return mock; } }
848
Mockito
27
src/org/mockito/internal/util/MockUtil.java
resetMock
public class MockUtil { private final MockCreationValidator creationValidator; public <T> void resetMock(T mock) {
MockHandlerInterface<T> oldMockHandler = getMockHandler(mock); MethodInterceptorFilter newFilter = newMethodInterceptorFilter(oldMockHandler.getMockSettings()); ((Factory) mock).setCallback(0, newFilter); } }
849
Mockito
28
src/org/mockito/internal/configuration/DefaultInjectionEngine.java
injectMockCandidate
public class DefaultInjectionEngine { private final MockCandidateFilter mockCandidateFilter = new TypeBasedCandidateFilter(new NameBasedCandidateFilter(new FinalMockCandidateFilter())); private Comparator<Field> supertypesLast = new Comparator<Field>() { public int compare(Field field1, Field field2) ...
for(Field field : orderedInstanceFieldsFrom(awaitingInjectionClazz)) { Object injected = mockCandidateFilter.filterCandidate(mocks, field, fieldInstance).thenInject(); mocks.remove(injected); } } }
850
Mockito
29
src/org/mockito/internal/matchers/Same.java
describeTo
public class Same extends ArgumentMatcher<Object> implements Serializable { private static final long serialVersionUID = -1226959355938572597L; private final Object wanted; public void describeTo(Description description) {
description.appendText("same("); appendQuoting(description); description.appendText(wanted == null ? "null" : wanted.toString()); appendQuoting(description); description.appendText(")"); } }
851
Mockito
30
src/org/mockito/exceptions/Reporter.java
smartNullPointerException
public class Reporter { public void smartNullPointerException(Object obj, Location location) {
throw new SmartNullPointerException(join( "You have a NullPointerException here:", new Location(), obj, "Because this method was *not* stubbed correctly:", location, "" )); } }
852
Mockito
32
src/org/mockito/internal/configuration/SpyAnnotationEngine.java
process
public class SpyAnnotationEngine implements AnnotationEngine { @SuppressWarnings("deprecation") public void process(Class<?> context, Object testClass) {
Field[] fields = context.getDeclaredFields(); for (Field field : fields) { if (field.isAnnotationPresent(Spy.class)) { assertNoAnnotations(Spy.class, field, Mock.class, org.mockito.MockitoAnnotations.Mock.class, Captor.class); boolean wasAccessible = field.isA...
853
Mockito
33
src/org/mockito/internal/invocation/InvocationMatcher.java
hasSameMethod
public class InvocationMatcher implements PrintableInvocation, PrintingFriendlyInvocation, CapturesArgumensFromInvocation, Serializable { private static final long serialVersionUID = -3047126096857467610L; private final Invocation invocation; private final List<Matcher> matchers; public boolean hasSam...
//not using method.equals() for 1 good reason: //sometimes java generates forwarding methods when generics are in play see JavaGenericsForwardingMethodsTest Method m1 = invocation.getMethod(); Method m2 = candidate.getMethod(); if (m1.getName() != null && m1.get...
854
Mockito
34
src/org/mockito/internal/invocation/InvocationMatcher.java
captureArgumentsFrom
public class InvocationMatcher implements PrintableInvocation, PrintingFriendlyInvocation, CapturesArgumensFromInvocation, Serializable { private static final long serialVersionUID = -3047126096857467610L; private final Invocation invocation; private final List<Matcher> matchers; public void captureAr...
int k = 0; for (Matcher m : matchers) { if (m instanceof CapturesArguments && i.getArguments().length > k) { ((CapturesArguments) m).captureFrom(i.getArguments()[k]); } k++; } } }
855
Mockito
35
src/org/mockito/Matchers.java
isA
public class Matchers { private static MockingProgress mockingProgress = new ThreadSafeMockingProgress(); public static <T> T same(T value); public static <T> T isA(Class<T> clazz) {
return reportMatcher(new InstanceOf(clazz)).<T>returnFor(clazz); } }
856
Mockito
35
src/org/mockito/Matchers.java
same
public class Matchers { private static MockingProgress mockingProgress = new ThreadSafeMockingProgress(); public static <T> T isA(Class<T> clazz); public static <T> T same(T value) {
return (T) reportMatcher(new Same(value)).<T>returnFor((Class) value.getClass()); } }
857
Mockito
36
src/org/mockito/internal/invocation/Invocation.java
callRealMethod
public class Invocation implements PrintableInvocation, InvocationOnMock, PrintingFriendlyInvocation { private static final long serialVersionUID = 8240069639250980199L; private static final int MAX_LINE_LENGTH = 45; private final int sequenceNumber; private final Object mock; private final Mockito...
if (this.getMethod().getDeclaringClass().isInterface()) { new Reporter().cannotCallRealMethodOnInterface(); } return realMethod.invoke(mock, rawArguments); } }
858
Mockito
37
src/org/mockito/internal/stubbing/answers/AnswersValidator.java
validate
public class AnswersValidator { private Reporter reporter = new Reporter(); public void validate(Answer<?> answer, Invocation invocation) {
if (answer instanceof ThrowsException) { validateException((ThrowsException) answer, invocation); } if (answer instanceof Returns) { validateReturnValue((Returns) answer, invocation); } if (answer instanceof DoesNothing) { val...
859
Mockito
38
src/org/mockito/internal/verification/argumentmatching/ArgumentMatchingTool.java
toStringEquals
public class ArgumentMatchingTool { private boolean toStringEquals(Matcher m, Object arg) {
return StringDescription.toString(m).equals(arg == null? "null" : arg.toString()); } }
860
Time
1
src/main/java/org/joda/time/field/UnsupportedDurationField.java
compareTo
public class UnsupportedDurationField extends DurationField implements Serializable { private static final long serialVersionUID = -6390301302770925357L; private static HashMap<DurationFieldType, UnsupportedDurationField> cCache; private final DurationFieldType iType; public int compareTo(DurationFiel...
return 0; } }
861
Time
2
src/main/java/org/joda/time/Partial.java
with
public class Partial extends AbstractPartial implements ReadablePartial, Serializable { private static final long serialVersionUID = 12324121189002L; private final Chronology iChronology; private final DateTimeFieldType[] iTypes; private final int[] iValues; private transient DateTimeFormatter[] iF...
if (fieldType == null) { throw new IllegalArgumentException("The field type must not be null"); } int index = indexOf(fieldType); if (index == -1) { DateTimeFieldType[] newTypes = new DateTimeFieldType[iTypes.length + 1]; int[] newValues = new int[newT...
862
Time
2
src/main/java/org/joda/time/field/UnsupportedDurationField.java
compareTo
public class UnsupportedDurationField extends DurationField implements Serializable { private static final long serialVersionUID = -6390301302770925357L; private static HashMap<DurationFieldType, UnsupportedDurationField> cCache; private final DurationFieldType iType; public int compareTo(DurationFiel...
if (durationField.isSupported()) { return 1; } return 0; } }
863
Time
3
src/main/java/org/joda/time/MutableDateTime.java
addDays
public class MutableDateTime extends BaseDateTime implements ReadWritableDateTime, Cloneable, Serializable { private static final long serialVersionUID = 2852608688135209575L; public static final int ROUND_NONE = 0; public static final int ROUND_FLOOR = 1; public static final int ROUND_CEILING = 2; ...
if (days != 0) { setMillis(getChronology().days().add(getMillis(), days)); } } }
864
Time
3
src/main/java/org/joda/time/MutableDateTime.java
addHours
public class MutableDateTime extends BaseDateTime implements ReadWritableDateTime, Cloneable, Serializable { private static final long serialVersionUID = 2852608688135209575L; public static final int ROUND_NONE = 0; public static final int ROUND_FLOOR = 1; public static final int ROUND_CEILING = 2; ...
if (hours != 0) { setMillis(getChronology().hours().add(getMillis(), hours)); } } }
865
Time
3
src/main/java/org/joda/time/MutableDateTime.java
addMonths
public class MutableDateTime extends BaseDateTime implements ReadWritableDateTime, Cloneable, Serializable { private static final long serialVersionUID = 2852608688135209575L; public static final int ROUND_NONE = 0; public static final int ROUND_FLOOR = 1; public static final int ROUND_CEILING = 2; ...
if (months != 0) { setMillis(getChronology().months().add(getMillis(), months)); } } }
866
Time
3
src/main/java/org/joda/time/MutableDateTime.java
addWeeks
public class MutableDateTime extends BaseDateTime implements ReadWritableDateTime, Cloneable, Serializable { private static final long serialVersionUID = 2852608688135209575L; public static final int ROUND_NONE = 0; public static final int ROUND_FLOOR = 1; public static final int ROUND_CEILING = 2; ...
if (weeks != 0) { setMillis(getChronology().weeks().add(getMillis(), weeks)); } } }
867
Time
3
src/main/java/org/joda/time/MutableDateTime.java
addYears
public class MutableDateTime extends BaseDateTime implements ReadWritableDateTime, Cloneable, Serializable { private static final long serialVersionUID = 2852608688135209575L; public static final int ROUND_NONE = 0; public static final int ROUND_FLOOR = 1; public static final int ROUND_CEILING = 2; ...
if (years != 0) { setMillis(getChronology().years().add(getMillis(), years)); } } }
868
Time
4
src/main/java/org/joda/time/Partial.java
with
public class Partial extends AbstractPartial implements ReadablePartial, Serializable { private static final long serialVersionUID = 12324121189002L; private final Chronology iChronology; private final DateTimeFieldType[] iTypes; private final int[] iValues; private transient DateTimeFormatter[] iF...
if (fieldType == null) { throw new IllegalArgumentException("The field type must not be null"); } int index = indexOf(fieldType); if (index == -1) { DateTimeFieldType[] newTypes = new DateTimeFieldType[iTypes.length + 1]; int[] newValues = new int[newT...
869
Time
5
src/main/java/org/joda/time/Period.java
normalizedStandard
public class Period extends BasePeriod implements ReadablePeriod, Serializable { public static final Period ZERO = new Period(); private static final long serialVersionUID = 741052353876488155L; public Period normalizedStandard(PeriodType type) {
type = DateTimeUtils.getPeriodType(type); long millis = getMillis(); // no overflow can happen, even with Integer.MAX_VALUEs millis += (((long) getSeconds()) * ((long) DateTimeConstants.MILLIS_PER_SECOND)); millis += (((long) getMinutes()) * ((long) DateTimeConstants.MILLIS_PER_MINUTE))...
870
Time
6
src/main/java/org/joda/time/chrono/GJChronology.java
getInstance
public class GJChronology extends AssembledChronology { private static final long serialVersionUID = -2545574827706931671L; static final Instant DEFAULT_CUTOVER = new Instant(-12219292800000L); private static final Map<DateTimeZone, ArrayList<GJChronology>> cCache = new HashMap<DateTimeZone, ArrayList<GJCh...
zone = DateTimeUtils.getZone(zone); Instant cutoverInstant; if (gregorianCutover == null) { cutoverInstant = DEFAULT_CUTOVER; } else { cutoverInstant = gregorianCutover.toInstant(); LocalDate cutoverDate = new LocalDate(cutoverInstant.getMilli...
871
Time
7
src/main/java/org/joda/time/format/DateTimeFormatter.java
parseInto
public class DateTimeFormatter { private final DateTimePrinter iPrinter; private final DateTimeParser iParser; private final Locale iLocale; private final boolean iOffsetParsed; private final Chronology iChrono; private final DateTimeZone iZone; private final Integer iPivotYear; private...
DateTimeParser parser = requireParser(); if (instant == null) { throw new IllegalArgumentException("Instant must not be null"); } long instantMillis = instant.getMillis(); Chronology chrono = instant.getChronology(); int defaultYear = DateTimeUtils.ge...
872
Time
8
src/main/java/org/joda/time/DateTimeZone.java
forOffsetHoursMinutes
public class DateTimeZone implements Serializable { private static final long serialVersionUID = 5546345482340108586L; public static final DateTimeZone UTC = new FixedDateTimeZone("UTC", "UTC", 0, 0); private static final int MAX_MILLIS = (86400 * 1000) - 1; private static Provider cProvider; priva...
if (hoursOffset == 0 && minutesOffset == 0) { return DateTimeZone.UTC; } if (hoursOffset < -23 || hoursOffset > 23) { throw new IllegalArgumentException("Hours out of range: " + hoursOffset); } if (minutesOffset < -59 || minutesOffset > 59) { t...
873
Time
9
src/main/java/org/joda/time/DateTimeZone.java
forOffsetHoursMinutes
public class DateTimeZone implements Serializable { private static final long serialVersionUID = 5546345482340108586L; public static final DateTimeZone UTC = new FixedDateTimeZone("UTC", "UTC", 0, 0); private static final int MAX_MILLIS = (86400 * 1000) - 1; private static Provider cProvider; priva...
if (hoursOffset == 0 && minutesOffset == 0) { return DateTimeZone.UTC; } if (hoursOffset < -23 || hoursOffset > 23) { throw new IllegalArgumentException("Hours out of range: " + hoursOffset); } if (minutesOffset < 0 || minutesOffset > 59) { thr...
874
Time
9
src/main/java/org/joda/time/DateTimeZone.java
forOffsetMillis
public class DateTimeZone implements Serializable { private static final long serialVersionUID = 5546345482340108586L; public static final DateTimeZone UTC = new FixedDateTimeZone("UTC", "UTC", 0, 0); private static final int MAX_MILLIS = (86400 * 1000) - 1; private static Provider cProvider; priva...
if (millisOffset < -MAX_MILLIS || millisOffset > MAX_MILLIS) { throw new IllegalArgumentException("Millis out of range: " + millisOffset); } String id = printOffset(millisOffset); return fixedOffsetZone(id, millisOffset); } }
875
Time
10
src/main/java/org/joda/time/base/BaseSingleFieldPeriod.java
between
public class BaseSingleFieldPeriod implements ReadablePeriod, Comparable<BaseSingleFieldPeriod>, Serializable { private static final long serialVersionUID = 9386874258972L; private static final long START_1972 = 2L * 365L * 86400L * 1000L; private volatile int iPeriod; protected static int between(Rea...
if (start == null || end == null) { throw new IllegalArgumentException("ReadablePartial objects must not be null"); } if (start.size() != end.size()) { throw new IllegalArgumentException("ReadablePartial objects must have the same set of fields"); } for (i...
876
Time
12
src/main/java/org/joda/time/LocalDate.java
fromCalendarFields
public class LocalDate extends BaseLocal implements ReadablePartial, Serializable { private static final long serialVersionUID = -8775358157899L; private static final int YEAR = 0; private static final int MONTH_OF_YEAR = 1; private static final int DAY_OF_MONTH = 2; private static final Set<Durati...
if (calendar == null) { throw new IllegalArgumentException("The calendar must not be null"); } int era = calendar.get(Calendar.ERA); int yearOfEra = calendar.get(Calendar.YEAR); return new LocalDate( (era == GregorianCalendar.AD ? yearOfEra : 1 - yearOfEra...
877
Time
12
src/main/java/org/joda/time/LocalDate.java
fromDateFields
public class LocalDate extends BaseLocal implements ReadablePartial, Serializable { private static final long serialVersionUID = -8775358157899L; private static final int YEAR = 0; private static final int MONTH_OF_YEAR = 1; private static final int DAY_OF_MONTH = 2; private static final Set<Durati...
if (date == null) { throw new IllegalArgumentException("The date must not be null"); } if (date.getTime() < 0) { // handle years in era BC GregorianCalendar cal = new GregorianCalendar(); cal.setTime(date); return fromCalendarFields(cal...
878
Time
12
src/main/java/org/joda/time/LocalDateTime.java
fromCalendarFields
public class LocalDateTime extends BaseLocal implements ReadablePartial, Serializable { private static final long serialVersionUID = -268716875315837168L; private static final int YEAR = 0; private static final int MONTH_OF_YEAR = 1; private static final int DAY_OF_MONTH = 2; private static final i...
if (calendar == null) { throw new IllegalArgumentException("The calendar must not be null"); } int era = calendar.get(Calendar.ERA); int yearOfEra = calendar.get(Calendar.YEAR); return new LocalDateTime( (era == GregorianCalendar.AD ? yearOfEra : 1 - yearO...
879
Time
12
src/main/java/org/joda/time/LocalDateTime.java
fromDateFields
public class LocalDateTime extends BaseLocal implements ReadablePartial, Serializable { private static final long serialVersionUID = -268716875315837168L; private static final int YEAR = 0; private static final int MONTH_OF_YEAR = 1; private static final int DAY_OF_MONTH = 2; private static final i...
if (date == null) { throw new IllegalArgumentException("The date must not be null"); } if (date.getTime() < 0) { // handle years in era BC GregorianCalendar cal = new GregorianCalendar(); cal.setTime(date); return fromCalendarFields(cal...
880
Time
14
src/main/java/org/joda/time/chrono/BasicMonthOfYearDateTimeField.java
add
public class BasicMonthOfYearDateTimeField extends ImpreciseDateTimeField { private static final long serialVersionUID = -8258715387168736L; private static final int MIN = DateTimeConstants.JANUARY; private final BasicChronology iChronology; private final int iMax; private final int iLeapMonth; ...
// overridden as superclass algorithm can't handle // 2004-02-29 + 48 months -> 2008-02-29 type dates if (valueToAdd == 0) { return values; } if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) { //...
881
Time
16
src/main/java/org/joda/time/format/DateTimeFormatter.java
parseInto
public class DateTimeFormatter { private final DateTimePrinter iPrinter; private final DateTimeParser iParser; private final Locale iLocale; private final boolean iOffsetParsed; private final Chronology iChrono; private final DateTimeZone iZone; private final Integer iPivotYear; private...
DateTimeParser parser = requireParser(); if (instant == null) { throw new IllegalArgumentException("Instant must not be null"); } long instantMillis = instant.getMillis(); Chronology chrono = instant.getChronology(); long instantLocal = instantMillis ...
882
Time
17
src/main/java/org/joda/time/DateTimeZone.java
adjustOffset
public class DateTimeZone implements Serializable { private static final long serialVersionUID = 5546345482340108586L; public static final DateTimeZone UTC = new FixedDateTimeZone("UTC", "UTC", 0, 0); private static Provider cProvider; private static NameProvider cNameProvider; private static Set<S...
// a bit messy, but will work in all non-pathological cases // evaluate 3 hours before and after to work out if anything is happening long instantBefore = instant - 3 * DateTimeConstants.MILLIS_PER_HOUR; long instantAfter = instant + 3 * DateTimeConstants.MILLIS_PER_HOUR; ...
883
Time
18
src/main/java/org/joda/time/chrono/GJChronology.java
getDateTimeMillis
public class GJChronology extends AssembledChronology { private static final long serialVersionUID = -2545574827706931671L; static final Instant DEFAULT_CUTOVER = new Instant(-12219292800000L); private static final Map<DateTimeZone, ArrayList<GJChronology>> cCache = new HashMap<DateTimeZone, ArrayList<GJCh...
Chronology base; if ((base = getBase()) != null) { return base.getDateTimeMillis (year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond); } // Assume date is Gregorian. long instant; try { ...
884
Time
19
src/main/java/org/joda/time/DateTimeZone.java
getOffsetFromLocal
public class DateTimeZone implements Serializable { private static final long serialVersionUID = 5546345482340108586L; public static final DateTimeZone UTC = new FixedDateTimeZone("UTC", "UTC", 0, 0); private static Provider cProvider; private static NameProvider cNameProvider; private static Set<S...
// get the offset at instantLocal (first estimate) final int offsetLocal = getOffset(instantLocal); // adjust instantLocal using the estimate and recalc the offset final long instantAdjusted = instantLocal - offsetLocal; final int offsetAdjusted = getOffset(instantAdjusted); ...
885
Time
23
src/main/java/org/joda/time/DateTimeZone.java
getConvertedId
public class DateTimeZone implements Serializable { private static final long serialVersionUID = 5546345482340108586L; public static final DateTimeZone UTC = new FixedDateTimeZone("UTC", "UTC", 0, 0); private static Provider cProvider; private static NameProvider cNameProvider; private static Set<S...
Map<String, String> map = cZoneIdConversion; if (map == null) { // Backwards compatibility with TimeZone. map = new HashMap<String, String>(); map.put("GMT", "UTC"); map.put("WET", "WET"); map.put("CET", "CET"); map.put("MET", "CET"...
886
Time
24
src/main/java/org/joda/time/format/DateTimeParserBucket.java
computeMillis
public class DateTimeParserBucket { private final Chronology iChrono; private final long iMillis; private DateTimeZone iZone; private int iOffset; private Locale iLocale; private Integer iPivotYear; private int iDefaultYear; private SavedField[] iSavedFields = new SavedField[8]; pri...
SavedField[] savedFields = iSavedFields; int count = iSavedFieldsCount; if (iSavedFieldsShared) { iSavedFields = savedFields = (SavedField[])iSavedFields.clone(); iSavedFieldsShared = false; } sort(savedFields, count); if (count > 0) { ...
887
Time
25
src/main/java/org/joda/time/DateTimeZone.java
getOffsetFromLocal
public class DateTimeZone implements Serializable { private static final long serialVersionUID = 5546345482340108586L; public static final DateTimeZone UTC = new FixedDateTimeZone("UTC", "UTC", 0, 0); private static Provider cProvider; private static NameProvider cNameProvider; private static Set<S...
// get the offset at instantLocal (first estimate) final int offsetLocal = getOffset(instantLocal); // adjust instantLocal using the estimate and recalc the offset final long instantAdjusted = instantLocal - offsetLocal; final int offsetAdjusted = getOffset(instantAdjusted); ...
888
Time
26
src/main/java/org/joda/time/DateTimeZone.java
convertLocalToUTC
public class DateTimeZone implements Serializable { private static final long serialVersionUID = 5546345482340108586L; public static final DateTimeZone UTC = new FixedDateTimeZone("UTC", "UTC", 0, 0); private static Provider cProvider; private static NameProvider cNameProvider; private static Set<S...
int offsetOriginal = getOffset(originalInstantUTC); long instantUTC = instantLocal - offsetOriginal; int offsetLocalFromOriginal = getOffset(instantUTC); if (offsetLocalFromOriginal == offsetOriginal) { return instantUTC; } return convertLocalToUTC(instantLoca...
889
Time
27
src/main/java/org/joda/time/format/PeriodFormatterBuilder.java
toFormatter
public class PeriodFormatterBuilder { private static final int PRINT_ZERO_RARELY_FIRST = 1; private static final int PRINT_ZERO_RARELY_LAST = 2; private static final int PRINT_ZERO_IF_SUPPORTED = 3; private static final int PRINT_ZERO_ALWAYS = 4; private static final int PRINT_ZERO_NEVER = 5; p...
if (notPrinter && notParser) { throw new IllegalStateException("Builder has created neither a printer nor a parser"); } int size = elementPairs.size(); if (size >= 2 && elementPairs.get(0) instanceof Separator) { Separator sep = (Separator) elementPairs.get(0); ...