首页 \ 问答 \ Guava ValueGraph的简单示例(Simple example of Guava ValueGraph)

Guava ValueGraph的简单示例(Simple example of Guava ValueGraph)

我正在寻找Guava ValueGraph的简单示例。 就像是:

class GraphNode {
  String name;
  String value;
  // Do I need to override equals & hashcode methods here??

}

class GraphUser {
  public ValueGraph<GraphNode,Double> createGraph(){
    ValueGraph<GraphNode,Double> graph = ValueGraphBuilder.directed.build();
    // How do I add the nodes to graph??
    // How do I add the edges to graph?
  }
}
  1. 如何使用自定义对象作为节点创建图形?
  2. 如何向图表添加节点和边缘?
  3. 我是否必须覆盖自定义节点类中的equals和hashCode方法?

一个简单的例子非常有用。


I'm looking for simple example of Guava ValueGraph. Something like:

class GraphNode {
  String name;
  String value;
  // Do I need to override equals & hashcode methods here??

}

class GraphUser {
  public ValueGraph<GraphNode,Double> createGraph(){
    ValueGraph<GraphNode,Double> graph = ValueGraphBuilder.directed.build();
    // How do I add the nodes to graph??
    // How do I add the edges to graph?
  }
}
  1. How do I create graph with custom object as node?
  2. How do I add nodes & edges to graph?
  3. Do I have to override the equals & hashCode methods in the custom node class?

A simple example would be very helpful.


原文:https://stackoverflow.com/questions/47337142
更新时间:2022-02-02 20:02

最满意答案

改变你的条件应该有助于你:

if(
  selection.anchorOffset !== selection.focusOffset 
  && 
  (event.keyCode == 8 || event.keyCode == 46)
) 

小提琴: https//jsfiddle.net/34L49xLr/


Changing your condition to this should help you:

if(
  selection.anchorOffset !== selection.focusOffset 
  && 
  (event.keyCode == 8 || event.keyCode == 46)
) 

Fiddle: https://jsfiddle.net/34L49xLr/

相关问答

更多
  • 使用html()方法并使用带有单词边界的属性值生成正则表达式(仅匹配确切的单词)以用包装的span替换单词。 $('div[data-text]').html(function(_, htm) { return htm.replace(new RegExp('\\b' + $(this).data('text') + '\\b', 'ig'), '$&') }) div span { color: red }