public String toString() { return (this.getAbbreviation() == null ? "" : this.getAbbreviation()); }
public boolean equals(Object obj) { if (!(obj instanceof Unit)) return false; return (obj.hashCode() == this.hashCode()); }
if (unit.getResource().equals(newUnit.getResource())) return this; // nothing to be done 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() + ")" ); Quantity newMeasurement = new Quantity(); newMeasurement.setUnit(newUnit); newMeasurement.setValue( ((value * unit.getMultiplier().getMultiplier() + unit.getMultiplier().getOffset()) - newUnit.getMultiplier().getOffset()) / newUnit.getMultiplier().getMultiplier() );
org.eclipse.rdf4j.model.URI uri = f.createURI(resource.toString()); Unit unit = new Unit(); unit.setResource(resource); Multiplier multiplier = new Multiplier(); unit.setSymbol(statement.getObject().stringValue()); } else if (statement.getPredicate().equals(QUDT.ABBREVIATION)) { unit.setAbbreviation(statement.getObject().stringValue()); } else if (statement.getPredicate().equals(QUDT.CONVERSION_OFFSET)) { multiplier.setOffset(Double.parseDouble(statement.getObject().stringValue())); } else if (statement.getPredicate().equals(QUDT.CONVERSION_MULTIPLIER)) { multiplier.setMultiplier(Double.parseDouble(statement.getObject().stringValue())); } else if (statement.getPredicate().equals(RDFS.LABEL)) { unit.setLabel(statement.getObject().stringValue()); } else if (statement.getPredicate().equals(RDF.TYPE)) { Object type = statement.getObject(); if (type instanceof org.eclipse.rdf4j.model.URI) { org.eclipse.rdf4j.model.URI typeURI = (org.eclipse.rdf4j.model.URI)type; if (!shouldBeIgnored(typeURI)) { unit.setType(new URI(typeURI.stringValue())); unit.setMultiplier(multiplier); } catch (Exception exception) { throw new IllegalStateException("Could not create the unit: " + exception.getMessage(), exception);
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); }
public List<Unit> getUnitsByType(URI type) { return availableUnits .stream() .filter(u -> u.getType().equals(type)) .collect(Collectors.toList()); } }
public Unit getUnitByLabel(String label) { try { return availableUnits.stream() .filter((Unit unit) -> unit.getLabel().equals(label)) .findFirst() .get(); } catch (NoSuchElementException e) { LOG.error("No unit with label \"" + label + "\" found"); return null; } }
if (unit.getResource().equals(newUnit.getResource())) return this; // nothing to be done 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() + ")" ); Quantity newMeasurement = new Quantity(); newMeasurement.setUnit(newUnit); newMeasurement.setValue( ((value * unit.getMultiplier().getMultiplier() + unit.getMultiplier().getOffset()) - newUnit.getMultiplier().getOffset()) / newUnit.getMultiplier().getMultiplier() );
org.eclipse.rdf4j.model.URI uri = f.createURI(resource.toString()); Unit unit = new Unit(); unit.setResource(resource); Multiplier multiplier = new Multiplier(); unit.setSymbol(statement.getObject().stringValue()); } else if (statement.getPredicate().equals(QUDT.ABBREVIATION)) { unit.setAbbreviation(statement.getObject().stringValue()); } else if (statement.getPredicate().equals(QUDT.CONVERSION_OFFSET)) { multiplier.setOffset(Double.parseDouble(statement.getObject().stringValue())); } else if (statement.getPredicate().equals(QUDT.CONVERSION_MULTIPLIER)) { multiplier.setMultiplier(Double.parseDouble(statement.getObject().stringValue())); } else if (statement.getPredicate().equals(RDFS.LABEL)) { unit.setLabel(statement.getObject().stringValue()); } else if (statement.getPredicate().equals(RDF.TYPE)) { Object type = statement.getObject(); if (type instanceof org.eclipse.rdf4j.model.URI) { org.eclipse.rdf4j.model.URI typeURI = (org.eclipse.rdf4j.model.URI)type; if (!shouldBeIgnored(typeURI)) { unit.setType(new URI(typeURI.stringValue())); unit.setMultiplier(multiplier); } catch (Exception exception) { throw new IllegalStateException("Could not create the unit: " + exception.getMessage(), exception);
public List<Unit> getUnitsByType(URI type) { return availableUnits .stream() .filter(u -> u.getType().equals(type)) .collect(Collectors.toList()); } }
public Unit getUnitByLabel(String label) { try { return availableUnits.stream() .filter((Unit unit) -> unit.getLabel().equals(label)) .findFirst() .get(); } catch (NoSuchElementException e) { LOG.error("No unit with label \"" + label + "\" found"); return null; } }
public String toString() { return (this.getAbbreviation() == null ? "" : this.getAbbreviation()); }
public boolean equals(Object obj) { if (!(obj instanceof Unit)) return false; return (obj.hashCode() == this.hashCode()); }