javax.measure.spi
Code IndexAdd Codota to your IDE (free)

Best code snippets using javax.measure.spi(Showing top 15 results out of 315)

origin: unitsofmeasurement/unit-api

 @Override
 public int compare(ServiceProvider p1, ServiceProvider p2) {
  return p2.getPriority() - p1.getPriority();
 }
});
origin: org.opengis/geoapi-conformance

/**
 * Returns the default units factory. This factory uses the unit service provider which is
 * {@linkplain ServiceProvider#current() current} at the time of the first invocation of this method.
 *
 * @return the default units factory.
 */
public static synchronized Units getDefault() {
  if (DEFAULT == null) {
    DEFAULT = new Units(ServiceProvider.current().getSystemOfUnitsService().getSystemOfUnits());
  }
  return DEFAULT;
}
origin: unitsofmeasurement/unit-api

/**
 * Returns the list of available service providers.
 *
 * @return all available service providers.
 */
public static List<ServiceProvider> available() {
 return Arrays.asList(getProviders());
}
origin: unitsofmeasurement/unit-api

@Test(expected = NullPointerException.class)
public void testSetDefault_Null() {
 ServiceProvider.setCurrent(null);
}
origin: unitsofmeasurement/unit-api

/**
 * Tests {@link ServiceProvider#current()} and {@link ServiceProvider#setCurrent(ServiceProvider)}. The getter and setter are tested in a single
 * method for avoiding issues with the order in which JUnit executes tests.
 */
@Test
public void testGetAndSetDefault() {
 assertEquals(0, ServiceProvider.available().size());
 try {
  ServiceProvider.current();
  fail("Expected no ServiceProvider before we set one.");
 } catch (IllegalStateException e) {
  // This is the expected exception.
 }
 TestServiceProvider testProv = new TestServiceProvider();
 assertNull("Expected no ServiceProvider before we set one.", ServiceProvider.setCurrent(testProv));
 assertSame("Setting the same ServiceProvider twice should be a no-op.", testProv, ServiceProvider.setCurrent(testProv));
 assertSame(testProv, ServiceProvider.current());
 assertArrayEquals(new ServiceProvider[] { testProv }, ServiceProvider.available().toArray());
}
origin: tec.uom.lib/uom-lib-common

  private static void printSoU(final SystemOfUnits sou, final boolean showIndex) {
  int index = 0;
  System.out.println("Reporting " + sou.getName());
  for (Unit<?> u : sou.getUnits()) {
    index++;
    if (showIndex) {
    System.out.println(index + "; " + u.getName() + "; " + u.getSymbol() + "; " + u);
    } else {
    System.out.println(u.getName() + "; " + u.getSymbol() + "; " + u);
    }
  }
  }
}
origin: org.opengis/geoapi-conformance

/**
 * Creates a new factory which will use the given system of units.
 *
 * @param  system  the system of units to use for creating base units.
 */
protected Units(final SystemOfUnits system) {
  metre     = system.getUnit(Length.class);
  radian    = system.getUnit(Angle.class);
  second    = system.getUnit(Time.class);
  one       = getDimensionless(system);
  kilometre = metre .multiply(1000);
  degree    = radian.multiply(Math.PI/180);
  day       = second.multiply(24*60*60);
  ppm       = one   .divide(1000000);
}
origin: tec.units/unit-ri

int compareTo(ServiceProvider o) {
 return compare(getPriority(), o.getPriority());
}
origin: tec.units/unit-ri

/**
 * Returns the dimension for the specified quantity type by aggregating the results of {@link DimensionService} or <code>null</code> if the
 * specified quantity is unknown.
 *
 * @param quantityType
 *          the quantity type.
 * @return the dimension for the quantity type or <code>null</code>.
 * @since 1.0.2
 */
public static <Q extends Quantity<Q>> Dimension of(Class<Q> quantityType) {
 // TODO: Track services and aggregate results (register custom
 // types)
 Unit<Q> siUnit = Units.getInstance().getUnit(quantityType);
 if (siUnit == null)
  logger.log(Level.FINER, "Quantity type: " + quantityType + " unknown"); // we're logging but probably FINER is
 // enough?
 return (siUnit != null) ? siUnit.getDimension() : null;
}
origin: org.opengis/geoapi-conformance

/**
 * Returns the dimensionless unit. This is a workaround for what seems to be a bug
 * in the reference implementation 1.0.1 of unit API.
 */
private static Unit<Dimensionless> getDimensionless(final SystemOfUnits system) {
  Unit<Dimensionless> unit = system.getUnit(Dimensionless.class);
  if (unit == null) try {
    unit = ((Unit<?>) Class.forName("tec.units.ri.AbstractUnit").getField("ONE").get(null)).asType(Dimensionless.class);
  } catch (ReflectiveOperationException | ClassCastException e) {
    throw new IllegalArgumentException("Can not create a dimensionless unit from the given provider.");
  }
  return unit;
}
origin: tec.uom/uom-se

@Override
public int compareTo(ServiceProvider o) {
  return Integer.compare(getPriority(), o.getPriority());
}
origin: javax.measure/unit-api

/**
 * Returns the current {@link ServiceProvider}. If necessary the {@link ServiceProvider} will be lazily loaded.
 * <p>
 * If there are no providers available, an {@linkplain IllegalStateException} is thrown, otherwise the provider with the highest priority is used or
 * the one explicitly designated via {@link setCurrent()} .
 * </p>
 * 
 * @return the {@link ServiceProvider} used.
 * @throws IllegalStateException
 *           if no {@link ServiceProvider} has been found.
 * @see #getPriority()
 * @see #setCurrent()
 */
public static ServiceProvider current() {
 ServiceProvider[] p = getProviders();
 if (p.length != 0) {
  return p[0];
 }
 throw new IllegalStateException("No measurement ServiceProvider found.");
}
origin: javax.measure/unit-api

 @Override
 public int compare(ServiceProvider p1, ServiceProvider p2) {
  return p2.getPriority() - p1.getPriority();
 }
});
origin: javax.measure/unit-api

/**
 * Returns the list of available service providers.
 *
 * @return all available service providers.
 */
public static List<ServiceProvider> available() {
 return Arrays.asList(getProviders());
}
origin: unitsofmeasurement/unit-api

/**
 * Returns the current {@link ServiceProvider}. If necessary the {@link ServiceProvider} will be lazily loaded.
 * <p>
 * If there are no providers available, an {@linkplain IllegalStateException} is thrown, otherwise the provider with the highest priority is used or
 * the one explicitly designated via {@link #setCurrent(ServiceProvider)} .
 * </p>
 * 
 * @return the {@link ServiceProvider} used.
 * @throws IllegalStateException
 *           if no {@link ServiceProvider} has been found.
 * @see #getPriority()
 * @see #setCurrent(ServiceProvider)
 */
public static ServiceProvider current() {
 ServiceProvider[] p = getProviders();
 if (p.length != 0) {
  return p[0];
 }
 throw new IllegalStateException("No measurement ServiceProvider found.");
}
javax.measure.spi

Most used classes

  • ServiceProvider
    Service Provider for Units of Measurement services. All the methods in this class are safe to use by
  • SystemOfUnits
    A system of units grouped together for historical or cultural reasons. Common system of units are "S
  • ServiceProviderTest$TestServiceProvider
  • SystemOfUnitsService
    This interface represents the service to obtain a SystemOfUnits. Common system of units are "SI" (Sy

For IntelliJ IDEA and
Android Studio

  • Codota IntelliJ IDEA pluginCodota Android Studio pluginCode IndexSign in
  • EnterpriseFAQAboutContact Us
  • Terms of usePrivacy policyCodeboxFind Usages
Add Codota to your IDE (free)