Esempio n. 1
0
 private void averageArea(int sx, int sy, int radius) {
   for (int x = Math.max(0, sx - radius); x < Math.min(m_width, sx + radius); x++) {
     for (int y = Math.max(0, sy - radius); y < Math.min(m_height, sy + radius); y++) {
       m_contour[x][y] = (m_contour[sx][sy] + m_contour[x][y]) / 2;
     }
   }
 }
Esempio n. 2
0
  private static Map<String, Integer> computeColumnWidths(
      final Iterable<CamelContext> camelContexts) throws Exception {
    if (camelContexts == null) {
      throw new IllegalArgumentException(
          "Unable to determine column widths from null Iterable<CamelContext>");
    } else {
      int maxNameLen = 0;
      int maxStatusLen = 0;
      int maxUptimeLen = 0;

      for (final CamelContext camelContext : camelContexts) {
        final String name = camelContext.getName();
        maxNameLen = java.lang.Math.max(maxNameLen, name == null ? 0 : name.length());

        final String status = camelContext.getStatus().toString();
        maxStatusLen = java.lang.Math.max(maxStatusLen, status == null ? 0 : status.length());

        final String uptime = camelContext.getUptime();
        maxUptimeLen = java.lang.Math.max(maxUptimeLen, uptime == null ? 0 : uptime.length());
      }

      final Map<String, Integer> retval = new Hashtable<String, Integer>(3);
      retval.put(NAME_COLUMN_LABEL, maxNameLen);
      retval.put(STATUS_COLUMN_LABEL, maxStatusLen);
      retval.put(UPTIME_COLUMN_LABEL, maxUptimeLen);

      return retval;
    }
  }
  /**
   * Calculates the size of each parition when the proportional partitioning scheme is used.
   *
   * @param dims represent the logical input space
   * @param blockSize the size, in bytes, of the blocks used to store the file that contains the
   *     data being partitioned
   * @param numBlocks the number of blocks to use for generating the per-partition size
   * @param fileLen the length of the file, in bytes
   * @param dataTypeSize the size, in bytes, of a single cell for the given data type stored in the
   *     file for which partitions are being generated
   * @param conf Configuration object for this current MR program
   * @return an int array that is the same length as dims, where each element is the length, in
   *     cells, that the step shape is in the given dimension
   */
  private int[] calcStepShape(
      int[] dims,
      long blockSize,
      long numBlocks,
      long fileLen,
      int dataTypeSize,
      Configuration conf) {

    int[] stepShape = new int[dims.length]; // sort out the max space

    for (int i = 0; i < dims.length; i++) {
      stepShape[i] = dims[i];
    }

    stepShape[0] = Math.round(Math.max(1, stepShape[0] / numBlocks));

    // if holistic functions are turned on, we need to make
    // sure this encompasses enough records
    // Also need to ensure that it ends up a
    // being a multiple of the zero-dimension of extraction shape
    if (Utils.queryDependantEnabled(conf)) {
      int numExShapesInStep =
          Math.max((stepShape[0] / Utils.getExtractionShape(conf, stepShape.length)[0]), 1);
      stepShape[0] = numExShapesInStep * Utils.getExtractionShape(conf, stepShape.length)[0];
    }

    return stepShape;
  }
Esempio n. 4
0
  public void drive(double x, double y, double rot) {
    l_angle = Math.toDegrees(MathUtils.atan2(-x, -y));
    l_magnitude = Math.sqrt((x * x) + (y * y));

    forward = y;
    right = -x;
    clockwise = rot;

    // make sure angles are in the expected range
    l_angle %= 360;
    r_angle %= 360;

    if (l_angle < 0) {
      l_angle = 360 + l_angle;
    }

    if (r_angle < 0) {
      r_angle = 360 + r_angle;
    }

    // make sure magnitudes are in range
    l_magnitude = Math.max(-1, l_magnitude);
    l_magnitude = Math.min(1, l_magnitude);
    r_magnitude = Math.max(-1, r_magnitude);
    r_magnitude = Math.min(1, r_magnitude);

    driveCartesianTest();
  }
Esempio n. 5
0
 public void leafLayer(int cx, int cy, int cz, int width) {
   for (int x = Math.max(0, cx - width); x < Math.min(m_width, cx + width); x++) {
     for (int y = Math.max(0, cy - width); y < Math.min(m_height, cy + width); y++) {
       m_blocks[x][y][cz] = BlockConstants.LEAVES;
     }
   }
 }
Esempio n. 6
0
 private double getDistanceTo(double x, double y, double z, Player player) {
   double x2 = player.getX();
   double y2 = player.getY();
   double z2 = player.getZ();
   double xResult = java.lang.Math.pow(java.lang.Math.max(x, x2) - java.lang.Math.min(x, x2), 2);
   double yResult = java.lang.Math.pow(java.lang.Math.max(y, y2) - java.lang.Math.min(y, y2), 2);
   double zResult = java.lang.Math.pow(java.lang.Math.max(z, z2) - java.lang.Math.min(z, z2), 2);
   return java.lang.Math.sqrt(xResult + yResult + zResult);
 }
Esempio n. 7
0
  public static ArthurImage multiply(ArthurImage one, ArthurImage two) {
    BufferedImage image = JavaImageMath.clone(one.bf);
    BufferedImage image2 = JavaImageMath.clone(two.bf);

    WritableRaster r1 = image.getRaster();
    WritableRaster r2 = image2.getRaster();
    int newWidth = Math.max(r1.getWidth(), r2.getWidth());
    int newHeight = Math.max(r1.getHeight(), r2.getHeight());

    BufferedImage collage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_RGB);
    WritableRaster raster = collage.getRaster();

    int[] p1 = new int[3];
    int[] p2 = new int[3];
    int[] pixelArray = new int[3];
    for (int y = 0; y < newHeight; y++) {
      for (int x = 0; x < newWidth; x++) {
        p1 = null;
        p2 = null;

        if (x < r1.getWidth() && y < r1.getHeight()) {
          p1 = r1.getPixel(x, y, p1);
        }

        if (x < r2.getWidth() && y < r2.getHeight()) {
          p2 = r2.getPixel(x, y, p2);
        }

        for (int i = 0; i < 3; i++) {
          if (p1 == null && p2 == null) {
            pixelArray[i] = 0;
          } else if (p1 == null && p2 != null) {
            pixelArray[i] = p2[i];
          } else if (p1 != null && p2 == null) {
            pixelArray[i] = p1[i];
          } else {
            pixelArray[i] = (int) ((p1[i] + p2[i]) / 2);
          }
        }
        raster.setPixel(x, y, pixelArray);
      }
    }

    // save image
    String outputFn =
        one.filename.substring(0, one.filename.indexOf(".jpg"))
            + "X"
            + // filename can't contain the / or *characters; decide later
            two.filename.substring(0, two.filename.indexOf(".jpg"))
            + counter
            + ".jpg";
    counter++;

    return new ArthurImage(collage, outputFn);
  }
Esempio n. 8
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

    int minw = getPaddingLeft() + getPaddingRight() + getSuggestedMinimumWidth();
    int w = Math.max(minw, MeasureSpec.getSize(widthMeasureSpec));

    int minh = getPaddingBottom() + getPaddingTop();
    int h = Math.max(minh, MeasureSpec.getSize(heightMeasureSpec));

    setMeasuredDimension(w, h);
  }
Esempio n. 9
0
  public boolean onToolTouchEvent(MotionEvent event) {
    if (mapView == null || mapView.isClickable()) {
      return false;
    }
    Projection pj = editingViewProjection;

    // handle drawing
    float currentX = event.getX();
    float currentY = event.getY();

    int action = event.getAction();
    switch (action) {
      case MotionEvent.ACTION_DOWN:
        GeoPoint startGeoPoint = pj.fromPixels(round(currentX), round(currentY));
        pj.toPixels(startGeoPoint, startP);

        lastX = currentX;
        lastY = currentY;
        break;
      case MotionEvent.ACTION_MOVE:
        float dx = currentX - lastX;
        float dy = currentY - lastY;
        if (abs(dx) < 1 && abs(dy) < 1) {
          lastX = currentX;
          lastY = currentY;
          return true;
        }
        GeoPoint currentGeoPoint = pj.fromPixels(round(currentX), round(currentY));
        pj.toPixels(currentGeoPoint, tmpP);

        left = Math.min(tmpP.x, startP.x);
        right = Math.max(tmpP.x, startP.x);
        bottom = Math.max(tmpP.y, startP.y);
        top = Math.min(tmpP.y, startP.y);
        rect.set((int) left, (int) top, (int) right, (int) bottom);

        EditManager.INSTANCE.invalidateEditingView();
        break;
      case MotionEvent.ACTION_UP:
        float deltaY = abs(top - bottom);
        float deltaX = abs(right - left);
        if (deltaX > TOUCH_BOX_THRES && deltaY > TOUCH_BOX_THRES) {
          GeoPoint ul = pj.fromPixels((int) left, (int) top);
          GeoPoint lr = pj.fromPixels((int) right, (int) bottom);

          select(ul.getLatitude(), ul.getLongitude(), lr.getLatitude(), lr.getLongitude());
        }

        break;
    }

    return true;
  }
Esempio n. 10
0
  /**
   * Decompress the input stream. The result is left in the a[] array and can be accessed using the
   * various get methods.
   */
  public void decompress() throws Exception {

    decode(); // Launch decoding
    undigitize(); // Un-Digitize

    if (tmp == null || tmp.length < Math.max(nx, ny)) {
      tmp = new int[Math.max(nx, ny)];
      flag = new boolean[Math.max(nx, ny)];
    }

    hinv(); // Inverse H-transform
  }
Esempio n. 11
0
  public void setCalculationValues() {
    int atom1 = myAtoms[0].getMM3TypeNum();
    int atom2 = myAtoms[1].getMM3TypeNum();
    int atom3 = myAtoms[2].getMM3TypeNum();

    if (atom1 < atom3 || atom1 < 1 || atom2 < 1 || atom3 < 1) {
      kBondAngle = 0.0;
      return;
    }

    try {
      AtomDataFile dataFile =
          new AtomDataFile(newNanocad.txtDir + newNanocad.fileSeparator + "mm3strbenddata.txt");
      // AtomDataFile dataFile = new AtomDataFile("mm3strbenddata.txt");
      if (dataFile.findData(atom1, 0)) kBondAngle = dataFile.parseDouble(1);
      else {
        kBondAngle = 0.0;
        return;
      }

      dataFile = new AtomDataFile(newNanocad.txtDir + newNanocad.fileSeparator + "mm3adata.txt");
      // dataFile = new AtomDataFile("mm3adata.txt");
      if (dataFile.findData(atom2, atom1, atom3, 1, 0, 2))
        idealAngle = convert * dataFile.parseDouble(4);
      else {
        idealAngle = 0.0;
        return;
      }

      dataFile = new AtomDataFile(newNanocad.txtDir + newNanocad.fileSeparator + "mm3ldata.txt");
      // dataFile = new AtomDataFile("mm3ldata.txt");
      if (dataFile.findData(Math.min(atom1, atom2), Math.max(atom1, atom2), 0, 1))
        idealLength1 = dataFile.parseDouble(3);
      else {
        idealLength1 = 0.0;
        return;
      }

      if (dataFile.findData(Math.min(atom2, atom3), Math.max(atom2, atom3), 0, 1))
        idealLength2 = dataFile.parseDouble(3);
      else {
        idealLength2 = 0.0;
        return;
      }
    } catch (java.io.IOException e) {
      System.err.println("Stretch-bend data lookup error");
      e.printStackTrace();
    }
  }
Esempio n. 12
0
 /* Result is the numeric value of the largest value.
  */
 public static SchemaTypeNumber max(SchemaTypeNumber value1, SchemaTypeNumber value2) {
   switch (java.lang.Math.max(value1.numericType(), value2.numericType())) {
     case SchemaTypeNumber.NUMERIC_VALUE_INT:
       return new SchemaInt(java.lang.Math.max(value1.intValue(), value2.intValue()));
     case SchemaTypeNumber.NUMERIC_VALUE_LONG:
       return new SchemaLong(java.lang.Math.max(value1.longValue(), value2.longValue()));
     case SchemaTypeNumber.NUMERIC_VALUE_BIGINTEGER:
       return new SchemaInteger(value1.bigIntegerValue().max(value2.bigIntegerValue()));
     case SchemaTypeNumber.NUMERIC_VALUE_FLOAT:
       return new SchemaFloat(java.lang.Math.max(value1.floatValue(), value2.floatValue()));
     case SchemaTypeNumber.NUMERIC_VALUE_DOUBLE:
       return new SchemaDouble(java.lang.Math.max(value1.doubleValue(), value2.doubleValue()));
   }
   return new SchemaDecimal(value1.bigDecimalValue().max(value2.bigDecimalValue()));
 }
Esempio n. 13
0
 public int maxArea(int[] height) {
   int left = 0;
   int right = height.length - 1;
   int area = 0;
   while (left < right) {
     if (height[left] < height[right]) {
       area = Math.max(area, (right - left) * height[left]);
       left++;
     } else {
       area = Math.max(area, (right - left) * height[right]);
       right--;
     }
   }
   return area;
 }
Esempio n. 14
0
 /**
  * Pushes a new Construct onto the end of the array. If the index is specified, this works like a
  * "insert" operation, in that all values are shifted to the right, starting with the value at
  * that index. If the array is associative though, you MUST send null, otherwise an {@link
  * IllegalArgumentException} is thrown. Ideally, you should use {@link #set} anyways for an
  * associative array.
  *
  * @param c The Construct to add to the array
  * @throws IllegalArgumentException If index is not null, and this is an associative array.
  * @throws IndexOutOfBoundsException If the index is not null, and the index specified is out of
  *     range.
  */
 public void push(Construct c, Integer index, Target t)
     throws IllegalArgumentException, IndexOutOfBoundsException {
   if (!associative_mode) {
     if (index != null) {
       array.add(index, c);
     } else {
       array.add(c);
     }
     next_index++;
   } else {
     if (index != null) {
       throw new IllegalArgumentException("Cannot insert into an associative array");
     }
     int max = 0;
     for (String key : associative_array.keySet()) {
       try {
         int i = Integer.parseInt(key);
         max = java.lang.Math.max(max, i);
       } catch (NumberFormatException e) {
       }
     }
     if (c instanceof CEntry) {
       associative_array.put(Integer.toString(max + 1), ((CEntry) c).construct());
     } else {
       associative_array.put(Integer.toString(max + 1), c);
     }
   }
   if (c instanceof CArray) {
     ((CArray) c).parent = this;
   }
   regenValue(new HashSet<CArray>());
 }
Esempio n. 15
0
  public static double Silhouette(
      ArrayList<ArrayList<ArrayList<Double>>> clusters, double[][] means) {
    /*
     * Silhouette is a measurement of how consistent the clusters are
     * It measures how tight and spread out the clusters are.
     * S(i) = (b(i) - a(i)) / max(b(i),a(i)
     * i = a single observation
     */
    double s = 0.0;
    double s_temp = 0.0;
    double a_j = 0.0;
    double b_j = 0.0;

    for (int i = 0; i < clusters.size(); i++) {
      for (int j = 0; j < clusters.get(i).size(); j++) {
        a_j = a(clusters, i, j);
        b_j = b(clusters, means, i, j);
        s_temp += ((b_j - a_j) / Math.max(b_j, a_j));
      }
      s += s_temp;
      s_temp = 0;
    }

    s = (double) s / (double) clusters.size();
    return s;
  }
Esempio n. 16
0
 private void startReadTrack() {
   setExecutionMode();
   clearRegs012();
   this.sectorIdCyl = this.args[2];
   this.sectorIdHead = this.args[3];
   this.sectorIdRec = 1;
   this.sectorIdSizeCode = this.args[5];
   this.curSectorReader = null;
   this.curSectorIdx = 0;
   this.tcEnabled = true;
   boolean done = false;
   FloppyDiskDrive drive = getArgDrive();
   if (drive != null) {
     if (drive.isReady()) {
       this.dataLen = getArgDataLen();
       this.executingDrive = drive;
       startIOTask(
           IOTaskCmd.READ_SECTOR_BY_INDEX,
           Math.max(this.tStatesPerRotation - this.tStateRotationCounter, 0));
       done = true;
     }
   }
   if (!done) {
     this.statusReg0 |= ST0_ABNORMAL_TERMINATION;
     this.statusReg0 |= ST0_EQUIPMENT_CHECK;
     this.statusReg0 |= ST0_NOT_READY;
     this.statusReg0 |= (this.args[1] & HEAD_DRIVE_MASK);
     stopExecution();
   }
 }
Esempio n. 17
0
 protected static SchemaType getCommonNumberInstance(SchemaType a_value, SchemaType b) {
   return (SchemaType)
       getCommonNumberInstance(
           java.lang.Math.max(
               ((SchemaTypeNumber) a_value).numericType(), ((SchemaTypeNumber) b).numericType()),
           (SchemaTypeNumber) a_value);
 }
Esempio n. 18
0
 public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
   int M = sc.nextInt();
   int N = sc.nextInt();
   int a[][] = new int[M + 1][N + 1];
   int dp[][] = new int[M + 1][N + 1];
   for (int i = 1; i <= M; i++) {
     for (int j = 1; j <= N; j++) {
       a[i][j] = sc.nextInt();
       if (a[i][j] == 0) a[i][j] = -9999999;
     }
   }
   for (int i = 1; i <= M; i++) {
     for (int j = 1; j <= N; j++) {
       dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + a[i][j];
     }
   }
   int max = -100000000;
   for (int i = 1; i <= M; i++) {
     for (int j = 1; j <= N; j++) {
       for (int k = 1; k <= M; k++) {
         if (i + k > M) break;
         else if (j + k > N) break;
         int temp = dp[i + k][j + k] - dp[i - 1][j + k] - dp[i + k][j - 1] + dp[i - 1][j - 1];
         max = Math.max(max, temp);
       }
     }
   }
   System.out.println(max);
 }
Esempio n. 19
0
 public CArray(Target t, int initialCapacity, Construct... items) {
   super("{}", ConstructType.ARRAY, t);
   if (initialCapacity == -1) {
     associative_mode = true;
   } else if (items != null) {
     for (Construct item : items) {
       if (item instanceof CEntry) {
         // it's an associative array
         associative_mode = true;
         break;
       }
     }
   }
   associative_array = new TreeMap<>(comparator);
   array =
       associative_mode
           ? new ArrayList<Construct>()
           : initialCapacity > 0
               ? new ArrayList<Construct>(initialCapacity)
               : items != null
                   ? new ArrayList<Construct>(items.length)
                   : new ArrayList<Construct>();
   if (associative_mode) {
     if (items != null) {
       for (Construct item : items) {
         if (item instanceof CEntry) {
           associative_array.put(
               normalizeConstruct(((CEntry) item).ckey), ((CEntry) item).construct);
         } else {
           int max = Integer.MIN_VALUE;
           for (String key : associative_array.keySet()) {
             try {
               int i = Integer.parseInt(key);
               max = java.lang.Math.max(max, i);
             } catch (NumberFormatException e) {
             }
           }
           if (max == Integer.MIN_VALUE) {
             max = -1; // Special case, there are no integer indexes in here yet.
           }
           associative_array.put(Integer.toString(max + 1), item);
           if (item instanceof CArray) {
             ((CArray) item).parent = this;
           }
         }
       }
     }
   } else {
     if (items != null) {
       for (Construct item : items) {
         array.add(item);
         if (item instanceof CArray) {
           ((CArray) item).parent = this;
         }
       }
     }
     this.next_index = array.size();
   }
   regenValue(new HashSet<CArray>());
 }
Esempio n. 20
0
 public static double max(double... vals) {
   double max = -Double.MAX_VALUE;
   for (double v : vals) {
     max = Math.max(v, max);
   }
   return max;
 }
Esempio n. 21
0
  /**
   * Compare this package's specification version with a desired version. It returns true if this
   * packages specification version number is greater than or equal to the desired version number.
   *
   * <p>Version numbers are compared by sequentially comparing corresponding components of the
   * desired and specification strings. Each component is converted as a decimal integer and the
   * values compared. If the specification value is greater than the desired value true is returned.
   * If the value is less false is returned. If the values are equal the period is skipped and the
   * next pair of components is compared.
   *
   * @param desired the version string of the desired version.
   * @return true if this package's version number is greater than or equal to the desired version
   *     number
   * @exception NumberFormatException if the desired or current version is not of the correct dotted
   *     form.
   */
  public boolean isCompatibleWith(String desired) throws NumberFormatException {
    if (specVersion == null || specVersion.length() < 1) {
      throw new NumberFormatException("Empty version string");
    }

    String[] sa = specVersion.split("\\.", -1);
    int[] si = new int[sa.length];
    for (int i = 0; i < sa.length; i++) {
      si[i] = Integer.parseInt(sa[i]);
      if (si[i] < 0) throw NumberFormatException.forInputString("" + si[i]);
    }

    String[] da = desired.split("\\.", -1);
    int[] di = new int[da.length];
    for (int i = 0; i < da.length; i++) {
      di[i] = Integer.parseInt(da[i]);
      if (di[i] < 0) throw NumberFormatException.forInputString("" + di[i]);
    }

    int len = Math.max(di.length, si.length);
    for (int i = 0; i < len; i++) {
      int d = (i < di.length ? di[i] : 0);
      int s = (i < si.length ? si[i] : 0);
      if (s < d) return false;
      if (s > d) return true;
    }
    return true;
  }
Esempio n. 22
0
  /**
   * check if the given position collides with the flashlight.
   *
   * @param point
   * @return
   */
  public boolean flashlightCollision(Point2D point) {

    flY23 = flY2 - flY3;
    flX32 = flX3 - flX2;
    flY31 = flY3 - flY1;
    flX13 = flX1 - flX3;
    flDet = flY23 * flX13 - flX32 * flY31;
    flMinD = Math.min(flDet, 0);
    flMaxD = Math.max(flDet, 0);

    double x = point.getX();
    double y = point.getY();
    double dx = x - flX3;
    double dy = y - flY3;
    double a = flY23 * dx + flX32 * dy;
    if (a < flMinD || a > flMaxD) {
      return false;
    }
    double b = flY31 * dx + flX13 * dy;
    if (b < flMinD || b > flMaxD) {
      return false;
    }
    double c = flDet - a - b;
    return !(c < flMinD || c > flMaxD);
  }
Esempio n. 23
0
 public void applyContour() {
   int maxHeight = 1;
   for (int x = 0; x < m_width; x++) {
     for (int y = 0; y < m_height; y++) {
       if (m_contour[x][y] > maxHeight) maxHeight = m_contour[x][y];
     }
   }
   m_logger.debug("Applying contour");
   for (int x = 0; x < m_width; x++) {
     for (int y = 0; y < m_height; y++) {
       int h = Math.max(0, Math.min(m_depth - 1, (m_depth / 2) + m_contour[x][y]));
       // int d = m_random.nextInt(8) - 4;
       for (int z = 0; z < m_depth; z++) {
         int type = BlockConstants.AIR;
         if (z >= h && z < m_depth / 2 - 1) {
           type = BlockConstants.WATER;
         } else if (z >= h) {
           type = BlockConstants.AIR;
         } else if (z == (h - 1)) {
           type = BlockConstants.GRASS;
         } else if (z < (h - 1) && z > (h - 5)) {
           type = BlockConstants.DIRT;
         } else if (z <= (h - 5)) {
           type = BlockConstants.ROCK;
         }
         m_blocks[x][y][z] = (byte) type;
       }
     }
   }
 }
Esempio n. 24
0
 @Override
 public void handleCommand(InsteonPLMBindingConfig conf, Command cmd, InsteonDevice dev) {
   try {
     if (cmd == OnOffType.ON) {
       Msg m = dev.makeStandardMessage((byte) 0x0f, (byte) 0x11, (byte) 0xff);
       dev.enqueueMessage(m, m_feature);
       logger.info("{}: sent msg to switch {} on", nm(), dev.getAddress());
     } else if (cmd == OnOffType.OFF) {
       Msg m = dev.makeStandardMessage((byte) 0x0f, (byte) 0x13, (byte) 0x00);
       dev.enqueueMessage(m, m_feature);
       logger.info("{}: sent msg to switch {} off", nm(), dev.getAddress());
     }
     // This used to be configurable, but was made static to make
     // the architecture of the binding cleaner.
     int delay = 2000;
     delay = Math.max(1000, delay);
     delay = Math.min(10000, delay);
     Timer timer = new Timer();
     timer.schedule(
         new TimerTask() {
           @Override
           public void run() {
             Msg m = m_feature.makePollMsg();
             InsteonDevice dev = m_feature.getDevice();
             if (m != null) dev.enqueueMessage(m, m_feature);
           }
         },
         delay);
   } catch (IOException e) {
     logger.error("{}: command send i/o error: ", nm(), e);
   } catch (FieldException e) {
     logger.error("{}: command send message creation error: ", nm(), e);
   }
 }
  private void drawGpsStatus(Graphics g) {
    if ((m_fix > 0) && (m_sats >= 0)) {
      // Set background to signal quality
      g.setColor(GREEN);
    } else
    // receiving data, but signal ist not good
    if ((m_fix == 0) && (m_sats >= 0)) {
      g.setColor(YELLOW);
    } else {
      g.setColor(RED);
    }

    String strSats = "Sats: -";
    if (m_sats >= 0) {
      strSats = "Sats: " + Convert.toString(m_sats) + "/" + Convert.toString(m_satsInView);
    }
    String strHdop = "HDOP: -";
    if (m_hdop >= 0) strHdop = "HDOP: " + Convert.toString(m_hdop);

    int textWidth = java.lang.Math.max(fm.getTextWidth(strSats), fm.getTextWidth(strHdop));
    int startX = location.width - (textWidth + 4);
    int startY = location.height - 2 * lineHeight;
    g.fillRect(startX, startY, location.width - startX, location.height - startY);

    g.setColor(Color.Black);
    g.drawText(strSats, startX + 2, startY);
    g.drawText(strHdop, startX + 2, startY + lineHeight);
  }
 public SparseVector(int length, int capacity) {
   if (length <= 0) throw new ArithmeticException("Vector must have a positive dimension");
   this.used = 0;
   capacity = Math.max(capacity, 10);
   this.length = length;
   this.indexes = new int[capacity];
   this.values = new double[capacity];
 }
 public void postOnNewPicture(Callable<Picture> pictureProvider) {
   if (mHasPendingOnNewPicture) return;
   mHasPendingOnNewPicture = true;
   long pictureTime =
       java.lang.Math.max(
           mLastPictureTime + ON_NEW_PICTURE_MIN_PERIOD_MILLIS, SystemClock.uptimeMillis());
   mHandler.sendMessageAtTime(
       mHandler.obtainMessage(MSG_ON_NEW_PICTURE, pictureProvider), pictureTime);
 }
  @Override
  public double max() {
    if (maxCache != null) return maxCache;

    double result = 0;
    for (int i = 0; i < used; i++) result = Math.max(result, values[i]);

    return (maxCache = result);
  }
  private void drawGpsData(Graphics g) {
    g.setColor(RED);

    String strHeadline = MyLocale.getMsg(1501, "Current");

    Double tmp = new Double();

    String strSpeed = null;
    String unit = null;

    // Allow for different metric systems
    if (Global.getPref().metricSystem == Metrics.IMPERIAL) {
      tmp.set(Metrics.convertUnit(m_speed, Metrics.KILOMETER, Metrics.MILES));
      unit = " mph";
      strSpeed = "- mph";
    } else {
      tmp.set(m_speed);
      unit = " km/h";
      strSpeed = "- km/h";
    }
    if (tmp.value >= 0) {
      if (tmp.value >= 100) {
        strSpeed = MyLocale.formatDouble(tmp, "0") + unit;
      } else {
        strSpeed = MyLocale.formatDouble(tmp, "0.0") + unit;
      }
    }

    tmp.set(moveDir);
    String strMoveDir = "---" + " " + MyLocale.getMsg(1502, "deg");
    if ((tmp.value <= 360) && (tmp.value >= -360))
      strMoveDir = tmp.toString(0, 0, 0) + " " + MyLocale.getMsg(1502, "deg");

    int textWidth = java.lang.Math.max(fm.getTextWidth(strSpeed), fm.getTextWidth(strMoveDir));
    textWidth = java.lang.Math.max(textWidth, fm.getTextWidth(strHeadline));

    int startX = location.width - (textWidth + 4);
    g.fillRect(startX, 0, location.width - startX, lineHeight);

    g.setColor(Color.Black);
    g.drawText(strHeadline, startX + 2, 0);
    g.drawText(strSpeed, startX + 2, lineHeight);
    g.drawText(strMoveDir, startX + 2, 2 * lineHeight);
  }
  @Override
  public Vec clone() {
    SparseVector copy = new SparseVector(length, Math.max(used, 10));

    System.arraycopy(this.values, 0, copy.values, 0, this.used);
    System.arraycopy(this.indexes, 0, copy.indexes, 0, this.used);
    copy.used = this.used;

    return copy;
  }