本文整理汇总了Java中javax.measure.unit.NonSI.DECIBEL属性的典型用法代码示例。如果您正苦于以下问题:Java NonSI.DECIBEL属性的具体用法?Java NonSI.DECIBEL怎么用?Java NonSI.DECIBEL使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.measure.unit.NonSI
的用法示例。
在下文中一共展示了NonSI.DECIBEL属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isDecibels
/**
* special case. Once a decibels unit has been restored from file, the equals comparison no longer
* works. So, we've copied the below content from the original sources. The original sources also
* includes a comparison of db.converter, but we've omitted that, since it's not visible. If we
* start getting false positives, we'll have to consider using the derived converter object.
*
* @param that
* object we're considering
* @return if it's the units of decibels
*/
private boolean isDecibels(Object that)
{
final TransformedUnit<Dimensionless> db =
(TransformedUnit<Dimensionless>) NonSI.DECIBEL;
if (this == that)
return true;
if (!(that instanceof TransformedUnit))
return false;
TransformedUnit<?> thatUnit = (TransformedUnit<?>) that;
return db.getParentUnit().equals(thatUnit.getParentUnit());
}
示例2: ProplossBetweenOperation
ProplossBetweenOperation(final List<IStoreItem> selection,
final IStoreGroup store, final String title, final String description,
final IDocument<?> timeProvider, final IContext context)
{
super(selection, store, title, description, timeProvider, context,
NonSI.DECIBEL);
}
示例3: testLogArithmeticIndexed
@Test
public void testLogArithmeticIndexed()
{
List<IStoreItem> selection = new ArrayList<IStoreItem>();
IStoreGroup destination = new StoreGroup("dest");
NumberDocumentBuilder docAb =
new NumberDocumentBuilder("doc a", NonSI.DECIBEL, null, SI.SECOND);
NumberDocumentBuilder docBb =
new NumberDocumentBuilder("doc b", NonSI.DECIBEL, null, SI.SECOND);
docAb.add(10d, 23d);
docAb.add(20d, 24d);
docAb.add(30d, 25d);
docBb.add(10d, 33d);
docBb.add(22d, 32d);
docBb.add(27d, 35d);
docBb.add(30d, 36d);
final NumberDocument docA = docAb.toDocument();
final NumberDocument docB = docBb.toDocument();
selection.add(docA);
selection.add(docB);
IOperation adder = new AddQuantityOperation();
List<ICommand> ops = adder.actionsFor(selection, destination, context);
assertEquals("only two commands", 2, ops.size());
// run the two operations
final ICommand logOp = ops.get(0);
final ICommand powerOp = ops.get(1);
logOp.execute();
powerOp.execute();
// check they're as expecetd
assertTrue("log is first", logOp.getName().startsWith("Log"));
assertTrue("power is second", powerOp.getName().startsWith("Power"));
System.out.println(docA.toListing());
System.out.println(docB.toListing());
NumberDocument logRes = (NumberDocument) logOp.getOutputs().get(0);
System.out.println(logRes.toListing());
NumberDocument powerRes = (NumberDocument) powerOp.getOutputs().get(0);
System.out.println(powerRes.toListing());
// and now the reverse operation
IOperation combinedSubber = new SubtractQuantityOperation();
selection.clear();
selection.add(logRes);
selection.add(docA);
List<ICommand> combinedOps =
combinedSubber.actionsFor(selection, destination, context);
assertEquals("have 4 combined ops", 4, combinedOps.size());
}
示例4: testSubtractLogInterpolated
@Test
public void testSubtractLogInterpolated()
{
List<IStoreItem> selection = new ArrayList<IStoreItem>();
IStoreGroup destination = new StoreGroup("data");
NumberDocumentBuilder docAb =
new NumberDocumentBuilder("docA", NonSI.DECIBEL, null, SI.SECOND);
NumberDocumentBuilder docBb =
new NumberDocumentBuilder("docB", NonSI.DECIBEL, null, SI.SECOND);
docAb.add(100d, 41d);
docAb.add(200d, 40d);
docAb.add(300d, 45d);
docBb.add(100d, 43d);
docBb.add(170d, 46d);
docBb.add(240d, 47d);
docBb.add(300d, 49d);
NumberDocument docA = docAb.toDocument();
NumberDocument docB = docBb.toDocument();
selection.add(docA);
selection.add(docB);
// add them first
IOperation adder = new AddQuantityOperation();
List<ICommand> ops = adder.actionsFor(selection, destination, context);
assertEquals("both offered", 2, ops.size());
assertTrue("log is first", ops.get(0).getName().startsWith("Log"));
assertTrue("power is second", ops.get(1).getName().startsWith("Power"));
ops.get(0).execute();
NumberDocument logSum = (NumberDocument) ops.get(0).getOutputs().get(0);
// check the first value
double valSum = logSum.getValueAt(0);
// sum if 41 & 43 calculated in Excel is
assertEquals("correct log10 sum", 45.12443, valSum, 0.001);
// change the name
logSum.setName("Log Sum");
// and now the subtract
selection.remove(docB);
selection.add(logSum);
IOperation combinedSub = new SubtractQuantityOperation();
List<ICommand> combinedOps =
combinedSub.actionsFor(selection, destination, context);
assertEquals("has ops", 4, combinedOps.size());
ICommand combinedOp = combinedOps.get(3);
// ok, do the old subtract first
assertTrue("We have log operation", combinedOp.getName().startsWith("Log"));
combinedOp.execute();
NumberDocument combinedOut =
(NumberDocument) combinedOp.getOutputs().get(0);
System.out.println(combinedOut.toListing());
double combinedRes = combinedOut.getValueAt(0);
assertEquals("correct result", 43, combinedRes, 0.001);
}
示例5: testCreateSingletonDecibelGenerator
@Test
public void testCreateSingletonDecibelGenerator()
{
StoreGroup store = new SampleData().getData(10);
CreateSingletonGenerator generator =
new CreateSingletonGenerator("Decibel", NonSI.DECIBEL);
assertNotNull("Create Single Generator is not NULL", generator);
List<IStoreItem> selection = new ArrayList<IStoreItem>();
StoreGroup storeGroup = new StoreGroup("Track 1");
selection.add(storeGroup);
IContext mockContext = EasyMock.createMock(MockContext.class);
Collection<ICommand> singleGeneratorActionFor =
generator.actionsFor(selection, store, mockContext);
assertEquals("Create location collection size", 1, singleGeneratorActionFor
.size());
ICommand singleGenCommand = singleGeneratorActionFor.iterator().next();
final String outName = "new_name";
EasyMock.expect(
mockContext.getInput("New variable", "Enter name for variable", "new Decibel"))
.andReturn(outName).times(1);
EasyMock.expect(
mockContext.getInput("New variable",
"Enter initial value for variable", "100")).andReturn("1234.56")
.times(1);
EasyMock.expect(
mockContext.getInput("New variable",
"Enter the range for variable (or cancel to leave un-ranged)", "0:100")).andReturn("5:100")
.times(1);
EasyMock.replay(mockContext);
singleGenCommand.execute();
NumberDocument output = (NumberDocument) singleGenCommand.getOutputs().get(0);
assertNotNull(output);
assertEquals("correct name", outName, output.getName());
assertEquals("correct size", 1, output.size());
assertEquals("correct value", 1234.56, output.getValueAt(0), 0.01);
assertEquals("correct range", new Range(5d,100d), output.getRange());
assertEquals("correct units", NonSI.DECIBEL, output.getUnits());
assertEquals("no index units", null, output.getIndexUnits());
assertFalse("not indexed", output.isIndexed());
assertTrue("is quantity", output.isQuantity());
}
示例6: testCreateSingletonDecibelGeneratorNoRange1
@Test
public void testCreateSingletonDecibelGeneratorNoRange1()
{
StoreGroup store = new SampleData().getData(10);
CreateSingletonGenerator generator =
new CreateSingletonGenerator("Decibel", NonSI.DECIBEL);
assertNotNull("Create Single Generator is not NULL", generator);
List<IStoreItem> selection = new ArrayList<IStoreItem>();
StoreGroup storeGroup = new StoreGroup("Track 1");
selection.add(storeGroup);
IContext mockContext = EasyMock.createMock(MockContext.class);
Collection<ICommand> singleGeneratorActionFor =
generator.actionsFor(selection, store, mockContext);
assertEquals("Create location collection size", 1, singleGeneratorActionFor
.size());
ICommand singleGenCommand = singleGeneratorActionFor.iterator().next();
final String outName = "new_name";
EasyMock.expect(
mockContext.getInput("New variable", "Enter name for variable", "new Decibel"))
.andReturn(outName).times(1);
EasyMock.expect(
mockContext.getInput("New variable",
"Enter initial value for variable", "100")).andReturn("1234.56")
.times(1);
EasyMock.expect(
mockContext.getInput("New variable",
"Enter the range for variable (or cancel to leave un-ranged)", "0:100")).andReturn("")
.times(1);
EasyMock.replay(mockContext);
singleGenCommand.execute();
NumberDocument output = (NumberDocument) singleGenCommand.getOutputs().get(0);
assertNotNull(output);
assertEquals("correct name", outName, output.getName());
assertEquals("correct size", 1, output.size());
assertEquals("correct value", 1234.56, output.getValueAt(0), 0.01);
assertEquals("correct range", null, output.getRange());
assertEquals("correct units", NonSI.DECIBEL, output.getUnits());
assertEquals("no index units", null, output.getIndexUnits());
assertFalse("not indexed", output.isIndexed());
assertTrue("is quantity", output.isQuantity());
}
示例7: testCreateSingletonDecibelGeneratorNoRange2
@Test
public void testCreateSingletonDecibelGeneratorNoRange2()
{
StoreGroup store = new SampleData().getData(10);
CreateSingletonGenerator generator =
new CreateSingletonGenerator("Decibel", NonSI.DECIBEL);
assertNotNull("Create Single Generator is not NULL", generator);
List<IStoreItem> selection = new ArrayList<IStoreItem>();
StoreGroup storeGroup = new StoreGroup("Track 1");
selection.add(storeGroup);
IContext mockContext = EasyMock.createMock(MockContext.class);
Collection<ICommand> singleGeneratorActionFor =
generator.actionsFor(selection, store, mockContext);
assertEquals("Create location collection size", 1, singleGeneratorActionFor
.size());
ICommand singleGenCommand = singleGeneratorActionFor.iterator().next();
final String outName = "new_name";
EasyMock.expect(
mockContext.getInput("New variable", "Enter name for variable", "new Decibel"))
.andReturn(outName).times(1);
EasyMock.expect(
mockContext.getInput("New variable",
"Enter initial value for variable", "100")).andReturn("1234.56")
.times(1);
EasyMock.expect(
mockContext.getInput("New variable",
"Enter the range for variable (or cancel to leave un-ranged)", "0:100")).andReturn("0-100")
.times(1);
EasyMock.replay(mockContext);
singleGenCommand.execute();
NumberDocument output = (NumberDocument) singleGenCommand.getOutputs().get(0);
assertNotNull(output);
assertEquals("correct name", outName, output.getName());
assertEquals("correct size", 1, output.size());
assertEquals("correct value", 1234.56, output.getValueAt(0), 0.01);
assertEquals("correct range", null, output.getRange());
assertEquals("correct units", NonSI.DECIBEL, output.getUnits());
assertEquals("no index units", null, output.getIndexUnits());
assertFalse("not indexed", output.isIndexed());
assertTrue("is quantity", output.isQuantity());
}
示例8: testExtrapolateOnInterpolate
public void testExtrapolateOnInterpolate()
{
CreateNewLookupDatafileOperation op =
new CreateNewLookupDatafileOperation();
StoreGroup store = new StoreGroup("data");
List<IStoreItem> selection = new ArrayList<IStoreItem>();
// start off with values all in range
NumberDocumentBuilder ndb =
new NumberDocumentBuilder("lookup", NonSI.DECIBEL, null, SI.METER);
ndb.add(100d, 55d);
ndb.add(200d, 50d);
ndb.add(300d, 45d);
ndb.add(400d, 40d);
NumberDocument lookup = ndb.toDocument();
NumberDocumentBuilder sbj =
new NumberDocumentBuilder("subject", SI.METER, null, null);
sbj.add(250d);
NumberDocument subject = sbj.toDocument();
selection.add(subject);
selection.add(lookup);
List<ICommand> ops = op.actionsFor(selection, store, context);
assertNotNull("found some actions", ops);
ops.get(0).execute();
NumberDocument output = (NumberDocument) ops.get(0).getOutputs().get(0);
assertEquals("correct interpolated value", 47.5, output.getValueAt(0), 0.1);
// now create value out of range (to the left)
selection.remove(subject);
sbj.clear();
sbj.add(50d);
subject = sbj.toDocument();
selection.add(subject);
ops = op.actionsFor(selection, store, context);
assertNotNull("found some actions", ops);
ops.get(0).execute();
output = (NumberDocument) ops.get(0).getOutputs().get(0);
// TODO: we still need a fix to extrapolate the value if it's outside
// the coverage of the lookup table. The current (default) behaviour
// is to return the first/last value
assertEquals("correct interpolated value", 55, output.getValueAt(0), 0.1);
// now create value out of range (to the right)
selection.remove(subject);
sbj.clear();
sbj.add(500d);
subject = sbj.toDocument();
selection.add(subject);
ops = op.actionsFor(selection, store, context);
assertNotNull("found some actions", ops);
ops.get(0).execute();
output = (NumberDocument) ops.get(0).getOutputs().get(0);
// TODO: we still need a fix to extrapolate the value if it's outside
// the coverage of the lookup table. The current (default) behaviour
// is to return the first/last value
assertEquals("correct interpolated value", 40, output.getValueAt(0), 0.1);
}