本文整理汇总了Java中javax.measure.unit.SI.SECOND属性的典型用法代码示例。如果您正苦于以下问题:Java SI.SECOND属性的具体用法?Java SI.SECOND怎么用?Java SI.SECOND使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.measure.unit.SI
的用法示例。
在下文中一共展示了SI.SECOND属性的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTimeFrequencyStats
public void testTimeFrequencyStats()
{
final List<String> tList = new ArrayList<String>();
final List<String> vList = new ArrayList<String>();
TimeFrequencyBins tBins = new TimeFrequencyBins()
{
@Override
protected void presentResults(List<String> titles, List<String> values)
{
tList.addAll(titles);
vList.addAll(values);
}
};
// collate the data
List<IStoreItem> selection = new ArrayList<IStoreItem>();
StringDocumentBuilder len1 =
new StringDocumentBuilder("some strings", null, SI.SECOND);
long t = new Date().getTime();
len1.add(t + 10000, "a");
len1.add(t + 20000, "b");
len1.add(t + 60000, "c");
len1.add(t + 120000, "a");
len1.add(t + 130000, "b");
len1.add(t + 180000, "a");
selection.add(len1.toDocument());
// run the analysis
tBins.analyse(selection);
// check the results
assertEquals("enough titles", 1, tList.size());
assertEquals("enough values", 1, vList.size());
outList(tList, vList);
}
示例2: testRateOfChangeCalculation
public void testRateOfChangeCalculation()
{
final StoreGroup group = new StoreGroup("data");
final List<IStoreItem> selection = new ArrayList<IStoreItem>();
final RateOfChangeOperation op = new RateOfChangeOperation();
final NumberDocumentBuilder ndb =
new NumberDocumentBuilder("number", SI.METER, null, SI.SECOND);
ndb.add(1, 22d);
ndb.add(2, 32d);
ndb.add(3, 37d);
ndb.add(4, 47d);
selection.clear();
final NumberDocument numberDoc = ndb.toDocument();
selection.add(numberDoc);
final List<ICommand> res = op.actionsFor(selection, group, context);
assertEquals("non-empty for doc with contents", 1, res.size());
res.get(0).execute();
final NumberDocument output =
(NumberDocument) res.get(0).getOutputs().get(0);
assertNotNull("output produced", output);
assertTrue("is indexed", output.isIndexed());
assertTrue("is quantity", output.isQuantity());
assertEquals("correct size", 3, output.size());
assertEquals("correct index", SI.SECOND, output.getIndexUnits());
assertEquals("correct rate", 10d, output.getValueAt(0), 0.001);
assertEquals("correct rate", 5d, output.getValueAt(1), 0.001);
assertEquals("correct rate", 10d, output.getValueAt(2), 0.001);
}
示例3: createNumberHelper
@SuppressWarnings("unused")
private RangeHelper createNumberHelper(final RangedEntity ranged,
final NumberDocument doc)
{
final RangeHelper helper;
if (doc.size() == 1 && doc.getRange() != null)
{
helper = new RangedEntityHelper(ranged);
}
else
{
// TODO: sort out if we introduce index filters,
// then remove the next line
final boolean allowIndexFilter = false;
if (allowIndexFilter
&& doc.isIndexed()
&& (doc.getIndexUnits() == SI.SECOND || doc.getIndexUnits() == SampleData.MILLIS))
{
final double start = doc.getIndexAt(0);
final double end = doc.getIndexAt(doc.size() - 1);
final String name = doc.getName();
final IStoreGroup group = findTopParent(doc);
helper =
new DateIndexHelper((long) start, (long) end, name, group, doc);
}
else
{
helper = null;
}
}
return helper;
}
示例4: 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());
}
示例5: 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);
}
示例6: testFilterIndexed
@Test
public void testFilterIndexed()
{
ArrayList<IStoreItem> selection = new ArrayList<IStoreItem>();
MockContext context = new MockContext();
StoreGroup store = new StoreGroup("data");
NumberDocumentBuilder builder = new NumberDocumentBuilder("doc 1", SI.METER, null, SI.SECOND);
builder.add(10d, 4d);
builder.add(20d, 5d);
builder.add(30d, 6d);
builder.add(40d, 7d);
builder.add(50d, 8d);
builder.add(60d, 7d);
builder.add(70d, 6d);
NumberDocument doc = builder.toDocument();
selection.add(doc);
List<ICommand> oper = new MaxMinFilterOperation().actionsFor(selection, store, context);
assertNotNull("operations present", oper);
assertEquals("correct operations", 0, oper.size());
// ok, give it a singleton
NumberDocumentBuilder sBuilder = new NumberDocumentBuilder("singleton", SI.CELSIUS, null, null);
sBuilder.add(6d);
NumberDocument singleton = sBuilder.toDocument();
selection.add(singleton);
oper = new MaxMinFilterOperation().actionsFor(selection, store, context);
assertNotNull("operations present", oper);
assertEquals("correct operations", 2, oper.size());
// ok, run it
oper.get(0).execute();
NumberDocument nd = (NumberDocument) oper.get(0).getOutputs().get(0);
assertNotNull("have output", nd);
assertEquals("correct length", 4, nd.size());
assertEquals("correct units", SI.METER, nd.getUnits());
assertEquals("correct index units", SI.SECOND, nd.getIndexUnits());
// have a got at applying the minimum filter
singleton.setValue(5d);
// ok, run it
// oper.get(1).execute();
// nd = (NumberDocument) oper.get(0).getOutputs().get(0);
assertNotNull("have output", nd);
assertEquals("correct length", 2, nd.size());
assertEquals("correct units", SI.METER, nd.getUnits());
assertEquals("correct index units", SI.SECOND, nd.getIndexUnits());
// check the name doesn't get reset
final String new_name = "New_Name";
nd.setName(new_name);
// update the singleton, which will cause the dataset to be re-filtered
singleton.setValue(6d);
assertEquals("correct length", 4, nd.size());
assertEquals("correct units", SI.METER, nd.getUnits());
assertEquals("correct index units", SI.SECOND, nd.getIndexUnits());
assertEquals("correct name", new_name, nd.getName());
}
示例7: testBinGeneration
public void testBinGeneration()
{
// ok, create some real docs
NumberDocumentBuilder len1 =
new NumberDocumentBuilder("len_1", SI.METER, null,
SI.SECOND);
NumberDocumentBuilder len2 =
new NumberDocumentBuilder("len_2", SI.METER, null,
SI.SECOND);
NumberDocumentBuilder len3 =
new NumberDocumentBuilder("len_2", SI.METER, null,
SI.SECOND);
NumberDocumentBuilder other1 =
new NumberDocumentBuilder("other1", SI.CELSIUS, null, SI.SECOND);
// put some data into them
for (int i = 0; i < 25; i++)
{
final double thisX = (double) (( i % 10) * (i % 3));
len1.add(i * 1000, thisX);
final double thisY = (double) (( i % 11) * (i % 5))/5d;
len2.add(i * 1000, thisY);
len3.add(i * 1000, (double) (( i % 11) * (i % 5))/50d);
final double thisZ = 100 * Math.sin(i);
other1.add(i * 1000, thisZ);
}
GenerateGridCommand comm = new GenerateGridCommand(null, null, null, null, null, null, null, null);
double[] bins1 = comm.binsFor(len1.toDocument());
assertNotNull("bins generated", bins1);
assertEquals("right length for array of size larger than cut-off", QuantityFrequencyBins.DEFAULT_NUM_BINS, bins1.length);
double[] bins2 = comm.binsFor(len2.toDocument());
assertNotNull("bins generated", bins2);
assertEquals("right length for array smaller than cut-off (but larger than min)", 7, bins2.length);
double[] bins3 = comm.binsFor(len3.toDocument());
assertNotNull("bins generated", bins3);
assertEquals("right length for tiny array", QuantityFrequencyBins.MIN_NUM_BINS, bins3.length);
// ok, now try to grid the data
GenerateGrid gen = new GenerateGrid();
StoreGroup store = new StoreGroup("Store");
List<IStoreItem> selection = new ArrayList<IStoreItem>();
selection.clear();
selection.add(len1.toDocument());
selection.add(len2.toDocument());
selection.add(other1.toDocument());
List<ICommand> ops = gen.actionsFor(selection, store, context);
assertEquals("Perm created", 2, ops.size());
// ok, now execute it
final GenerateGridCommand thisOp = (GenerateGridCommand) ops.get(0);
thisOp.execute();
assertEquals("output produced", 1, thisOp.getOutputs().size());
Document<?> output = thisOp.getOutputs().get(0);
assertNotNull("Output produced", output);
}
示例8: testOperations
@Test
public void testOperations()
{
GenerateGrid gen = new GenerateGrid();
StoreGroup store = new StoreGroup("Store");
List<IStoreItem> selection = new ArrayList<IStoreItem>();
List<ICommand> ops = gen.actionsFor(selection, store, context);
assertEquals("empty ops", 0, ops.size());
// ok, create some real docs
NumberDocumentBuilder ang1 =
new NumberDocumentBuilder("ang_1", SampleData.DEGREE_ANGLE, null,
SI.SECOND);
NumberDocumentBuilder ang2 =
new NumberDocumentBuilder("ang_2", SampleData.DEGREE_ANGLE, null,
SI.SECOND);
NumberDocumentBuilder other1 =
new NumberDocumentBuilder("other1", SI.METER, null, SI.SECOND);
// put some data into them
for (int i = 0; i < 25; i++)
{
ang1.add(i * 10000, i * 13d);
ang2.add(i * 10000, i * 12d);
other1.add(i * 10000, 100 * Math.sin(i));
}
selection.clear();
selection.add(other1.toDocument());
selection.add(ang1.toDocument());
selection.add(ang2.toDocument());
ops = gen.actionsFor(selection, store, context);
assertEquals("Perm created", 2, ops.size());
selection.clear();
selection.add(ang1.toDocument());
selection.add(ang2.toDocument());
selection.add(other1.toDocument());
ops = gen.actionsFor(selection, store, context);
assertEquals("Perm created", 2, ops.size());
// ok, now execute it
final GenerateGridCommand thisOp = (GenerateGridCommand) ops.get(0);
thisOp.execute();
double[] bins = thisOp.binsFor(ang1.toDocument());
assertEquals("correct num bins", 360 / thisOp.getAngleBinSize(), bins.length);
assertEquals("output produced", 1, thisOp.getOutputs().size());
Document<?> output = thisOp.getOutputs().get(0);
assertNotNull("Output produced", output);
System.out.println(output.toListing());
store.clear();
final GenerateGridCommand thisOp2 = (GenerateGridCommand) ops.get(1);
thisOp2.execute();
assertEquals("output produced", 1, thisOp2.getOutputs().size());
output = thisOp2.getOutputs().get(0);
assertNotNull("Output produced", output);
System.out.println(output.toListing());
}
示例9: testGenActionsSameDims
@Test
public void testGenActionsSameDims()
{
GenerateGrid gen = new GenerateGrid();
StoreGroup store = new StoreGroup("Store");
List<IStoreItem> selection = new ArrayList<IStoreItem>();
List<ICommand> ops = gen.actionsFor(selection, store, context);
assertEquals("empty ops", 0, ops.size());
// ok, create some real docs
NumberDocumentBuilder ang1 =
new NumberDocumentBuilder("ang_1", SampleData.DEGREE_ANGLE, null,
SI.SECOND);
NumberDocumentBuilder ang2 =
new NumberDocumentBuilder("ang_2", SampleData.DEGREE_ANGLE, null,
SI.SECOND);
NumberDocumentBuilder ang3 =
new NumberDocumentBuilder("ang_3", SampleData.DEGREE_ANGLE, null,
SI.SECOND);
selection.add(ang1.toDocument());
selection.add(ang2.toDocument());
selection.add(ang3.toDocument());
assertEquals("still empty", 0, gen.actionsFor(selection, store, context)
.size());
// put some data into them
for (int i = 0; i < 5; i++)
{
ang1.add(i * 10000, i * 3d);
ang2.add(i * 10000, i * 2d);
if (i < 4)
{
ang3.add(i * 10000, Math.sin(i));
}
}
selection.clear();
selection.add(ang1.toDocument());
selection.add(ang2.toDocument());
assertEquals("still empty", 0, gen.actionsFor(selection, store, context)
.size());
// and add the third dataset
selection.add(ang3.toDocument());
ops = gen.actionsFor(selection, store, context);
assertEquals("3 perms created", 6, ops.size());
}
示例10: testRateOfChangeAppliesTo
public void testRateOfChangeAppliesTo()
{
final StoreGroup group = new StoreGroup("data");
final List<IStoreItem> selection = new ArrayList<IStoreItem>();
final RateOfChangeOperation op = new RateOfChangeOperation();
final List<ICommand> res = op.actionsFor(selection, group, context);
assertEquals("empty for empty list", 0, res.size());
StringDocumentBuilder sdb =
new StringDocumentBuilder("strings", null, null);
sdb.add("aa");
StringDocument sDoc = sdb.toDocument();
selection.clear();
selection.add(sDoc);
assertEquals("empty for string doc", 0, op.actionsFor(selection, group,
context).size());
sdb = new StringDocumentBuilder("strings", null, SI.MILLIMETER);
sdb.add(200, "aa");
sDoc = sdb.toDocument();
selection.clear();
selection.add(sDoc);
assertEquals("empty for indexed string doc", 0, op.actionsFor(selection,
group, context).size());
NumberDocumentBuilder ndb =
new NumberDocumentBuilder("number", SI.METER, null, null);
ndb.add(22d);
selection.clear();
selection.add(ndb.toDocument());
assertEquals("empty for non indexed number doc", 0, op.actionsFor(
selection, group, context).size());
ndb = new NumberDocumentBuilder("number", SI.METER, null, SI.SECOND);
ndb.add(200, 22d);
selection.clear();
selection.add(ndb.toDocument());
assertEquals("empty for singleton doc", 0, op.actionsFor(selection, group,
context).size());
ndb.add(400, 3d);
selection.clear();
selection.add(ndb.toDocument());
assertEquals("non-empty for doc with contents", 1, op.actionsFor(selection,
group, context).size());
}
示例11: getXMLDuration
/**
* Create an XML Duration object for the Duration Amount
*
* @param duration
* @return
*/
public static javax.xml.datatype.Duration getXMLDuration(Amount<Duration> duration) {
if (AmountUtils.approximatesZero(duration)) {
return ZERO_XML_DURATION;
}
boolean is0x8000000000000000L = false;
long l;
boolean isDurationInSeconds = (duration.getUnit() == SI.SECOND);
if (isDurationInSeconds) {
// special casing seconds makes us much faster for this common case
l = duration.longValue(SI.SECOND);
} else {
l = duration.longValue(DateUtils.MILLISECONDS);
}
int signum;
if (l > 0) {
signum = 1;
} else if (l < 0) {
signum = -1;
if (l == 0x8000000000000000L) {
// negating 0x8000000000000000L causes an overflow
l++;
is0x8000000000000000L = true;
}
l *= -1;
} else {
signum = 0;
}
BigDecimal seconds;
if (isDurationInSeconds) {
// special casing seconds makes us much faster for this common case
seconds = BigDecimal.valueOf((l % 60L) + (is0x8000000000000000L ? 1 : 0));
l /= 60L;
} else {
seconds = BigDecimal.valueOf((l % 60000L) + (is0x8000000000000000L ? 1 : 0), 3);
l /= 60000L;
}
BigInteger minutes = BigInteger.valueOf(l % 60L);
l /= 60L;
BigInteger hours = BigInteger.valueOf(l % 24L);
l /= 24L;
BigInteger days = BigInteger.valueOf(l);
return DATATYPE_FACTORY.newDuration(signum >= 0, null, null, days, hours, minutes, seconds);
}