Ejemplo n.º 1
0
  /*
   *  Making sure that the user input is in range
   *  @param1 Scanner object for input
   *  @param2 lowerbound integer
   *  @param3 upperbound integer
   *  @param4 String that specifies for which attribute/field input is for
   *  printing purposes
   *  @param5 ValType enum that specifies whether the primitive value is
   *  an int or double
   *  @param6 boolean that specifies whether the input is an Enum value
   *  @param7 boolean that specifies whether to return the value if out of
   *  range (false) or not (true)
   */
  public static Number makeSureValInRange(
      Scanner input,
      int lowerbound,
      int upperbound,
      String inputFor,
      ValType valType,
      boolean enumeration,
      boolean withinRange) {

    boolean valid = !withinRange;
    Number val = 0;

    while (!valid) {

      System.out.println(inputString(inputFor, null, StringOption.SELECT, enumeration));

      val = valType == ValType.INTEGER ? input.nextInt() : input.nextDouble();

      if (val.intValue() < lowerbound || val.intValue() > upperbound) {
        System.out.println(inputString(inputFor, null, StringOption.INCORRECT, enumeration));
      } else {
        valid = true;
      }
    }
    return val;
  }
 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);
 }
Ejemplo n.º 3
0
  protected void prepare(
      Map stormConf, final TopologyContext context, final IOutputCollector collector) {

    _rand = new Random();
    _collector = collector;

    _context = context;

    heartbeatTimeoutMills = getHeartbeatTimeoutMillis(stormConf);

    _process = new NuShellProcess(_command, this, this);

    // subprocesses must send their pid first thing
    Number subpid = _process.launch(stormConf, context);
    LOG.info("Launched subprocess with pid " + subpid);
    this.pid = subpid.longValue();

    /**
     * randomizing the initial delay would prevent all shell bolts from heartbeating at the same
     * time frame
     */
    int initialDelayMillis = random.nextInt(4000) + 1000;
    BoltHeartbeatTimerTask task = new BoltHeartbeatTimerTask(this);
    heartBeatExecutorService.scheduleAtFixedRate(
        task, initialDelayMillis, getHeartbeatPeriodMillis(stormConf), TimeUnit.MILLISECONDS);
  }
  /** {@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;
        }
      }
    }
  }
Ejemplo n.º 5
0
 private int DomainMin() {
   double smallest = Double.MAX_VALUE;
   for (Number d : dates) {
     if (d.doubleValue() < smallest) smallest = d.doubleValue();
   }
   return (int) (smallest / 86400);
 }
Ejemplo n.º 6
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));
        }
Ejemplo n.º 7
0
 /**
  * Tests if this object is equal to another
  *
  * @param a_obj the other object
  * @return true: this object is equal to the other one
  * @author Klaus Meffert
  * @since 2.3
  */
 public boolean equals(final Object a_obj) {
   if (a_obj == null) {
     return false;
   }
   if (a_obj == this) {
     return true;
   }
   if (!(a_obj instanceof KeyedValues)) {
     return false;
   }
   final KeyedValues kvs = (KeyedValues) a_obj;
   final int count = size();
   if (count != kvs.size()) {
     return false;
   }
   for (int i = 0; i < count; i++) {
     final Comparable k1 = getKey(i);
     final Comparable k2 = kvs.getKey(i);
     if (!k1.equals(k2)) {
       return false;
     }
     final Number v1 = getValue(i);
     final Number v2 = kvs.getValue(i);
     if (v1 == null) {
       if (v2 != null) {
         return false;
       }
     } else {
       if (!v1.equals(v2)) {
         return false;
       }
     }
   }
   return true;
 }
  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;
    }
  }
Ejemplo n.º 9
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;
  }
Ejemplo n.º 10
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;
 }
Ejemplo n.º 11
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;
 }
Ejemplo n.º 12
0
  private int DomainMax() {
    double greatest = 0.0;
    for (Number d : dates) {
      if (d.doubleValue() > greatest) greatest = d.doubleValue();
    }

    return (int) (greatest / 86400);
  }
Ejemplo n.º 13
0
 @Override
 public long getLong(final String key) {
   final Number number = this.extractNumber(this.findLastTag(key));
   if (number == null) {
     return 0L;
   }
   return number.longValue();
 }
Ejemplo n.º 14
0
 @Override
 public int getInt(final String key) {
   final Number number = this.extractNumber(this.findLastTag(key));
   if (number == null) {
     return 0;
   }
   return number.intValue();
 }
Ejemplo n.º 15
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();
 }
Ejemplo n.º 16
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();
 }
Ejemplo n.º 17
0
 public boolean setDefault(MutableAttributeSet target) {
   Number old = (Number) target.getAttribute(swingName);
   if (old == null) old = swingDefault;
   if (old != null
       && ((scale == 1f && old.intValue() == rtfDefault)
           || (Math.round(old.floatValue() * scale) == rtfDefault))) return true;
   set(target, rtfDefault);
   return true;
 }
Ejemplo n.º 18
0
 /**
  * Looks up the given key in the given map, converting the result into a {@link Float}. First,
  * {@link #getNumber(Map,Object)} is invoked. If the result is null, then null is returned.
  * Otherwise, the float 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 Float} or null
  */
 public static Float getFloat(Map map, Object key) {
   Number answer = getNumber(map, key);
   if (answer == null) {
     return null;
   } else if (answer instanceof Float) {
     return (Float) answer;
   }
   return new Float(answer.floatValue());
 }
Ejemplo n.º 19
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);
 }
 /** @param args the command line arguments */
 public static void main(String[] args) {
   // TODO code application logic here
   print();
   showauthor();
   JavaAccessPractice test = JavaAccessPractice.getInstance();
   System.out.print(test);
   System.out.print("Number is:" + Number.returnint(Number.ZERO) + "\n");
   System.out.print("Number is:" + Number.returnint(Number.ONE) + "\n");
 }
Ejemplo n.º 21
0
 /**
  * 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());
 }
Ejemplo n.º 22
0
 /**
  * Looks up the given key in the given map, converting the result into an {@link Integer}. First,
  * {@link #getNumber(Map,Object)} is invoked. If the result is null, then null is returned.
  * Otherwise, the integer 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 an {@link Integer} or null
  */
 public static Integer getInteger(Map map, Object key) {
   Number answer = getNumber(map, key);
   if (answer == null) {
     return null;
   } else if (answer instanceof Integer) {
     return (Integer) answer;
   }
   return new Integer(answer.intValue());
 }
Ejemplo n.º 23
0
 /**
  * Looks up the given key in the given map, converting the result into a {@link Long}. First,
  * {@link #getNumber(Map,Object)} is invoked. If the result is null, then null is returned.
  * Otherwise, the long 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 Long} or null
  */
 public static Long getLong(Map map, Object key) {
   Number answer = getNumber(map, key);
   if (answer == null) {
     return null;
   } else if (answer instanceof Long) {
     return (Long) answer;
   }
   return new Long(answer.longValue());
 }
Ejemplo n.º 24
0
 /**
  * Looks up the given key in the given map, converting the result into a {@link Short}. First,
  * {@link #getNumber(Map,Object)} is invoked. If the result is null, then null is returned.
  * Otherwise, the short 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 Short} or null
  */
 public static Short getShort(Map map, Object key) {
   Number answer = getNumber(map, key);
   if (answer == null) {
     return null;
   } else if (answer instanceof Short) {
     return (Short) answer;
   }
   return new Short(answer.shortValue());
 }
Ejemplo n.º 25
0
 /**
  * Looks up the given key in the given map, converting the result into a {@link Byte}. First,
  * {@link #getNumber(Map,Object)} is invoked. If the result is null, then null is returned.
  * Otherwise, the byte 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 Byte} or null
  */
 public static Byte getByte(Map map, Object key) {
   Number answer = getNumber(map, key);
   if (answer == null) {
     return null;
   } else if (answer instanceof Byte) {
     return (Byte) answer;
   }
   return new Byte(answer.byteValue());
 }
Ejemplo n.º 26
0
 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;
 }
  /**
   * This does not explicitly delete the names because its assumed the recalculation will clean it
   * up.
   */
  public boolean deleteSystemOfRecordPerson(
      final SorPerson sorPerson, final boolean mistake, final String terminationTypes) {
    Assert.notNull(sorPerson, "sorPerson cannot be null.");
    final String terminationTypeToUse =
        terminationTypes != null ? terminationTypes : Type.TerminationTypes.UNSPECIFIED.name();

    final Person person = this.personRepository.findByInternalId(sorPerson.getPersonId());
    Assert.notNull(person, "person cannot be null.");

    if (mistake) {
      Set<Role> rolesToDelete = new HashSet<Role>();

      for (final SorRole sorRole : sorPerson.getRoles()) {
        for (final Role role : person.getRoles()) {
          if (sorRole.getId().equals(role.getSorRoleId())) {
            rolesToDelete.add(role);
          }
        }
      }

      for (final Role role : rolesToDelete) {
        // let sorRoleElector delete the role and add another role if required
        sorRoleElector.removeCalculatedRole(
            person, role, this.personRepository.getSoRRecordsForPerson(person));
      }

      final Number number = this.personRepository.getCountOfSoRRecordsForPerson(person);

      if (number.intValue() == 1) {
        this.personRepository.deletePerson(person);
      }

      this.personRepository.deleteSorPerson(sorPerson);
      return true;
    }

    // we do this explicitly here because once they're gone we can't re-calculate?  We might move to
    // this to the recalculateCalculatedPerson method.
    final Type terminationReason =
        this.referenceRepository.findType(Type.DataTypes.TERMINATION, terminationTypeToUse);

    for (final SorRole sorRole : sorPerson.getRoles()) {
      for (final Role role : person.getRoles()) {
        if (!role.isTerminated() && sorRole.getId().equals(role.getSorRoleId())) {
          role.expireNow(terminationReason, true);
        }
      }
    }

    this.personRepository.deleteSorPerson(sorPerson);
    this.personRepository.savePerson(person);

    Person p = recalculatePersonBiodemInfo(person, sorPerson, RecalculationType.DELETE, mistake);
    this.personRepository.savePerson(p);
    return true;
  }
Ejemplo n.º 28
0
  public float getFloat(Prop<? extends Number> n, float def) {
    Object x = get(n);
    if (x instanceof Float[]) return ((Float[]) x)[0].floatValue();
    if (x instanceof Boolean) return ((Boolean) x).booleanValue() ? 1 : 0f;
    if (x instanceof float[]) return ((float[]) x)[0];

    Number gotten = (Number) x;
    if (gotten != null) return gotten.floatValue();
    return def;
  }
Ejemplo n.º 29
0
 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;
 }
Ejemplo n.º 30
0
  /**
   * Overrides the parent implementation to provide a more efficient mechanism for generating
   * primary keys, while generating the primary key support on the fly.
   *
   * @param count the batch size
   * @param entity the entity requesting primary keys
   * @param channel open JDBCChannel
   * @return NSArray of NSDictionary where each dictionary corresponds to a unique primary key value
   */
  public NSArray newPrimaryKeys(int count, EOEntity entity, JDBCChannel channel) {
    if (isPrimaryKeyGenerationNotSupported(entity)) {
      return null;
    }

    EOAttribute attribute = (EOAttribute) entity.primaryKeyAttributes().lastObject();
    String attrName = attribute.name();
    boolean isIntType = "i".equals(attribute.valueType());

    NSMutableArray results = new NSMutableArray(count);
    String sequenceName = sequenceNameForEntity(entity);
    DB2Expression expression = new DB2Expression(entity);

    boolean succeeded = false;
    for (int tries = 0; !succeeded && tries < 2; tries++) {
      while (results.count() < count) {
        try {
          StringBuffer sql = new StringBuffer();
          sql.append("SELECT ");
          sql.append("next value for " + sequenceName + " AS KEY");
          sql.append(" from sysibm.sysdummy1");
          expression.setStatement(sql.toString());
          channel.evaluateExpression(expression);
          try {
            NSDictionary row;
            while ((row = channel.fetchRow()) != null) {
              Enumeration pksEnum = row.allValues().objectEnumerator();
              while (pksEnum.hasMoreElements()) {
                Number pkObj = (Number) pksEnum.nextElement();
                Number pk;
                if (isIntType) {
                  pk = Integer.valueOf(pkObj.intValue());
                } else {
                  pk = Long.valueOf(pkObj.longValue());
                }
                results.addObject(new NSDictionary(pk, attrName));
              }
            }
          } finally {
            channel.cancelFetch();
          }
          succeeded = true;
        } catch (JDBCAdaptorException ex) {
          throw ex;
        }
      }
    }

    if (results.count() != count) {
      throw new IllegalStateException(
          "Unable to generate primary keys from the sequence for " + entity + ".");
    }

    return results;
  }