_id
stringlengths 2
7
| title
stringlengths 3
140
| partition
stringclasses 3
values | text
stringlengths 73
34.1k
| language
stringclasses 1
value | meta_information
dict |
---|---|---|---|---|---|
q179100
|
SqliteReal.isTypeOf
|
test
|
boolean isTypeOf(TypeMirror typeMirror) {
if (realKinds.contains(typeMirror.getKind())) {
return true;
}
if (realObjects.contains(typeMirror.toString())) {
return true;
}
return false;
}
|
java
|
{
"resource": ""
}
|
q179101
|
OrderByBuilder.descending
|
test
|
public Builder<T> descending() {
this.query.append(" DESC");
return new Builder<T>(shillelagh, tableObject, query);
}
|
java
|
{
"resource": ""
}
|
q179102
|
OneWireTemperatureSensor.readTemperature
|
test
|
public float readTemperature() throws IOException {
byte[] encoded = Files.readAllBytes(new File(deviceFile, "w1_slave").toPath());
String tmp = new String(encoded);
int tmpIndex = tmp.indexOf("t=");
if (tmpIndex < 0) {
throw new IOException("Could not read temperature!");
}
return Integer.parseInt(tmp.substring(tmpIndex + 2).trim()) / 1000f;
}
|
java
|
{
"resource": ""
}
|
q179103
|
CursorFunctions.get
|
test
|
public static String get(String type) {
final String returnValue = SUPPORTED_CURSOR_METHODS.get(type);
return returnValue != null ? returnValue : SUPPORTED_CURSOR_METHODS.get(BLOB);
}
|
java
|
{
"resource": ""
}
|
q179104
|
ShillelaghLogger.n
|
test
|
void n(String message, Object... args) {
messenger.printMessage(NOTE, formatString(message, args));
}
|
java
|
{
"resource": ""
}
|
q179105
|
ShillelaghLogger.e
|
test
|
void e(String message, Object... args) {
messenger.printMessage(ERROR, formatString(message, args));
}
|
java
|
{
"resource": ""
}
|
q179106
|
Bundle.getIconFonts
|
test
|
public static List<IconFont> getIconFonts() {
List<IconFont> list = new ArrayList<>();
list.add(GoogleMaterialDesignIcons.getIconFont());
list.add(Elusive.getIconFont());
list.add(Entypo.getIconFont());
list.add(FontAwesome.getIconFont());
list.add(Iconic.getIconFont());
list.add(Typicons.getIconFont());
return list;
}
|
java
|
{
"resource": ""
}
|
q179107
|
Bundle.getIcons
|
test
|
public static List<IconCode> getIcons() {
List<IconCode> list = new ArrayList<>();
for (IconCode icon : GoogleMaterialDesignIcons.values()) {
list.add(icon);
}
for (IconCode icon : Elusive.values()) {
list.add(icon);
}
for (IconCode icon : Entypo.values()) {
list.add(icon);
}
for (IconCode icon : FontAwesome.values()) {
list.add(icon);
}
for (IconCode icon : Iconic.values()) {
list.add(icon);
}
for (IconCode icon : Typicons.values()) {
list.add(icon);
}
return list;
}
|
java
|
{
"resource": ""
}
|
q179108
|
SldEditorWidgetViewImpl.createSldEditorLayout
|
test
|
public VLayout createSldEditorLayout() {
final VLayout vLayout = new VLayout();
toolStrip = new ToolStrip();
toolStrip.setWidth100();
codeMirrorPanel = new CodeMirrorPanel();
WidgetCanvas canvas = new WidgetCanvas(codeMirrorPanel);
canvas.setWidth100();
canvas.setHeight100();
vLayout.addMember(toolStrip);
vLayout.addMember(canvas);
ToolStripButton saveButton = new ToolStripButton();
saveButton.setIcon("[ISOMORPHIC]/" + "icons/silk/disk.png");
saveButton.setTitle(msg.saveButtonTitle());
saveButton.setTooltip(msg.saveButtonTooltip());
saveButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
presenter.onSaveButton();
}
});
ToolStripButton cancelButton = new ToolStripButton();
cancelButton.setIcon("[ISOMORPHIC]/" + "icons/silk/cancel.png");
cancelButton.setTitle(msg.cancelButtonTitle());
cancelButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
presenter.onCancelButton();
}
});
ToolStripButton validateButton = new ToolStripButton();
validateButton.setIcon("[ISOMORPHIC]/" + "icons/silk/tick.png");
validateButton.setTitle(msg.validateButtonTitle());
validateButton.setTooltip(msg.validateButtonTooltip());
validateButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
presenter.onValidateButton();
}
});
ToolStripButton formatBtn = new ToolStripButton();
formatBtn.setIcon("[ISOMORPHIC]/" + "icons/silk/text_align_left.png");
formatBtn.setTitle(msg.formatButtonTitle());
formatBtn.setTooltip(msg.formatButtonTooltip());
formatBtn.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
presenter.onFormatButton();
}
});
selectTemplate = new SelectItem();
selectTemplate.setTitle(msg.templateSelectTitle());
selectTemplate.setTooltip(msg.templateSelectTooltip());
selectTemplate.setWidth(200);
selectTemplate.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent changeEvent) {
presenter.onTemplateSelect((String) changeEvent.getValue());
}
});
toolStrip.addFormItem(selectTemplate);
toolStrip.addButton(saveButton);
toolStrip.addButton(validateButton);
toolStrip.addButton(formatBtn);
/*
* toolStrip.addSeparator(); toolStrip.addButton(saveButton);
*/
toolStrip.addFill();
toolStrip.addButton(cancelButton);
return vLayout;
}
|
java
|
{
"resource": ""
}
|
q179109
|
SldEditorPanel.getBackgroundDecoration
|
test
|
private HTMLFlow getBackgroundDecoration() {
// Show some background content in the tab.
HTMLFlow htmlFlow = new HTMLFlow();
htmlFlow.setWidth100();
htmlFlow.setHeight100();
String contents =
"<div style='margin-left: 5px; font-size: 100pt; font-weight: bold; color:#DDFFDD'>GEOMAJAS</div>"
+ "<div style='margin-left: 10px; margin-top:-70px; font-size: 50pt; color:#CCCCCC'>SLD-Editor</div>"
+ "<div style='margin-left: 10px; margin-top:-15px; font-size: 28pt; color:#DDDDDD'>EXPERT-mode</div>";
htmlFlow.setContents(contents);
return htmlFlow;
}
|
java
|
{
"resource": ""
}
|
q179110
|
IntPower.raise
|
test
|
public static double raise (final double px, final int pexponent)
{
double x = px;
int exponent = pexponent;
if (exponent < 0)
return 1 / raise (x, -exponent);
double power = 1;
// Loop to compute x^exponent.
while (exponent > 0)
{
// Is the rightmost exponent bit a 1?
if ((exponent & 1) == 1)
power *= x;
// Square x and shift the exponent 1 bit to the right.
x *= x;
exponent >>= 1;
}
return power;
}
|
java
|
{
"resource": ""
}
|
q179111
|
ColumnVector.set
|
test
|
protected void set (final float values[])
{
this.m_nRows = values.length;
this.m_nCols = 1;
this.m_aValues = new float [m_nRows] [1];
for (int r = 0; r < m_nRows; ++r)
{
this.m_aValues[r][0] = values[r];
}
}
|
java
|
{
"resource": ""
}
|
q179112
|
BigFunctions.intPower
|
test
|
public static BigDecimal intPower (@Nonnull final BigDecimal px, final long pexponent, final int scale)
{
BigDecimal x = px;
long exponent = pexponent;
// If the exponent is negative, compute 1/(x^-exponent).
if (exponent < 0)
{
return BigDecimal.ONE.divide (intPower (x, -exponent, scale), scale, RoundingMode.HALF_EVEN);
}
BigDecimal power = BigDecimal.ONE;
// Loop to compute value^exponent.
while (exponent > 0)
{
// Is the rightmost bit a 1?
if ((exponent & 1) == 1)
{
power = power.multiply (x).setScale (scale, RoundingMode.HALF_EVEN);
}
// Square x and shift exponent 1 bit to the right.
x = x.multiply (x).setScale (scale, RoundingMode.HALF_EVEN);
exponent >>= 1;
Thread.yield ();
}
return power;
}
|
java
|
{
"resource": ""
}
|
q179113
|
BigFunctions.intRoot
|
test
|
public static BigDecimal intRoot (@Nonnull final BigDecimal px, final long index, final int scale)
{
BigDecimal x = px;
// Check that x >= 0.
if (x.signum () < 0)
{
throw new IllegalArgumentException ("x < 0: " + x);
}
final int sp1 = scale + 1;
final BigDecimal n = x;
final BigDecimal i = BigDecimal.valueOf (index);
final BigDecimal im1 = BigDecimal.valueOf (index - 1);
final BigDecimal tolerance = BigDecimal.valueOf (5).movePointLeft (sp1);
BigDecimal xPrev;
// The initial approximation is x/index.
x = x.divide (i, scale, RoundingMode.HALF_EVEN);
// Loop until the approximations converge
// (two successive approximations are equal after rounding).
do
{
// x^(index-1)
final BigDecimal xToIm1 = intPower (x, index - 1, sp1);
// x^index
final BigDecimal xToI = x.multiply (xToIm1).setScale (sp1, RoundingMode.HALF_EVEN);
// n + (index-1)*(x^index)
final BigDecimal numerator = n.add (im1.multiply (xToI)).setScale (sp1, RoundingMode.HALF_EVEN);
// (index*(x^(index-1))
final BigDecimal denominator = i.multiply (xToIm1).setScale (sp1, RoundingMode.HALF_EVEN);
// x = (n + (index-1)*(x^index)) / (index*(x^(index-1)))
xPrev = x;
x = numerator.divide (denominator, sp1, RoundingMode.DOWN);
Thread.yield ();
} while (x.subtract (xPrev).abs ().compareTo (tolerance) > 0);
return x;
}
|
java
|
{
"resource": ""
}
|
q179114
|
BigFunctions._expTaylor
|
test
|
private static BigDecimal _expTaylor (final BigDecimal x, final int scale)
{
BigDecimal factorial = BigDecimal.ONE;
BigDecimal xPower = x;
BigDecimal sumPrev;
// 1 + x
BigDecimal sum = x.add (BigDecimal.ONE);
// Loop until the sums converge
// (two successive sums are equal after rounding).
int i = 2;
do
{
// x^i
xPower = xPower.multiply (x).setScale (scale, RoundingMode.HALF_EVEN);
// i!
factorial = factorial.multiply (BigDecimal.valueOf (i));
// x^i/i!
final BigDecimal term = xPower.divide (factorial, scale, RoundingMode.HALF_EVEN);
// sum = sum + x^i/i!
sumPrev = sum;
sum = sum.add (term);
++i;
Thread.yield ();
} while (sum.compareTo (sumPrev) != 0);
return sum;
}
|
java
|
{
"resource": ""
}
|
q179115
|
BigFunctions.ln
|
test
|
public static BigDecimal ln (@Nonnull final BigDecimal x, final int scale)
{
// Check that x > 0.
if (x.signum () <= 0)
{
throw new IllegalArgumentException ("x <= 0: " + x);
}
// The number of digits to the left of the decimal point.
final int magnitude = x.toString ().length () - x.scale () - 1;
if (magnitude < 3)
{
return _lnNewton (x, scale);
}
// Compute magnitude*ln(x^(1/magnitude)).
// x^(1/magnitude)
final BigDecimal root = intRoot (x, magnitude, scale);
// ln(x^(1/magnitude))
final BigDecimal lnRoot = _lnNewton (root, scale);
// magnitude*ln(x^(1/magnitude))
return BigDecimal.valueOf (magnitude).multiply (lnRoot).setScale (scale, RoundingMode.HALF_EVEN);
}
|
java
|
{
"resource": ""
}
|
q179116
|
BigFunctions._lnNewton
|
test
|
private static BigDecimal _lnNewton (@Nonnull final BigDecimal px, final int scale)
{
BigDecimal x = px;
final int sp1 = scale + 1;
final BigDecimal n = x;
BigDecimal term;
// Convergence tolerance = 5*(10^-(scale+1))
final BigDecimal tolerance = BigDecimal.valueOf (5).movePointLeft (sp1);
// Loop until the approximations converge
// (two successive approximations are within the tolerance).
do
{
// e^x
final BigDecimal eToX = exp (x, sp1);
// (e^x - n)/e^x
term = eToX.subtract (n).divide (eToX, sp1, RoundingMode.DOWN);
// x - (e^x - n)/e^x
x = x.subtract (term);
Thread.yield ();
} while (term.compareTo (tolerance) > 0);
return x.setScale (scale, RoundingMode.HALF_EVEN);
}
|
java
|
{
"resource": ""
}
|
q179117
|
BigFunctions.arctan
|
test
|
public static BigDecimal arctan (@Nonnull final BigDecimal x, final int scale)
{
// Check that |x| < 1.
if (x.abs ().compareTo (BigDecimal.ONE) >= 0)
{
throw new IllegalArgumentException ("|x| >= 1: " + x);
}
// If x is negative, return -arctan(-x).
if (x.signum () == -1)
{
return arctan (x.negate (), scale).negate ();
}
return _arctanTaylor (x, scale);
}
|
java
|
{
"resource": ""
}
|
q179118
|
BigFunctions._arctanTaylor
|
test
|
private static BigDecimal _arctanTaylor (final BigDecimal x, final int scale)
{
final int sp1 = scale + 1;
int i = 3;
boolean addFlag = false;
BigDecimal power = x;
BigDecimal sum = x;
BigDecimal term;
// Convergence tolerance = 5*(10^-(scale+1))
final BigDecimal tolerance = BigDecimal.valueOf (5).movePointLeft (sp1);
// Loop until the approximations converge
// (two successive approximations are within the tolerance).
do
{
// x^i
power = power.multiply (x).multiply (x).setScale (sp1, RoundingMode.HALF_EVEN);
// (x^i)/i
term = power.divide (BigDecimal.valueOf (i), sp1, RoundingMode.HALF_EVEN);
// sum = sum +- (x^i)/i
sum = addFlag ? sum.add (term) : sum.subtract (term);
i += 2;
addFlag = !addFlag;
Thread.yield ();
} while (term.compareTo (tolerance) > 0);
return sum;
}
|
java
|
{
"resource": ""
}
|
q179119
|
BigFunctions.sqrt
|
test
|
public static BigDecimal sqrt (@Nonnull final BigDecimal x, final int scale)
{
// Check that x >= 0.
if (x.signum () < 0)
{
throw new IllegalArgumentException ("x < 0: " + x);
}
// n = x*(10^(2*scale))
final BigInteger n = x.movePointRight (scale << 1).toBigInteger ();
// The first approximation is the upper half of n.
final int bits = (n.bitLength () + 1) >> 1;
BigInteger ix = n.shiftRight (bits);
BigInteger ixPrev;
// Loop until the approximations converge
// (two successive approximations are equal after rounding).
do
{
ixPrev = ix;
// x = (x + n/x)/2
ix = ix.add (n.divide (ix)).shiftRight (1);
Thread.yield ();
} while (ix.compareTo (ixPrev) != 0);
return new BigDecimal (ix, scale);
}
|
java
|
{
"resource": ""
}
|
q179120
|
AbstractPiFormula.printPi
|
test
|
protected void printPi (final String piString)
{
System.out.print ("\npi = " + piString.substring (0, 2));
int index = 2;
int line = 0;
int group = 0;
final int length = piString.length ();
// Loop for each group of 5 digits
while (index + 5 < length)
{
System.out.print (piString.substring (index, index + 5) + " ");
index += 5;
// End of line after 10 groups.
if (++group == 10)
{
System.out.println ();
// Print a blank line after 10 lines.
if (++line == 10)
{
System.out.println ();
line = 0;
}
System.out.print (" ");
group = 0;
}
}
// Print the last partial line.
if (index < length)
{
System.out.println (piString.substring (index));
}
}
|
java
|
{
"resource": ""
}
|
q179121
|
AbstractPiFormula.timestamp
|
test
|
protected String timestamp (final long time)
{
// Current time followed by elapsed time as (hh:mm:ss).
final LocalDateTime aLDT = PDTFactory.getCurrentLocalDateTime ();
final LocalDateTime aOld = PDTFactory.createLocalDateTime (time);
return aLDT.toLocalTime ().toString () + " (" + Duration.between (aOld, aLDT).toString () + ")";
}
|
java
|
{
"resource": ""
}
|
q179122
|
Buckets.setLimits
|
test
|
public void setLimits (final float rMin, final float rMax)
{
this.m_fMin = rMin;
this.m_fMax = rMax;
this.m_fWidth = (rMax - rMin) / m_n;
}
|
java
|
{
"resource": ""
}
|
q179123
|
Buckets.put
|
test
|
public void put (final float r)
{
// Ignore the value if it's out of range.
if ((r < m_fMin) || (r > m_fMax))
return;
// Determine its interval and count it.
final int i = (int) ((r - m_fMin) / m_fWidth);
++m_aCounters[i];
}
|
java
|
{
"resource": ""
}
|
q179124
|
Buckets.print
|
test
|
public void print ()
{
// Get the longest bar's length.
int maxCount = 0;
for (int i = 0; i < m_n; ++i)
{
maxCount = Math.max (maxCount, m_aCounters[i]);
}
// Compute the scaling factor.
final float factor = ((float) MAX_BAR_SIZE) / maxCount;
// Loop to print each bar.
for (int i = 0; i < m_n; ++i)
{
final int b = m_aCounters[i];
// Interval number.
m_aAlignRight.print (i, 2);
m_aAlignRight.print (b, 7);
System.out.print (": ");
// Bar.
final int length = Math.round (factor * b);
for (int j = 0; j < length; ++j)
System.out.print ("*");
System.out.println ();
}
}
|
java
|
{
"resource": ""
}
|
q179125
|
Complex.add
|
test
|
public Complex add (final Complex z)
{
return new Complex (m_fReal + z.real (), m_fImaginary + z.imaginary ());
}
|
java
|
{
"resource": ""
}
|
q179126
|
Complex.subtract
|
test
|
public Complex subtract (final Complex z)
{
return new Complex (m_fReal - z.real (), m_fImaginary - z.imaginary ());
}
|
java
|
{
"resource": ""
}
|
q179127
|
Complex.multiply
|
test
|
public Complex multiply (final Complex z)
{
return new Complex (m_fReal * z.real () -
m_fImaginary * z.imaginary (),
m_fReal * z.imaginary () + m_fImaginary * z.real ());
}
|
java
|
{
"resource": ""
}
|
q179128
|
Complex.divide
|
test
|
public Complex divide (final Complex z)
{
final float denom = z.real () * z.real () + z.imaginary () * z.imaginary ();
final float qr = (m_fReal * z.real () + m_fImaginary * z.imaginary ()) / denom;
final float qi = (m_fImaginary * z.real () - m_fReal * z.imaginary ()) / denom;
return new Complex (qr, qi);
}
|
java
|
{
"resource": ""
}
|
q179129
|
RowVector._set
|
test
|
private void _set (final Matrix m)
{
m_nRows = 1;
m_nCols = m.m_nCols;
m_aValues = m.m_aValues;
}
|
java
|
{
"resource": ""
}
|
q179130
|
Matrix.getRow
|
test
|
public RowVector getRow (final int r) throws MatrixException
{
if ((r < 0) || (r >= m_nRows))
{
throw new MatrixException (MatrixException.INVALID_INDEX);
}
final RowVector rv = new RowVector (m_nCols);
for (int c = 0; c < m_nCols; ++c)
{
rv.m_aValues[0][c] = m_aValues[r][c];
}
return rv;
}
|
java
|
{
"resource": ""
}
|
q179131
|
Matrix.getColumn
|
test
|
public ColumnVector getColumn (final int c) throws MatrixException
{
if ((c < 0) || (c >= m_nCols))
{
throw new MatrixException (MatrixException.INVALID_INDEX);
}
final ColumnVector cv = new ColumnVector (m_nRows);
for (int r = 0; r < m_nRows; ++r)
{
cv.m_aValues[r][0] = m_aValues[r][c];
}
return cv;
}
|
java
|
{
"resource": ""
}
|
q179132
|
Matrix.set
|
test
|
protected void set (final float values[][])
{
m_nRows = values.length;
m_nCols = values[0].length;
m_aValues = values;
for (int r = 1; r < m_nRows; ++r)
{
m_nCols = Math.min (m_nCols, values[r].length);
}
}
|
java
|
{
"resource": ""
}
|
q179133
|
Matrix.transpose
|
test
|
public Matrix transpose ()
{
final float tv[][] = new float [m_nCols] [m_nRows]; // transposed values
// Set the values of the transpose.
for (int r = 0; r < m_nRows; ++r)
{
for (int c = 0; c < m_nCols; ++c)
{
tv[c][r] = m_aValues[r][c];
}
}
return new Matrix (tv);
}
|
java
|
{
"resource": ""
}
|
q179134
|
Matrix.add
|
test
|
public Matrix add (final Matrix m) throws MatrixException
{
// Validate m's size.
if ((m_nRows != m.m_nRows) && (m_nCols != m.m_nCols))
{
throw new MatrixException (MatrixException.INVALID_DIMENSIONS);
}
final float sv[][] = new float [m_nRows] [m_nCols]; // sum values
// Compute values of the sum.
for (int r = 0; r < m_nRows; ++r)
{
for (int c = 0; c < m_nCols; ++c)
{
sv[r][c] = m_aValues[r][c] + m.m_aValues[r][c];
}
}
return new Matrix (sv);
}
|
java
|
{
"resource": ""
}
|
q179135
|
Matrix.subtract
|
test
|
public Matrix subtract (final Matrix m) throws MatrixException
{
// Validate m's size.
if ((m_nRows != m.m_nRows) && (m_nCols != m.m_nCols))
{
throw new MatrixException (MatrixException.INVALID_DIMENSIONS);
}
final float dv[][] = new float [m_nRows] [m_nCols]; // difference values
// Compute values of the difference.
for (int r = 0; r < m_nRows; ++r)
{
for (int c = 0; c < m_nCols; ++c)
{
dv[r][c] = m_aValues[r][c] - m.m_aValues[r][c];
}
}
return new Matrix (dv);
}
|
java
|
{
"resource": ""
}
|
q179136
|
Matrix.multiply
|
test
|
public Matrix multiply (final float k)
{
final float pv[][] = new float [m_nRows] [m_nCols]; // product values
// Compute values of the product.
for (int r = 0; r < m_nRows; ++r)
{
for (int c = 0; c < m_nCols; ++c)
{
pv[r][c] = k * m_aValues[r][c];
}
}
return new Matrix (pv);
}
|
java
|
{
"resource": ""
}
|
q179137
|
Matrix.multiply
|
test
|
public Matrix multiply (final Matrix m) throws MatrixException
{
// Validate m's dimensions.
if (m_nCols != m.m_nRows)
{
throw new MatrixException (MatrixException.INVALID_DIMENSIONS);
}
final float pv[][] = new float [m_nRows] [m.m_nCols]; // product values
// Compute values of the product.
for (int r = 0; r < m_nRows; ++r)
{
for (int c = 0; c < m.m_nCols; ++c)
{
float dot = 0;
for (int k = 0; k < m_nCols; ++k)
{
dot += m_aValues[r][k] * m.m_aValues[k][c];
}
pv[r][c] = dot;
}
}
return new Matrix (pv);
}
|
java
|
{
"resource": ""
}
|
q179138
|
Matrix.print
|
test
|
public void print (final int width, @Nonnull final PrintStream aPS)
{
final SystemOutAlignRight ar = new SystemOutAlignRight (aPS);
for (int r = 0; r < m_nRows; ++r)
{
ar.print ("Row ", 0);
ar.print (r + 1, 2);
ar.print (":", 0);
for (int c = 0; c < m_nCols; ++c)
{
ar.print (m_aValues[r][c], width);
}
ar.println ();
}
}
|
java
|
{
"resource": ""
}
|
q179139
|
SldEditorToolBarButton.setResource
|
test
|
public void setResource(ImageResource imageResource) {
Image img = new Image(imageResource);
DOM.insertChild(getElement(), img.getElement(), 0);
}
|
java
|
{
"resource": ""
}
|
q179140
|
RegressionLine._validateCoefficients
|
test
|
private void _validateCoefficients ()
{
if (m_bCoefsValid)
return;
if (m_nDataPoints >= 2)
{
final float xBar = (float) m_dSumX / m_nDataPoints;
final float yBar = (float) m_dSumY / m_nDataPoints;
m_fA1 = (float) ((m_nDataPoints * m_dSumXY - m_dSumX * m_dSumY) / (m_nDataPoints * m_dSumXX - m_dSumX * m_dSumX));
m_fA0 = yBar - m_fA1 * xBar;
}
else
{
m_fA0 = m_fA1 = Float.NaN;
}
m_bCoefsValid = true;
}
|
java
|
{
"resource": ""
}
|
q179141
|
FixedPointRootFinder.computeNextPosition
|
test
|
@Override
protected void computeNextPosition ()
{
m_fPrevXn = m_fXn;
m_fXn = m_fGn;
m_fGn = m_aFunction.at (m_fXn);
}
|
java
|
{
"resource": ""
}
|
q179142
|
SldModelImpl.clear
|
test
|
public void clear() {
rawSld = new RawSld();
dirty = false;
valid = false;
template = null;
sldDescriptor = null;
}
|
java
|
{
"resource": ""
}
|
q179143
|
InMemorySldServiceImpl.toXml
|
test
|
public RawSld toXml(StyledLayerDescriptorInfo sldi) throws SldException {
try {
if (sldi.getVersion() == null) {
sldi.setVersion("1.0.0");
}
return parseSldI(sldi);
} catch (JiBXException e) {
throw new SldException("Validation error", e);
}
}
|
java
|
{
"resource": ""
}
|
q179144
|
InMemorySldServiceImpl.toSldI
|
test
|
public StyledLayerDescriptorInfo toSldI(RawSld sld) throws SldException {
try {
return parseXml(sld.getName(), sld.getXml());
} catch (JiBXException e) {
throw new SldException("Validation error", e);
}
}
|
java
|
{
"resource": ""
}
|
q179145
|
InMemorySldServiceImpl.validate
|
test
|
public void validate(StyledLayerDescriptorInfo sld) throws SldException {
try {
parseSldI(sld);
} catch (JiBXException e) {
throw new SldException("Validation error", e);
}
}
|
java
|
{
"resource": ""
}
|
q179146
|
InMemorySldServiceImpl.validate
|
test
|
public boolean validate(RawSld sld) throws SldException {
try {
parseXml("", sld.getXml());
return true;
} catch (JiBXException e) {
return false;
}
}
|
java
|
{
"resource": ""
}
|
q179147
|
TrapezoidalIntegrator._areaOf
|
test
|
private float _areaOf (final float x1, final float h)
{
final float x2 = x1 + h; // right bound of the region
final float y1 = m_aIntegrand.at (x1); // value at left bound
final float y2 = m_aIntegrand.at (x2); // value at right bound
final float area = h * (y1 + y2) / 2; // area of the region
return area;
}
|
java
|
{
"resource": ""
}
|
q179148
|
SquareMatrix._set
|
test
|
private void _set (final Matrix m)
{
this.m_nRows = this.m_nCols = Math.min (m.m_nRows, m.m_nCols);
this.m_aValues = m.m_aValues;
}
|
java
|
{
"resource": ""
}
|
q179149
|
SquareMatrix.set
|
test
|
@Override
protected void set (final float values[][])
{
super.set (values);
m_nRows = m_nCols = Math.min (m_nRows, m_nCols);
}
|
java
|
{
"resource": ""
}
|
q179150
|
InvertibleMatrix.inverse
|
test
|
public InvertibleMatrix inverse () throws MatrixException
{
final InvertibleMatrix inverse = new InvertibleMatrix (m_nRows);
final IdentityMatrix identity = new IdentityMatrix (m_nRows);
// Compute each column of the inverse matrix
// using columns of the identity matrix.
for (int c = 0; c < m_nCols; ++c)
{
final ColumnVector col = solve (identity.getColumn (c), true);
inverse.setColumn (col, c);
}
return inverse;
}
|
java
|
{
"resource": ""
}
|
q179151
|
InvertibleMatrix.determinant
|
test
|
public float determinant () throws MatrixException
{
decompose ();
// Each row exchange during forward elimination flips the sign
// of the determinant, so check for an odd number of exchanges.
float determinant = ((m_nExchangeCount & 1) == 0) ? 1 : -1;
// Form the product of the diagonal elements of matrix U.
for (int i = 0; i < m_nRows; ++i)
{
final int pi = m_aPermutation[i]; // permuted index
determinant *= m_aLU.at (pi, i);
}
return determinant;
}
|
java
|
{
"resource": ""
}
|
q179152
|
InvertibleMatrix.norm
|
test
|
public float norm ()
{
float sum = 0;
for (int r = 0; r < m_nRows; ++r)
{
for (int c = 0; c < m_nCols; ++c)
{
final float v = m_aValues[r][c];
sum += v * v;
}
}
return (float) Math.sqrt (sum);
}
|
java
|
{
"resource": ""
}
|
q179153
|
LinearSystem.solve
|
test
|
public ColumnVector solve (final ColumnVector b, final boolean improve) throws MatrixException
{
// Validate b's size.
if (b.m_nRows != m_nRows)
{
throw new MatrixException (MatrixException.INVALID_DIMENSIONS);
}
decompose ();
// Solve Ly = b for y by forward substitution.
// Solve Ux = y for x by back substitution.
final ColumnVector y = _forwardSubstitution (b);
final ColumnVector x = _backSubstitution (y);
// Improve and return x.
if (improve)
_improve (b, x);
return x;
}
|
java
|
{
"resource": ""
}
|
q179154
|
LinearSystem.printDecomposed
|
test
|
public void printDecomposed (final int width, @Nonnull final PrintStream aPS) throws MatrixException
{
decompose ();
final SystemOutAlignRight ar = new SystemOutAlignRight (aPS);
for (int r = 0; r < m_nRows; ++r)
{
final int pr = m_aPermutation[r]; // permuted row index
ar.print ("Row ", 0);
ar.print (r + 1, 2);
ar.print (":", 0);
for (int c = 0; c < m_nCols; ++c)
{
ar.print (m_aLU.m_aValues[pr][c], width);
}
ar.println ();
}
}
|
java
|
{
"resource": ""
}
|
q179155
|
LinearSystem._forwardElimination
|
test
|
private void _forwardElimination (final float scales[]) throws MatrixException
{
// Loop once per pivot row 0..nRows-1.
for (int rPivot = 0; rPivot < m_nRows - 1; ++rPivot)
{
float largestScaledElmt = 0;
int rLargest = 0;
// Starting from the pivot row rPivot, look down
// column rPivot to find the largest scaled element.
for (int r = rPivot; r < m_nRows; ++r)
{
// Use the permuted row index.
final int pr = m_aPermutation[r];
final float absElmt = Math.abs (m_aLU.at (pr, rPivot));
final float scaledElmt = absElmt * scales[pr];
if (largestScaledElmt < scaledElmt)
{
// The largest scaled element and
// its row index.
largestScaledElmt = scaledElmt;
rLargest = r;
}
}
// Is the matrix singular?
if (largestScaledElmt == 0)
{
throw new MatrixException (MatrixException.SINGULAR);
}
// Exchange rows if necessary to choose the best
// pivot element by making its row the pivot row.
if (rLargest != rPivot)
{
final int temp = m_aPermutation[rPivot];
m_aPermutation[rPivot] = m_aPermutation[rLargest];
m_aPermutation[rLargest] = temp;
++m_nExchangeCount;
}
// Use the permuted pivot row index.
final int prPivot = m_aPermutation[rPivot];
final float pivotElmt = m_aLU.at (prPivot, rPivot);
// Do the elimination below the pivot row.
for (int r = rPivot + 1; r < m_nRows; ++r)
{
// Use the permuted row index.
final int pr = m_aPermutation[r];
final float multiple = m_aLU.at (pr, rPivot) / pivotElmt;
// Set the multiple into matrix L.
m_aLU.set (pr, rPivot, multiple);
// Eliminate an unknown from matrix U.
if (multiple != 0)
{
for (int c = rPivot + 1; c < m_nCols; ++c)
{
float elmt = m_aLU.at (pr, c);
// Subtract the multiple of the pivot row.
elmt -= multiple * m_aLU.at (prPivot, c);
m_aLU.set (pr, c, elmt);
}
}
}
}
}
|
java
|
{
"resource": ""
}
|
q179156
|
LinearSystem._forwardSubstitution
|
test
|
private ColumnVector _forwardSubstitution (final ColumnVector b) throws MatrixException
{
final ColumnVector y = new ColumnVector (m_nRows);
// Do forward substitution.
for (int r = 0; r < m_nRows; ++r)
{
final int pr = m_aPermutation[r]; // permuted row index
float dot = 0;
for (int c = 0; c < r; ++c)
{
dot += m_aLU.at (pr, c) * y.at (c);
}
y.set (r, b.at (pr) - dot);
}
return y;
}
|
java
|
{
"resource": ""
}
|
q179157
|
LinearSystem._backSubstitution
|
test
|
private ColumnVector _backSubstitution (final ColumnVector y) throws MatrixException
{
final ColumnVector x = new ColumnVector (m_nRows);
// Do back substitution.
for (int r = m_nRows - 1; r >= 0; --r)
{
final int pr = m_aPermutation[r]; // permuted row index
float dot = 0;
for (int c = r + 1; c < m_nRows; ++c)
{
dot += m_aLU.at (pr, c) * x.at (c);
}
x.set (r, (y.at (r) - dot) / m_aLU.at (pr, r));
}
return x;
}
|
java
|
{
"resource": ""
}
|
q179158
|
LinearSystem._improve
|
test
|
private void _improve (final ColumnVector b, final ColumnVector x) throws MatrixException
{
// Find the largest x element.
float largestX = 0;
for (int r = 0; r < m_nRows; ++r)
{
final float absX = Math.abs (x.m_aValues[r][0]);
if (largestX < absX)
largestX = absX;
}
// Is x already as good as possible?
if (largestX == 0)
return;
final ColumnVector residuals = new ColumnVector (m_nRows);
// Iterate to improve x.
for (int iter = 0; iter < MAX_ITER; ++iter)
{
// Compute residuals = b - Ax.
// Must use double precision!
for (int r = 0; r < m_nRows; ++r)
{
double dot = 0;
for (int c = 0; c < m_nRows; ++c)
{
final double elmt = at (r, c);
dot += elmt * x.at (c); // dbl.prec. *
}
final double value = b.at (r) - dot; // dbl.prec. -
residuals.set (r, (float) value);
}
// Solve Az = residuals for z.
final ColumnVector z = solve (residuals, false);
// Set x = x + z.
// Find largest the largest difference.
float largestDiff = 0;
for (int r = 0; r < m_nRows; ++r)
{
final float oldX = x.at (r);
x.set (r, oldX + z.at (r));
final float diff = Math.abs (x.at (r) - oldX);
if (largestDiff < diff)
largestDiff = diff;
}
// Is any further improvement possible?
if (largestDiff < largestX * TOLERANCE)
return;
}
// Failed to converge because A is nearly singular.
throw new MatrixException (MatrixException.NO_CONVERGENCE);
}
|
java
|
{
"resource": ""
}
|
q179159
|
IdentityMatrix.convert
|
test
|
public static void convert (final SquareMatrix sm)
{
for (int r = 0; r < sm.m_nRows; ++r)
{
for (int c = 0; c < sm.m_nCols; ++c)
{
sm.m_aValues[r][c] = (r == c) ? 1 : 0;
}
}
}
|
java
|
{
"resource": ""
}
|
q179160
|
RandomExponential.nextVonNeumann
|
test
|
public float nextVonNeumann ()
{
int n;
int k = 0;
float u1;
// Loop to try sequences of uniformly-distributed
// random values.
for (;;)
{
n = 1;
u1 = GENERATOR.nextFloat ();
float u = u1;
float uPrev = Float.NaN;
// Loop to generate a sequence of ramdom values
// as long as they are decreasing.
for (;;)
{
uPrev = u;
u = GENERATOR.nextFloat ();
// No longer decreasing?
if (u > uPrev)
{
// n is even.
if ((n & 1) == 0)
{
return u1 + k; // return a random value
}
// n is odd.
++k;
break; // try another sequence
}
++n;
}
}
}
|
java
|
{
"resource": ""
}
|
q179161
|
RegulaFalsiRootFinder.doIterationProcedure
|
test
|
@Override
protected void doIterationProcedure (final int n)
{
if (n == 1)
return; // already initialized
if (m_fFalse < 0)
{
m_fXNeg = m_fXFalse; // the root is in the xPos side
m_fNeg = m_fFalse;
}
else
{
m_fXPos = m_fXFalse; // the root is in the xNeg side
m_fPos = m_fFalse;
}
}
|
java
|
{
"resource": ""
}
|
q179162
|
RegulaFalsiRootFinder.computeNextPosition
|
test
|
@Override
protected void computeNextPosition ()
{
m_fPrevXFalse = m_fXFalse;
m_fXFalse = m_fXPos - m_fPos * (m_fXNeg - m_fXPos) / (m_fNeg - m_fPos);
m_fFalse = m_aFunction.at (m_fXFalse);
}
|
java
|
{
"resource": ""
}
|
q179163
|
RegulaFalsiRootFinder.checkPosition
|
test
|
@Override
protected void checkPosition () throws AbstractRootFinder.PositionUnchangedException
{
if (EqualsHelper.equals (m_fXFalse, m_fPrevXFalse))
{
throw new AbstractRootFinder.PositionUnchangedException ();
}
}
|
java
|
{
"resource": ""
}
|
q179164
|
ImprovedRegulaFalsiRootFinder.computeNextPosition
|
test
|
@Override
protected void computeNextPosition ()
{
m_fPrevXFalse = m_fXFalse;
m_fPrevFFalse = m_fFalse;
m_fXFalse = m_fXPos - m_fPos * (m_fXNeg - m_fXPos) / (m_fNeg - m_fPos);
m_fFalse = m_aFunction.at (m_fXFalse);
m_bDecreasePos = m_bDecreaseNeg = false;
// If there was no sign change in f(xFalse),
// or if this is the first iteration step,
// then decrease the slope of the secant.
if (Float.isNaN (m_fPrevFFalse) || (m_fPrevFFalse * m_fFalse > 0))
{
if (m_fFalse < 0)
m_bDecreasePos = true;
else
m_bDecreaseNeg = true;
}
}
|
java
|
{
"resource": ""
}
|
q179165
|
AbstractRootFinder.checkInterval
|
test
|
public void checkInterval (final float x1, final float x2) throws InvalidIntervalException
{
final float y1 = m_aFunction.at (x1);
final float y2 = m_aFunction.at (x2);
// The interval is invalid if y1 and y2 have the same signs.
if (y1 * y2 > 0)
throw new InvalidIntervalException ();
}
|
java
|
{
"resource": ""
}
|
q179166
|
KahanSummation.add
|
test
|
public void add (final float addend)
{
// Correct the addend value and add it to the running sum.
m_fCorrectedAddend = addend + m_fCorrection;
final float tempSum = m_fSum + m_fCorrectedAddend;
// Compute the next correction and set the running sum.
// The parentheses are necessary to compute the high-order
// bits of the addend.
m_fCorrection = m_fCorrectedAddend - (tempSum - m_fSum);
m_fSum = tempSum;
}
|
java
|
{
"resource": ""
}
|
q179167
|
ModuloArithmetic.multiply
|
test
|
public static int multiply (final int pa, final int pb, final int m)
{
int a = pa;
int b = pb;
int product = 0;
// Loop to compute product = (a*b)%m.
while (a > 0)
{
// Does the rightmost bit of a == 1?
if ((a & 1) == 1)
{
product += b;
product %= m;
}
// Double b modulo m, and
// shift a 1 bit to the right.
b <<= 1;
b %= m;
a >>= 1;
}
return product;
}
|
java
|
{
"resource": ""
}
|
q179168
|
ModuloArithmetic.raise
|
test
|
public static int raise (final int pbase, final int pexponent, final int m)
{
int base = pbase;
int exponent = pexponent;
int power = 1;
// Loop to compute power = (base^exponent)%m.
while (exponent > 0)
{
// Does the rightmost bit of the exponent == 1?
if ((exponent & 1) == 1)
{
power = multiply (power, base, m);
}
// Square the base modulo m and
// shift the exponent 1 bit to the right.
base = multiply (base, base, m);
exponent >>= 1;
}
return power;
}
|
java
|
{
"resource": ""
}
|
q179169
|
SecantRootFinder.doIterationProcedure
|
test
|
@Override
protected void doIterationProcedure (final int n)
{
if (n == 1)
return; // already initialized
// Use the latest two points.
m_fXnm1 = m_fXn; // x[n-1] = x[n]
m_fXn = m_fXnp1; // x[n] = x[n+1]
m_fFnm1 = m_fFn; // f(x[n-1]) = f(x[n])
m_fFn = m_fFnp1; // f(x[n]) = f(x[n+1])
}
|
java
|
{
"resource": ""
}
|
q179170
|
SldEditor.getSldManager
|
test
|
public SldManager getSldManager() {
if (sldManager == null) {
sldManager = new SldManagerImpl(getEventBus(), getSldEditorServiceFactory().createSldGwtServiceAsync());
}
return sldManager;
}
|
java
|
{
"resource": ""
}
|
q179171
|
IEEE754._toCharBitArray
|
test
|
private static char [] _toCharBitArray (final long pvalue, final int size)
{
long value = pvalue;
final char bits[] = new char [size];
// Convert each bit from right to left.
for (int i = size - 1; i >= 0; --i)
{
bits[i] = (value & 1) == 0 ? '0' : '1';
value >>>= 1;
}
return bits;
}
|
java
|
{
"resource": ""
}
|
q179172
|
IEEE754._decompose
|
test
|
private void _decompose (final char [] bits,
final int bias,
final int reserved,
final int signIndex,
final int signSize,
final int exponentIndex,
final int exponentSize,
final int fractionIndex,
final int fractionSize)
{
this.m_nBias = bias;
// Extract the individual parts as strings of '0' and '1'.
m_sSignBit = new String (bits, signIndex, signSize);
m_sExponentBits = new String (bits, exponentIndex, exponentSize);
m_sFractionBits = new String (bits, fractionIndex, fractionSize);
try
{
m_nBiased = Integer.parseInt (m_sExponentBits, 2);
m_nFraction = Long.parseLong (m_sFractionBits, 2);
}
catch (final NumberFormatException ex)
{}
m_bIsZero = (m_nBiased == 0) && (m_nFraction == 0);
m_bIsDenormalized = (m_nBiased == 0) && (m_nFraction != 0);
m_bIsReserved = (m_nBiased == reserved);
m_sImpliedBit = m_bIsDenormalized || m_bIsZero || m_bIsReserved ? "0" : "1";
}
|
java
|
{
"resource": ""
}
|
q179173
|
IEEE754.print
|
test
|
public void print (@Nonnull final PrintStream aPW)
{
aPW.println ("------------------------------");
// Print the value.
if (isDouble ())
aPW.println ("double value = " + doubleValue ());
else
aPW.println ("float value = " + floatValue ());
// Print the sign.
aPW.print ("sign=" + signBit ());
// Print the bit representation of the exponent and its
// biased and unbiased values. Indicate whether the value
// is denormalized, or whether the exponent is reserved.
aPW.print (", exponent=" + exponentBits () + " (biased=" + biasedExponent ());
if (isZero ())
aPW.println (", zero)");
else
if (isExponentReserved ())
aPW.println (", reserved)");
else
if (isDenormalized ())
aPW.println (", denormalized, use " + unbiasedExponent () + ")");
else
aPW.println (", normalized, unbiased=" + unbiasedExponent () + ")");
// Print the significand.
aPW.println ("significand=" + significandBits ());
}
|
java
|
{
"resource": ""
}
|
q179174
|
IEEE754.validateFloatBiasedExponent
|
test
|
public static void validateFloatBiasedExponent (final int biased) throws IEEE754Exception
{
if ((biased < 0) || (biased > IEEE754Constants.FLOAT_EXPONENT_RESERVED))
{
throw new IEEE754Exception ("The biased exponent value should be " +
"0 through " +
IEEE754Constants.FLOAT_EXPONENT_RESERVED +
".");
}
}
|
java
|
{
"resource": ""
}
|
q179175
|
IEEE754.validateFloatUnbiasedExponent
|
test
|
public static void validateFloatUnbiasedExponent (final int unbiased) throws IEEE754Exception
{
if ((unbiased < -IEEE754Constants.FLOAT_EXPONENT_BIAS + 1) || (unbiased > IEEE754Constants.FLOAT_EXPONENT_BIAS))
{
throw new IEEE754Exception ("The unbiased exponent value should be " +
-(IEEE754Constants.FLOAT_EXPONENT_BIAS - 1) +
" through " +
IEEE754Constants.FLOAT_EXPONENT_BIAS +
".");
}
}
|
java
|
{
"resource": ""
}
|
q179176
|
IEEE754.validateDoubleBiasedExponent
|
test
|
public static void validateDoubleBiasedExponent (final int biased) throws IEEE754Exception
{
if ((biased < 0) || (biased > IEEE754Constants.DOUBLE_EXPONENT_RESERVED))
{
throw new IEEE754Exception ("The biased exponent value should be " +
"0 through " +
IEEE754Constants.DOUBLE_EXPONENT_RESERVED +
".");
}
}
|
java
|
{
"resource": ""
}
|
q179177
|
IEEE754.validateDoubleUnbiasedExponent
|
test
|
public static void validateDoubleUnbiasedExponent (final int unbiased) throws IEEE754Exception
{
if ((unbiased < -IEEE754Constants.DOUBLE_EXPONENT_BIAS + 1) || (unbiased > IEEE754Constants.DOUBLE_EXPONENT_BIAS))
{
throw new IEEE754Exception ("The unbiased exponent value should be " +
-(IEEE754Constants.DOUBLE_EXPONENT_BIAS - 1) +
" through " +
IEEE754Constants.DOUBLE_EXPONENT_BIAS +
".");
}
}
|
java
|
{
"resource": ""
}
|
q179178
|
SldEditorServiceFactory.createSldGwtServiceAsync
|
test
|
public SldGwtServiceAsync createSldGwtServiceAsync() {
this.service = GWT.create(SldGwtService.class);
ServiceDefTarget endpoint = (ServiceDefTarget) service;
endpoint.setServiceEntryPoint(GWT.getHostPageBaseURL() + "d/sldTemplates");
return service;
}
|
java
|
{
"resource": ""
}
|
q179179
|
RandomNormal.nextCentral
|
test
|
public float nextCentral ()
{
// Average 12 uniformly-distributed random values.
float sum = 0.0f;
for (int j = 0; j < 12; ++j)
sum += GENERATOR.nextFloat ();
// Subtract 6 to center about 0.
return m_fStddev * (sum - 6) + m_fMean;
}
|
java
|
{
"resource": ""
}
|
q179180
|
RandomNormal.nextPolar
|
test
|
public float nextPolar ()
{
// If there's a saved value, return it.
if (m_bHaveNextPolar)
{
m_bHaveNextPolar = false;
return m_fNextPolar;
}
// point coordinates and their radius
float u1, u2, r;
do
{
// u1 and u2 will be uniformly-distributed
// random values in [-1, +1).
u1 = 2 * GENERATOR.nextFloat () - 1;
u2 = 2 * GENERATOR.nextFloat () - 1;
// Want radius r inside the unit circle.
r = u1 * u1 + u2 * u2;
} while (r >= 1);
// Factor incorporates the standard deviation.
final float factor = (float) (m_fStddev * Math.sqrt (-2 * Math.log (r) / r));
// v1 and v2 are normally-distributed random values.
final float v1 = factor * u1 + m_fMean;
final float v2 = factor * u2 + m_fMean;
// Save v1 for next time.
m_fNextPolar = v1;
m_bHaveNextPolar = true;
return v2;
}
|
java
|
{
"resource": ""
}
|
q179181
|
RandomNormal.nextRatio
|
test
|
public float nextRatio ()
{
float u, v, x, xx;
do
{
// u and v are two uniformly-distributed random values
// in [0, 1), and u != 0.
while ((u = GENERATOR.nextFloat ()) == 0)
{
// try again if 0
}
v = GENERATOR.nextFloat ();
// y coord of point (u, y)
final float y = C1 * (v - 0.5f);
// ratio of point's coords
x = y / u;
xx = x * x;
} while ((xx > 5f - C2 * u) && // quick acceptance
((xx >= C3 / u + 1.4f) || // quick rejection
(xx > (float) (-4 * Math.log (u)))) // final test
);
return m_fStddev * x + m_fMean;
}
|
java
|
{
"resource": ""
}
|
q179182
|
PrimeFactors.primeSieve
|
test
|
public static boolean [] primeSieve (final int n)
{
final int halfN = (n + 1) >> 1;
final boolean sieve[] = new boolean [n + 1];
// Initialize every integer from 2 onwards to prime.
for (int i = 2; i <= n; ++i)
sieve[i] = true;
int prime = 2; // first prime number
// Loop to create the sieve.
while (prime < halfN)
{
// Mark as composites multiples of the prime.
for (int composite = prime << 1; composite <= n; composite += prime)
sieve[composite] = false;
// Skip over composites to the next prime.
while ((++prime < halfN) && (!sieve[prime]))
{}
}
return sieve;
}
|
java
|
{
"resource": ""
}
|
q179183
|
PrimeFactors.factorsOf
|
test
|
public static int [] factorsOf (final int pn)
{
int n = pn;
final boolean isPrime[] = primeSieve (n); // primes <= n
final ICommonsList <Integer> v = new CommonsArrayList<> ();
// Loop to try prime divisors.
for (int factor = 2; n > 1; ++factor)
{
if (isPrime[factor] && (n % factor == 0))
{
// Prime divisor found.
v.add (Integer.valueOf (factor));
// Factor out multiples of the divisor.
do
{
n /= factor;
} while (n % factor == 0);
}
}
// Create an array of the distinct prime factors.
final int factors[] = new int [v.size ()];
for (int i = 0; i < v.size (); ++i)
{
factors[i] = v.get (i).intValue ();
}
return factors;
}
|
java
|
{
"resource": ""
}
|
q179184
|
BisectionRootFinder.doIterationProcedure
|
test
|
@Override
protected void doIterationProcedure (final int n)
{
if (n == 1)
return; // already initialized
if (m_fMid < 0)
{
m_fXNeg = m_fXMid; // the root is in the xPos half
m_fNeg = m_fMid;
}
else
{
m_fXPos = m_fXMid; // the root is in the xNeg half
m_fPos = m_fMid;
}
}
|
java
|
{
"resource": ""
}
|
q179185
|
BisectionRootFinder.computeNextPosition
|
test
|
@Override
protected void computeNextPosition ()
{
m_fPrevXMid = m_fXMid;
m_fXMid = (m_fXNeg + m_fXPos) / 2;
m_fMid = m_aFunction.at (m_fXMid);
}
|
java
|
{
"resource": ""
}
|
q179186
|
BisectionRootFinder.checkPosition
|
test
|
@Override
protected void checkPosition () throws AbstractRootFinder.PositionUnchangedException
{
if (EqualsHelper.equals (m_fXMid, m_fPrevXMid))
{
throw new AbstractRootFinder.PositionUnchangedException ();
}
}
|
java
|
{
"resource": ""
}
|
q179187
|
JavaFXExtension.setJavaFxApplication
|
test
|
public static void setJavaFxApplication(final CdiApplication javaFxApplication) {
final CountDownLatch latch = new CountDownLatch(1);
Platform.runLater(() -> {
JAVA_FX_APPLICATION.set(javaFxApplication);
latch.countDown();
});
if (!Platform.isFxApplicationThread()) {
try {
latch.await();
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
}
}
|
java
|
{
"resource": ""
}
|
q179188
|
Calabash.setConfiguration
|
test
|
public void setConfiguration(File configFile) {
if (configFile == null)
nextConfig = null;
else
try {
XProcConfiguration config = new XProcConfiguration("he", false);
nextConfig = config.getProcessor().newDocumentBuilder()
.build(new SAXSource(new InputSource(new FileReader(configFile)))); }
catch (FileNotFoundException e) {
throw new IllegalArgumentException("Config file does not exist", e); }
catch (SaxonApiException e) {
throw new RuntimeException(e); }
}
|
java
|
{
"resource": ""
}
|
q179189
|
Calabash.setDefaultConfiguration
|
test
|
public void setDefaultConfiguration(Reader defaultConfig) {
XProcConfiguration config = new XProcConfiguration("he", false);
try {
nextDefaultConfig = config.getProcessor().newDocumentBuilder()
.build(new SAXSource(new InputSource(defaultConfig))); }
catch (SaxonApiException e) {
throw new RuntimeException(e); }
}
|
java
|
{
"resource": ""
}
|
q179190
|
CdiFXMLLoaderFactory.initializeFXMLLoader
|
test
|
static void initializeFXMLLoader(final FXMLLoader fxmlLoader, final Class<?> targetClass, final String location, final String resources, final String charset) {
checkAndSetLocation(fxmlLoader, targetClass, location);
if (charset != null && !charset.equals(CHARSET_UNSPECIFIED)) {
fxmlLoader.setCharset(Charset.forName(charset));
}
if (resources != null && !resources.equals(RESOURCES_UNSPECIFIED)) {
fxmlLoader.setResources(ResourceBundle.getBundle(resources));
}
}
|
java
|
{
"resource": ""
}
|
q179191
|
ReverseGeocodeRequestBuilder.latlng
|
test
|
public ReverseGeocodeRequestBuilder latlng(Double lat, Double lng) {
parameters.put("latlng", lat + "," + lng);
return this;
}
|
java
|
{
"resource": ""
}
|
q179192
|
ServiceRegistryConfigurationProvider.getHostPortPair
|
test
|
public static InetSocketAddress getHostPortPair(Service svc) {
try {
return new InetSocketAddress(svc.getMetadata().get("service.host"),
Integer.parseInt(svc.getMetadata().get("service.port")));
} catch (Exception e) {
logger.error("Exception extracting metadata from service instance {}", svc, e);
return null;
}
}
|
java
|
{
"resource": ""
}
|
q179193
|
AttrbuteFilterExpressionCollectionEvaluator.getApplicableAttributeDefinition
|
test
|
protected AttributeDefinition getApplicableAttributeDefinition(final UUID attributeDefinitionUuid, final List<AttributeDefinition> attributeDefinitions) {
if (LOG.isTraceEnabled()) {
LOG.entry(attributeDefinitionUuid, attributeDefinitions);
}
AttributeDefinition attributeDefinition = null;
for (AttributeDefinition anAttributeDefinition : attributeDefinitions) {
if (anAttributeDefinition.getUUID().equals(attributeDefinitionUuid)) {
attributeDefinition = anAttributeDefinition;
break;
}
}
if (LOG.isTraceEnabled()) {
LOG.exit(attributeDefinition);
}
return attributeDefinition;
}
|
java
|
{
"resource": ""
}
|
q179194
|
AttrbuteFilterExpressionCollectionEvaluator.evaluate
|
test
|
protected boolean evaluate(final UUID attributeDefinitionUuid, final AttributeFilterExpression attributeFilter, final Map<UUID, String> eventAttributes, final List<AttributeDefinition> attributeDefinitions) throws ParseException {
if (LOG.isTraceEnabled()) {
LOG.entry(attributeDefinitionUuid, attributeFilter, eventAttributes, attributeDefinitions);
}
// Find a matching attribute
final String attributeValue = eventAttributes.get(attributeDefinitionUuid);
if (attributeValue == null) {
// No attribute value to match attribute filter.
if (LOG.isTraceEnabled()) {
LOG.trace("An attributeValue was not specified for this attribute definition.");
LOG.exit(false);
}
return false;
}
// Find the Attribute definition that matches our filter.
final AttributeDefinition attributeDefinition = getApplicableAttributeDefinition(attributeDefinitionUuid, attributeDefinitions);
if (attributeDefinition == null) {
// Really shouldn't have any filters defined for attributes that don't exist.
if (LOG.isTraceEnabled()) {
LOG.trace("The attributeDefinition did not exist.");
LOG.exit(false);
}
return false;
}
final Unit unit = attributeDefinition.getUnits();
try {
boolean result = unit.evaluate(attributeFilter.getOperator(), attributeValue, attributeFilter.getOperand());
if (LOG.isTraceEnabled()) {
LOG.exit(result);
}
return result;
} catch (ParseException e) {
if (LOG.isTraceEnabled()) {
LOG.throwing(e);
}
throw e;
}
}
|
java
|
{
"resource": ""
}
|
q179195
|
Utils.sanitizeTag
|
test
|
public static String sanitizeTag(String s) {
// if > 55 chars, assume max entropy is at the end (like a class name).
if (s.length() > MAX_TAG_LENGTH) {
s = s.substring(s.length() - MAX_TAG_LENGTH);
}
return s;
}
|
java
|
{
"resource": ""
}
|
q179196
|
GeocodeRequestBuilder.address
|
test
|
public GeocodeRequestBuilder address(String address) {
parameters.put("address", address != null ? address.replace(' ', '+')
: address);
return this;
}
|
java
|
{
"resource": ""
}
|
q179197
|
GeocodeRequestBuilder.componenets
|
test
|
public GeocodeRequestBuilder componenets(Map<String, String> components) {
StringBuffer filters = new StringBuffer();
for (Iterator<Map.Entry<String, String>> iterator = components
.entrySet().iterator(); iterator.hasNext();) {
Map.Entry<String, String> entry = iterator.next();
filters.append(entry.getKey() + ":" + entry.getValue() != null ? entry
.getValue().replace(' ', '+') : entry.getValue());
if (iterator.hasNext())
filters.append("|");
}
parameters.put("components", filters.toString());
return this;
}
|
java
|
{
"resource": ""
}
|
q179198
|
RSRServiceDiscoveryImpl.queryForNames
|
test
|
public Collection<String> queryForNames() throws Exception {
Set<String> names = new HashSet<String>();
// todo: it would be better to do:
// services = client.getServicesClient().list(options, typeTag);
// but there are some validation problems (the tag is allowed to be written, but not queried on).
Iterator<Service> services = client.getServicesClient().list(new MethodOptions(100, null));
while (services.hasNext()) {
Service service = services.next();
// this conditional can be removed when the above operation works.
if (!service.getTags().contains(typeTag)) {
continue;
}
String name = service.getMetadata().get(ServiceTracker.NAME);
if (!names.contains(name)) {
names.add(name);
}
}
return names;
}
|
java
|
{
"resource": ""
}
|
q179199
|
RSRServiceDiscoveryImpl.queryForInstances
|
test
|
public Collection<ServiceInstance<T>> queryForInstances(String name) throws Exception {
List<ServiceInstance<T>> serviceInstances = new ArrayList<ServiceInstance<T>>();
Iterator<Service> services = client.getServicesClient().list(new MethodOptions(100, null));
while (services.hasNext()) {
Service service = services.next();
if (service.getTags().contains(typeTag) && service.getMetadata().get(ServiceTracker.NAME).equals(name)) {
// does the job of the serializer in the curator code (theirs is just a json marshaller anyway).
serviceInstances.add(convert(service));
}
}
return serviceInstances;
}
|
java
|
{
"resource": ""
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.