IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Design Patterns Discussion :

Conception d'un système multi-agent extensible


Sujet :

Design Patterns

  1. #81
    Membre régulier
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    255
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 255
    Points : 99
    Points
    99
    Par défaut
    Voici un code Java trouvé sur le net qui permet en Java de connaître le caller sans avoir besoin d'ajouter un paramètre dans la méthode ; ça ralenti un peu le code, mais au moins on est peinard !!!

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    /**
     * Class for investigating the call stack.
     * 
     * @author John Evans (john@jpevans.com)
     */
    public class Callstack {
    	/**
    	 * Private Constructor to prevent instantiations.
    	 */
    	private Callstack() {
    		// Do nothing, as we will never be called.
    	}
    
    	/**
    	 * Get the class of the method that called the method that called this
    	 * method.
    	 * 
    	 * @return String the name of the class that called the method that called
    	 *         this method.
    	 */
    	public static String getCallingClass() {
    		return getCallerInfo(true, false);
    	}
    
    	/**
    	 * Get the method of the method that called the method that called this
    	 * method.
    	 * 
    	 * @return String the name of the method that called the method that called
    	 *         this method.
    	 */
    	public static String getCallingMethod() {
    		return getCallerInfo(false, true);
    	}
    
    	/**
    	 * Gets 'em both. (See docs for other methods in this class. Should be
    	 * obvious anyway).
    	 * 
    	 * @return I don't know why she swallowed the fly.
    	 */
    	public static String getCallingClassAndMethod() {
    		return getCallerInfo(true, true);
    	}
    
    	/**
    	 * The method that does the heavy lifting for the other public methods of
    	 * this class.
    	 * 
    	 * @param includeClass
    	 *            Should the class be included?
    	 * @param includeMethod
    	 *            Should the method be included?
    	 * @return The class and/or method of the method that called into the
    	 *         Callstack class.
    	 */
    	public static String getCallerInfo(boolean includeClass,
    			boolean includeMethod) {
    		StringBuffer result = null;
    
    		if (includeClass || includeMethod) {
    			Exception utilException = new Exception();
    
    			StackTraceElement[] stackElements = utilException.getStackTrace();
    
    			int i = findFirstNotOneOfUs(stackElements) + 1;
    
    			if ((-1 != i) && (i < stackElements.length)) {
    				StackTraceElement theOneWeWant = stackElements[i];
    
    				if (includeClass) {
    					result = new StringBuffer(theOneWeWant.getClassName());
    				}
    
    				if (includeMethod) {
    					if (result == null) {
    						result = new StringBuffer();
    					} else {
    						result.append(".");
    					}
    
    					result.append(theOneWeWant.getMethodName());
    				}
    			}
    		}
    
    		return (result == null) ? null : result.toString();
    	}
    
    	/**
    	 * Find the first caller outside of the methods within Callstack.
    	 * 
    	 * @param elements
    	 *            The stack to search.
    	 * @return The index of the found element or -1 if none was found.
    	 */
    	private static int findFirstNotOneOfUs(StackTraceElement[] elements) {
    		int first = -1;
    
    		for (int i = 0; i < elements.length; i++) {
    			if (!elements[i].getClassName().equals(Callstack.class.getName())) {
    				first = i;
    
    				break;
    			}
    		}
    
    		return first;
    	}
    }

  2. #82
    Membre régulier
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    255
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 255
    Points : 99
    Points
    99
    Par défaut
    MàJ pour Hervé :

    roodmj.rar

Discussions similaires

  1. Programmer un système multi-agent
    Par elalia dans le forum Programmation par agent
    Réponses: 10
    Dernier message: 29/04/2011, 12h22
  2. [IA] Systèmes multi-agents et jeux vidéos simples ?
    Par progfou dans le forum Intelligence artificielle
    Réponses: 4
    Dernier message: 04/03/2011, 20h18
  3. Système multi agents en Delphi
    Par Promeneur dans le forum Delphi
    Réponses: 7
    Dernier message: 08/11/2006, 18h03
  4. Système multi agents
    Par Promeneur dans le forum Algorithmes et structures de données
    Réponses: 8
    Dernier message: 05/11/2006, 02h22
  5. Les Système Multi-agent avec Java
    Par oussam dans le forum Langage
    Réponses: 1
    Dernier message: 09/02/2006, 01h41

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo