Пример #1
0
  /**
   * Draw the given polygon, filled with the specified colour.
   *
   * @param p The polygon to draw.
   * @param col The colour to fill the polygon with.
   */
  public void drawPolygonFilled(Polygon p, final Q col) {
    // clip to the frame
    p = p.intersect(this.targetImage.getBounds().asPolygon());

    this.drawPolygon(p, col);

    if (p.getNumInnerPoly() == 1) {
      ScanRasteriser.scanFill(
          p.points,
          new ScanLineListener() {
            @Override
            public void process(final int x1, final int x2, final int y) {
              ImageRenderer.this.drawHorizLine(x1, x2, y, col);
            }
          });
    } else {
      // final ConnectedComponent cc = new ConnectedComponent(p);
      // cc.process(new BlobRenderer<Q>(this.targetImage, col));

      final int minx = Math.max(0, (int) Math.round(p.minX()));
      final int maxx = Math.min((int) Math.round(p.maxX()), targetImage.getWidth() - 1);
      final int miny = Math.max(0, (int) Math.round(p.minY()));
      final int maxy = Math.min((int) Math.round(p.maxY()), targetImage.getHeight() - 1);

      final Pixel tmp = new Pixel();
      for (tmp.y = miny; tmp.y <= maxy; tmp.y++) {
        for (tmp.x = minx; tmp.x <= maxx; tmp.x++) {
          if (p.isInside(tmp)) this.targetImage.setPixel(tmp.x, tmp.y, col);
        }
      }
    }
  }
 @SuppressWarnings("unchecked")
 private I createArchiveInputStream() throws IOException {
   I archiveIn;
   FileInputStream in;
   if (file.isFile() && file.canRead()) {
     in = new FileInputStream(file);
   } else {
     throw new FileNotFoundException(
         "can't open for input, check existence or access rights: " + path);
   }
   String pathStr = path.toString();
   Set<String> streamCodecs = CompressCodecService.getCodecs();
   for (String codec : streamCodecs) {
     if (pathStr.endsWith("." + codec)) {
       archiveIn =
           (I)
               archiveService
                   .getCodec(getName())
                   .createArchiveInputStream(codecService.getCodec(codec).decode(in));
       archiveIn.setWatcher(watcher);
       return archiveIn;
     }
   }
   archiveIn = (I) archiveService.getCodec(getName()).createArchiveInputStream(in);
   archiveIn.setWatcher(watcher);
   return archiveIn;
 }
Пример #3
0
    public TreeNode remove(I t, TreeNode n) {
      if (t == null) {
        throw new RuntimeException("Node not found with data: " + t);
      }
      if (n == null) {
        throw new RuntimeException("Invalid node!");
      }

      I x = n.data;

      if (n.left != null || n.right != null) {
        if (x.compareTo(t) < 0) {
          n.left = remove(t, n.left);

        } else if (x.compareTo(t) > 0) {
          n.right = remove(t, n.right);

        } else if (n.left != null && n.right != null) { // Two children
          // n.data = findMin( n.right ).element;
          // n.right = removeMin( n.right );
        } else {
          n = (n.left != null) ? n.left : n.right;
        }
      } else {
        n = null;
      }
      return n;
    }
 /**
  * 设置全部结束
  *
  * @return
  * @throws WebDataException
  */
 public String setIssueClose() {
   Map<String, Object> map = new HashMap<String, Object>();
   try {
     AdminUser adminUser = getAdminUser();
     if (null == adminUser) {
       throw new WebDataException("你还没有登录!");
     }
     if (this.id == null) {
       throw new DataException("期号ID不能为空.");
     }
     kenoService.updateIssueState(this.getId(), IssueState.ISSUE_SATE_FINISH);
     I issueData = kenoService.findIssueDataById(this.getId());
     // 同传统彩的期实体传数据
     Period period = new Period();
     period.setId(issueData.getId());
     period.setPeriodNumber(issueData.getPeriodNumber());
     // 记录操作日志
     eventLogManager.saveSimpleEventLog(
         period, getLottery(), adminUser, EventLogType.CloseIssue, "期号为ID:" + this.getId());
     map.put("success", true);
     map.put("msg", "期号设置结束成功");
   } catch (DataException e) {
     e.printStackTrace();
     map.put("success", false);
     map.put("msg", e.getMessage());
   } catch (Exception e) {
     e.printStackTrace();
     map.put("success", false);
     map.put("msg", "期号设置结束发生异常!");
   }
   Struts2Utils.renderJson(map);
   return null;
 }
Пример #5
0
	public static void main(String[] args) {
		I i = @Marker Y.@Marker Z @Marker [][] @Marker []::foo;
		I i2 = @Value("Joe") Y.@Value2(@Value("Joe")) @Marker Z @Marker [][] @Marker []::foo;
		I i3 = @Value("Duo") Y.@Value2(@Value("Joe")) @Marker Z::foo;
		i.foo(10);
		Zork z;
	}
  /**
   * Post merge clean up.
   *
   * <p>- Remove the removed items. - Clear the state of all the items (this allow newly overridden
   * items to lose their WRITTEN state) - Set the items that are part of the new merge to be WRITTEN
   * to allow the next merge to be incremental.
   */
  private void postMergeCleanUp() {
    ListMultimap<String, I> itemMap = ArrayListMultimap.create();

    // remove all removed items, and copy the rest in the full map while resetting their state.
    for (S dataSet : mDataSets) {
      ListMultimap<String, I> map = dataSet.getDataMap();

      List<String> keys = Lists.newArrayList(map.keySet());
      for (String key : keys) {
        List<I> list = map.get(key);
        for (int i = 0; i < list.size(); ) {
          I item = list.get(i);
          if (item.isRemoved()) {
            list.remove(i);
          } else {
            //noinspection unchecked
            itemMap.put(key, (I) item.resetStatus());
            i++;
          }
        }
      }
    }

    // for the last items (the one that have been written into the consumer), set their
    // state to WRITTEN
    for (String key : itemMap.keySet()) {
      List<I> itemList = itemMap.get(key);
      itemList.get(itemList.size() - 1).resetStatusToWritten();
    }
  }
 public void setMetadata(Map<String, Object> metadata) {
   info.clear();
   for (String key : metadata.keySet()) {
     info.addMetadata(createMetadataEntry(key, metadata.get(key).toString()));
   }
   saveMetadata();
 }
Пример #8
0
  public final boolean loadFrom(File source) {
    if (source == null) {
      throw new IllegalArgumentException(
          "The file must not be null in order to load the reflected!");
    }
    if (source.exists()) {
      I in = null;
      try {

        in = getCodec().newInput(source);
        this.loadFrom(in);
      } catch (IOException e) {
        throw new IllegalArgumentException("File to load from cannot be accessed!", e);
      } finally {
        if (in != null) {
          try {
            in.close();
          } catch (IOException e) {
            Reflector.LOGGER.log(WARNING, "Failed to close the input stream!", e);
          }
        }
      }
      this.onLoaded(source);
      return true;
    }
    LOGGER.log(Level.INFO, "Could not load reflected from file! Using default...");
    return false;
  }
 @Override
 public synchronized ArchivePacket read() throws IOException {
   if (!isOpen()) {
     throw new IOException("not open");
   }
   if (in == null) {
     throw new IOException("no input stream found");
   }
   ArchiveEntry entry = in.getNextEntry();
   if (entry == null) {
     return null;
   }
   ArchivePacket packet = newPacket();
   String name = entry.getName();
   packet.meta("name", name);
   ArchiveUtils.decodeArchiveEntryName(packet, name);
   int size = (int) entry.getEntrySize();
   if (size >= 0) {
     byte[] b = new byte[size]; // naive but fast, heap may explode
     int num = in.read(b, 0, size); // fill byte array from stream
     packet.payload(new String(b));
   } else {
     // slow copy, unknown size (zip deflate method)
     ByteArrayOutputStream b = new ByteArrayOutputStream();
     Streams.copy(in, b);
     packet.payload(new String(b.toByteArray()));
   }
   packetCounter++;
   return packet;
 }
Пример #10
0
 public Tree<I> add(I data) {
   TreeNode node = this.root;
   if (data == null) {
     return this;
   }
   if (node == null || node.data == null) {
     this.root = new TreeNode(data);
     return this;
   }
   while (node != null) {
     if (data.compareTo(node.data) == 0) {
       // I found my place in heaven - the search is over
       node = null;
     } else if (data.compareTo(node.data) < 0) {
       // The poor ones go to the south left
       if (node.left != null) {
         node = node.left;
       } else {
         node.left = new TreeNode(data);
         break;
       }
     } else if (data.compareTo(node.data) > 0) {
       // The rich ones go to the north right
       if (node.right != null) {
         node = node.right;
       } else {
         node.right = new TreeNode(data);
         break;
       }
     }
   }
   return this;
 }
  @Override
  public void doRequest(ServerData serverData) {
    CentralizedServiceWorker<I, ?, ?> serviceWorker = serverData.getServiceWorker();
    // Get the initial size of ByteArrayVertexIdMessages per partition
    // on this worker. To make sure every ByteArrayVertexIdMessages to have
    // enough space to store the messages, we divide the original one-to-all
    // message size by the number of partitions and double the size
    // (Assume the major component in one-to-all message is a id list.
    // Now each target id has a copy of message,
    // therefore we double the buffer size)
    // to get the initial size of ByteArrayVertexIdMessages.
    int initialSize =
        oneToAllMsgs.getSize() / serverData.getPartitionStore().getNumPartitions() * 2;
    // Create ByteArrayVertexIdMessages for
    // message reformatting.
    Int2ObjectOpenHashMap<ByteArrayVertexIdMessages> partitionIdMsgs =
        new Int2ObjectOpenHashMap<ByteArrayVertexIdMessages>();

    // Put data from ByteArrayOneToAllMessages to ByteArrayVertexIdMessages
    ExtendedDataInput reader = oneToAllMsgs.getOneToAllMessagesReader();
    I vertexId = getConf().createVertexId();
    M msg = oneToAllMsgs.createMessage();
    int idCount = 0;
    int partitionId = 0;
    try {
      while (reader.available() != 0) {
        msg.readFields(reader);
        idCount = reader.readInt();
        for (int i = 0; i < idCount; i++) {
          vertexId.readFields(reader);
          PartitionOwner owner = serviceWorker.getVertexPartitionOwner(vertexId);
          partitionId = owner.getPartitionId();
          ByteArrayVertexIdMessages<I, M> idMsgs = partitionIdMsgs.get(partitionId);
          if (idMsgs == null) {
            idMsgs =
                new ByteArrayVertexIdMessages<I, M>(getConf().<M>getOutgoingMessageValueFactory());
            idMsgs.setConf(getConf());
            idMsgs.initialize(initialSize);
            partitionIdMsgs.put(partitionId, idMsgs);
          }
          idMsgs.add(vertexId, msg);
        }
      }
    } catch (IOException e) {
      throw new RuntimeException("doRequest: Got IOException ", e);
    }
    // Read ByteArrayVertexIdMessages and write to message store
    try {
      for (Entry<Integer, ByteArrayVertexIdMessages> idMsgs : partitionIdMsgs.entrySet()) {
        if (!idMsgs.getValue().isEmpty()) {
          serverData
              .getIncomingMessageStore()
              .addPartitionMessages(idMsgs.getKey(), idMsgs.getValue());
        }
      }
    } catch (IOException e) {
      throw new RuntimeException("doRequest: Got IOException.", e);
    }
  }
Пример #12
0
 public Ecaille() {
   A.add(new Attribut("ResFroid", -10));
   A.add(new Attribut("ResChaud", 10));
   A.add(new Attribut("Combat", 10));
   Nom = "Ecaille";
   I.add(new Interdit("Plumage"));
   I.add(new Interdit("Fourrure"));
 }
 @Override
 public void initialize() {
   final I inType = in().firstElement().createVariable();
   final double minVal = inType.getMinValue();
   final UnaryComputerOp<I, O> invert =
       minVal < 0 ? new SignedRealInvert<>() : new UnsignedRealInvert<>(inType.getMaxValue());
   mapper = Computers.unary(ops(), Ops.Map.class, out(), in(), invert);
 }
Пример #14
0
 @Override
 public final int hashCode() {
   int h = 0;
   for (I item : this) {
     if (item == null) continue;
     h += item.hashCode();
   }
   return h;
 }
Пример #15
0
  /**
   * Draw into this image the provided image at the given coordinates. Parts of the image outside
   * the bounds of this image will be ignored.
   *
   * @param image The image to draw.
   * @param x The x-coordinate of the top-left of the image
   * @param y The y-coordinate of the top-left of the image
   */
  public void drawImage(final I image, final int x, final int y) {
    final int stopx = Math.min(this.targetImage.getWidth(), x + image.getWidth());
    final int stopy = Math.min(this.targetImage.getHeight(), y + image.getHeight());
    final int startx = Math.max(0, x);
    final int starty = Math.max(0, y);

    for (int yy = starty; yy < stopy; yy++)
      for (int xx = startx; xx < stopx; xx++)
        this.targetImage.setPixel(xx, yy, image.getPixel(xx - x, yy - y));
  }
 /**
  * 显示更新期数据页
  *
  * @return
  * @throws WebDataException
  */
 public String edit() throws WebDataException {
   AdminUser adminUser = getAdminUser();
   if (null == adminUser) {
     throw new WebDataException("你还没有登录!");
   }
   if (issueData != null && issueData.getId() != null) {
     issueData = kenoService.findIssueDataById(issueData.getId());
   }
   return INPUT;
 }
 protected void processIdentifiers(I objectToEnrich, I objectSource) throws EnricherException {
   EnricherUtils.mergeXrefs(
       objectToEnrich,
       objectToEnrich.getIdentifiers(),
       objectSource.getIdentifiers(),
       true,
       true,
       getInteractionEnricherListener(),
       getInteractionEnricherListener());
 }
  protected void processParticipants(I objectToEnrich, I objectSource) throws EnricherException {
    EnricherUtils.mergeParticipants(
        objectToEnrich,
        objectToEnrich.getParticipants(),
        objectSource.getParticipants(),
        true,
        getInteractionEnricherListener(),
        getParticipantEnricher());

    processParticipants(objectToEnrich);
  }
Пример #19
0
 @Override
 public ItemDefinition getItemDefinition() {
   ItemDefinition propDef = null;
   if (container.getItemDefinition() != null) {
     propDef =
         container.getItemDefinition().findItemDefinition(property.getDefinition().getName());
   }
   if (propDef == null) {
     propDef = property.getDefinition();
   }
   return propDef;
 }
Пример #20
0
  /**
   * Computes the hessian from the original input image. Only Sobel and Three supported.
   *
   * @param type Type of gradient to compute
   * @param input Input image
   * @param derivXX Output. Derivative XX
   * @param derivYY Output. Derivative YY
   * @param derivXY Output. Derivative XY
   * @param borderType How it should handle borders. null == skip border
   * @param <I> Input image type
   * @param <D> Output image type
   */
  public static <I extends ImageSingleBand, D extends ImageSingleBand> void hessian(
      DerivativeType type, I input, D derivXX, D derivYY, D derivXY, BorderType borderType) {
    ImageBorder<I> border =
        BorderType.SKIP == borderType ? null : FactoryImageBorder.general(input, borderType);

    switch (type) {
      case SOBEL:
        if (input instanceof ImageFloat32) {
          HessianSobel.process(
              (ImageFloat32) input,
              (ImageFloat32) derivXX,
              (ImageFloat32) derivYY,
              (ImageFloat32) derivXY,
              (ImageBorder_F32) border);
        } else if (input instanceof ImageUInt8) {
          HessianSobel.process(
              (ImageUInt8) input,
              (ImageSInt16) derivXX,
              (ImageSInt16) derivYY,
              (ImageSInt16) derivXY,
              (ImageBorder_I32) border);
        } else {
          throw new IllegalArgumentException(
              "Unknown input image type: " + input.getClass().getSimpleName());
        }
        break;

      case THREE:
        if (input instanceof ImageFloat32) {
          HessianThree.process(
              (ImageFloat32) input,
              (ImageFloat32) derivXX,
              (ImageFloat32) derivYY,
              (ImageFloat32) derivXY,
              (ImageBorder_F32) border);
        } else if (input instanceof ImageUInt8) {
          HessianThree.process(
              (ImageUInt8) input,
              (ImageSInt16) derivXX,
              (ImageSInt16) derivYY,
              (ImageSInt16) derivXY,
              (ImageBorder_I32) border);
        } else {
          throw new IllegalArgumentException(
              "Unknown input image type: " + input.getClass().getSimpleName());
        }
        break;

      default:
        throw new IllegalArgumentException("Unsupported derivative type " + type);
    }
  }
Пример #21
0
    @Override
    @SuppressWarnings("unchecked")
    public void handleSuccess(ItemUpdates<I> aResult) {
      GWT.log("RPC-response: received new items");
      isLoading = false;
      if (myKnownItems == null) {
        myKnownItems = new HashMap<U, I>();
      }

      ArrayList<I> theOldValue = null;
      if (myVisibleItems != null) {
        theOldValue = new ArrayList<I>();
        theOldValue.addAll(myVisibleItems);
        myVisibleItems.clear();
      } else {
        myVisibleItems = new ArrayList<I>();
      }

      // update the local data.
      updateItems(aResult.getItems());
      if (aResult.getNewlyCreatedItem() != null) {
        updateItems(Arrays.asList(aResult.getNewlyCreatedItem()));
      }

      final ArrayList<BonitaUUID> theVisibleItemsUUIDs = new ArrayList<BonitaUUID>();
      for (I theItem : aResult.getItems()) {
        myVisibleItems.add(myKnownItems.get(theItem.getUUID()));
        theVisibleItemsUUIDs.add(theItem.getUUID());
      }

      // Keep the selection consistent
      final ArrayList<U> selectedItems = new ArrayList<U>(myItemSelection.getSelectedItems());
      for (U theItemUUID : selectedItems) {
        if (!theVisibleItemsUUIDs.contains(theItemUUID)) {
          GWT.log(
              "Removed item from selection as it do not belong to the visible items anymore: "
                  + theItemUUID.getValue());
          myItemSelection.removeItemFromSelection(theItemUUID);
        }
      }

      // Store the total size.
      mySize = aResult.getNbOfItems();
      if (myMessageDataSource != null) {
        myMessageDataSource.addInfoMessage(
            patterns.lastTimeRefreshed(
                DateTimeFormat.getFormat(constants.timeShortFormat()).format(new Date())));
      }
      myChanges.fireModelChange(ITEM_LIST_PROPERTY, theOldValue, myVisibleItems);
    }
Пример #22
0
 private <C extends Collection<R>> C mapInto(C collection, ResultSet rs) throws SQLException {
   R root = null;
   I previousId = null;
   while (rs.next()) {
     I id = mapId(rs);
     if (!id.equals(previousId)) {
       root = mapRoot(id, rs);
       collection.add(root);
     }
     addChild(root, rs);
     previousId = id;
   }
   return collection;
 }
Пример #23
0
 public static String test(
     boolean b,
     String p0,
     String p1,
     String p2,
     String p3,
     String p4,
     String p5,
     String p6,
     String p7,
     String p8,
     String p9) {
   I i = b ? new A() : new B();
   return i.test(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
 }
Пример #24
0
  public void B(boolean flag) {
    boolean flag1 = !H.A(this);
    synchronized (P) {
      for (Iterator iterator = P.iterator(); iterator.hasNext(); ) {
        I i = (I) iterator.next();
        if (i.A()) {
          F++;
          A.C();
        }
        int j = 0;
        Packet b = i.D();
        int k = b.I();
        do {
          com.jcumulus.server.rtmfp.stream.B b1 = H.B();
          if (b1.D() < 12) {
            H.A(false);
            flag1 = true;
          }
          boolean flag2 = flag1;
          int l = k;
          int i1 = l + 4;
          N++;
          if (flag2) i1 += D(N);
          byte byte0 = 0;
          if (j > 0) byte0 |= com.jcumulus.server.rtmfp.publisher.E.M.intValue();
          if (i1 > b1.D()) {
            byte0 |= com.jcumulus.server.rtmfp.publisher.E.C.intValue();
            l = b1.D() - (i1 - l);
            i1 = b1.D();
            flag1 = true;
          } else {
            flag1 = false;
          }
          i1 -= 3;
          A(H.A(((byte) (flag2 ? 16 : 17)), (short) i1, this), N, byte0, flag2, b, l);
          i.B().put(Integer.valueOf(j), Integer.valueOf(N));
          k -= l;
          j += l;
        } while (k > 0);
        synchronized (O) {
          O.add(i);
        }
      }

      P.clear();
    }
    if (flag) H.A(true);
  }
Пример #25
0
 /**
  * This is related to the status change listeners ({@link #statusListeners}).
  *
  * <p style="color='ORANGE'">Don't need to override this method.
  *
  * @param commId
  */
 protected void sendManagerSystemRemoved(I commId) {
   synchronized (statusListeners) {
     for (L sl : statusListeners) {
       sl.managerSystemRemoved(commId.toString());
     }
   }
 }
Пример #26
0
 /**
  * This is related to the status change listeners ({@link #statusListeners}).
  *
  * <p style="color='ORANGE'">Don't need to override this method.
  *
  * @param commId
  * @param status
  */
 protected void sendManagerSystemStatusChanged(I commId, int status) {
   synchronized (statusListeners) {
     for (L sl : statusListeners) {
       sl.managerSystemStatusChanged(commId.toString(), status);
     }
   }
 }
 @Override
 public void readFieldsRequest(DataInput input) throws IOException {
   partitionId = input.readInt();
   int vertexIdMutationsSize = input.readInt();
   vertexIdMutations = Maps.newHashMapWithExpectedSize(vertexIdMutationsSize);
   for (int i = 0; i < vertexIdMutationsSize; ++i) {
     I vertexId = getConf().createVertexId();
     vertexId.readFields(input);
     VertexMutations<I, V, E> vertexMutations = new VertexMutations<I, V, E>();
     vertexMutations.setConf(getConf());
     vertexMutations.readFields(input);
     if (vertexIdMutations.put(vertexId, vertexMutations) != null) {
       throw new IllegalStateException("readFields: Already has vertex id " + vertexId);
     }
   }
 }
  /** @see Transformer#transform(Object) */
  @SuppressWarnings("unchecked")
  @Override
  public Boolean transform(I input) {
    boolean valid;

    if ((input == null) && (minimumValue == null)) {
      valid = true;
    } else if (input == null) {
      // exactValue is not null, everything is bigger than null
      valid = false;
    } else if (minimumValue == null) {
      // input is not null, everything is bigger than null
      valid = true;
    } else if (input instanceof Comparable<?>) {
      // Both are not null
      valid = (((Comparable) input).compareTo(minimumValue) >= 0);
    } else if (minimumValue instanceof Comparable<?>) {
      // Both are not null
      valid = (((Comparable) minimumValue).compareTo(input) <= 0);
    } else {
      // Both are not null
      valid = input.equals(minimumValue);
    }

    return valid;
  }
Пример #29
0
 @Override
 public O compute(I x, O output) {
   double xt = x.getRealDouble();
   double value = 0.5 * Math.log((1 + xt) / (1 - xt));
   output.setReal(value);
   return output;
 }
Пример #30
0
 public void start(
     I iface,
     getStruct_args args,
     org.apache.thrift.async.AsyncMethodCallback<SharedStruct> resultHandler)
     throws TException {
   iface.getStruct(args.key, resultHandler);
 }