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

Java Discussion :

Vérification implémentation interface a


Sujet :

Java

  1. #1
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Février 2013
    Messages
    144
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2013
    Messages : 144
    Points : 83
    Points
    83
    Par défaut Vérification implémentation interface a
    j'ai

    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
    package org.essilab.exercices.bases.string.interfaces;
     
    public interface IStringUtil {
     
    	/**
             * <p>Suppress invisible character placed before of after the given string</p>
             * <p>for example : "    a test "  will return "a test"</p>
             * @param string the string to trim
             * @return the trimed string.
             */
    	public String trim(String string);
     
    	/**
             * <p>Turn to lowercase the given string.</p>
             * <p>for example : "AdCvD,de" will return "adcvd,de" 
             * </p><p>you can not use Character.is* method</p>
             * @param string lowercased string
             * @return
             */
    	public String toLowercase(String string);
     
    	/**
             * <p>Turn to uppercase the given string.</p>
             * <p>for example : "AdCvD,de" will return "ADCVD,DE" </p>
             * <p>you can not use Character.is* method</p>
             * @param string uppercased string
             * @return
             */
    	public String toUppercase(String string);
     
    	/**
             * <p>Capitalize the given string</p>
             * <p>for example, "aDc bbb,ddd?e:fgh" will return "Adc Bbb,Ddd?E:Fgh"
             * </p><p>you can use Character.is* method</p>
             * @param string the string to capitalize
             * @return
             */
    	public String capitalize(String string);
     
    	/**
             * <p>return the camelized upper representation of the given string</p>
             * <p>for example, "abg Def.ghi, bla" will return AbaDefGhiBla</p>
             * @param string
             * @return
             */
    	public String camelizeUpper(String string);
     
    	/**
             * <p>return the camelized lower representation of the given string</p>
             * <p>for example, "aba Def.ghi, bla" will return abaDefGhiBla</p>
             * @param string
             * @return
             */
    	public String camelizeLower(String string);
     
    	/**
             * <p>Revert the given string</p>
             * <p>for example, "abc" will return "cba"
             * @param string
             * @return
             */
    	public String revert(String string);
     
    	/**
             * </p><p>Replace in the given input the founded patterns by the replacement.</p>
             * <p>You can't use any replace method or any regexp</p>
             * <p>for example</p>
             * <p>"hello world, hello" with pattern "hello" and replacement "goodbye" will produce</p>
             * <p>goodbye world, goodbye</p>
             * @param input to input to analyse
             * @param pattern the pattern to look for.
             * @param replacement the replacement to apply for the matched occurence
             * @param all applied replacement to all occurence ?
             * @return
             */
    	public String replace(String input, String pattern, String replacement, boolean all);
     
    	/**
             * <p>Search for pattern in the given string and call the callback for each replacement</p>
             * <p>You can't use any replace method or any regexp</p>
             * <p>for example</p>
             * <pre>         * public class HrefReplacement implements IReplacementCallback {
             *    public String replace(String pattern) {
             *       return "<a href=\"/tags/"+pattern+".html\">"+pattern+"";
             *    }
             * }
             * </pre>
             * <p>will produce for given string : "hello world" with given pattern "world" : hello <a href="http://10.50.126.57:8181/tags/hello.html">world&lgt;/a>
             * @param input to input to analyse
             * @param pattern the pattern to look for.
             * @param replacement the replacement to apply for the matched occurence
             * @param all applied replacement to all occurence ?
             * @return
             */
    	public String replace(String input, String pattern, IReplacementCallback callback, boolean all);
     
    	public interface IReplacementCallback{
    		public String replace(String pattern);
    	}
    }
    et
    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
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    package org.essilab.exercices.bases.string;
     
    import org.essilab.exercices.bases.string.interfaces.IStringUtil;
    import org.essilab.exercices.bases.string.interfaces.IStringUtil.IReplacementCallback;
     
    public abstract  class StringUtil implements IStringUtil {
    	private String String retour;
     
     
     
    	/**
             * <p>Suppress invisible character placed before of after the given string</p>
             * <p>for example : "    a test "  will return "a test"</p>
             * @param string the string to trim
             * @return the trimed string.
             */
    	public String trim(String string){
    		string = string.trim();
    		return string;
    	}
     
    	/**
             * <p>Turn to lowercase the given string.</p>
             * <p>for example : "AdCvD,de" will return "adcvd,de" 
             * </p><p>you can not use Character.is* method</p>
             * @param string lowercased string
             * @return
             */
    	public String toLowercase(String string){
    		String a = new String();
    		a = string.toLowerCase();
    		return  a ;
    	}
     
    	/**
             * <p>Turn to uppercase the given string.</p>
             * <p>for example : "AdCvD,de" will return "ADCVD,DE" </p>
             * <p>you can not use Character.is* method</p>
             * @param string uppercased string
             * @return
             */
    	public String toUppercase(String string){
    		String b = new String();
    		b = string.toUpperCase();
    		return b;
    	}
     
    	/**
             * <p>Capitalize the given string</p>
             * <p>for example, "aDc bbb,ddd?e:fgh" will return "Adc Bbb,Ddd?E:Fgh"
             * </p><p>you can use Character.is* method</p>
             * @param string the string to capitalize
             * @return
             */
     
     
    	public  String capitalize (String string) {
            boolean flag;
            String charSpecials = ";\":? ,";
            StringBuffer buffer = new StringBuffer("");
     
            for (int i = 0; i < string.length(); i++) {
                flag = false;
                buffer.append(string.charAt(i));
     
                for (int j = 0; j < charSpecials.length(); j++) {
                    if (string.charAt(i) == charSpecials.charAt(j)) {
                        flag = true;
                        break;
                    }
                }
     
                if (flag == true) {
                    if (i < string.length() - 1) {
                        i++;
                    }
                    buffer.append(Character.toUpperCase(string.charAt(i)));
                }
            }
     
            buffer.deleteCharAt(buffer.length() - 1);
            String retour = buffer.toString();
            return retour;
        }
     
     
    	/**
             * <p>return the camelized upper representation of the given string</p>
             * <p>for example, "abg Def.ghi, bla" will return AbaDefGhiBla</p>
             * @param string
             * @return
             */
    	public String camelizeUpper(String string){
            boolean flag;
            String charSpecials = ";\":? ,";
            StringBuffer buffer = new StringBuffer("");
     
            for (int i = 0; i < string.length(); i++) {
                flag = false;
                buffer.append(string.charAt(i));
     
                for (int j = 0; j < charSpecials.length(); j++) {
                    if (string.charAt(i) == charSpecials.charAt(j)) {
                        flag = true;
                        break;
                    }
                }
     
                if (flag == true) {
                    if (i < string.length() - 1) {
                        i++;
                    }
                    buffer.append(Character.toUpperCase(string.charAt(i)));
                }
            }
     
            buffer.deleteCharAt(buffer.length() - 1);
            String retour = buffer.toString();
            String rendu = retour.replaceAll("[\\s\\p{Punct}]","");
            return rendu;
    	}
     
     
     
    	/**
             * <p>return the camelized lower representation of the given string</p>
             * <p>for example, "aba Def.ghi, bla" will return abaDefGhiBla</p>
             * @param string
             * @return
             */
    	public String camelizeLower(String string){ 
    		boolean flag;
    		String charSpecials = ";\":? ,";
    		StringBuffer buffer = new StringBuffer("");
     
    		for (int i = 0; i < string.length(); i++) {
    			flag = false;
    			buffer.append(string.charAt(i));
    			for (int j = 0; j < charSpecials.length(); j++) {
    				if (string.charAt(i) == charSpecials.charAt(j)) {
    					flag = true;
    					break;
    				}
    			}
     
    			if (flag == true) {
    				if (i < string.length() - 1) {
    					i++;
    				}
    				buffer.append(Character.toUpperCase(string.charAt(i)));
    			}
    		}
     
    		buffer.deleteCharAt(buffer.length() - 1);
    		String retour = buffer.toString();
    		//suppression de toute ponctuation
    		String rendu = retour.replaceAll("[\\s\\p{Punct}]","");
    		String nouveau= rendu.substring(0,1).toLowerCase();
    		return nouveau;
    	}
     
     
     
     
    	/**
             * <p>Revert the given string</p>
             * <p>for example, "abc" will return "cba"
             * @param string
             * @return
             */
    	public String revert(String string){
    		StringBuilder lettersBuff = new StringBuilder(string);
    		String inverse = lettersBuff.reverse().toString();
    		return inverse ;
    	}
     
     
     
     
     
    	/**
             * </p><p>Replace in the given input the founded patterns by the replacement.</p>
             * <p>You can't use any replace method or any regexp</p>
             * <p>for example</p>
             * <p>"hello world, hello" with pattern "hello" and replacement "goodbye" will produce</p>
             * <p>goodbye world, goodbye</p>
             * @param input to input to analyse
             * @param pattern the pattern to look for.
             * @param replacement the replacement to apply for the matched occurence
             * @param all applied replacement to all occurence ?
             * @return
             */
    	/*
    	 * public String replace(String input, String pattern, String replacement, boolean all){
    		if (StringUtils.isNotBlank(input)){
    			if (all){
    				return input.replaceAll(pattern, replacement);
    			}else{
    				return input.replaceFirst(pattern, replacement);
    			}
    		}
    		return null;
    	}*/
     
    	/*public String replace(String input, String pattern, String replacement, boolean all){
    		all = false;
    		int tab [] = new int [6];
    		int a = 0;
    		if(input.contains(pattern)){
    			for(int i =0; i<6;i++){
    				a = input.indexOf(pattern, a+1);
    				tab[i] = a;
    			}
    			all = true;
    		}
    		if (all == true){
    			for(int j = 0; j<6;j++){
    				int e = 0;
    				if(input.indexOf(a + 1) == tab[e]))
    			}
    		}
     
    	}
    	*/
     
     
     
     
     
    	/**
             * <p>Search for pattern in the given string and call the callback for each replacement</p>
             * <p>You can't use any replace method or any regexp</p>
             * <p>for example</p>
             * <pre>         * public class HrefReplacement implements IReplacementCallback {
             *    public String replace(String pattern) {
             *       return "<a href=\"/tags/"+pattern+".html\">"+pattern+"";
             *    }
             * }
             * </pre>
             * <p>will produce for given string : "hello world" with given pattern "world" : hello <a href="http://10.50.126.57:8181/tags/hello.html">world&lgt;/a>
             * @param input to input to analyse
             * @param pattern the pattern to look for.
             * @param replacement the replacement to apply for the matched occurence
             * @param all applied replacement to all occurence ?
             * @return
             */
     
     
    	//public String replace(String input, String pattern, IReplacementCallback callback, boolean all);
     
    	public interface IReplacementCallback{
    		public String replace(String pattern);
    	}
    }
    ou dois-je mettre mon main pour vérifier si mon implémentation fonctionne?

    si possible donner un exemple de main sur une fonction de l'implémentation

  2. #2
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Points : 48 807
    Points
    48 807
    Par défaut
    Dans une classe à part, que tu appellera MonApplication, par exemple.

  3. #3
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Février 2013
    Messages
    144
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2013
    Messages : 144
    Points : 83
    Points
    83
    Par défaut
    Citation Envoyé par tchize_ Voir le message
    Dans une classe à part, que tu appellera MonApplication, par exemple.
    C'est ce que je fais mais il me mets une erreur
    impossibilité d'iinstancier StringUtil;
    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
    package org.essilab.exercices.bases.string;
     
    import org.essilab.exercices.bases.string.interfaces.IStringUtil;
     
    public class Test {
     
     
    	public static void main(String[] args) {
    		String a = 'abcd';
    		IStringUtil hw = new StringUtil();
    		System.out.println(hw.revert(a));
    		//IHelloWorld hw = new HelloWorld();
    		//System.out.println(hw.helloWorld());
     
    		}
     
    }

  4. #4
    Membre chevronné

    Profil pro
    Inscrit en
    Décembre 2011
    Messages
    974
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2011
    Messages : 974
    Points : 1 825
    Points
    1 825
    Par défaut
    StringUtil est une classe abstraite donc pas instanciable .

  5. #5
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Points : 48 807
    Points
    48 807
    Par défaut
    Tu dois retirer ce abstract sur StringUtil , pourquoi l'avoir défini comme abstrait

  6. #6
    Membre expérimenté Avatar de Nico02
    Homme Profil pro
    Developpeur Java/JEE
    Inscrit en
    Février 2011
    Messages
    728
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Developpeur Java/JEE
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2011
    Messages : 728
    Points : 1 622
    Points
    1 622
    Par défaut
    Sinon pour une class outil tu peux aussi définir tes méthodes en static et ainsi pouvoir y accéder partout sans devoir instancier un objet à chaque fois.

  7. #7
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Février 2013
    Messages
    144
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2013
    Messages : 144
    Points : 83
    Points
    83
    Par défaut ea
    Merci j'ai resolu le probleme

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Implémentation interface Iterator,Iterable
    Par small44 dans le forum Débuter avec Java
    Réponses: 18
    Dernier message: 16/11/2013, 02h14
  2. Implémenter interface ICloneable
    Par babozfr dans le forum C++/CLI
    Réponses: 5
    Dernier message: 16/01/2007, 20h24
  3. [Débutant] Explication implémentation interface
    Par HaTnuX dans le forum Langage
    Réponses: 3
    Dernier message: 16/01/2007, 16h37
  4. Réponses: 5
    Dernier message: 29/11/2005, 14h32
  5. Réponses: 2
    Dernier message: 13/10/2005, 11h08

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