|
| 1 | +/* |
| 2 | + * JBoss, Home of Professional Open Source. |
| 3 | + * Copyright 2015, Red Hat, Inc., and individual contributors |
| 4 | + * as indicated by the @author tags. See the copyright.txt file in the |
| 5 | + * distribution for a full listing of individual contributors. |
| 6 | + * |
| 7 | + * This is free software; you can redistribute it and/or modify it |
| 8 | + * under the terms of the GNU Lesser General Public License as |
| 9 | + * published by the Free Software Foundation; either version 2.1 of |
| 10 | + * the License, or (at your option) any later version. |
| 11 | + * |
| 12 | + * This software is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | + * Lesser General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU Lesser General Public |
| 18 | + * License along with this software; if not, write to the Free |
| 19 | + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 20 | + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. |
| 21 | + */ |
| 22 | + |
| 23 | +package org.jboss.as.patching.generator; |
| 24 | + |
| 25 | +/** |
| 26 | + * |
| 27 | + * @author Alexey Loubyansky |
| 28 | + */ |
| 29 | +public class OptionalPath { |
| 30 | + |
| 31 | + public static OptionalPath create(String path) { |
| 32 | + return new OptionalPath(path, null); |
| 33 | + } |
| 34 | + |
| 35 | + public static OptionalPath create(String path, String requires) { |
| 36 | + return new OptionalPath(path, requires); |
| 37 | + } |
| 38 | + |
| 39 | + private final String value; |
| 40 | + private final String requires; |
| 41 | + |
| 42 | + OptionalPath(String value, String requires) { |
| 43 | + assert value != null : "value is null"; |
| 44 | + this.value = value; |
| 45 | + this.requires = requires; |
| 46 | + } |
| 47 | + |
| 48 | + public String getValue() { |
| 49 | + return value; |
| 50 | + } |
| 51 | + |
| 52 | + public String getRequires() { |
| 53 | + return requires; |
| 54 | + } |
| 55 | + |
| 56 | + /* (non-Javadoc) |
| 57 | + * @see java.lang.Object#hashCode() |
| 58 | + */ |
| 59 | + @Override |
| 60 | + public int hashCode() { |
| 61 | + final int prime = 31; |
| 62 | + int result = 1; |
| 63 | + result = prime * result + ((requires == null) ? 0 : requires.hashCode()); |
| 64 | + result = prime * result + ((value == null) ? 0 : value.hashCode()); |
| 65 | + return result; |
| 66 | + } |
| 67 | + |
| 68 | + /* (non-Javadoc) |
| 69 | + * @see java.lang.Object#equals(java.lang.Object) |
| 70 | + */ |
| 71 | + @Override |
| 72 | + public boolean equals(Object obj) { |
| 73 | + if (this == obj) |
| 74 | + return true; |
| 75 | + if (obj == null) |
| 76 | + return false; |
| 77 | + if (getClass() != obj.getClass()) |
| 78 | + return false; |
| 79 | + OptionalPath other = (OptionalPath) obj; |
| 80 | + if (requires == null) { |
| 81 | + if (other.requires != null) |
| 82 | + return false; |
| 83 | + } else if (!requires.equals(other.requires)) |
| 84 | + return false; |
| 85 | + if (value == null) { |
| 86 | + if (other.value != null) |
| 87 | + return false; |
| 88 | + } else if (!value.equals(other.value)) |
| 89 | + return false; |
| 90 | + return true; |
| 91 | + } |
| 92 | + |
| 93 | + @Override |
| 94 | + public String toString() { |
| 95 | + return "[" + value + " requires " + requires + "]"; |
| 96 | + } |
| 97 | +} |
0 commit comments