Beispiel #1
0
 private int DomainMin() {
   double smallest = Double.MAX_VALUE;
   for (Number d : dates) {
     if (d.doubleValue() < smallest) smallest = d.doubleValue();
   }
   return (int) (smallest / 86400);
 }
  private Number incrValue(int dir) {
    Number newValue;
    if ((value instanceof Float) || (value instanceof Double)) {
      double v = value.doubleValue() + (stepSize.doubleValue() * (double) dir);
      if (value instanceof Double) {
        newValue = new Double(v);
      } else {
        newValue = new Float(v);
      }
    } else {
      long v = value.longValue() + (stepSize.longValue() * (long) dir);

      if (value instanceof Long) {
        newValue = new Long(v);
      } else if (value instanceof Integer) {
        newValue = new Integer((int) v);
      } else if (value instanceof Short) {
        newValue = new Short((short) v);
      } else {
        newValue = new Byte((byte) v);
      }
    }

    if ((maximum != null) && (maximum.compareTo(newValue) < 0)) {
      return null;
    }
    if ((minimum != null) && (minimum.compareTo(newValue) > 0)) {
      return null;
    } else {
      return newValue;
    }
  }
  /** {@inheritDoc} */
  @Override
  protected void updateMinMax(Number min, Number max) {
    // we always use the double values, because that way the response Object class is
    // consistent regardless of whether we only have 1 value or many that we min/max
    //
    // TODO: would be nice to have subclasses for each type of Number ... breaks backcompat

    if (computeMin) { // nested if to encourage JIT to optimize aware final var?
      if (null != min) {
        double minD = min.doubleValue();
        if (null == this.min || minD < this.minD) {
          // Double for result & cached primitive doulbe to minimize unboxing in future comparisons
          this.min = this.minD = minD;
        }
      }
    }
    if (computeMax) { // nested if to encourage JIT to optimize aware final var?
      if (null != max) {
        double maxD = max.doubleValue();
        if (null == this.max || this.maxD < maxD) {
          // Double for result & cached primitive doulbe to minimize unboxing in future comparisons
          this.max = this.maxD = maxD;
        }
      }
    }
  }
Beispiel #4
0
 private Double FindMinimum() {
   Double smallest = 1000.0;
   for (Number d : weights) {
     if (d.doubleValue() < smallest.doubleValue()) smallest = d.doubleValue();
   }
   Double bit = smallest % 1;
   return smallest - bit;
 }
Beispiel #5
0
 private Double FindMaximum() {
   Double greatest = 0.0;
   for (Number d : weights) {
     if (d.doubleValue() > greatest) greatest = d.doubleValue();
   }
   Double bit = 1 - greatest % 1;
   return greatest + bit;
 }
Beispiel #6
0
  private int DomainMax() {
    double greatest = 0.0;
    for (Number d : dates) {
      if (d.doubleValue() > greatest) greatest = d.doubleValue();
    }

    return (int) (greatest / 86400);
  }
 private Double getAveragePositive(List<? extends Number> intervals) {
   List<Double> positiveIntervals = new ArrayList<>();
   Double result = 0.0;
   for (Number interval : intervals) {
     if (interval.doubleValue() > 0.0) positiveIntervals.add(interval.doubleValue());
   }
   for (Double interval : positiveIntervals) {
     result += interval / positiveIntervals.size();
   }
   return result;
 }
 public int compare(Number o1, Number o2) {
   final double d1 = o1.doubleValue();
   final double d2 = o2.doubleValue();
   if (d1 < d2) {
     return -1;
   }
   if (d1 == d2) {
     return 0;
   }
   return 1;
 }
Beispiel #9
0
        public Object call(Scope sc, Object pointsInt, Object fo00000o[]) {
          Number n = (Number) (sc.getThis());
          int num = 0;
          if (pointsInt != null && pointsInt instanceof Number)
            num = ((Number) pointsInt).intValue();

          double mult = Math.pow(10, num);

          long foo = Math.round(n.doubleValue() * mult);
          double d = foo;
          d = d / mult;

          String s = String.valueOf(d);
          int idx = s.indexOf(".");

          if (idx < 0) {
            if (num > 0) {
              s += ".";
              while (num > 0) {
                s += "0";
                num--;
              }
            }
            return new JSString(s);
          }

          if (s.length() - idx <= num) { // need more
            int toAdd = (num + 1) - (s.length() - idx);
            for (int i = 0; i < toAdd; i++) s += "0";
            return new JSString(s);
          }

          if (num == 0) return s.substring(0, idx);
          return new JSString(s.substring(0, idx + 1 + num));
        }
Beispiel #10
0
  public Matrix createVector(BitVector selector) {
    int rows = selector != null ? selector.countOnBits() : frame.size();
    Matrix m = new Matrix(rows, 1);

    for (int i = 0, j = 0; j < frame.size(); j++) {
      if (selector == null || selector.isOn(j)) {
        M rowValue = frame.object(j);

        try {
          Number numValue = (Number) numericField.get(rowValue);
          m.set(i, 0, numValue.doubleValue());

        } catch (IllegalAccessException e) {
          e.printStackTrace();
          throw new IllegalStateException(
              String.format(
                  "Couldn't access field %s: %s", numericField.getName(), e.getMessage()));
        }

        i++;
      }
    }

    return m;
  }
 public void saveDisplayObjectType() {
   DOTPoint newDOTPoint =
       (DOTPoint) _dotDefinitionDialogFrame.getScratchDisplayObjectType().getCopy(null);
   final String name = _dotDefinitionDialogFrame.getNameText();
   if ((name == null) || (name.length() == 0)) {
     JOptionPane.showMessageDialog(
         new JFrame(), "Bitte geben Sie einen Namen an!", "Fehler", JOptionPane.ERROR_MESSAGE);
     return;
   }
   if (!_dotDefinitionDialogFrame.isReviseOnly()) {
     if (_dotDefinitionDialogFrame.getDotManager().containsDisplayObjectType(name)) {
       JOptionPane.showMessageDialog(
           new JFrame(),
           "Ein Darstellungstyp mit diesem Namen existiert bereits!",
           "Fehler",
           JOptionPane.ERROR_MESSAGE);
       return;
     }
   }
   newDOTPoint.setName(name);
   newDOTPoint.setInfo(_dotDefinitionDialogFrame.getInfoText());
   final Object value = _translationFactorSpinner.getValue();
   if (value instanceof Number) {
     final Number number = (Number) value;
     newDOTPoint.setTranslationFactor(number.doubleValue());
   }
   newDOTPoint.setJoinByLine(_joinByLineCheckBox.isSelected());
   _dotDefinitionDialogFrame.getDotManager().saveDisplayObjectType(newDOTPoint);
   _dotDefinitionDialogFrame.setDisplayObjectType(newDOTPoint, true);
 }
Beispiel #12
0
  public Object power(Number d, Complex c) {
    Complex base = new Complex(d.doubleValue(), 0.0);
    Complex temp = base.power(c);

    if (temp.im() == 0) return new Double(temp.re());
    else return temp;
  }
Beispiel #13
0
 @Override
 public double getDouble(final String key) {
   final Number number = this.extractNumber(this.findLastTag(key));
   if (number == null) {
     return 0.0;
   }
   return number.doubleValue();
 }
 public String getInvalidValueText(Frame frame, Slot slot, Object value, Collection facetValues) {
   String result = null;
   Number n = (Number) CollectionUtilities.getFirstItem(facetValues);
   if (n != null) {
     double max = n.doubleValue();
     result = getInvalidValueText(max, value);
   }
   return result;
 }
Beispiel #15
0
 /** Return a double parsed from the given string, possibly formatted with a "%" sign */
 public static double parseDouble(String val) throws NumberFormatException, ParseException {
   NumberFormat formatPercent = NumberFormat.getPercentInstance(Locale.US); // for zoom factor
   if (val.indexOf("%") == -1) { // not in percent format !
     return Double.parseDouble(val);
   }
   // else it's a percent format -> parse it
   Number n = formatPercent.parse(val);
   return n.doubleValue();
 }
Beispiel #16
0
 private Double getPositiveFraction(List<? extends Number> intervals) {
   long success = 0;
   long fail = 0;
   for (Number interval : intervals) {
     if (interval.doubleValue() < 0.0) fail++;
     else success++;
   }
   return 1.0 * (success) / (success + fail);
 }
 /**
  * Looks up the given key in the given map, converting the result into a {@link Double}. First,
  * {@link #getNumber(Map,Object)} is invoked. If the result is null, then null is returned.
  * Otherwise, the double value of the resulting {@link Number} is returned.
  *
  * @param map the map whose value to look up
  * @param key the key whose value to look up in that map
  * @return a {@link Double} or null
  */
 public static Double getDouble(Map map, Object key) {
   Number answer = getNumber(map, key);
   if (answer == null) {
     return null;
   } else if (answer instanceof Double) {
     return (Double) answer;
   }
   return new Double(answer.doubleValue());
 }
 public Map<ILinguistic<Number>, IDegree> fuzzify(Number val) {
   ValueSortedMap<ILinguistic<Number>, IDegree> vsmap =
       new ValueSortedMap<ILinguistic<Number>, IDegree>();
   IDegree master = getDegree(iterator().next());
   for (ILinguistic ling : getSupport()) {
     vsmap.put(ling, master.fromConst(ling.getSet().containment(val.doubleValue())));
   }
   return vsmap;
 }
 private static String getInvalidValueText(double max, Object value) {
   String result = null;
   if (value instanceof Number) {
     Number n = (Number) value;
     if (n.doubleValue() > max) {
       result = "The maximum value is " + max;
     }
   }
   return result;
 }
 private String convertNumber(Number number) {
   if (Integer.class.isInstance(number)) {
     return NumericUtils.intToPrefixCoded(number.intValue());
   } else if (Double.class.isInstance(number)) {
     return NumericUtils.doubleToPrefixCoded(number.doubleValue());
   } else if (Long.class.isInstance(number)) {
     return NumericUtils.longToPrefixCoded(number.longValue());
   } else if (Float.class.isInstance(number)) {
     return NumericUtils.floatToPrefixCoded(number.floatValue());
   } else if (Byte.class.isInstance(number)) {
     return NumericUtils.intToPrefixCoded(number.intValue());
   } else if (Short.class.isInstance(number)) {
     return NumericUtils.intToPrefixCoded(number.intValue());
   } else if (BigDecimal.class.isInstance(number)) {
     return NumericUtils.doubleToPrefixCoded(number.doubleValue());
   } else if (BigInteger.class.isInstance(number)) {
     return NumericUtils.longToPrefixCoded(number.longValue());
   } else {
     throw new IllegalArgumentException("Unsupported numeric type " + number.getClass().getName());
   }
 }
Beispiel #21
0
 public double getParameter(String key, double defaultValue) {
   Number n = getNumbers().get(key);
   if (n != null) {
     return n.doubleValue();
   }
   String value = getParameter(key);
   if (value == null || value.length() == 0) {
     return defaultValue;
   }
   double d = Double.parseDouble(value);
   getNumbers().put(key, d);
   return d;
 }
 /** {@inheritDoc} */
 @Override
 public void updateTypeSpecificStats(Number v, int count) {
   double value = v.doubleValue();
   if (computeSumOfSquares) {
     sumOfSquares += (value * value * count); // for std deviation
   }
   if (computeSum) {
     sum += value * count;
   }
   if (computePercentiles) {
     tdigest.add(value, count);
   }
 }
Beispiel #23
0
    @Override
    public int compareTo(Number number) {
      double thisDouble = this.doubleValue();

      double thatValue = number.doubleValue();

      if (thisDouble > thatValue) {
        return 1;
      } else if (thisDouble < thatValue) {
        return -1;
      } else {
        return 0;
      }
    }
 protected int putNumber(String name, Number n) {
   int start = _buf.position();
   if (n instanceof Integer) {
     _put(NUMBER_INT, name);
     _buf.putInt(n.intValue());
   } else if (n instanceof Long) {
     _put(NUMBER_LONG, name);
     _buf.putLong(n.longValue());
   } else {
     _put(NUMBER, name);
     _buf.putDouble(n.doubleValue());
   }
   return _buf.position() - start;
 }
 public String getInvalidValuesText(
     Frame frame, Slot slot, Collection slotValues, Collection facetValues) {
   String result = null;
   Number n = (Number) CollectionUtilities.getFirstItem(facetValues);
   if (n != null) {
     double max = n.doubleValue();
     Iterator i = slotValues.iterator();
     while (result == null && i.hasNext()) {
       Object value = i.next();
       result = getInvalidValueText(max, value);
     }
   }
   return result;
 }
Beispiel #26
0
 public Number coerceNumber(Object inputArgument, Class<?> paraType) {
   Number number = (Number) inputArgument;
   if (paraType == int.class || paraType == Integer.class) {
     return number.intValue();
   } else if (paraType == double.class || paraType == Double.class) {
     return number.doubleValue();
   } else if (paraType == float.class || paraType == Float.class) {
     return number.floatValue();
   } else if (paraType == short.class || paraType == Short.class) {
     return number.shortValue();
   } else if (paraType == byte.class || paraType == Byte.class) {
     return number.byteValue();
   }
   return null;
 }
Beispiel #27
0
 private void dump(String dirName, String filename, List<? extends Number> intervals) {
   try {
     File dir = new File("testOut/" + dirName + "/");
     dir.mkdirs();
     File outFile = new File(dir.getPath() + "/" + filename);
     FileWriter out = new FileWriter(outFile);
     BufferedWriter outStream = new BufferedWriter(out);
     for (Number interval : intervals)
       if (interval.doubleValue() > 0.0) {
         outStream.write(String.valueOf(interval) + "\n");
       }
     outStream.close();
   } catch (IOException e) {
     e.printStackTrace();
   }
   System.out.println("Data saved to " + filename);
 }
Beispiel #28
0
 public RexNode toRex(Expression expression) {
   switch (expression.getNodeType()) {
     case MemberAccess:
       return rexBuilder.makeFieldAccess(
           toRex(((MemberExpression) expression).expression),
           ((MemberExpression) expression).field.getName());
     case GreaterThan:
       return binary(expression, SqlStdOperatorTable.greaterThanOperator);
     case LessThan:
       return binary(expression, SqlStdOperatorTable.lessThanOperator);
     case Parameter:
       return parameter((ParameterExpression) expression);
     case Call:
       MethodCallExpression call = (MethodCallExpression) expression;
       SqlOperator operator = RexToLixTranslator.JAVA_TO_SQL_METHOD_MAP.get(call.method);
       if (operator != null) {
         return rexBuilder.makeCall(
             operator,
             toRex(
                 Expressions.<Expression>list()
                     .appendIfNotNull(call.targetExpression)
                     .appendAll(call.expressions)));
       }
       throw new RuntimeException("Could translate call to method " + call.method);
     case Constant:
       final ConstantExpression constant = (ConstantExpression) expression;
       Object value = constant.value;
       if (value instanceof Number) {
         Number number = (Number) value;
         if (value instanceof Double || value instanceof Float) {
           return rexBuilder.makeApproxLiteral(BigDecimal.valueOf(number.doubleValue()));
         } else if (value instanceof BigDecimal) {
           return rexBuilder.makeExactLiteral((BigDecimal) value);
         } else {
           return rexBuilder.makeExactLiteral(BigDecimal.valueOf(number.longValue()));
         }
       } else if (value instanceof Boolean) {
         return rexBuilder.makeLiteral((Boolean) value);
       } else {
         return rexBuilder.makeLiteral(constant.toString());
       }
     default:
       throw new UnsupportedOperationException(
           "unknown expression type " + expression.getNodeType() + " " + expression);
   }
 }
Beispiel #29
0
 protected void putNumber(String name, Number n) {
   if (n instanceof Integer
       || n instanceof Short
       || n instanceof Byte
       || n instanceof AtomicInteger) {
     _put(NUMBER_INT, name);
     _buf.writeInt(n.intValue());
   } else if (n instanceof Long || n instanceof AtomicLong) {
     _put(NUMBER_LONG, name);
     _buf.writeLong(n.longValue());
   } else if (n instanceof Float || n instanceof Double) {
     _put(NUMBER, name);
     _buf.writeDouble(n.doubleValue());
   } else {
     throw new IllegalArgumentException("can't serialize " + n.getClass());
   }
 }
Beispiel #30
0
  public Matrix createVector() {
    int rows = frame.size();
    Matrix m = new Matrix(rows, 1);

    for (int i = 0; i < rows; i++) {
      M rowValue = frame.object(i);
      try {
        Number numValue = (Number) numericField.get(rowValue);
        m.set(i, 0, numValue.doubleValue());

      } catch (IllegalAccessException e) {
        e.printStackTrace();
        throw new IllegalStateException(
            String.format("Couldn't access field %s: %s", numericField.getName(), e.getMessage()));
      }
    }

    return m;
  }