Пример #1
0
  private void process(OsmRelation relation) {
    boolean hasChildRelations = false;
    TLongList childRelationMembers = new TLongArrayList();
    for (OsmRelationMember member : OsmModelUtil.membersAsList(relation)) {
      if (member.getType() == EntityType.Relation) {
        hasChildRelations = true;
        idsIsChildRelation.add(member.getId());
        childRelationMembers.add(member.getId());
        if (storeSimpleRelations) {
          idsSimpleRelations.remove(member.getId());
        }
      }
    }
    long id = relation.getId();
    if (hasChildRelations) {
      idsHasChildRelations.add(id);
      if (!graph.getNodes().contains(id)) {
        graph.addNode(id);
      }

      TLongIterator iterator = childRelationMembers.iterator();
      while (iterator.hasNext()) {
        long member = iterator.next();
        if (!graph.getNodes().contains(member)) {
          graph.addNode(member);
        }
        graph.addEdge(id, member);
      }
    } else {
      if (storeSimpleRelations && !idsIsChildRelation.contains(id)) {
        idsSimpleRelations.add(id);
      }
      numNoChildren++;
    }
  }
 /**
  * Compares this set with another set for equality of their stored entries.
  *
  * @param other an <code>Object</code> value
  * @return true if the sets are identical
  */
 @Override
 public boolean equals(Object other) {
   if (_set.equals(other)) {
     return true; // comparing two trove sets
   } else if (other instanceof Set) {
     Set<?> that = (Set<?>) other;
     if (that.size() != _set.size()) {
       return false; // different sizes, no need to compare
     } else { // now we have to do it the hard way
       Iterator<?> it = that.iterator();
       for (int i = that.size(); i-- > 0; ) {
         Object val = it.next();
         if (val instanceof Long) {
           long v = ((Long) val).longValue();
           if (_set.contains(v)) {
             // match, ok to continue
           } else {
             return false; // no match: we're done
           }
         } else {
           return false; // different type in other set
         }
       }
       return true; // all entries match
     }
   } else {
     return false;
   }
 }
  private void extract(Path path) throws IOException {
    Path pathWays = path.resolve(fileNamesWays);
    Path pathNodeIds = path.resolve(fileNamesNodeIds);

    InputStream input = StreamUtil.bufferedInputStream(pathWays.toFile());
    OsmIterator osmIterator = OsmIoUtils.setupOsmIterator(input, inputFormat, false);

    OutputStream outputNodeIds = StreamUtil.bufferedOutputStream(pathNodeIds.toFile());
    IdListOutputStream idOutputNodeIds = new IdListOutputStream(outputNodeIds);

    TLongSet nodeIdsSet = new TLongHashSet();

    for (EntityContainer container : osmIterator) {
      if (container.getType() != EntityType.Way) {
        continue;
      }
      OsmWay way = (OsmWay) container.getEntity();
      for (long id : OsmModelUtil.nodesAsList(way).toArray()) {
        nodeIdsSet.add(id);
      }
    }

    input.close();

    long[] nodesIds = nodeIdsSet.toArray();
    Arrays.sort(nodesIds);
    for (long id : nodesIds) {
      idOutputNodeIds.write(id);
    }
    idOutputNodeIds.close();
  }
Пример #4
0
  public List<Group> buildGroupsUndirected() {
    List<Group> groups = new LinkedList<>();

    TLongSet nodes = new TLongHashSet(graph.getNodes());
    while (!nodes.isEmpty()) {
      long id = any(nodes);

      TLongSet reachable = reachable(graph, id);
      nodes.removeAll(reachable);

      groups.add(new Group(id, reachable));
    }
    return groups;
  }
 private void test(Data data) throws Exception {
   Random r = getRandom();
   final int numDocs = 1000 + r.nextInt(19000);
   final List<TLongSet> values = new ArrayList<TLongSet>(numDocs);
   for (int i = 0; i < numDocs; ++i) {
     final int numValues = data.numValues(r);
     final TLongSet vals = new TLongHashSet(numValues);
     for (int j = 0; j < numValues; ++j) {
       vals.add(data.nextValue(r));
     }
     values.add(vals);
   }
   test(values);
 }
  private void test(List<TLongSet> values) throws Exception {
    StringField id = new StringField("_id", "", Field.Store.NO);

    for (int i = 0; i < values.size(); ++i) {
      Document doc = new Document();
      id.setStringValue("" + i);
      doc.add(id);
      final TLongSet v = values.get(i);
      for (TLongIterator it = v.iterator(); it.hasNext(); ) {
        LongField value = new LongField("value", it.next(), Field.Store.NO);
        doc.add(value);
      }
      writer.addDocument(doc);
    }
    writer.forceMerge(1);

    final IndexNumericFieldData indexFieldData = getForField("value");
    final AtomicNumericFieldData atomicFieldData = indexFieldData.load(refreshReader());
    final LongValues data = atomicFieldData.getLongValues();
    final DoubleValues doubleData = atomicFieldData.getDoubleValues();
    final TLongSet set = new TLongHashSet();
    final TDoubleSet doubleSet = new TDoubleHashSet();
    for (int i = 0; i < values.size(); ++i) {
      final TLongSet v = values.get(i);

      assertThat(data.hasValue(i), equalTo(!v.isEmpty()));
      assertThat(doubleData.hasValue(i), equalTo(!v.isEmpty()));

      if (v.isEmpty()) {
        assertThat(data.getValue(i), equalTo(0L));
        assertThat(doubleData.getValue(i), equalTo(0d));
      }

      set.clear();
      for (LongValues.Iter iter = data.getIter(i); iter.hasNext(); ) {
        set.add(iter.next());
      }
      assertThat(set, equalTo(v));

      final TDoubleSet doubleV = new TDoubleHashSet();
      for (TLongIterator it = v.iterator(); it.hasNext(); ) {
        doubleV.add((double) it.next());
      }
      doubleSet.clear();
      for (DoubleValues.Iter iter = doubleData.getIter(i); iter.hasNext(); ) {
        doubleSet.add(iter.next());
      }
      assertThat(doubleSet, equalTo(doubleV));
    }
  }
Пример #7
0
 @Override
 public boolean equals(Object other) {
   if (!(other instanceof TLongSet)) {
     return false;
   }
   final TLongSet that = (TLongSet) other;
   if (that.size() != this.size()) {
     return false;
   }
   for (int i = _states.length; i-- > 0; ) {
     if (_states[i] == FULL) {
       if (!that.contains(_set[i])) {
         return false;
       }
     }
   }
   return true;
 }
Пример #8
0
  private Group build(long start) {
    TLongSet group = new TLongHashSet();
    group.add(start);

    TLongSet left = new TLongHashSet();
    left.addAll(graph.getEdgesOut(start));

    while (!left.isEmpty()) {
      long next = any(left);

      if (group.contains(next)) {
        continue;
      }
      group.add(next);
      Set<Long> out = graph.getEdgesOut(next);
      left.addAll(out);
    }

    return new Group(start, group);
  }
Пример #9
0
  private TLongSet reachable(Graph<Long> graph, long id) {
    TLongSet reached = new TLongHashSet();
    TLongSet queue = new TLongHashSet();

    queue.add(id);

    while (!queue.isEmpty()) {
      long current = any(queue);
      reached.add(current);

      Set<Long> out = graph.getEdgesOut(current);
      for (long next : out) {
        if (!reached.contains(next)) {
          queue.add(next);
        }
      }
    }

    return reached;
  }
 /**
  * Inserts a value into the set.
  *
  * @param value true if the set was modified by the insertion
  */
 @Override
 public boolean add(Long value) {
   return value != null && _set.add(value.longValue());
 }
Пример #11
0
  @Override
  public void onBindViewHolder(CommentView view, int position) {
    CommentEntry entry = comments.get(position);
    Comment comment = entry.comment;

    view.setCommentDepth(entry.depth);
    view.senderInfo.setSenderName(comment.getName(), comment.getMark());
    view.senderInfo.setOnSenderClickedListener(v -> doOnAuthorClicked(comment));

    AndroidUtility.linkify(view.comment, comment.getContent());

    // show the points
    if (equalsIgnoreCase(comment.getName(), selfName)
        || comment.getCreated().isBefore(scoreVisibleThreshold)) {

      view.senderInfo.setPoints(getCommentScore(entry));
    } else {
      view.senderInfo.setPointsUnknown();
    }

    // and the date of the post
    view.senderInfo.setDate(comment.getCreated());

    // enable or disable the badge
    boolean badge = op.transform(op -> op.equalsIgnoreCase(comment.getName())).or(false);
    view.senderInfo.setBadgeOpVisible(badge);

    // and register a vote handler
    view.vote.setVote(entry.vote, true);
    view.vote.setOnVoteListener(
        v -> {
          boolean changed = doVote(entry, v);
          notifyItemChanged(position);
          return changed;
        });

    // set alpha for the sub views. sadly, setting alpha on view.itemView is not working
    view.comment.setAlpha(entry.vote == Vote.DOWN ? 0.5f : 1f);
    view.senderInfo.setAlpha(entry.vote == Vote.DOWN ? 0.5f : 1f);

    view.senderInfo.setOnAnswerClickedListener(v -> doAnswer(comment));

    Context context = view.itemView.getContext();
    view.itemView.setBackgroundColor(
        ContextCompat.getColor(
            context,
            comment.getId() == selectedCommentId
                ? R.color.selected_comment_background
                : R.color.feed_background));

    if (view.kFav != null) {
      if (showFavCommentButton) {
        boolean isFavorite = favedComments.contains(comment.getId());

        view.kFav.setTextColor(
            isFavorite
                ? ContextCompat.getColor(context, R.color.primary)
                : ContextCompat.getColor(context, R.color.grey_700));

        view.kFav.setVisibility(View.VISIBLE);
        view.kFav.setOnClickListener(
            v -> {
              commentActionListener.onCommentMarkAsFavoriteClicked(comment, !isFavorite);
            });
      } else {
        view.kFav.setVisibility(View.GONE);
      }
    }
  }
Пример #12
0
 public boolean isEmpty() {
   return set.isEmpty();
 }
Пример #13
0
 public long pop() {
   long value = stack.pop();
   set.remove(value);
   return value;
 }
Пример #14
0
 public boolean contains(long value) {
   return set.contains(value);
 }
Пример #15
0
 /** It is not allowed to push values that are already contained in the set. */
 public void push(long value) {
   set.add(value);
   stack.push(value);
 }
Пример #16
0
 private long any(TLongSet nodes) {
   TLongIterator iterator = nodes.iterator();
   long id = iterator.next();
   iterator.remove();
   return id;
 }
Пример #17
0
  public List<Group> buildGroupsDirected() {
    List<Group> groups = new LinkedList<>();

    // First determine 'start' relations, i.e. relations without incoming
    // edges in the relation graph
    TLongSet starts = new TLongHashSet();
    Collection<Long> ids = graph.getNodes();
    for (long id : ids) {
      if (graph.getEdgesIn(id).isEmpty()) {
        starts.add(id);
      }
    }
    // Build sub-graphs reachable from 'start' relations
    logger.debug("Number of start relations: " + starts.size());
    for (long start : starts.toArray()) {
      groups.add(build(start));
    }

    // In case of circles within the relation graph that are not reachable
    // from any start relation, there may be some relations left, that have
    // not been put into groups yet.
    TLongSet remaining = new TLongHashSet();
    remaining.addAll(ids);
    for (Group group : groups) {
      remaining.removeAll(group.getRelationIds());
    }
    if (remaining.size() > 0) {
      logger.debug("remaining: " + remaining.size());
      while (!remaining.isEmpty()) {
        long id = any(remaining);

        TLongSet reachable = reachable(graph, id);
        remaining.removeAll(reachable);

        long lowest = IdUtil.lowestId(reachable);
        groups.add(new Group(lowest, reachable));
      }
    }

    return groups;
  }
 /**
  * Deletes a value from the set.
  *
  * @param value an <code>Object</code> value
  * @return true if the set was modified
  */
 @Override
 public boolean remove(Object value) {
   return value instanceof Long && _set.remove(((Long) value).longValue());
 }
 /** {@inheritDoc} */
 @Override
 public boolean contains(Object o) {
   if (!(o instanceof Long)) return false;
   return _set.contains(((Long) o).longValue());
 }
 @Override
 public long[] getPriorStepExecutionIds() {
   return priorStepExecutionIds.toArray();
 }