我使用jgrapht库创建了一个有向图,我的顶点是AudioFile
个对象:
case class JsonResponse(meta: Meta, items: List[Item])
val pipeline: Future[HttpRequest => Future[JsonResponse]] = for (
Http.HostConnectorInfo(connector, _) <-
IO(Http) ? Http.HostConnectorSetup("somehost.com", port = 80)
) yield sendReceive(connector) ~> unmarshal[JsonResponse]
// .....
def getJson(relativeUrl: String)(implicit m: Monoid[Future[List[JsObject]]]) : Future[List[JsObject]] = {
val jsr = pipeline.flatMap(_(Get(relativeUrl)))
// Grab only those entries that we are interested in
val objList = jsr.map(js => js.items.collect{ case o if(o.whatever.isDefined) => o.toJson.asJsObject })
jsr.flatMap(js => js.meta.next.map(next => m.append(getJson(next), objList)).getOrElse(objList))
}
我可以浏览所有顶点并获得每个点的后继者:*
Point
我需要按对定义if语句的条件,但只能在一个或两个Point参数上定义。例如,这些是我的观点:
public static class Point {
public int x;
public int y;
public String type;
public Point(int x, int y, String type)
{
this.x = x;
this.y = y;
this.type = type;
}
@Override
public String toString() {
return ("[x="+x+" y="+y+" type="+type+ "]");
}
@Override
public int hashCode() {
int hash = 7;
hash = 71 * hash + this.x;
hash = 71 * hash + this.y;
return hash;
}
@Override
public boolean equals(Object other)
{
if (this == other)
return true;
if (!(other instanceof Point))
return false;
Point otherPoint = (Point) other;
return otherPoint.x == x && otherPoint.y == y;
}
}
我希望有条件确保myPoint和后继者没有特定的&#34;输入&#34;:
for (Point myPoint : directedGraph.vertexSet ()) {
for (Point successor : Graphs.successorListOf (directedGraph, myPoint)){
// Add if statement
}
}
所以我需要的是将条件设置在几个点上,但仅限于我public static Point startPoint = new Point(2, 6, "A");
public static Point firstPoint = new Point(2, 7, "A");
public static Point secondPoint = new Point(2, 8, "B");
public static Point thirdPoint = new Point(2, 9, "B");
public static Point fourthPoint = new Point(2, 10, "B");
public static Point fifthPoint = new Point(3, 7, "C");
public static Point sixthPoint = new Point(4, 7, "C");
public static Point seventhPoint = new Point(5, 7, "C");
个对象的一个参数[这对(myPoint和后继者)不能分别(类型A和类型B)和(类型A和类型C)。
这可以这样做吗?我无法找到任何相关的资源(并且无法制定我的问题所以它没有帮助)
答案 0 :(得分:1)
调查javatuples您可以按照本文https://stackoverflow.com/a/10631692/3944563
中所述制作自己的内容但它可能看起来不漂亮。你会做类似的事情,
//define your tuple class
class myTuple
{
final String T1;
final String T2;
public myTuple(String t1, String t2)
{
T1 = t1;
T2 = t2;
}
if(myTupple(myPoint.type, successos.type) == myTupple("A", "B"))
{ /* do something */ }`
无论如何,我不认为你可以做到漂亮,但你明白了。
我要做的是在该类中添加一个静态方法,名为“validateType”或者其他什么,并将这两点传递给你的签到