001/* Copyright (C) 2013 TU Dortmund 002 * This file is part of AutomataLib, http://www.automatalib.net/. 003 * 004 * AutomataLib is free software; you can redistribute it and/or 005 * modify it under the terms of the GNU Lesser General Public 006 * License version 3.0 as published by the Free Software Foundation. 007 * 008 * AutomataLib is distributed in the hope that it will be useful, 009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 011 * Lesser General Public License for more details. 012 * 013 * You should have received a copy of the GNU Lesser General Public 014 * License along with AutomataLib; if not, see 015 * http://www.gnu.de/documents/lgpl.en.html. 016 */ 017package net.automatalib.brics; 018 019import dk.brics.automaton.Transition; 020 021/** 022 * The properties of an edge in a Brics automaton. 023 * 024 * @author Malte Isberner <malte.isberner@gmail.com> 025 */ 026public class BricsTransitionProperty { 027 028 public static String toString(char min, char max) { 029 StringBuilder sb = new StringBuilder(); 030 sb.append('\'').append(min).append('\''); 031 if(max > min) 032 sb.append("..'").append(max).append('\''); 033 return sb.toString(); 034 } 035 036 private final char min; 037 private final char max; 038 039 /** 040 * Constructor. 041 * @param min lower bound of the character range. 042 * @param max upper bound of the character range. 043 */ 044 public BricsTransitionProperty(char min, char max) { 045 this.min = min; 046 this.max = max; 047 } 048 049 /** 050 * Constructor. Constructs the property from a Brics {@link Transition}. 051 * @param trans the Brics transition object 052 */ 053 public BricsTransitionProperty(Transition trans) { 054 this(trans.getMin(), trans.getMax()); 055 } 056 057 /** 058 * Retrieves the lower bound of the character range. 059 * @return the lower bound of the character range 060 * @see Transition#getMin() 061 */ 062 public char getMin() { 063 return min; 064 } 065 066 /** 067 * Retrieves the upper bound of the character range. 068 * @return the upper bound of the character range 069 * @see Transition#getMax() 070 */ 071 public char getMax() { 072 return max; 073 } 074 075 /* 076 * (non-Javadoc) 077 * @see java.lang.Object#hashCode() 078 */ 079 @Override 080 public int hashCode() { 081 final int prime = 31; 082 int result = 1; 083 result = prime * result + max; 084 result = prime * result + min; 085 return result; 086 } 087 088 /* 089 * (non-Javadoc) 090 * @see java.lang.Object#equals(java.lang.Object) 091 */ 092 @Override 093 public boolean equals(Object obj) { 094 if (this == obj) 095 return true; 096 if (obj == null) 097 return false; 098 if (getClass() != obj.getClass()) 099 return false; 100 BricsTransitionProperty other = (BricsTransitionProperty) obj; 101 if (max != other.max) 102 return false; 103 if (min != other.min) 104 return false; 105 return true; 106 } 107 108 /* 109 * (non-Javadoc) 110 * @see java.lang.Object#toString() 111 */ 112 @Override 113 public String toString() { 114 return toString(min, max); 115 } 116 117 118 119}