List of usage examples for java.lang Number equals
public boolean equals(Object obj)
From source file:org.apache.calcite.runtime.SqlFunctions.java
public static boolean toBoolean(Number number) { return !number.equals(0); }
From source file:eu.dasish.annotation.backend.dao.impl.DBDispatcherImlp.java
@Override public ReferenceList getTargetsForTheSameLinkAs(Number targetID) { List<Number> targetIDs = targetDao.getTargetsForLink(targetDao.getLink(targetID)); ReferenceList referenceList = new ReferenceList(); for (Number siblingID : targetIDs) { if (!siblingID.equals(targetID)) { referenceList.getHref().add(targetDao.getHrefFromInternalID(siblingID)); }/*from www. j ava 2 s . c o m*/ } return referenceList; }
From source file:org.pentaho.chart.plugin.jfreechart.JFreeChartFactoryEngine.java
protected Number scaleNumber(Number number, Number scale) { Number scaledNumber = number; if ((number != null) && (scale != null) && !scale.equals(1) && !scale.equals(0)) { int startingSignificantDigits = 0; if (!(number instanceof Integer)) { int indexOfDecimalPoint = number.toString().indexOf("."); if (indexOfDecimalPoint >= 0) { String fractionalPart = number.toString().substring(indexOfDecimalPoint + 1); if ((fractionalPart.length() > 1) || Integer.parseInt(fractionalPart) > 0) { startingSignificantDigits = fractionalPart.length(); }//from ww w . j av a2 s . c o m } } int preferredSignificantDigits = Math.max(2, Math.min(startingSignificantDigits, 6)); scaledNumber = number.doubleValue() / scale.doubleValue(); int scaledSignificantDigits = 0; int indexOfDecimalPoint = scaledNumber.toString().indexOf("."); String fractionalPart = scaledNumber.toString().substring(indexOfDecimalPoint + 1); if ((fractionalPart.length() > 1) || Integer.parseInt(fractionalPart) > 0) { scaledSignificantDigits = fractionalPart.length(); } if (scaledSignificantDigits > preferredSignificantDigits) { double multiplier = Math.pow(10, preferredSignificantDigits); scaledNumber = Math.round(scaledNumber.doubleValue() * multiplier) / multiplier; } } return scaledNumber; }
From source file:adams.data.statistics.StatUtils.java
/** * Returns the (first) index of the number one is looking for in the given * array. -1 is returned if not found.// w w w . j ava2 s . c o m * * @param array the array to search * @param toFind the number to find * @return the index */ public static int findFirst(Number[] array, Number toFind) { int result; int i; result = -1; for (i = 0; i < array.length; i++) { if (toFind.equals(array[i])) { result = i; break; } } return result; }
From source file:eu.dasish.annotation.backend.dao.impl.DBDispatcherImlp.java
@Override public boolean canDo(Access action, Number principalID, Number resourceID, Resource resource) { switch (resource) { case ANNOTATION: { if (principalID.equals(annotationDao.getOwner(resourceID)) || principalDao.getTypeOfPrincipalAccount(principalID).equals(admin)) { return true; }/*from ww w . j a v a 2 s . c o m*/ Access access = this.getAccess(resourceID, principalID); return this.greaterOrEqual(access, action); } case CACHED_REPRESENTATION: { return true; } case TARGET: { return true; } case PRINCIPAL: { return true; } default: return false; } }
From source file:eu.dasish.annotation.backend.dao.impl.DBDispatcherImlp.java
@Override public int updateAnnotation(Annotation annotation, String remoteUser) throws NotInDataBaseException, ForbiddenException { Number annotationID = annotationDao.getInternalID(UUID.fromString(annotation.getId())); Number ownerID = principalDao.getInternalIDFromHref(annotation.getOwnerHref()); Number remoteUserID = principalDao.getPrincipalInternalIDFromRemoteID(remoteUser); boolean isOwner = ownerID.equals(remoteUserID); boolean hasAllAccess = annotationDao.getAccess(annotationID, remoteUserID).equals(Access.ALL); boolean isAdmin = remoteUserID.equals(principalDao.getDBAdminID()); boolean weakPrincipal = (!isOwner && !hasAllAccess && !isAdmin); if (weakPrincipal) { // we need to check if permissions are intact if (!(annotation.getPermissions().getPublic()).equals(annotationDao.getPublicAttribute(annotationID))) { throw new ForbiddenException( "The inlogged user does not have rights to update 'public' attribute in this annotation."); }//w w w .jav a2 s.co m List<Map<Number, String>> permissionsDB = annotationDao.getPermissions(annotationID); if (!this.permissionsIntact(annotation.getPermissions().getPermission(), permissionsDB)) { throw new ForbiddenException( "The inlogged user does not have rights to update permissions in this annotation."); } } int updatedAnnotations = annotationDao.updateAnnotation(annotation, annotationID, ownerID); int deletedTargets = annotationDao.deleteAllAnnotationTarget(annotationID); int addedTargets = this.addTargets(annotation, annotationID); if (!weakPrincipal) { // if weak permissions reach this point then permissions are the same int changedPermissions = this.updateOrAddPermissions(annotationID, annotation.getPermissions()); } return updatedAnnotations; }
From source file:org.pentaho.chart.plugin.openflashchart.OpenFlashChartFactoryEngine.java
private StackedBarChart makeStackedBarChart(ChartModel chartModel, MultiSeriesDataModel chartTableModel, IChartLinkGenerator chartLinkGenerator) { StackedBarChart stackedBarChart = new StackedBarChart(); BarPlot barPlot = (BarPlot) chartModel.getPlot(); Palette palette = getPalette(barPlot); if (barPlot.getOpacity() != null) { stackedBarChart.setAlpha(barPlot.getOpacity()); }//from ww w.jav a2 s . c o m boolean firstCategory = true; for (DomainData category : chartTableModel.getDomainData()) { Stack stack = stackedBarChart.newStack(); int index = 0; for (NamedValue namedValue : category) { String color = "#" + Integer.toHexString(0x00FFFFFF & palette.get(index)); if (firstCategory && (chartModel.getLegend() != null) && chartModel.getLegend().getVisible()) { StackKey key = new StackKey(); key.setText(namedValue.getName()); key.setColour(color); Integer legendSize = chartModel.getLegend().getFontSize(); if ((legendSize != null) && (legendSize > 0)) { stackedBarChart.setFontSize(legendSize); } stackedBarChart.addKeys(key); } Number value = namedValue.getValue(); if ((value != null) && !value.equals(0)) { StackValue stackValue = new StackValue(scaleNumber(value, chartTableModel.getScalingFactor()), color); if (chartLinkGenerator != null) { String barLink = chartLinkGenerator.generateLink(namedValue.getName(), category.getDomainName(), namedValue.getValue()); if (barLink != null) { stackValue.setOnClick(barLink.replaceAll("javascript:", "")); //$NON-NLS-1$ //$NON-NLS-2$ } } stack.addStackValues(stackValue); } index++; } firstCategory = false; } return stackedBarChart; }
From source file:org.pentaho.platform.plugin.action.openflashchart.factory.AbstractChartFactory.java
public Axis setupDomain() { String[] labels = null;/*w w w . jav a 2 s. c o m*/ Number domainMin = null; Number domainMax = null; Integer stepforchart = null; String domainRotation = null; if (CATEGORY_TYPE.equals(datasetType)) { int rowCount = getRowCount(); labels = new String[rowCount]; for (int j = 0; j < rowCount; j++) { labels[j] = getRowHeader(j); } } else if (XYZ_TYPE.equals(datasetType) || XY_TYPE.equals(datasetType)) { domainMin = ((Number) getValueAt(0, 0)).intValue(); domainMax = domainMin; // Iterate over rows for (int r = 1; r < getRowCount(); r++) { if (domainMin.intValue() > ((Number) getValueAt(r, 0)).intValue()) { domainMin = ((Number) getValueAt(r, 0)).intValue(); } if (domainMax.intValue() < ((Number) getValueAt(r, 0)).intValue()) { domainMax = ((Number) getValueAt(r, 0)).intValue(); } } if (domainMin.equals(domainMax)) { if (domainMin.intValue() == 0) { domainMax = new Integer(100); } else if (domainMin.intValue() < 0) { domainMax = new Integer(0); } else { domainMin = new Integer(0); } } int steps = 9; int diff = domainMax.intValue() - domainMin.intValue(); Node temp = chartNode.selectSingleNode(DOMAIN_STEPS_NODE_LOC); if (getValue(temp) != null) { steps = new Integer(getValue(temp)).intValue(); } int chunksize = diff / steps; if (chunksize > 0) { stepforchart = new Integer(chunksize); // If actual min is positive, don't go below ZERO if (domainMin.intValue() >= 0 && domainMin.intValue() - chunksize < 0) { domainMin = 0; } else { domainMin = domainMin.intValue() - chunksize; } domainMax = domainMin.intValue() + (chunksize * (steps + 2)); } temp = chartNode.selectSingleNode(DOMAIN_MINIMUM_NODE_LOC); if (getValue(temp) != null) { domainMin = new Integer(getValue(temp)).intValue(); } temp = chartNode.selectSingleNode(DOMAIN_MAXIMUM_NODE_LOC); if (getValue(temp) != null) { domainMax = new Integer(getValue(temp)).intValue(); } } String domainColor = AXIS_COLOR_DEFAULT; String domainGridColor = AXIS_GRID_COLOR_DEFAULT; int domainStroke = 1; Node temp = chartNode.selectSingleNode(DOMAIN_COLOR_NODE_LOC); if (getValue(temp) != null) { domainColor = getValue(temp); } temp = chartNode.selectSingleNode(DOMAIN_GRID_COLOR_NODE_LOC); if (getValue(temp) != null) { domainGridColor = getValue(temp); } temp = chartNode.selectSingleNode(DOMAIN_STROKE_NODE_LOC); if (getValue(temp) != null) { domainStroke = Integer.parseInt(getValue(temp)); } temp = chartNode.selectSingleNode(DOMAIN_ROTATION_NODE_LOC); if (getValue(temp) != null) { domainRotation = getValue(temp); } // Orientation temp = chartNode.selectSingleNode(ORIENTATION_NODE_LOC); if (getValue(temp) != null) { orientation = getValue(temp); } else { orientation = ORIENTATION_DEFAULT; } if (HORIZONTAL_ORIENTATION.equals(orientation)) { YAxis yaxis = new YAxis(); if (labels != null) { // BISERVER-3075: must reverse the category labels on hbar // charts due to bug in OFC2. String[] reversedLabels = new String[labels.length]; int reversedLabelCount = 0; for (int i = reversedLabels.length - 1; i >= 0; i--) { reversedLabels[reversedLabelCount++] = labels[i]; } yaxis.setLabels(reversedLabels); } yaxis.setStroke(domainStroke); yaxis.setColour(domainColor); yaxis.setGridColour(domainGridColor); if (domainMin != null && domainMax != null) { yaxis.setRange(domainMin.intValue(), domainMax.intValue(), stepforchart); } chart.setYAxis(yaxis); return yaxis; } else { XAxis xaxis = new XAxis(); if (labels != null) { xaxis.addLabels(labels); } xaxis.setStroke(domainStroke); xaxis.setColour(domainColor); xaxis.setGridColour(domainGridColor); if (domainMin != null && domainMax != null) { xaxis.setRange(domainMin.intValue(), domainMax.intValue(), stepforchart); } if (domainRotation != null) { Rotation rot = null; if (domainRotation.equals("vertical")) { rot = Rotation.VERTICAL; } else if (domainRotation.equals("diagonal")) { rot = Rotation.DIAGONAL; } else { rot = Rotation.HORIZONTAL; } xaxis.getLabels().setRotation(rot); } chart.setXAxis(xaxis); return xaxis; } }
From source file:com.xyphos.vmtgen.GUI.java
private void writeSpinner(PrintWriter out, JSpinner spinner, Number defaultValue, String key, int padding) { Number value = ((SpinnerNumberModel) spinner.getModel()).getNumber(); writeKeyValue(!defaultValue.equals(value), out, key, value.toString(), padding); }
From source file:org.pentaho.chart.plugin.openflashchart.OpenFlashChartFactoryEngine.java
private AxisConfiguration getAxisConfiguration(NumericAxis axis, List<Number> axisValues) { Number minValue = axis.getMinValue(); Number maxValue = axis.getMaxValue(); boolean calculateMinValue = (minValue == null); boolean calculateMaxValue = (maxValue == null); boolean hasChartData = false; for (Number value : axisValues) { if (calculateMaxValue) { if (maxValue == null) { maxValue = value;/* w w w .j a va 2s . c o m*/ } else if (value != null) { maxValue = Math.max(maxValue.doubleValue(), value.doubleValue()); } } if (calculateMinValue) { if (minValue == null) { minValue = value; } else if (value != null) { minValue = Math.min(minValue.doubleValue(), value.doubleValue()); } } hasChartData = hasChartData || (value != null); } AxisConfiguration rangeDescription = null; if (hasChartData) { if (calculateMinValue) { minValue = Math.min(0, minValue.doubleValue()); } minValue = Math.floor(minValue.doubleValue()); maxValue = Math.ceil(maxValue.doubleValue()); if (maxValue.equals(minValue)) { maxValue = maxValue.intValue() + 1; } Number spread = maxValue.doubleValue() - minValue.doubleValue(); int exponent = Integer.toString(Math.abs(spread.intValue())).length() - 1; int stepSize = (int) (((long) (spread.intValue() / Math.pow(10, exponent))) * Math.pow(10, exponent - 1)) * 2; if (stepSize < 1) { stepSize = 1; } if ((maxValue.doubleValue() % stepSize) != 0) { maxValue = (maxValue.doubleValue() - (maxValue.doubleValue() % stepSize)) + stepSize; } rangeDescription = new AxisConfiguration(minValue.intValue(), maxValue.intValue(), stepSize); } return rangeDescription; }