javax.measure.spi.ServiceProvider Java Examples

The following examples show how to use javax.measure.spi.ServiceProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SystemOfUnitsServiceTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
// TODO consolidate asserts
public void testUnitSystemServiceAlias() {
	final ServiceProvider cldrProvider = ServiceProvider.of("Unicode");
	assertNotNull(cldrProvider);
	final SystemOfUnitsService cldrService = cldrProvider.getSystemOfUnitsService();
	assertNotNull(cldrService);
	assertEquals("systems.uom.unicode.spi.CLDRSystemService", cldrService.getClass().getName());
	SystemOfUnits system = cldrService.getSystemOfUnits("CLDR");
	assertNotNull(system);
	assertEquals("systems.uom.unicode.CLDR", system.getClass().getName());
	assertEquals("Unicode CLDR", system.getName());
	assertNotNull(system.getUnits());
	assertEquals(NUM_OF_UNITS_CLDR, system.getUnits().size());
	SystemOfUnits system2 = cldrService.getSystemOfUnits("Unicode");
	assertEquals(system, system2);
}
 
Example #2
Source File: SystemOfUnitsServiceTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
// TODO consolidate asserts
public void testCommonUnitSystemServiceAlias() {
	final ServiceProvider commonProvider = ServiceProvider.of("Common");
	assertNotNull(commonProvider);
	final SystemOfUnitsService commonService = commonProvider.getSystemOfUnitsService();
	assertNotNull(commonService);
	assertEquals(COMMON_SERVICE_CLASSNAME, commonService.getClass().getName());
	SystemOfUnits system = commonService.getSystemOfUnits("USCustomary");
	assertNotNull(system);
	assertEquals("systems.uom.common.USCustomary", system.getClass().getName());
	assertEquals("United States Customary Units", system.getName());
	assertNotNull(system.getUnits());
	assertEquals(NUM_OF_UNITS_US, system.getUnits().size());
	SystemOfUnits system2 = commonService.getSystemOfUnits("US");
	assertEquals(system, system2);

	system = commonService.getSystemOfUnits("CGS");
	assertNotNull(system);
	assertEquals("Centimetre–gram–second System of Units", system.getName());
	system2 = commonService.getSystemOfUnits("Centimetre–gram–second");
	assertEquals(system, system2);
	assertEquals(NUM_OF_UNITS_CGS, system.getUnits().size());
}
 
Example #3
Source File: UnitServicesTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the default system of units.
 */
@Test
public void testDefaultSystemOfUnits() {
    final ServiceProvider provider = ServiceProvider.current();
    Set<? extends Unit<?>> units = provider.getSystemOfUnitsService().getSystemOfUnits().getUnits();
    assertTrue("METRE",                units.contains(Units.METRE));
    assertTrue("KILOMETRE",            units.contains(Units.KILOMETRE));
    assertTrue("CUBIC_METRE",          units.contains(Units.CUBIC_METRE));
    assertTrue("METRES_PER_SECOND",    units.contains(Units.METRES_PER_SECOND));
    assertTrue("KILOMETRES_PER_HOUR",  units.contains(Units.KILOMETRES_PER_HOUR));
    assertTrue("NAUTICAL_MILE",        units.contains(Units.NAUTICAL_MILE));
    assertTrue("STATUTE_MILE",         units.contains(Units.STATUTE_MILE));
    assertTrue("DEGREE",               units.contains(Units.DEGREE));
    assertTrue("RADIAN",               units.contains(Units.RADIAN));
    assertTrue("GRAD",                 units.contains(Units.GRAD));
}
 
Example #4
Source File: UnitServicesTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the "SI" system of units.
 */
@Test
public void testSI() {
    final ServiceProvider provider = ServiceProvider.current();
    Set<? extends Unit<?>> units = provider.getSystemOfUnitsService().getSystemOfUnits("SI").getUnits();
    assertTrue ("METRE",                units.contains(Units.METRE));
    assertTrue ("KILOMETRE",            units.contains(Units.KILOMETRE));
    assertTrue ("CUBIC_METRE",          units.contains(Units.CUBIC_METRE));
    assertTrue ("METRES_PER_SECOND",    units.contains(Units.METRES_PER_SECOND));
    assertFalse("KILOMETRES_PER_HOUR",  units.contains(Units.KILOMETRES_PER_HOUR));
    assertFalse("NAUTICAL_MILE",        units.contains(Units.NAUTICAL_MILE));
    assertFalse("STATUTE_MILE",         units.contains(Units.STATUTE_MILE));
    assertFalse("DEGREE",               units.contains(Units.DEGREE));
    assertTrue ("RADIAN",               units.contains(Units.RADIAN));
    assertFalse("GRAD",                 units.contains(Units.GRAD));
}
 
Example #5
Source File: UnitServicesTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the "SI + accepted" system of units.
 */
@Test
public void testAccepted() {
    final ServiceProvider provider = ServiceProvider.current();
    Set<? extends Unit<?>> units = provider.getSystemOfUnitsService().getSystemOfUnits("SI + accepted").getUnits();
    assertTrue ("METRE",                units.contains(Units.METRE));
    assertTrue ("KILOMETRE",            units.contains(Units.KILOMETRE));
    assertTrue ("CUBIC_METRE",          units.contains(Units.CUBIC_METRE));
    assertTrue ("METRES_PER_SECOND",    units.contains(Units.METRES_PER_SECOND));
    assertTrue ("KILOMETRES_PER_HOUR",  units.contains(Units.KILOMETRES_PER_HOUR));
    assertFalse("NAUTICAL_MILE",        units.contains(Units.NAUTICAL_MILE));
    assertFalse("STATUTE_MILE",         units.contains(Units.STATUTE_MILE));
    assertTrue ("DEGREE",               units.contains(Units.DEGREE));
    assertTrue ("RADIAN",               units.contains(Units.RADIAN));
    assertFalse("GRAD",                 units.contains(Units.GRAD));
}
 
Example #6
Source File: UnitServicesTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link UnitServices#getUnitFormat(String)}.
 */
@Test
public void testGetUnitFormat() {
    final ServiceProvider provider = ServiceProvider.current();
    final UnitFormat f = provider.getUnitFormatService().getUnitFormat("name");
    ((org.apache.sis.measure.UnitFormat) f).setLocale(Locale.US);
    assertEquals("CUBIC_METRE", "cubic meter", f.format(Units.CUBIC_METRE));
}
 
Example #7
Source File: UnitFormatTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@BeforeEach
	public void init() {
		sut = ServiceProvider.current().getQuantityFactory(Length.class).create(10,
				METRE);
		
//		format = EBNFUnitFormat.getInstance();
		format2 = SimpleUnitFormat.getInstance();
		
//		format.label(SI.BEL, "B");
		format2.label(CLDR.CARAT, "ct");
		format2.label(CLDR.ACRE, "ac");
		format2.label(CLDR.TONNE, "t");
	}
 
Example #8
Source File: UnitFormatServiceTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testGetService() throws Exception {
  UnitFormatService ufs = ServiceProvider.current().getUnitFormatService();
  assertNotNull(ufs);
  assertNotNull(ufs.getUnitFormat());
  assertEquals("Parsing", ufs.getUnitFormat().getClass().getSimpleName());
}
 
Example #9
Source File: SystemOfUnitsServiceTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testCommonUnitSystemService() {
	final ServiceProvider commonProvider = ServiceProvider.of("Common");
	assertNotNull(commonProvider);
	final SystemOfUnitsService commonService = commonProvider.getSystemOfUnitsService();
	assertNotNull(commonService);
	assertEquals("systems.uom.common.spi.CommonSystemService", commonService.getClass().getName());
	SystemOfUnits system = commonService.getSystemOfUnits();
	assertNotNull(system);
	assertEquals("systems.uom.common.USCustomary", system.getClass().getName());
	assertEquals("United States Customary Units", system.getName());
	assertNotNull(system.getUnits());
	assertEquals(NUM_OF_UNITS_US, system.getUnits().size());
}
 
Example #10
Source File: SystemOfUnitsServiceTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testOtherUnitSystemServices() {
	Collection<ServiceProvider> services = ServiceProvider.available();
	assertNotNull(services);
	assertEquals(3, services.size());
	for (ServiceProvider provider : services) {
		LOGGER.info(String.valueOf(provider));
		// TODO change to DEBUG or lower after https://github.com/unitsofmeasurement/unit-api/issues/195 was resolved
	}
	// for (SystemOfUnitsService service : services) {
	// checkService(service);
	// }
}
 
Example #11
Source File: UnitServicesTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the "Imperial" system of units.
 */
@Test
public void testImperial() {
    final ServiceProvider provider = ServiceProvider.current();
    Set<? extends Unit<?>> units = provider.getSystemOfUnitsService().getSystemOfUnits("Imperial").getUnits();
    assertFalse("METRE",                units.contains(Units.METRE));
    assertFalse("KILOMETRE",            units.contains(Units.KILOMETRE));
    assertFalse("CUBIC_METRE",          units.contains(Units.CUBIC_METRE));
    assertFalse("METRES_PER_SECOND",    units.contains(Units.METRES_PER_SECOND));
    assertFalse("KILOMETRES_PER_HOUR",  units.contains(Units.KILOMETRES_PER_HOUR));
    assertTrue ("STATUTE_MILE",         units.contains(Units.STATUTE_MILE));
    assertFalse("DEGREE",               units.contains(Units.DEGREE));
    assertFalse("RADIAN",               units.contains(Units.RADIAN));
    assertFalse("GRAD",                 units.contains(Units.GRAD));
}
 
Example #12
Source File: ServiceProviderTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
  public void testAvailable() throws Exception {
List<ServiceProvider> providers = ServiceProvider.available();
assertNotNull(providers);
assertFalse(providers.isEmpty());
assertEquals(3, providers.size());
assertEquals("UCUMServiceProvider", providers.get(0).toString());
  }
 
Example #13
Source File: SystemOfUnitsServiceTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
  public void testOtherUnitSystemServices() {
Collection<ServiceProvider> services = ServiceProvider.available();
assertNotNull(services);
assertEquals(3, services.size());
// for (SystemOfUnitsService service : services) {
// checkService(service);
// }
  }
 
Example #14
Source File: UnitServicesTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link UnitServices#getAvailableFormatNames()}.
 */
@Test
public void testGetAvailableFormatNames() {
    final ServiceProvider provider = ServiceProvider.current();
    assertSetEquals(Arrays.asList("SYMBOL", "UCUM", "NAME"),
            provider.getUnitFormatService().getAvailableFormatNames());
}
 
Example #15
Source File: SystemOfUnitsServiceTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
	public void testOtherUnitSystemServices() {
		Collection<ServiceProvider> services = ServiceProvider.available();
		assertNotNull(services);
		assertEquals(2, services.size());
//	for (ServiceProvider service : services) {
//	    checkService(service);
//	}
	}
 
Example #16
Source File: SystemOfUnitsServiceTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testCLDRUnitSystemService() {
	final ServiceProvider cldrProvider = ServiceProvider.of("Unicode");
	assertNotNull(cldrProvider);
	final SystemOfUnitsService cldrService = cldrProvider.getSystemOfUnitsService();
	assertNotNull(cldrService);
	assertEquals("systems.uom.unicode.spi.CLDRSystemService", cldrService.getClass().getName());
	SystemOfUnits system = cldrService.getSystemOfUnits();
	assertNotNull(system);
	assertEquals("systems.uom.unicode.CLDR", system.getClass().getName());
	assertEquals("Unicode CLDR", system.getName());
	assertNotNull(system.getUnits());
	assertEquals(NUM_OF_UNITS_CLDR, system.getUnits().size());
}
 
Example #17
Source File: UnitFormatServiceTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void testGetCIFound() throws Exception {
  UnitFormatService ufs = ServiceProvider.current().getUnitFormatService();
  assertNotNull(ufs);
  assertNotNull(ufs.getUnitFormat("CI"));
}
 
Example #18
Source File: SystemOfUnitsServiceTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@BeforeClass
public static void setUp() {
	defaultService = ServiceProvider.current().getSystemOfUnitsService();
}
 
Example #19
Source File: ArithmeticTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@BeforeAll
public static void init() {
	sut = ServiceProvider.current().getQuantityFactory(Length.class).create(10, METRE);
}
 
Example #20
Source File: UnitFormatServiceTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void testGetFormatNotFoundEither() throws Exception {
  UnitFormatService ufs = ServiceProvider.current().getUnitFormatService();
  assertNotNull(ufs);
  assertNotNull(ufs.getUnitFormat("UCUM"));
}
 
Example #21
Source File: UnitFormatServiceTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void testGetFormatNotFound() throws Exception {
  UnitFormatService ufs = ServiceProvider.current().getUnitFormatService();
  assertNotNull(ufs);
  assertNull(ufs.getUnitFormat("XYZ"));
}
 
Example #22
Source File: UnitFormatServiceTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void testGetPrintFound() throws Exception {
  UnitFormatService ufs = ServiceProvider.current().getUnitFormatService();
  assertNotNull(ufs);
  assertNotNull(ufs.getUnitFormat("Print"));
}
 
Example #23
Source File: UnitFormatServiceTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void testGetCSFound() throws Exception {
  UnitFormatService ufs = ServiceProvider.current().getUnitFormatService();
  assertNotNull(ufs);
  assertNotNull(ufs.getUnitFormat("CS"));
}
 
Example #24
Source File: UCUMFormatVolumeTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
   public void testParseUCUMCSMicroSt() {
final UnitFormat unitFormat = ServiceProvider.current().getUnitFormatService().getUnitFormat("CS");
final Unit<?> ust = unitFormat.parse("ust");
assertEquals(MICRO(UCUM.STERE), ust);
   }
 
Example #25
Source File: UCUMFormatVolumeTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
   public void testParseUCUMCSDeciSt() {
final UnitFormat unitFormat = ServiceProvider.current().getUnitFormatService().getUnitFormat("CS");
final Unit<?> dst = unitFormat.parse("dst");
assertEquals(DECI(UCUM.STERE), dst);
   }
 
Example #26
Source File: UCUMFormatVolumeTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
   public void testParseUCUMCIMicroSt() {
final UnitFormat unitFormat = ServiceProvider.current().getUnitFormatService().getUnitFormat("CI");
final Unit<?> ust = unitFormat.parse("USTR");
assertEquals(MICRO(UCUM.STERE), ust);
   }
 
Example #27
Source File: UCUMFormatVolumeTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
   public void testParseUCUMCIDeciSt() {
final UnitFormat unitFormat = ServiceProvider.current().getUnitFormatService().getUnitFormat("CI");
final Unit<?> dst = unitFormat.parse("DSTR");
assertEquals(DECI(UCUM.STERE), dst);
   }
 
Example #28
Source File: UCUMFormat135Test.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void testParseUCUMCSComplexDenominator() {
	final UnitFormat unitFormat = ServiceProvider.current().getUnitFormatService().getUnitFormat("CI");
	final Unit<?> dst = unitFormat.parse("m/(bar.s)");
	assertEquals("m/(bar.s)",FORMAT_CS.format(dst));
}
 
Example #29
Source File: UCUMFormat135Test.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void testParseUCUMCSM3PerSecond() {
	final UnitFormat unitFormat = ServiceProvider.current().getUnitFormatService().getUnitFormat("CI");
	final Unit<?> dst = unitFormat.parse("m3/s");
	assertEquals("m3/s",FORMAT_CS.format(dst));
}
 
Example #30
Source File: ServiceProviderTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
  public void testCurrent() throws Exception {
ServiceProvider provider = ServiceProvider.current();
assertNotNull(provider);
assertEquals("UCUMServiceProvider", provider.toString());
  }