Пример #1
0
 @Override
 public boolean equals(Object obj) {
   if (this == obj) {
     return true;
   }
   if (obj == null) {
     return false;
   }
   if (getClass() != obj.getClass()) {
     return false;
   }
   Pair<?, ?> other = (Pair<?, ?>) obj;
   if (first == null) {
     if (other.first != null) {
       return false;
     }
   } else if (!first.equals(other.first)) {
     return false;
   }
   if (second == null) {
     if (other.second != null) {
       return false;
     }
   } else if (!second.equals(other.second)) {
     return false;
   }
   return true;
 }
Пример #2
0
 @Override
 @SuppressWarnings("rawtypes")
 public boolean equals(Object obj) {
   if (obj == null || obj.getClass() != getClass()) return false;
   TraversalItem other = (TraversalItem) obj;
   return data.equals(other.data) && state.equals(other.state);
 }
Пример #3
0
  public boolean equals(Object o) {
    if (this == o) return true;
    if (!(o instanceof Pair)) return false;

    final Pair<F, S> pair = (Pair<F, S>) o;

    if (first != null ? !first.equals(pair.first) : pair.first != null) return false;
    if (second != null ? !second.equals(pair.second) : pair.second != null) return false;

    return true;
  }
Пример #4
0
 public List<S> getBestPath(Trellis<S> trellis) {
   List<S> states = new ArrayList<S>();
   S currentState = trellis.getStartState();
   states.add(currentState);
   while (!currentState.equals(trellis.getEndState())) {
     Counter<S> transitions = trellis.getForwardTransitions(currentState);
     S nextState = transitions.argMax();
     states.add(nextState);
     currentState = nextState;
   }
   return states;
 }
Пример #5
0
 @Override
 public boolean equals(Object obj) {
   if (this == obj) return true;
   if (obj == null) return false;
   if (getClass() != obj.getClass()) return false;
   DfaEdge<?> other = (DfaEdge<?>) obj;
   if (src == null) {
     if (other.src != null) return false;
   } else if (!src.equals(other.src)) return false;
   if (symbol == null) {
     if (other.symbol != null) return false;
   } else if (!symbol.equals(other.symbol)) return false;
   return true;
 }
Пример #6
0
 /**
  * Prioritizes the given <code>high</code> strategy over the given <code>low</code> strategy,
  * iff <code>high</code> has a lower priority than <code>low</code> else nothing is done. Both
  * <code>high</code> and <code>low</code> must be contained, <b>not</b> as backup strategies, by
  * this instance and must be non-{@linkplain Strategy#strict()}.
  *
  * @param high the non-strict strategy to ensure higher priority for
  * @param low the non-strict strategy to be shadowed by high
  * @throws IllegalArgumentException if high and/or low is strict or not contained as non-backup
  *     by this instance
  */
 public void prioritize(S high, S low) {
   // validate:
   this.validateForPrioritize(high);
   this.validateForPrioritize(low);
   // prioritize:
   final ListIterator<S> rangeItr = this.range.listIterator();
   while (rangeItr.hasNext()) {
     S crt = rangeItr.next();
     if (crt.equals(high)) {
       return;
     }
     if (crt.equals(low)) {
       final int lowIdx = rangeItr.nextIndex() - 1;
       while (rangeItr.hasNext()) {
         crt = rangeItr.next();
         if (crt.equals(high)) {
           rangeItr.remove();
           this.range.add(lowIdx, crt);
           return;
         }
       }
     }
   }
 }
Пример #7
0
 /**
  * Creates a new layer from a plotter.
  *
  * @param plotter plotter
  * @param geom data geom
  * @param dataSpec data spec
  * @param config style configuration
  * @return layer, or null in case of failure
  */
 public <S extends Style> PlotLayer createLayer(
     Plotter<S> plotter, DataGeom geom, DataSpec dataSpec, ConfigMap config) {
   S style;
   try {
     style = plotter.createStyle(config);
     lastFailed_ = false;
   } catch (ConfigException e) {
     if (!lastFailed_) {
       String name = e.getConfigKey().getMeta().getLongName();
       String[] msg = new String[] {name + ": ", e.getMessage()};
       JOptionPane.showMessageDialog(parent_, msg, name + " Error", JOptionPane.ERROR_MESSAGE);
       lastFailed_ = true;
     }
     return null;
   }
   try {
     S dupStyle = plotter.createStyle(config);
     assert style.equals(dupStyle);
     assert style.hashCode() == dupStyle.hashCode();
   } catch (ConfigException e) {
     assert false : "Shouldn't happen";
   }
   return plotter.createLayer(geom, dataSpec, style);
 }
Пример #8
0
 public boolean isValid() {
   return oldSelection != newSelection
       && (newSelection == null || !newSelection.equals(oldSelection));
 }
Пример #9
0
 public boolean equals(Pair<S, F> other) {
   return first.equals(other.first) && second.equals(other.second);
 }
Пример #10
0
  @Override
  public Object set(
      final SecurityContext securityContext,
      final NodeInterface targetNode,
      final Iterable<S> collection)
      throws FrameworkException {

    final App app = StructrApp.getInstance(securityContext);
    final PropertyMap properties = new PropertyMap();
    final NodeInterface actualTargetNode =
        (NodeInterface) unwrap(securityContext, relation.getClass(), targetNode, properties);
    final Set<S> toBeDeleted =
        new LinkedHashSet<>(Iterables.toList(get(securityContext, actualTargetNode, null)));
    final Set<S> toBeCreated = new LinkedHashSet<>();

    if (collection != null) {
      Iterables.addAll(toBeCreated, collection);
    }

    // create intersection of both sets
    final Set<S> intersection = new HashSet<>(toBeCreated);
    intersection.retainAll(toBeDeleted);

    // intersection needs no change
    toBeCreated.removeAll(intersection);
    toBeDeleted.removeAll(intersection);

    // remove existing relationships
    for (S sourceNode : toBeDeleted) {

      for (AbstractRelationship rel : actualTargetNode.getIncomingRelationships()) {

        final String relTypeName = rel.getRelType().name();
        final String desiredRelType = relation.name();

        if (sourceNode.equals(actualTargetNode)) {

          logger.warn(
              "Preventing deletion of self relationship {}-[{}]->{}. If you experience issue with this, please report to [email protected].",
              new Object[] {sourceNode, rel.getRelType(), actualTargetNode});

          // skip self relationships
          continue;
        }

        if (relTypeName.equals(desiredRelType) && rel.getSourceNode().equals(sourceNode)) {
          app.delete(rel);
        }
      }
    }

    final List<Relation> createdRelationship = new LinkedList<>();

    // create new relationships
    for (S sourceNode : toBeCreated) {

      if (sourceNode != null && actualTargetNode != null) {

        properties.clear();

        final S actualSourceNode =
            (S) unwrap(securityContext, relation.getClass(), sourceNode, properties);
        final PropertyMap notionProperties =
            getNotionProperties(
                securityContext,
                relation.getClass(),
                actualSourceNode.getName() + relation.name() + actualTargetNode.getName());

        if (notionProperties != null) {

          properties.putAll(notionProperties);
        }

        relation.ensureCardinality(securityContext, actualSourceNode, actualTargetNode);

        createdRelationship.add(
            app.create(actualSourceNode, actualTargetNode, relation.getClass(), properties));
      }
    }

    return createdRelationship;
  }