Commit b9b4b135 authored by Dominique Marcadet's avatar Dominique Marcadet

Merge branch '21-allow-to-not-display-messages-that-have-already-been-displayed' into 'master'

Resolve "allow to not display messages that have already been displayed"

Closes #21

See merge request RiseClipseGroup/RiseClipseMain!21
parents 1f9289eb feed205f
......@@ -18,6 +18,9 @@
*/
package fr.centralesupelec.edf.riseclipse.util;
import java.util.HashSet;
import java.util.Set;
/**
* Base class for RiseClipse consoles.
* It implements the Singleton design pattern, handle the level of messages
......@@ -60,6 +63,11 @@ public abstract class AbstractRiseClipseConsole implements IRiseClipseConsole {
* The current level of displayed messages
*/
protected int currentLevel;
/**
* Messages which have been displayed once
*/
private Set< String > displayedMessages;
/**
* Constructs a new console, using it as the unique one
......@@ -98,7 +106,7 @@ public abstract class AbstractRiseClipseConsole implements IRiseClipseConsole {
*/
public final void info( Object o ) {
if( currentLevel <= INFO_LEVEL ) {
doOutputMessage( "INFO: " + o.toString() );
outputMessage( "INFO: " + o.toString() );
}
}
......@@ -108,7 +116,7 @@ public abstract class AbstractRiseClipseConsole implements IRiseClipseConsole {
*/
public final void warning( Object o ) {
if( currentLevel <= WARNING_LEVEL ) {
doOutputMessage( "WARNING: " + o.toString() );
outputMessage( "WARNING: " + o.toString() );
}
}
......@@ -118,7 +126,7 @@ public abstract class AbstractRiseClipseConsole implements IRiseClipseConsole {
*/
public final void error( Object o ) {
if( currentLevel <= ERROR_LEVEL ) {
doOutputMessage( "ERROR: " + o.toString() );
outputMessage( "ERROR: " + o.toString() );
}
}
......@@ -127,14 +135,34 @@ public abstract class AbstractRiseClipseConsole implements IRiseClipseConsole {
* then throws a {@link RiseClipseFatalException}
*/
public final void fatal( Object o ) {
doOutputMessage( "FATAL: " + o.toString() );
outputMessage( "FATAL: " + o.toString() );
throw new RiseClipseFatalException( "FATAL: " + o.toString(), null );
}
private void outputMessage( String m ) {
if( displayedMessages != null ) {
if( displayedMessages.contains( m )) {
return;
}
displayedMessages.add( m );
}
doOutputMessage( m );
}
/**
* Output message s on the current console
* @param m message to display
*/
protected abstract void doOutputMessage( String m );
@Override
public void displayIdenticalMessages() {
displayedMessages = null;
}
@Override
public void doNotDisplayIdenticalMessages() {
displayedMessages = new HashSet< String >();
}
}
......@@ -78,5 +78,15 @@ public interface IRiseClipseConsole {
*/
public void fatal( Object o );
/**
* All messages will be displayed, even if an identical one has already been displayed
*/
public void displayIdenticalMessages();
/**
* Messages will be displayed only once. An identical one will be ignored
*/
public void doNotDisplayIdenticalMessages();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment