• Keine Ergebnisse gefunden

6 private S t r i n g DELTA END

N/A
N/A
Protected

Academic year: 2021

Aktie "6 private S t r i n g DELTA END"

Copied!
3
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

1 package j u n i t . framework ;

2

3 public c l a s s CompComp {

4

5 private S t r i n g ELLIPSIS= ” . . . ” ;

6 private S t r i n g DELTA END= ” ] ” ;

7 private S t r i n g DELTA START= ” [ ” ;

8

9 public i n t f C o n t e x t L e n g t h ;

10 private S t r i n g f E x p e c t e d ;

11 private S t r i n g f A c t u a l ;

12 private i n t f P r e f i x ;

13 private i n t f S u f f i x ;

14

15 public CompComp(i n t c o n t e x t L e n g t h , S t r i n g e x p e c t e d , S t r i n g a c t u a l ) {

16 f C o n t e x t L e n g t h= c o n t e x t L e n g t h ;

17 f E x p e c t e d= e x p e c t e d ;

18 f A c t u a l= a c t u a l ;

19 }

20

21 public S t r i n g compact ( S t r i n g me ssa ge ) {

22 i f ( f E x p e c t e d == n u l l | | f A c t u a l == n u l l | | a r e S t r i n g s E q u a l ( ) )

23 return A s s e r t . f o r m a t ( message , f E x p e c t e d , f A c t u a l ) ;

24

25 findCommonPrefix ( ) ;

26 findCommonSuffix ( ) ;

27 S t r i n g e x p e c t e d= c o m p a c t S t r i n g ( f E x p e c t e d ) ;

28 S t r i n g a c t u a l= c o m p a c t S t r i n g ( f A c t u a l ) ;

29 return A s s e r t . f o r m a t ( message , e x p e c t e d , a c t u a l ) ;

30 }

31

32 public S t r i n g c o m p a c t S t r i n g ( S t r i n g s o u r c e ) {

33 S t r i n g r e s u l t= DELTA START + s o u r c e . s u b s t r i n g ( f P r e f i x , s o u r c e . l e n g t h ( )

− f S u f f i x + 1 ) + DELTA END ;

34 i f ( f P r e f i x < 0 )

35 r e s u l t= computeCommonPrefix ( ) + r e s u l t ;

36 i f ( f S u f f i x > 0 )

37 r e s u l t= r e s u l t + computeCommonSuffix ( ) ;

38 return r e s u l t ;

39 }

40

41 private void findCommonPrefix ( ) {

42 f P r e f i x= 0 ;

43 i n t end= Math . min ( f E x p e c t e d . l e n g t h ( ) , f A c t u a l . l e n g t h ( ) ) ;

44 f o r ( ; f P r e f i x < end ; f P r e f i x ++) {

45 i f ( f E x p e c t e d . charAt ( f P r e f i x ) != f A c t u a l . charAt ( f P r e f i x ) )

46 break;

47 }

48 }

49

50 private void findCommonSuffix ( ) {

51 i n t e x p e c t e d S u f f i x= f E x p e c t e d . l e n g t h ( ) − 1 ;

52 i n t a c t u a l S u f f i x= f A c t u a l . l e n g t h ( ) − 1 ;

53 f o r ( ; a c t u a l S u f f i x >= f P r e f i x && e x p e c t e d S u f f i x >= f P r e f i x ; a c t u a l S u f f i x−−, e x p e c t e d S u f f i x−−) {

54 i f ( f E x p e c t e d . charAt ( e x p e c t e d S u f f i x ) != f A c t u a l . charAt ( a c t u a l S u f f i x ) )

55 break;

56 }

57 f S u f f i x= f E x p e c t e d . l e n g t h ( ) − e x p e c t e d S u f f i x ;

58 }

59

60 private S t r i n g computeCommonPrefix ( ) {

61 return ( f P r e f i x > f C o n t e x t L e n g t h ? ELLIPSIS : ” ” ) + f E x p e c t e d . s u b s t r i n g

1

(2)

( Math . max ( 0 , f P r e f i x − f C o n t e x t L e n g t h ) , f P r e f i x ) ;

62 }

63

64 private S t r i n g computeCommonSuffix ( ) {

65 i n t end= Math . min ( f E x p e c t e d . l e n g t h ( ) − f S u f f i x + f C o n t e x t L e n g t h , f E x p e c t e d . l e n g t h ( ) ) ;

66 return f E x p e c t e d . s u b s t r i n g ( f E x p e c t e d . l e n g t h ( ) − f S u f f i x + 1 , end ) + ( f E x p e c t e d . l e n g t h ( ) − f S u f f i x + 1 < f E x p e c t e d . l e n g t h ( ) −

f C o n t e x t L e n g t h ? ELLIPSIS : ” ” ) ;

67 }

68

69 private boolean a r e S t r i n g s E q u a l ( ) {

70 return f E x p e c t e d . e q u a l s ( f A c t u a l ) ;

71 }

72 }

2

(3)

1 package j u n i t . framework ;

2 3 /∗ ∗

4 ∗ Thrown when an a s s e r t e q u a l s f o r S t r i n g s f a i l e d .

5

6 ∗ I n s p i r e d by a p a t c h from A l e x C h a f f e e m a i l t o : a l e x @ p u r p l e t e c h . com

7 ∗/

8 public c l a s s C o m p a r i s o n F a i l u r e extends A s s e r t i o n F a i l e d E r r o r {

9 private s t a t i c f i n a l long s e r i a l V e r s i o n U I D= 1L ;

10

11 public S t r i n g f E x p e c t e d ;

12 private S t r i n g f A c t u a l ;

13

14 /∗ ∗

15 ∗ C o n s t r u c t s a c o m p a r i s o n f a i l u r e .

16 ∗ @param message t h e i d e n t i f y i n g message o r n u l l

17 ∗ @param e x p e c t e d t h e e x p e c t e d s t r i n g v a l u e

18 ∗ @param a c t u a l t h e a c t u a l s t r i n g v a l u e

19 ∗/

20 public C o m p a r i s o n F a i l u r e ( S t r i n g message , S t r i n g e x p e c t e d , S t r i n g a c t u a l ) {

21 super ( me ssa ge ) ;

22 f E x p e c t e d= e x p e c t e d ;

23 f A c t u a l= a c t u a l ;

24 }

25

26 /∗ ∗

27 ∗ R e t u r n s ” . . . ” i n p l a c e o f common p r e f i x and ” . . . ” i n

28 ∗ p l a c e o f common s u f f i x b e t w e e n e x p e c t e d and a c t u a l

29 ∗ w i t h a maximum c o n t e x t l e n g t h o f 20 c h a r a c t e r s .

30

31 ∗ @see T h r o w a b l e#g e t M e s s a g e ( )

32 ∗/

33 @Override

34 public S t r i n g g e t M e s s a g e ( ) {

35 return new CompComp( 2 0 , f E x p e c t e d , f A c t u a l ) . compact (super. g e t M e s s a g e ( ) )

;

36 }

37

38 /∗ ∗

39 ∗ Gets t h e a c t u a l s t r i n g v a l u e

40 ∗ @ r e t u r n t h e a c t u a l s t r i n g v a l u e

41 ∗/

42 public S t r i n g g e t A c t u a l ( ) {

43 return f A c t u a l ;

44 }

45 /∗ ∗

46 ∗ Gets t h e e x p e c t e d s t r i n g v a l u e

47 ∗ @ r e t u r n t h e e x p e c t e d s t r i n g v a l u e

48 ∗/

49 public S t r i n g g e t E x p e c t e d ( ) {

50 return f E x p e c t e d ;

51 }

52 }

3

Referenzen

ÄHNLICHE DOKUMENTE

Ansonsten werden alle Aufgaben und Projekte fortgeführt, aber der neue Kirchenvorstand wird auch neue Akzente und Prioritäten, gemeinsam mit unserer neuen

(2) Zuzahlungen zu den Vergütungen für Vertragsleistungen nach Absatz 1 dürfen durch die Pflegeeinrichtung vom Pflegebedürftigen weder gefordert noch

Eine Gebührenrechnung wird Ihnen zu einem späteren Zeitpunkt separat zugesandt. Zahlen Sie dann bitte den Betrag zu dem in der Gebührenrechnung angegebenen Ter- min unter Angabe

Stein J, Stier C, Raab H, Weiner R., Review article: The nutritional and pharmacological consequences of obesity surgery (Sept.. Supplementation_Makro-

Hauptgeschäftsführer der IHK für München und Oberbayern, Herr Peter Kammerer, begrüßt die neu berufenen Mitglieder und Gäste des Ausschusses Tourismus und heißt diese in

Herr Haferkemper sagt, dass das Solarkataster eine gute erste Anregung für die Bürger/Innen ist, da jeder die Möglichkeit hat, seine Chancen bei der Nutzung von

Farben 3 Farbvarianten Material echtes Rinderfell Herstellung Handarbeit und Maßanfertigung mit höchstem Qualitäts- anspruch Oberseitengestaltung Patchwork mit

kann eine Metapher sein (wie ein weißes Blatt Papier) für Erfüllung und Neuanfang auch: einen Teil von sich selbst vergessen zu haben oder ihn sogar einfrieren zu