Set material group non-null in the constructor
This commit is contained in:
		
							parent
							
								
									4e45a194e2
								
							
						
					
					
						commit
						f2fbcc69d3
					
				| @ -152,9 +152,9 @@ public abstract class Material implements Comparable<Material> { | ||||
| 	private Material(String name, double density, MaterialGroup group, boolean userDefined, boolean documentMaterial) { | ||||
| 		this.name = name; | ||||
| 		this.density = density; | ||||
| 		this.group = group; | ||||
| 		this.userDefined = userDefined; | ||||
| 		this.documentMaterial = documentMaterial; | ||||
| 		this.group = getEquivalentGroup(group, userDefined); | ||||
| 	} | ||||
| 
 | ||||
| 	private Material(String name, double density, MaterialGroup group, boolean userDefined) { | ||||
| @ -198,9 +198,13 @@ public abstract class Material implements Comparable<Material> { | ||||
| 	/** | ||||
| 	 * Some materials have a null group. This method returns the equivalent group, i.e. CUSTOM for user-defined materials, | ||||
| 	 * and OTHER for materials with a null group. | ||||
| 	 * | ||||
| 	 * @param group: the group of the material | ||||
| 	 * @param userDefined: whether the material is user-defined or not | ||||
| 	 * | ||||
| 	 * @return the equivalent group | ||||
| 	 */ | ||||
| 	public MaterialGroup getEquivalentGroup() { | ||||
| 	private static MaterialGroup getEquivalentGroup(MaterialGroup group, boolean userDefined) { | ||||
| 		if (group != null) { | ||||
| 			return group; | ||||
| 		} | ||||
| @ -298,7 +302,7 @@ public abstract class Material implements Comparable<Material> { | ||||
| 	} | ||||
| 	 | ||||
| 	public String toStorableString() { | ||||
| 		return getType().name() + "|" + name.replace('|', ' ') + '|' + density + '|' + getEquivalentGroup().getDatabaseString(); | ||||
| 		return getType().name() + "|" + name.replace('|', ' ') + '|' + density + '|' + group.getDatabaseString(); | ||||
| 	} | ||||
| 	 | ||||
| 	 | ||||
|  | ||||
| @ -218,7 +218,7 @@ public abstract class BaseComponentDTO { | ||||
| 		AnnotatedMaterialDTO(Material theMaterial) { | ||||
| 			type = theMaterial.getType().name(); | ||||
| 			material = theMaterial.getName(); | ||||
| 			materialGroup = theMaterial.getEquivalentGroup().getDatabaseString(); | ||||
| 			materialGroup = theMaterial.getGroup().getDatabaseString(); | ||||
| 		} | ||||
| 
 | ||||
| 		public Material.Type getORMaterialType() { | ||||
|  | ||||
| @ -40,7 +40,7 @@ public class MaterialDTO { | ||||
| 	public MaterialDTO(final Material theMaterial) { | ||||
| 		this(theMaterial.getName(), theMaterial.getDensity(), MaterialTypeDTO.asDTO(theMaterial.getType()), | ||||
| 				theMaterial.getType().getUnitGroup().getDefaultUnit().toString(), | ||||
| 				MaterialGroupDTO.asDTO(theMaterial.getEquivalentGroup())); | ||||
| 				MaterialGroupDTO.asDTO(theMaterial.getGroup())); | ||||
| 	} | ||||
| 
 | ||||
| 	public MaterialDTO(final String theName, final double theDensity, final MaterialTypeDTO theType, | ||||
|  | ||||
| @ -210,7 +210,7 @@ public class MaterialPanel extends JPanel implements Invalidatable, Invalidating | ||||
|             for (MaterialGroup group : sortedGroups) { | ||||
|                 List<Material> itemsForGroup = new ArrayList<>(); | ||||
|                 for (Material material : materials) { | ||||
|                     materialGroup = material.getEquivalentGroup(); | ||||
|                     materialGroup = material.getGroup(); | ||||
|                     if (materialGroup.equals(group)) { | ||||
|                         itemsForGroup.add(material); | ||||
|                     } | ||||
|  | ||||
| @ -124,7 +124,7 @@ public class CustomMaterialDialog extends JDialog { | ||||
| 		panel.add(new JLabel(trans.get("custmatdlg.lbl.MaterialGroup"))); | ||||
| 		groupBox = new JComboBox<>(MaterialGroup.ALL_GROUPS); | ||||
| 		if (material != null && !material.isUserDefined()) { | ||||
| 			groupBox.setSelectedItem(material.getEquivalentGroup()); | ||||
| 			groupBox.setSelectedItem(material.getGroup()); | ||||
| 		} else { | ||||
| 			groupBox.setSelectedItem(MaterialGroup.CUSTOM); | ||||
| 		} | ||||
|  | ||||
| @ -105,7 +105,7 @@ public class MaterialEditPanel extends JPanel { | ||||
| 				new Column(trans.get("matedtpan.col.Group")) { | ||||
| 					@Override | ||||
| 					public Object getValueAt(int row) { | ||||
| 						return getMaterial(row).getEquivalentGroup().getName(); | ||||
| 						return getMaterial(row).getGroup().getName(); | ||||
| 					} | ||||
| 
 | ||||
| 					@Override | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user