001package conexp.fx.core.context.negation; 002 003/* 004 * #%L 005 * Concept Explorer FX 006 * %% 007 * Copyright (C) 2010 - 2023 Francesco Kriegel 008 * %% 009 * This program is free software: you can redistribute it and/or modify 010 * it under the terms of the GNU General Public License as 011 * published by the Free Software Foundation, either version 3 of the 012 * License, or (at your option) any later version. 013 * 014 * This program is distributed in the hope that it will be useful, 015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 017 * GNU General Public License for more details. 018 * 019 * You should have received a copy of the GNU General Public 020 * License along with this program. If not, see 021 * <http://www.gnu.org/licenses/gpl-3.0.html>. 022 * #L% 023 */ 024 025public class Literal<M> { 026 027 public enum Type { 028 POSITIVE, 029 NEGATIVE; 030 } 031 032 private final Literal.Type type; 033 private final M m; 034 035 public Literal(final Literal.Type type, final M m) { 036 super(); 037 this.type = type; 038 this.m = m; 039 } 040 041 public Literal(final M m) { 042 this(Literal.Type.POSITIVE, m); 043 } 044 045 public final M getM() { 046 return m; 047 } 048 049 public final Literal.Type getType() { 050 return type; 051 } 052 053 @Override 054 public final String toString() { 055 switch (type) { 056 case POSITIVE: 057 return m.toString(); 058 case NEGATIVE: 059 return "-" + m; 060 } 061 return null; 062 } 063 064 @Override 065 public final boolean equals(Object obj) { 066 if (obj == null) 067 return false; 068 if (!(obj instanceof Literal)) 069 return false; 070 final Literal<?> other = (Literal<?>) obj; 071 return other.type.equals(this.type) && other.m.equals(this.m); 072 } 073 074 @Override 075 public final int hashCode() { 076 return type.hashCode() + 3 * m.hashCode(); 077 } 078}