Results 1 to 6 of 6
  1. #1
    harryblue is offline Member
    Join Date
    Mar 2009
    Posts
    4
    Rep Power
    0

    Default [REQ] could anybody clean this method up for me?

    hi just wondering if sombody could clean up this method since its so messy, i need it set out only like this.....

    Java Code:
                if(i == 2)
                
                if(i == 3)
                    
                if(i == 12)
                    
                if(i == 13)
                    
                if(i == 14)
                    
                if(i == 17)
    atm it has loads of "else" etc

    here is what i need cleaning

    Java Code:
    public void readValues(int i, Stream stream, boolean bool) {
    	anInt1459++;
    	if (i != 1) {
    	    if (i != 2) {
    		if (i != 12) {
    		    if (i != 13) {
    			if (i == 14)//walk animation?
    			    anInt1440 = stream.readUnsignedWord(1355769544);
    			else if (i != 15) {
    			    if (i != 16) {
    				if (i != 17) {
    				    if (i > 30 || i <= 35) {
    					if (i == 40) {
    					    int k = stream.readUnsignedByte(-6677);
    					    OriginalModelColors = new short[k];
    					    ChangedModelColors = new short[k];
    					    for (int k1 = 0; k > k1; k1++) 
    					    {
    						OriginalModelColors[k1] = (short) (stream.readUnsignedWord(1355769544));
    						ChangedModelColors[k1] = (short) (stream.readUnsignedWord(1355769544));
    					    }
    					} else if (i == 41) {
    					    int i_11_ = stream.readUnsignedByte(-6677);
    					    aShortArray1442 = new short[i_11_];
    					    aShortArray1425 = new short[i_11_];
    					    for (int i_12_ = 0;((i_12_ ^ 0xffffffff) > (i_11_ ^ 0xffffffff));i_12_++) {
    						aShortArray1442[i_12_] = (short) (stream.readUnsignedWord(1355769544));
    						aShortArray1425[i_12_]= (short) (stream.readUnsignedWord(1355769544));
    					    }
    					} else if (i == 42) {
    					    int i_13_ = stream.readUnsignedByte(-6677);
    					    aByteArray1422 = new byte[i_13_];
    					    for (int i_14_ = 0;((i_13_ ^ 0xffffffff) < (i_14_ ^ 0xffffffff));i_14_++)
    						aByteArray1422[i_14_] = stream.method955(3390);
    					} else if (i != 60) {
    					    if (i != 93) {
    						if (i == 95)
    						    anInt1444 = (stream.readUnsignedWord(1355769544));//combat lvl
    						else if (i != 97) {
    						    if (i == 98)
    						    	scaleNPCheight = (stream.readUnsignedWord(1355769544));
    						    else if (i != 99) {
    							if (i != 100) {
    							    if (i != 101) {
    								if (i == 102)
    								    anInt1439 = (stream.readUnsignedWord(1355769544));//headicon
    								else if (i == 103)
    								    anInt1456 = (stream.readUnsignedWord(1355769544));
    								else if (i == 106 || i == 118) {
    								    anInt1426 = (stream.readUnsignedWord(1355769544));
    								    if ((anInt1426 ^ 0xffffffff)== -65536)
    									anInt1426 = -1;
    								    anInt1469 = (stream.readUnsignedWord(1355769544));
    								    if (anInt1469 == 65535)
    									anInt1469 = -1;
    								    int i_15_ = -1;
    								    if (i == 118) {
    									i_15_ = stream.readUnsignedWord(1355769544);
    									if (i_15_ == 65535)
    									    i_15_ = -1;
    								    }
    								    int i_16_ = (stream.readUnsignedByte(-6677));
    								    anIntArray1431 = (new int[2 + i_16_]);
    								    for (int i_17_ = 0;((i_17_^ 0xffffffff)>= (i_16_^ 0xffffffff));i_17_++) {
    									anIntArray1431[i_17_] = stream.readUnsignedWord(1355769544);
    									if ((anIntArray1431[i_17_]^ 0xffffffff)== -65536)
    									    anIntArray1431[i_17_] = -1;
    								    }
    								    anIntArray1431[1 + i_16_] = i_15_;
    								} else if (i != 107) {
    								    if (i == -110)
    									aBoolean1424= false;
    								    else if (i== 111)
    									aBoolean1448= false;
    								    else if (i== 113) {
    									aShort1464= (short) stream.readUnsignedWord(1355769544);
    									aShort1436= (short) stream.readUnsignedWord(1355769544);
    								    } else if (i== 114) {
    									aByte1470= stream.method955(3390);
    									aByte1453= stream.method955(3390);
    								    } else if (i == 115) {
    									aShort1419 = (short) (4 * stream.readUnsignedByte(-6677));
    									aShort1423 = (short) (stream.readUnsignedByte(-6677) * 4);
    								    } else if ((i ^ 0xffffffff)== 119)
    									aByte1446= stream.method955(3390);
    								    else if ((i^ 0xffffffff)!= 120) {
    									if (i== 121) {
    									    anIntArrayArray1457 = new int[anIntArray1454.length][];
    									    int i_18_ = stream.readUnsignedByte(-6677);
    									    for (int i_19_ = 0; i_19_ < i_18_; i_19_++) {
    										int i_20_ = stream.readUnsignedByte(-6677);
    										int[] is = anIntArrayArray1457[i_20_] = new int[3];
    										is[0] = stream.method955(3390);
    										is[1] = stream.method955(3390);
    										is[2] = stream.method955(3390);
    									    }
    									} else if (i == 122)
    									    anInt1437 = stream.readUnsignedWord(1355769544);
    									else if (i == 249) {
    									    int i_21_ = stream.readUnsignedByte(-6677);
    									    if (aClass113_1413 == null) {
    										int i_22_ = Class90.method1517(i_21_, -21189);
    										aClass113_1413 = new Class113(i_22_);
    									    }
    									    for (int i_23_ = 0; i_21_ > i_23_; i_23_++) {
    										boolean bool_24_ = (stream.readUnsignedByte(-6677) ^ 0xffffffff) == -2;
    										int i_25_ = stream.method921((byte) 50);
    										Class68 class68;
    										if (bool_24_)
    										    class68 = new Class68_Sub5(stream.readString(127));
    										else
    										    class68 = new Class68_Sub10(stream.readDWord());
    										aClass113_1413.method1677((byte) -59, class68, (long) i_25_);
    									    }
    									}
    								    } else {
    									anInt1429 = stream.readUnsignedWord(1355769544);
    									anInt1430 = stream.readUnsignedWord(1355769544);
    									anInt1471 = stream.readUnsignedWord(1355769544);
    									anInt1463 = stream.readUnsignedByte(-6677);
    								    }
    								} else
    								    aBoolean1433 = false;
    							    } else
    								ModelContrast = (5 * (stream.method955(3390)));
    							} else
    							    ModelBrightness = (stream.method955(3390));
    						    } else
    							aBoolean1420 = true;
    						} else
    						    scaleNPCwidth = (stream.readUnsignedWord(1355769544));
    					    } else
    						aBoolean1438 = false;
    					} else {
    					    int i_26_ = stream.readUnsignedByte(-6677);
    					    anIntArray1435 = new int[i_26_];
    					    for (int i_27_ = 0;((i_26_ ^ 0xffffffff)< (i_27_ ^ 0xffffffff));i_27_++)
    						anIntArray1435[i_27_]= (stream.readUnsignedWord(1355769544));
    					}
    				    } else {
    					aRSStringArray1432[-30 + i] = stream.readString(127);
    					if (aRSStringArray1432[i - 30].method1600(false,Class13_Sub2.aRSString_2647))
    					    aRSStringArray1432[i - 30] = null;
    				    }
    				} else {//walking type animations
    				    anInt1440 = stream.readUnsignedWord(1355769544);
    				    anInt1410 = stream.readUnsignedWord(1355769544);
    				    anInt1447 = stream.readUnsignedWord(1355769544);
    				    anInt1415 = stream.readUnsignedWord(1355769544);
    				}
    			    } else
    				anInt1421 = stream.readUnsignedWord(1355769544);
    			} else
    			    anInt1467 = stream.readUnsignedWord(1355769544);
    		    } else
    			anInt1409 = stream.readUnsignedWord(1355769544);
    		} else
    		    anInt1451 = stream.readUnsignedByte(-6677);
    	    } else
    		aRSString_1466 = stream.readString(127);
    	} else {
    	    int i_28_ = stream.readUnsignedByte(-6677);
    	    anIntArray1454 = new int[i_28_];
    	    for (int i_29_ = 0; (i_29_ ^ 0xffffffff) > (i_28_ ^ 0xffffffff);i_29_++)
    		anIntArray1454[i_29_] = stream.readUnsignedWord(1355769544);
    	}
    	if (bool != false)
    	    method1447(29);
        }

  2. #2
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    double posted in new to java sub-forum.
    mod please remove this nonsense.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  3. #3
    harryblue is offline Member
    Join Date
    Mar 2009
    Posts
    4
    Rep Power
    0

    Default

    stfu wanabe mod i is TX!!!!

  4. #4
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    If this is *not* a homework assignment, please fire whoever wrote it and tell them never to touch a keyboard again.

    To clean it up, get rid of all the useless if(i !=...) statements. For example, if i==14, then it is not 1, it is not 2, etc. The whole first section of crap code condenses to:

    Java Code:
    if (i == 14)//walk animation
      anInt1440 = stream.readUnsignedWord(1355769544);
    
    if(i == 40){ 
      int k = stream.readUnsignedByte(-6677);
      ...
    }
    ...
    This could be further cleaned up by using a switch statement instead of a bunch of ifs:

    Java Code:
    switch(i) {
      case 1:
         int i_28_ = stream.readUnsignedByte(-6677);
         anIntArray1454 = new int[i_28_];
         for (int i_29_ = 0; (i_29_ ^ 0xffffffff) > (i_28_ ^ 0xffffffff);i_29_++)
         anIntArray1454[i_29_] = stream.readUnsignedWord(1355769544);
         break;
    
      case 2:
         aRSString_1466 = stream.readString(127);
         break;
    
    ...
    
      case 14:
          anInt1440 = stream.readUnsignedWord(1355769544);
          break;
    
      case 40:
           ...
         
       default:
    }
    Then, it would make sense to not execute all this code directly in the switch statement, but to call methods to do that to make the code readable. In the end though, this looks like a complete failure to understand OO coding. All these various stupid nested ifs should probably be various classes and let the virtual function table sort it all out.

  5. #5
    harryblue is offline Member
    Join Date
    Mar 2009
    Posts
    4
    Rep Power
    0

    Default

    yea im gonna start to clean it now, my "programming" partner wrote this. We are developing our own java game tho i have no idea why he did it like this

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by harryblue View Post
    stfu wanabe mod i is TX!!!!
    One more for the do-not-help-list.

Similar Threads

  1. Replies: 2
    Last Post: 03-26-2010, 05:12 PM
  2. [REQ] can sombody clean up this code?
    By harryblue in forum New To Java
    Replies: 1
    Last Post: 03-18-2009, 08:40 PM
  3. clean and Build
    By bhanu in forum Eclipse
    Replies: 3
    Last Post: 07-03-2008, 01:13 PM
  4. cannot call private method from static method
    By jon80 in forum New To Java
    Replies: 3
    Last Post: 05-07-2008, 08:37 AM
  5. Clean the content of the JTextField
    By elizabeth in forum AWT / Swing
    Replies: 1
    Last Post: 07-26-2007, 08:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •