public List<Unit> getUnitsByType(URI type) { return availableUnits .stream() .filter(u -> u.getType().equals(type)) .collect(Collectors.toList()); } }
public List<Unit> getUnitsByType(URI type) { return availableUnits .stream() .filter(u -> u.getType().equals(type)) .collect(Collectors.toList()); } }
if (!unit.getType().equals(newUnit.getType())) { LOG.error("The new unit does not have the same parent type " + "(source: " + unit.getType() + "; target: " + newUnit.getType() + ")"); throw new IllegalAccessException( "The new unit does not have the same parent type " + "(source: " + unit.getType() + "; target: " + newUnit.getType() + ")" );
if (!unit.getType().equals(newUnit.getType())) { LOG.error("The new unit does not have the same parent type " + "(source: " + unit.getType() + "; target: " + newUnit.getType() + ")"); throw new IllegalAccessException( "The new unit does not have the same parent type " + "(source: " + unit.getType() + "; target: " + newUnit.getType() + ")" );
public String getFittingUnits(UnitDescription unitDescription) throws AdapterException { List<UnitDescription> unitDescriptionList = new LinkedList<>(); Unit unit; if(unitDescription.getResource() == null) throw new AdapterException("The resource cannot be null"); try { unit = UnitProvider.INSTANCE.getUnit(unitDescription.getResource()); } catch (IllegalStateException e) { throw new AdapterException("Invalid URI: " + unitDescription.getResource()); } List<Unit> units = UnitProvider.INSTANCE.getUnitsByType(unit.getType()); for ( Iterator iter = units.iterator(); iter.hasNext(); ) { Unit unitTmp = (Unit) iter.next(); try { UnitDescription unitDescriptionTmp = new UnitDescription(unitTmp.getResource().toString(), unitTmp.getLabel()); unitDescriptionList.add(unitDescriptionTmp); } catch (NullPointerException e) { logger.error("Unit has no resource and/or Label"); } } return gson.toJson(unitDescriptionList); }