001package conexp.fx.core.algorithm.exploration; 002 003/* 004 * #%L 005 * Concept Explorer FX 006 * %% 007 * Copyright (C) 2010 - 2019 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 025import java.util.Arrays; 026import java.util.Collection; 027import java.util.HashSet; 028import java.util.Set; 029 030import conexp.fx.core.context.Context; 031import conexp.fx.core.context.Implication; 032 033public final class CounterExample<G, M> { 034 035 private final G object; 036 private final Set<M> attributes; 037 038 @SafeVarargs 039 public CounterExample(final G object, final M... attributes) { 040 this(object, Arrays.asList(attributes)); 041 } 042 043 public CounterExample(final G object, final Collection<M> attributes) { 044 super(); 045 this.object = object; 046 this.attributes = new HashSet<M>(attributes); 047 } 048 049 public final G getObject() { 050 return object; 051 } 052 053 public final Set<M> getAttributes() { 054 return attributes; 055 } 056 057 public final void insertIn(final Context<G, M> cxt) { 058 cxt.rowHeads().add(object); 059 cxt.row(object).addAll(attributes); 060// for (M m : attributes) 061// cxt.add(object, m); 062 } 063 064 public final void addTo(final Implication<G, M> implication) { 065 implication.getSupport().add(object); 066 implication.getConclusion().retainAll(attributes); 067 } 068 069 @Override 070 public final boolean equals(final Object obj) { 071 if (!(obj instanceof CounterExample)) 072 return false; 073 final CounterExample<?, ?> that = (CounterExample<?, ?>) obj; 074 return this.object.equals(that.object) && this.attributes.equals(that.attributes); 075 } 076 077 @Override 078 public final int hashCode() { 079 return object.hashCode() + attributes.hashCode(); 080 } 081 082 @Override 083 public final String toString() { 084 return "counter-example (" + object + "): " + attributes; 085 } 086 087}