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) { | 	private Material(String name, double density, MaterialGroup group, boolean userDefined, boolean documentMaterial) { | ||||||
| 		this.name = name; | 		this.name = name; | ||||||
| 		this.density = density; | 		this.density = density; | ||||||
| 		this.group = group; |  | ||||||
| 		this.userDefined = userDefined; | 		this.userDefined = userDefined; | ||||||
| 		this.documentMaterial = documentMaterial; | 		this.documentMaterial = documentMaterial; | ||||||
|  | 		this.group = getEquivalentGroup(group, userDefined); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	private Material(String name, double density, MaterialGroup group, boolean 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, | 	 * 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. | 	 * 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 | 	 * @return the equivalent group | ||||||
| 	 */ | 	 */ | ||||||
| 	public MaterialGroup getEquivalentGroup() { | 	private static MaterialGroup getEquivalentGroup(MaterialGroup group, boolean userDefined) { | ||||||
| 		if (group != null) { | 		if (group != null) { | ||||||
| 			return group; | 			return group; | ||||||
| 		} | 		} | ||||||
| @ -298,7 +302,7 @@ public abstract class Material implements Comparable<Material> { | |||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public String toStorableString() { | 	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) { | 		AnnotatedMaterialDTO(Material theMaterial) { | ||||||
| 			type = theMaterial.getType().name(); | 			type = theMaterial.getType().name(); | ||||||
| 			material = theMaterial.getName(); | 			material = theMaterial.getName(); | ||||||
| 			materialGroup = theMaterial.getEquivalentGroup().getDatabaseString(); | 			materialGroup = theMaterial.getGroup().getDatabaseString(); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		public Material.Type getORMaterialType() { | 		public Material.Type getORMaterialType() { | ||||||
|  | |||||||
| @ -40,7 +40,7 @@ public class MaterialDTO { | |||||||
| 	public MaterialDTO(final Material theMaterial) { | 	public MaterialDTO(final Material theMaterial) { | ||||||
| 		this(theMaterial.getName(), theMaterial.getDensity(), MaterialTypeDTO.asDTO(theMaterial.getType()), | 		this(theMaterial.getName(), theMaterial.getDensity(), MaterialTypeDTO.asDTO(theMaterial.getType()), | ||||||
| 				theMaterial.getType().getUnitGroup().getDefaultUnit().toString(), | 				theMaterial.getType().getUnitGroup().getDefaultUnit().toString(), | ||||||
| 				MaterialGroupDTO.asDTO(theMaterial.getEquivalentGroup())); | 				MaterialGroupDTO.asDTO(theMaterial.getGroup())); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public MaterialDTO(final String theName, final double theDensity, final MaterialTypeDTO theType, | 	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) { |             for (MaterialGroup group : sortedGroups) { | ||||||
|                 List<Material> itemsForGroup = new ArrayList<>(); |                 List<Material> itemsForGroup = new ArrayList<>(); | ||||||
|                 for (Material material : materials) { |                 for (Material material : materials) { | ||||||
|                     materialGroup = material.getEquivalentGroup(); |                     materialGroup = material.getGroup(); | ||||||
|                     if (materialGroup.equals(group)) { |                     if (materialGroup.equals(group)) { | ||||||
|                         itemsForGroup.add(material); |                         itemsForGroup.add(material); | ||||||
|                     } |                     } | ||||||
|  | |||||||
| @ -124,7 +124,7 @@ public class CustomMaterialDialog extends JDialog { | |||||||
| 		panel.add(new JLabel(trans.get("custmatdlg.lbl.MaterialGroup"))); | 		panel.add(new JLabel(trans.get("custmatdlg.lbl.MaterialGroup"))); | ||||||
| 		groupBox = new JComboBox<>(MaterialGroup.ALL_GROUPS); | 		groupBox = new JComboBox<>(MaterialGroup.ALL_GROUPS); | ||||||
| 		if (material != null && !material.isUserDefined()) { | 		if (material != null && !material.isUserDefined()) { | ||||||
| 			groupBox.setSelectedItem(material.getEquivalentGroup()); | 			groupBox.setSelectedItem(material.getGroup()); | ||||||
| 		} else { | 		} else { | ||||||
| 			groupBox.setSelectedItem(MaterialGroup.CUSTOM); | 			groupBox.setSelectedItem(MaterialGroup.CUSTOM); | ||||||
| 		} | 		} | ||||||
|  | |||||||
| @ -105,7 +105,7 @@ public class MaterialEditPanel extends JPanel { | |||||||
| 				new Column(trans.get("matedtpan.col.Group")) { | 				new Column(trans.get("matedtpan.col.Group")) { | ||||||
| 					@Override | 					@Override | ||||||
| 					public Object getValueAt(int row) { | 					public Object getValueAt(int row) { | ||||||
| 						return getMaterial(row).getEquivalentGroup().getName(); | 						return getMaterial(row).getGroup().getName(); | ||||||
| 					} | 					} | ||||||
| 
 | 
 | ||||||
| 					@Override | 					@Override | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user