Thread: Writing better Java

Page 13 of 13 FirstFirst ... 3111213
Results 121 to 129 of 129
  1. #121  


    Major's Avatar
    Join Date
    Jan 2011
    Posts
    2,997
    Thanks given
    1,293
    Thanks received
    3,556
    Rep Power
    5000
    Quote Originally Posted by Discardedx2 View Post
    I know some of the comments in the OP are opinionated but this link is literally just the opinion of whoever wrote it... please keep this thread free of stuff like that

    ---

    I've added a new post, about unit testing.
    Reply With Quote  
     

  2. #122  
    (Official) Thanksgiver

    Arham's Avatar
    Join Date
    Jan 2013
    Age
    23
    Posts
    3,415
    Thanks given
    7,254
    Thanks received
    1,938
    Rep Power
    3905
    Quote Originally Posted by Major View Post
    I've added a new post, about unit testing.
    Poor Eve...
    Attached image
    Attached image
    Quote Originally Posted by MrClassic View Post
    Arham is the official thanker!
    List of my work here!
    Reply With Quote  
     

  3. Thankful user:


  4. #123  
    Banned
    Join Date
    Jul 2012
    Age
    27
    Posts
    996
    Thanks given
    646
    Thanks received
    266
    Rep Power
    0
    Quote Originally Posted by Major View Post
    I know some of the comments in the OP are opinionated but this link is literally just the opinion of whoever wrote it... please keep this thread free of stuff like that

    ---

    I've added a new post, about unit testing.
    Thank you
    Quote Originally Posted by arham 4 View Post
    Poor Eve...
    ikr lol
    Reply With Quote  
     

  5. #124  
    :doge:

    Join Date
    Jan 2009
    Posts
    3,758
    Thanks given
    221
    Thanks received
    817
    Rep Power
    2116
    Quote Originally Posted by Major View Post
    I know some of the comments in the OP are opinionated but this link is literally just the opinion of whoever wrote it... please keep this thread free of stuff like that

    ---

    I've added a new post, about unit testing.
    I'll keep things like that off this thread, but the reason I linked it is due to the fact that it is the standard that all developers at google follow when writing their code. There is a lot of useful information in there that can be used to write better code, I was simply posting it as an addition to what you may already have posted on this thread.
    Reply With Quote  
     

  6. #125  
    Registered Member
    Tyluur's Avatar
    Join Date
    Jun 2010
    Age
    26
    Posts
    5,103
    Thanks given
    1,819
    Thanks received
    1,767
    Rep Power
    2438
    still relevant tyvm
    Quote Originally Posted by blakeman8192 View Post
    Keep trying. Quitting is the only true failure.
    Spoiler for skrrrrr:

    Attached image
    Reply With Quote  
     

  7. #126  
    Registered Member
    Join Date
    May 2016
    Posts
    1
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    Quote Originally Posted by Major View Post
    ItemDefinitionBuilder

    Code:
    package tld.removed.old.fs.archive.config.build;
    
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    
    import tld.removed.old.fs.archive.build.ConfigBuilder;
    import tld.removed.old.fs.archive.config.ItemDefinition;
    
    /**
     * A {@link ConfigBuilder} for {@link ItemDefinition}s.
     * 
     * @author Major
     */
    public final class ItemDefinitionBuilder extends ConfigBuilder<ItemDefinition> {
    
    	/**
    	 * The default equipment model ids.
    	 */
    	protected static final List<Integer> DEFAULT_EQUIP_IDS = Arrays.asList(-1, -1, -1);
    
    	/**
    	 * The default ground scale values.
    	 */
    	protected static final List<Integer> DEFAULT_GROUND_SCALES = Arrays.asList(128, 128, 128);
    
    	/**
    	 * The default head piece ids.
    	 */
    	protected static final List<Integer> DEFAULT_HEAD_PIECES = Arrays.asList(-1, -1);
    
    	/**
    	 * The description of this item.
    	 */
    	protected String description = "null";
    
    	/**
    	 * The female primary, secondary, and tertiary equipment ids of this item.
    	 */
    	protected List<Integer> femaleEquipIds = new ArrayList<>(DEFAULT_EQUIP_IDS);
    
    	/**
    	 * The y-translation for the female equipment piece of this item.
    	 */
    	protected int femaleEquipTranslation = 0;
    
    	/**
    	 * The female head piece ids.
    	 */
    	protected List<Integer> femaleHeadPieces = new ArrayList<>(DEFAULT_HEAD_PIECES);
    
    	/**
    	 * The ground menu actions of this item.
    	 */
    	protected List<String> groundMenuActions = new ArrayList<>(5);
    
    	/**
    	 * The x, y, and z ground scale values of this item.
    	 */
    	protected List<Integer> groundScales = new ArrayList<>(DEFAULT_GROUND_SCALES);
    
    	/**
    	 * The inventory menu actions of this item.
    	 */
    	protected List<String> inventoryMenuActions = new ArrayList<>(5);
    
    	/**
    	 * The light ambience of this item.
    	 */
    	protected int lightAmbience = 0;
    
    	/**
    	 * The light diffusion of this item.
    	 */
    	protected int lightDiffusion = 0;
    
    	/**
    	 * The male primary, secondary, and tertiary equipment ids of this item.
    	 */
    	protected List<Integer> maleEquipIds = new ArrayList<>(DEFAULT_EQUIP_IDS);
    
    	/**
    	 * The y-translation for the male equipment piece of this item.
    	 */
    	protected int maleEquipTranslation = 0;
    
    	/**
    	 * The male head piece ids.
    	 */
    	protected List<Integer> maleHeadPieces = new ArrayList<>(DEFAULT_HEAD_PIECES);
    
    	/**
    	 * The members flag of this item.
    	 */
    	protected boolean members = false;
    
    	/**
    	 * The id of this item's model.
    	 */
    	protected int modelId = 0;
    
    	/**
    	 * The name of this item.
    	 */
    	protected String name = "null";
    
    	/**
    	 * The note info id of this item.
    	 */
    	protected int noteInfoId = -1;
    
    	/**
    	 * The note template id of this item.
    	 */
    	protected int noteTemplateId = -1;
    
    	/**
    	 * The map of original model colours to replacement colours for this item.
    	 */
    	protected Map<Integer, Integer> replacementColours = new HashMap<>(3);
    
    	/**
    	 * The camera roll of this item's sprite.
    	 */
    	protected int spriteCameraRoll = 0;
    
    	/**
    	 * The sprite camera yaw of this item.
    	 */
    	protected int spriteCameraYaw = 0;
    
    	/**
    	 * The pitch of this item's sprite.
    	 */
    	protected int spritePitch = 0;
    
    	/**
    	 * The scale of this item's sprite.
    	 */
    	protected int spriteScale = 2000;
    
    	/**
    	 * The x-translation of this item's sprite.
    	 */
    	protected int spriteTranslateX = 0;
    
    	/**
    	 * The y-translation of this item's sprite.
    	 */
    	protected int spriteTranslateY = 0;
    
    	/**
    	 * The stackable flag of this item.
    	 */
    	protected boolean stackable = false;
    
    	/**
    	 * The stack amounts of this item.
    	 */
    	protected List<Integer> stackAmounts = new ArrayList<>();
    
    	/**
    	 * The stack model ids of this item.
    	 */
    	protected List<Integer> stackModelIds = new ArrayList<>();
    
    	/**
    	 * The team id of this item.
    	 */
    	protected int team = 0;
    
    	/**
    	 * The value of this item.
    	 */
    	protected int value = 1;
    
    	/**
    	 * Creates the item definition builder.
    	 * 
    	 * @param id The id of the item.
    	 */
    	protected ItemDefinitionBuilder(int id) {
    		super(id);
    	}
    
    	/**
    	 * Builds and returns {@link ItemDefinition}.
    	 * 
    	 * @return The item definition.
    	 */
    	@Override
    	public ItemDefinition build() {
    		return new ItemDefinition(description, femaleEquipIds, femaleEquipTranslation, femaleHeadPieces,
    				groundMenuActions, groundScales, id, inventoryMenuActions, lightAmbience, lightDiffusion, maleEquipIds,
    				maleEquipTranslation, maleHeadPieces, members, modelId, name, noteInfoId, noteTemplateId,
    				replacementColours, spriteCameraRoll, spriteCameraYaw, spritePitch, spriteScale, spriteTranslateX,
    				spriteTranslateY, stackable, stackAmounts, stackModelIds, team, value);
    	}
    
    	/**
    	 * Sets the description of this item.
    	 *
    	 * @param description The description.
    	 */
    	public final void setDescription(String description) {
    		this.description = description;
    	}
    
    	/**
    	 * Sets a female equip id of this item.
    	 *
    	 * @param index The index.
    	 * @param femaleEquipId The female equip id.
    	 */
    	public final void setFemaleEquipId(int index, int femaleEquipId) {
    		femaleEquipIds.add(femaleEquipId);
    	}
    
    	/**
    	 * Sets the female equip translation of this item.
    	 *
    	 * @param femaleEquipTranslation The female equip translation.
    	 */
    	public final void setFemaleEquipTranslation(int femaleEquipTranslation) {
    		this.femaleEquipTranslation = femaleEquipTranslation;
    	}
    
    	/**
    	 * Sets a ground scale value. TODO use an enum for direction.
    	 * 
    	 * @param direction The direction.
    	 * @param scale The scale.
    	 */
    	public final void setGroundScale(int direction, int scale) {
    		groundScales.add(scale);
    	}
    
    	/**
    	 * Sets a female head piece of the item.
    	 *
    	 * @param index The index
    	 * @param femaleHeadPiece The female head piece.
    	 */
    	public final void setFemaleHeadPiece(int index, int femaleHeadPiece) {
    		femaleHeadPieces.add(femaleHeadPiece);
    	}
    
    	/**
    	 * Sets the ground menu action at the specified index.
    	 * 
    	 * @param index The index.
    	 * @param action The action string.
    	 */
    	public final void setGroundAction(int index, String action) {
    		groundMenuActions.add(action);
    	}
    
    	/**
    	 * Sets the inventory menu action at the specified index.
    	 * 
    	 * @param index The action index.
    	 * @param action The action string.
    	 */
    	public final void setInventoryAction(int index, String action) {
    		inventoryMenuActions.add(action);
    	}
    
    	/**
    	 * Sets the light ambience of this item.
    	 *
    	 * @param lightAmbience The light ambience.
    	 */
    	public final void setLightAmbience(int lightAmbience) {
    		this.lightAmbience = lightAmbience;
    	}
    
    	/**
    	 * Sets the light diffusion of this item.
    	 *
    	 * @param lightDiffusion The light diffusion.
    	 */
    	public final void setLightDiffusion(int lightDiffusion) {
    		this.lightDiffusion = lightDiffusion;
    	}
    
    	/**
    	 * Sets a male equip id of this item.
    	 *
    	 * @param index The index.
    	 * @param maleEquipId The male equip id.
    	 */
    	public final void setMaleEquipId(int index, int maleEquipId) {
    		maleEquipIds.add(maleEquipId);
    	}
    
    	/**
    	 * Sets the male equip translation of this item.
    	 *
    	 * @param maleEquipTranslation The male equip translation.
    	 */
    	public final void setMaleEquipTranslation(int maleEquipTranslation) {
    		this.maleEquipTranslation = maleEquipTranslation;
    	}
    
    	/**
    	 * Sets a male head piece of the item.
    	 *
    	 * @param maleHeadPiece The male head piece.
    	 */
    	public final void setMaleHeadPiece(int index, int maleHeadPiece) {
    		maleHeadPieces.add(maleHeadPiece);
    	}
    
    	/**
    	 * Sets the members flag of this item.
    	 *
    	 * @param members The members flag.
    	 */
    	public final void setMembers(boolean members) {
    		this.members = members;
    	}
    
    	/**
    	 * Sets the model id of this item.
    	 * 
    	 * @param modelId The model id.
    	 */
    	public final void setModelId(int modelId) {
    		this.modelId = modelId;
    	}
    
    	/**
    	 * Sets the name of this item.
    	 *
    	 * @param name The name.
    	 */
    	public final void setName(String name) {
    		this.name = name;
    	}
    
    	/**
    	 * Sets the note info id of this item.
    	 *
    	 * @param noteInfoId The note info id.
    	 */
    	public final void setNoteInfoId(int noteInfoId) {
    		this.noteInfoId = noteInfoId;
    	}
    
    	/**
    	 * Sets the note template id of this item.
    	 *
    	 * @param noteTemplateId The note template id.
    	 */
    	public final void setNoteTemplateId(int noteTemplateId) {
    		this.noteTemplateId = noteTemplateId;
    	}
    
    	/**
    	 * Sets the replacement model colours of this item.
    	 *
    	 * @param replacementColours The replacement model colours.
    	 */
    	public final void setReplacementColours(Map<Integer, Integer> replacementColours) {
    		this.replacementColours = replacementColours;
    	}
    
    	/**
    	 * Sets the sprite camera roll of this item.
    	 *
    	 * @param spriteCameraRoll The sprite camera roll.
    	 */
    	public final void setSpriteCameraRoll(int spriteCameraRoll) {
    		this.spriteCameraRoll = spriteCameraRoll;
    	}
    
    	/**
    	 * Sets the sprite camera yaw of this item.
    	 *
    	 * @param spriteCameraYaw The sprite camera yaw.
    	 */
    	public final void setSpriteCameraYaw(int spriteCameraYaw) {
    		this.spriteCameraYaw = spriteCameraYaw;
    	}
    
    	/**
    	 * Sets the sprite pitch of this item.
    	 *
    	 * @param spritePitch The sprite pitch.
    	 */
    	public final void setSpritePitch(int spritePitch) {
    		this.spritePitch = spritePitch;
    	}
    
    	/**
    	 * Sets the sprite scale of this item.
    	 *
    	 * @param spriteScale The sprite scale.
    	 */
    	public final void setSpriteScale(int spriteScale) {
    		this.spriteScale = spriteScale;
    	}
    
    	/**
    	 * Sets the sprite x translation of this item.
    	 *
    	 * @param spriteTranslateX The sprite x translation.
    	 */
    	public final void setSpriteTranslateX(int spriteTranslateX) {
    		this.spriteTranslateX = spriteTranslateX;
    	}
    
    	/**
    	 * Sets the sprite y translation of this item.
    	 *
    	 * @param spriteTranslateY The sprite y translation.
    	 */
    	public final void setSpriteTranslateY(int spriteTranslateY) {
    		this.spriteTranslateY = spriteTranslateY;
    	}
    
    	/**
    	 * Sets the stackable flag of this item.
    	 *
    	 * @param stackable The stackable flag.
    	 */
    	public final void setStackable(boolean stackable) {
    		this.stackable = stackable;
    	}
    
    	/**
    	 * Sets a stack amount of this item.
    	 *
    	 * @param index The index.
    	 * @param stackAmount The stack amount.
    	 */
    	public final void setStackAmount(int index, int stackAmount) {
    		stackAmounts.add(stackAmount);
    	}
    
    	/**
    	 * Sets a stack model id of this item.
    	 *
    	 * @param index The index.
    	 * @param stackModelId The stack model id.
    	 */
    	public final void setStackModelIds(int index, int stackModelId) {
    		stackModelIds.add(stackModelId);
    	}
    
    	/**
    	 * Sets the team of this item.
    	 *
    	 * @param team The team.
    	 */
    	public final void setTeam(int team) {
    		this.team = team;
    	}
    
    	/**
    	 * Sets the value of this item.
    	 *
    	 * @param value The value.
    	 */
    	public final void setValue(int value) {
    		this.value = value;
    	}
    
    }
    Can you elaborate why you made all these fields protected since the class is final any will not be overridden anyways?
    Reply With Quote  
     

  8. #127  
    Software Developer

    Tyrant's Avatar
    Join Date
    Jul 2013
    Age
    24
    Posts
    1,562
    Thanks given
    678
    Thanks received
    423
    Rep Power
    1060
    Quote Originally Posted by HomieG View Post
    Can you elaborate why you made all these fields protected since the class is final any will not be overridden anyways?
    Protected means only classes withing package ratio may access those variables, or alternatively subclasses in a different package.
    Reply With Quote  
     

  9. Thankful user:


  10. #128  


    Major's Avatar
    Join Date
    Jan 2011
    Posts
    2,997
    Thanks given
    1,293
    Thanks received
    3,556
    Rep Power
    5000
    Quote Originally Posted by HomieG View Post
    Can you elaborate why you made all these fields protected since the class is final any will not be overridden anyways?
    Cos I'm an idiot and forgot to change it. That code is adapted from a class where it actually makes sense for them to be protected; however, here they should be private. Thanks for pointing that out.
    Reply With Quote  
     

  11. #129  
    Donator
    conmenderls's Avatar
    Join Date
    Sep 2014
    Posts
    129
    Thanks given
    15
    Thanks received
    18
    Rep Power
    11
    This is a pretty amazing post, has lots of information. Great for creating nice, and clean code. Good job.
    Reply With Quote  
     

Page 13 of 13 FirstFirst ... 3111213

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Replies: 29
    Last Post: 09-29-2009, 06:25 PM
  2. Replies: 20
    Last Post: 07-31-2009, 11:19 AM
  3. Making a Java File Write Content on Websites
    By Nima304 in forum Application Development
    Replies: 2
    Last Post: 03-09-2009, 05:13 PM
  4. Replies: 4
    Last Post: 01-16-2009, 03:42 AM
  5. [503-PD] Better Theiving.java
    By Ian... in forum Configuration
    Replies: 4
    Last Post: 08-16-2008, 06:04 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •