001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019package org.apache.oozie.util.graph; 020 021import org.apache.oozie.client.WorkflowAction; 022 023import java.awt.Point; 024import java.util.HashMap; 025import java.util.Map; 026 027public class WorkflowActionNode { 028 private String name; 029 private String type; 030 private Point loc; 031 private final Map<String, Boolean> arcs; 032 private WorkflowAction.Status status = null; 033 034 private WorkflowActionNode(final String name, 035 final String type, 036 final HashMap<String, Boolean> arcs, 037 final Point loc, 038 final WorkflowAction.Status status) { 039 this.name = name; 040 this.type = type; 041 this.arcs = arcs; 042 this.loc = loc; 043 this.status = status; 044 } 045 046 WorkflowActionNode(final String name, final String type) { 047 this(name, type, new HashMap<String, Boolean>(), new Point(0, 0), null); 048 } 049 050 void addArc(final String arc, final boolean isError) { 051 arcs.put(arc, isError); 052 } 053 054 void addArc(final String arc) { 055 addArc(arc, false); 056 } 057 058 public void setName(final String name) { 059 this.name = name; 060 } 061 062 public void setType(final String type) { 063 this.type = type; 064 } 065 066 public void setLocation(final Point loc) { 067 this.loc = loc; 068 } 069 070 void setLocation(final double x, final double y) { 071 loc.setLocation(x, y); 072 } 073 074 public void setStatus(final WorkflowAction.Status status) { 075 this.status = status; 076 } 077 078 public String getName() { 079 return name; 080 } 081 082 public String getType() { 083 return type; 084 } 085 086 Map<String, Boolean> getArcs() { 087 return arcs; 088 } 089 090 public Point getLocation() { 091 return loc; 092 } 093 094 public WorkflowAction.Status getStatus() { 095 return status; 096 } 097 098 @Override 099 public String toString() { 100 final StringBuilder s = new StringBuilder(); 101 102 s.append("Node: ").append(name).append("\t"); 103 s.append("Type: ").append(type).append("\t"); 104 s.append("Location: (").append(loc.getX()).append(", ").append(loc.getY()).append(")\t"); 105 s.append("Status: ").append(status).append("\n"); 106 107 for (final Map.Entry<String, Boolean> entry : arcs.entrySet()) { 108 s.append("\t").append(entry.getKey()); 109 if (entry.getValue()) { 110 s.append(" on error\n"); 111 } else { 112 s.append("\n"); 113 } 114 } 115 116 return s.toString(); 117 } 118 119 @Override 120 public boolean equals(final Object o) { 121 if (this == o) { 122 return true; 123 } 124 if (o == null || getClass() != o.getClass()) { 125 return false; 126 } 127 128 final WorkflowActionNode that = (WorkflowActionNode) o; 129 130 if (!name.equals(that.name)) { 131 return false; 132 } 133 if (!type.equals(that.type)) { 134 return false; 135 } 136 137 return status == that.status; 138 } 139 140 @Override 141 public int hashCode() { 142 int result = name.hashCode(); 143 144 result = 31 * result + type.hashCode(); 145 result = 31 * result + (status != null ? status.hashCode() : 0); 146 147 return result; 148 } 149}