예제 #1
0
 /**
  * @param data
  * @param page
  * @param filters
  * @return the page of data
  */
 static <T, F extends Filters<T>> Page<T> find(List<T> data, int page, int pageSize, F filters) {
   if (filters != null && !filters.isEmpty()) {
     ProbeLogger.LOG.filtersApplied(filters);
     for (Iterator<T> iterator = data.iterator(); iterator.hasNext(); ) {
       T element = iterator.next();
       if (!filters.test(element)) {
         iterator.remove();
       }
     }
   }
   if (pageSize == 0) {
     return new Page<T>(page, 1, data.size(), data);
   } else {
     if (data.isEmpty()) {
       return new Page<T>(0, 0, 0, Collections.emptyList());
     }
     if ((page <= 0) || (page > 1 && (((page - 1) * pageSize) >= data.size()))) {
       page = 1;
     }
     int lastIdx = data.size() / pageSize;
     if (data.size() % pageSize > 0) {
       lastIdx++;
     }
     if (lastIdx == 1) {
       return new Page<T>(1, lastIdx, data.size(), data);
     }
     int start = (page - 1) * pageSize;
     int end = start + pageSize;
     if (end > data.size()) {
       end = data.size();
     }
     return new Page<T>(page, lastIdx, data.size(), data.subList(start, end));
   }
 }
  @Transactional
  public boolean importData(UserInfo userInfo, List<F> list) {
    logger.infoCode("I0001");
    try {

      for (int i = 0; i < list.size(); i++) {
        F form = list.get(i);

        T entity = (T) form.getNewTbl();
        entity = this.getPortfolioTbl(form, entity);

        entity.setPublicFlag(form.getPublicFlag());

        UsUserTbl usUserTbl = new UsUserTbl();
        usUserTbl.setUserKey(userInfo.getTargetUserKey());
        entity.setUsUserTbl(usUserTbl);
        entity.setUpdUserKey(userInfo.getLoginUserKey());
        entity.setUpdDate(DateUtil.getNowTimestamp());

        repository.save(entity);
      }

      repository.flush();
      logger.infoCode("I0002");
      return true;
    } catch (Exception e) {
      logger.errorCode("E1007", e); // E1007=登録に失敗しました。{0}
    }
    return false;
  }
  /**
   * @param nodes Nodes.
   * @param id ID.
   * @throws IgniteCheckedException If failed.
   */
  private void sendAllPartitions(
      Collection<? extends ClusterNode> nodes, GridDhtPartitionExchangeId id)
      throws IgniteCheckedException {
    GridDhtPartitionsFullMessage m =
        new GridDhtPartitionsFullMessage(id, lastVer.get(), id.topologyVersion());

    for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
      if (!cacheCtx.isLocal()) {
        AffinityTopologyVersion startTopVer = cacheCtx.startTopologyVersion();

        boolean ready = startTopVer == null || startTopVer.compareTo(id.topologyVersion()) <= 0;

        if (ready)
          m.addFullPartitionsMap(cacheCtx.cacheId(), cacheCtx.topology().partitionMap(true));
      }
    }

    // It is important that client topologies be added after contexts.
    for (GridClientPartitionTopology top : cctx.exchange().clientTopologies())
      m.addFullPartitionsMap(top.cacheId(), top.partitionMap(true));

    if (log.isDebugEnabled())
      log.debug(
          "Sending full partition map [nodeIds="
              + F.viewReadOnly(nodes, F.node2id())
              + ", exchId="
              + exchId
              + ", msg="
              + m
              + ']');

    cctx.io().safeSend(nodes, m, SYSTEM_POOL, null);
  }
  @Transactional
  public boolean update(UserInfo userInfo, F form) {
    logger.infoCode("I0001");
    try {
      T entity = (T) form.getNewTbl();

      if (form.getPageMode().equals(CommonConst.PAGE_MODE_EDIT)) {
        entity =
            findOne(
                form.getGyosekiKey(), userInfo.getTargetUserKey(), form.getUpdDateAsTimestamp());
        if (entity == null) {
          throw new Exception();
        }
      }

      entity = (T) getPortfolioTbl(form, entity);

      UsUserTbl usUserTbl = new UsUserTbl();
      usUserTbl.setUserKey(userInfo.getTargetUserKey());
      entity.setUsUserTbl(usUserTbl);
      entity.setUpdUserKey(userInfo.getLoginUserKey());
      entity.setUpdDate(DateUtil.getNowTimestamp());

      entity = (T) repository.saveAndFlush(entity);

      if (entity != null) {
        logger.infoCode("I0002");
        return true;
      }

    } catch (Exception e) {
      logger.errorCode("E1007", e); // E1007=登録に失敗しました。{0}
    }
    return false;
  }
예제 #5
0
  /**
   * @param keys keys.
   * @param topVer Topology version.
   * @return Nodes for the keys.
   */
  public Collection<GridNode> remoteNodes(Iterable<? extends K> keys, long topVer) {
    Collection<Collection<GridNode>> colcol = new GridLeanSet<>();

    for (K key : keys) colcol.add(nodes(key, topVer));

    return F.view(F.flatCollections(colcol), F.remoteNodes(cctx.localNodeId()));
  }
  /** {@inheritDoc} */
  @Override
  public final Map<UUID, GridNodeMetrics> metrics(Collection<UUID> nodeIds)
      throws GridSpiException {
    assert !F.isEmpty(nodeIds);

    long now = U.currentTimeMillis();

    Collection<UUID> expired = new LinkedList<>();

    for (UUID id : nodeIds) {
      GridNodeMetrics nodeMetrics = metricsMap.get(id);

      Long ts = tsMap.get(id);

      if (nodeMetrics == null || ts == null || ts < now - metricsExpireTime) expired.add(id);
    }

    if (!expired.isEmpty()) {
      Map<UUID, GridNodeMetrics> refreshed = metrics0(expired);

      for (UUID id : refreshed.keySet()) tsMap.put(id, now);

      metricsMap.putAll(refreshed);
    }

    return F.view(metricsMap, F.contains(nodeIds));
  }
  /** @throws Exception If failed. */
  public void testCreateFileColocated() throws Exception {
    GridGgfsPath path = new GridGgfsPath("/colocated");

    UUID uuid = UUID.randomUUID();

    GridUuid affKey;

    long idx = 0;

    while (true) {
      affKey = new GridUuid(uuid, idx);

      if (grid(0).mapKeyToNode(DATA_CACHE_NAME, affKey).id().equals(grid(0).localNode().id()))
        break;

      idx++;
    }

    try (GridGgfsOutputStream out = fs.create(path, 1024, true, affKey, 0, 1024, null)) {
      // Write 5M, should be enough to test distribution.
      for (int i = 0; i < 15; i++) out.write(new byte[1024 * 1024]);
    }

    GridGgfsFile info = fs.info(path);

    Collection<GridGgfsBlockLocation> affNodes = fs.affinity(path, 0, info.length());

    assertEquals(1, affNodes.size());
    Collection<UUID> nodeIds = F.first(affNodes).nodeIds();

    assertEquals(1, nodeIds.size());
    assertEquals(grid(0).localNode().id(), F.first(nodeIds));
  }
  /** @param node Node to remove. */
  public void removeMappedNode(GridNode node) {
    if (mappedDhtNodes.contains(node))
      mappedDhtNodes = new ArrayList<>(F.view(mappedDhtNodes, F.notEqualTo(node)));

    if (mappedNearNodes != null && mappedNearNodes.contains(node))
      mappedNearNodes = new ArrayList<>(F.view(mappedNearNodes, F.notEqualTo(node)));
  }
예제 #9
0
  public ListVectorElement(F field, Sampler<BigInteger> sampler) {
    this(field);

    coeff = new ArrayList<E>(field.getN());
    for (int i = 0, size = field.getN(); i < size; i++)
      coeff.add((E) field.getTargetField().newElementFromSampler(sampler));
  }
예제 #10
0
  public ListVectorElement(F field) {
    super(field);

    coeff = new ArrayList<E>(field.getN());
    for (int i = 0, size = field.getN(); i < size; i++)
      coeff.add((E) field.getTargetField().newElement());
  }
예제 #11
0
 /**
  * Render the text in the given font in the given colour with the default style.
  *
  * @param <F> the font
  * @param text the text
  * @param pt the coordinate to render at
  * @param f the font
  * @param sz the size
  * @param col the font colour
  */
 public <F extends Font<F>> void drawText(
     final String text, final Point2d pt, final F f, final int sz, final Q col) {
   final FontStyle<Q> sty = f.createStyle(this);
   sty.setFontSize(sz);
   sty.setColour(col);
   f.getRenderer(this).renderText(this, text, (int) pt.getX(), (int) pt.getY(), sty);
 }
예제 #12
0
  @SuppressWarnings("unchecked")
  @Override
  public INetSystem<F, N, P, T, M> clone(Map<N, N> map) {
    INetSystem<F, N, P, T, M> clone = null;
    try {
      clone = (INetSystem<F, N, P, T, M>) NetSystem.class.newInstance();
    } catch (InstantiationException exception) {
      return null;
    } catch (IllegalAccessException exception) {
      return null;
    }

    for (P p : this.getPlaces()) {
      P np = (P) p.clone();
      map.put((N) p, (N) np);
      clone.addPlace(np);
    }

    for (T t : this.getTransitions()) {
      T nt = (T) t.clone();
      map.put((N) t, (N) nt);
      clone.addTransition(nt);
    }

    for (F f : this.getFlow()) {
      clone.addFlow(map.get(f.getSource()), map.get(f.getTarget()));
    }

    for (P p : this.getPlaces()) {
      clone.putTokens((P) map.get(p), this.getTokens(p));
    }

    return clone;
  }
예제 #13
0
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result =
       prime * result + ((movieBasic.getUrl() == null) ? 0 : movieBasic.getUrl().hashCode());
   return result;
 }
 /**
  * Создает презентер блока визарда в заданном режиме (Place).
  *
  * @param place режим, в котором необходимо создать презентер
  * @param clientFactory клиентская фабрика блока визарда
  */
 @SuppressWarnings("unchecked")
 public BlockPresenter(Place place, F clientFactory) {
   super(place, clientFactory);
   view = (V) clientFactory.getView();
   fields = view.getFieldManager();
   service = clientFactory.getService();
   blockPlaceController = clientFactory.getPlaceController();
 }
예제 #15
0
  public static <F extends File> F mockFile(Class<F> type) {

    final F file = mock(type);
    when(file.getMimeType()).thenReturn(TEXT_PLAIN_VALUE);
    when(file.getModified()).thenReturn(new Date());

    return file;
  }
예제 #16
0
 protected void appendField(StringBuilder sb) {
   for (JobPort port : frame.getInputPorts()) {
     appendField(sb, port, "In");
   }
   for (JobPort port : frame.getOutputPorts()) {
     appendField(sb, port, "Out");
   }
 }
예제 #17
0
  /**
   * @param part Partition.
   * @param topVer Topology version.
   * @return Backup nodes.
   */
  public Collection<GridNode> backups(int part, long topVer) {
    Collection<GridNode> nodes = nodes(part, topVer);

    assert !F.isEmpty(nodes);

    if (nodes.size() <= 1) return Collections.emptyList();

    return F.view(nodes, F.notEqualTo(nodes.iterator().next()));
  }
예제 #18
0
 /**
  * Returns a parser that produces an element from the stream that satisfies the given predicate,
  * or fails.
  *
  * @param missing The error if no element is available.
  * @param sat The error if the element does not satisfy the predicate.
  * @param f The predicate that the element should satisfy.
  * @return A parser that produces an element from the stream that satisfies the given predicate,
  *     or fails.
  */
 public static <I, E> Parser<Stream<I>, I, E> satisfy(
     final F0<E> missing, final F<I, E> sat, final F<I, Boolean> f) {
   return StreamParser.<I, E>element(missing)
       .bind(
           x ->
               f.f(x)
                   ? Parser.<Stream<I>, I, E>value(x)
                   : Parser.<Stream<I>, I, E>fail(sat.f(x)));
 }
 protected void initDefaultSettings(final F figure) {
   final OverlayService overlayService = getContext().getService(OverlayService.class);
   final OverlaySettings settings = overlayService.getDefaultSettings();
   figure.set(AttributeKeys.STROKE_WIDTH, getDefaultLineWidth(settings));
   figure.set(AttributeKeys.FILL_COLOR, getDefaultFillColor(settings));
   figure.set(AttributeKeys.STROKE_COLOR, getDefaultStrokeColor(settings));
   // Avoid IllegalArgumentException: miter limit < 1 on the EDT
   figure.set(AttributeKeys.IS_STROKE_MITER_LIMIT_FACTOR, false);
 }
예제 #20
0
  /**
   * Gets an instance of T from the {@link RandomAccessibleInterval} by querying the value at the
   * min coordinate
   *
   * @param <T> - the T
   * @param rai - the {@link RandomAccessibleInterval}
   * @return - an instance of T
   */
  public static final <T, F extends RealInterval & RealRandomAccessible<T>>
      T getTypeFromRealInterval(final F rai) {
    // create RealRandomAccess
    final RealRandomAccess<T> realRandomAccess = rai.realRandomAccess();

    // place it at the first pixel
    for (int d = 0; d < rai.numDimensions(); ++d) realRandomAccess.setPosition(rai.realMin(d), d);

    return realRandomAccess.get();
  }
 public void mousePressed(MouseEvent me) {
   POINT = me.getPoint();
   double xa = POINT.x - w / 2 - (a - originX) * scale;
   F.addVariable("x", a);
   double ya = POINT.y - h / 2 + (F.getValue() - originY) * scale;
   if (xa * xa + ya * ya < rr) {
     newA = true;
   }
   requestFocus();
 }
예제 #22
0
파일: Util.java 프로젝트: imglib/imglib2
  /**
   * Gets an instance of T from the {@link RandomAccessibleInterval} by querying the value at the
   * min coordinate
   *
   * @param <T> - the T
   * @param rai - the {@link RandomAccessibleInterval}
   * @return - an instance of T
   */
  public static final <T, F extends RealInterval & RealRandomAccessible<T>>
      T getTypeFromRealInterval(final F rai) {
    // create RealRandomAccess
    final RealRandomAccess<T> realRandomAccess = rai.realRandomAccess();

    // place it at the first pixel
    rai.realMin(realRandomAccess);

    return realRandomAccess.get();
  }
예제 #23
0
 public <A, B> HashMap<A, B> map(
     F<K, A> keyFunction, F<V, B> valueFunction, Equal<A> equal, Hash<A> hash) {
   final HashMap<A, B> hashMap = new HashMap<>(equal, hash);
   for (K key : keys()) {
     final A newKey = keyFunction.f(key);
     final B newValue = valueFunction.f(get(key).some());
     hashMap.set(newKey, newValue);
   }
   return hashMap;
 }
  public List<F> getDtoList(List<T> list) {
    List<F> dtoList = new ArrayList<>();

    for (int i = 0; i < list.size(); i++) {
      F form = getPortfolioForm(list.get(i));
      form.setViewType(CommonForm.VIEW_TYPE_FORM);
      dtoList.add(form);
    }
    return dtoList;
  }
예제 #25
0
 void THROWS(Class<? extends Throwable> k, F... fs) {
   for (F f : fs)
     try {
       f.f();
       fail("Expected " + k.getName() + " not thrown");
     } catch (Throwable t) {
       if (k.isAssignableFrom(t.getClass())) pass();
       else unexpected(t);
     }
 }
  /** @throws Exception If failed. */
  public void testAffinityPut() throws Exception {
    Thread.sleep(2 * TOP_REFRESH_FREQ);

    assertEquals(NODES_CNT, client.compute().refreshTopology(false, false).size());

    Map<UUID, Grid> gridsByLocNode = new HashMap<>(NODES_CNT);

    GridClientData partitioned = client.data(PARTITIONED_CACHE_NAME);

    GridClientCompute compute = client.compute();

    for (int i = 0; i < NODES_CNT; i++) gridsByLocNode.put(grid(i).localNode().id(), grid(i));

    for (int i = 0; i < 100; i++) {
      String key = "key" + i;

      UUID primaryNodeId = grid(0).mapKeyToNode(PARTITIONED_CACHE_NAME, key).id();

      assertEquals("Affinity mismatch for key: " + key, primaryNodeId, partitioned.affinity(key));

      assertEquals(primaryNodeId, partitioned.affinity(key));

      // Must go to primary node only. Since backup count is 0, value must present on
      // primary node only.
      partitioned.put(key, "val" + key);

      for (Map.Entry<UUID, Grid> entry : gridsByLocNode.entrySet()) {
        Object val = entry.getValue().cache(PARTITIONED_CACHE_NAME).peek(key);

        if (primaryNodeId.equals(entry.getKey())) assertEquals("val" + key, val);
        else assertNull(val);
      }
    }

    // Now check that we will see value in near cache in pinned mode.
    for (int i = 100; i < 200; i++) {
      String pinnedKey = "key" + i;

      UUID primaryNodeId = grid(0).mapKeyToNode(PARTITIONED_CACHE_NAME, pinnedKey).id();

      UUID pinnedNodeId = F.first(F.view(gridsByLocNode.keySet(), F.notEqualTo(primaryNodeId)));

      GridClientNode node = compute.node(pinnedNodeId);

      partitioned.pinNodes(node).put(pinnedKey, "val" + pinnedKey);

      for (Map.Entry<UUID, Grid> entry : gridsByLocNode.entrySet()) {
        Object val = entry.getValue().cache(PARTITIONED_CACHE_NAME).peek(pinnedKey);

        if (primaryNodeId.equals(entry.getKey()) || pinnedNodeId.equals(entry.getKey()))
          assertEquals("val" + pinnedKey, val);
        else assertNull(val);
      }
    }
  }
    /** @param nodes Nodes. */
    private Queue<ClusterNode> fallbacks(Collection<ClusterNode> nodes) {
      Queue<ClusterNode> fallbacks = new LinkedList<>();

      ClusterNode node = F.first(F.view(nodes, IS_LOC_NODE));

      if (node != null) fallbacks.add(node);

      fallbacks.addAll(node != null ? F.view(nodes, F.not(IS_LOC_NODE)) : nodes);

      return fallbacks;
    }
 @Override
 protected F computeNext() {
   if (!iterator.hasNext()) {
     return endOfData();
   }
   F next = iterator.next();
   String featureId = next.getIdentifier().getID();
   Ref ref = currentTypeTree.get(featureId);
   String versionId = ref == null ? null : ref.getObjectId().toString();
   return VersionedFeatureWrapper.wrap(next, versionId);
 }
  /**
   * @param cacheId Cache ID.
   * @return {@code True} if local client has been added.
   */
  public boolean isLocalClientAdded(int cacheId) {
    if (!F.isEmpty(reqs)) {
      for (DynamicCacheChangeRequest req : reqs) {
        if (req.start() && F.eq(req.initiatingNodeId(), cctx.localNodeId())) {
          if (CU.cacheId(req.cacheName()) == cacheId) return true;
        }
      }
    }

    return false;
  }
예제 #30
0
 /** {@inheritDoc} */
 @Override
 public void stopListenAsync(@Nullable GridInClosure<? super GridFuture<R>>... lsnr) {
   if (F.isEmpty(lsnr))
     synchronized (mux) {
       lsnrs.clear();
     }
   else
     synchronized (mux) {
       lsnrs.removeAll(F.asList(lsnr));
     }
 }