List of usage examples for java.lang Long signum
public static int signum(long i)
From source file:Main.java
public static void main(String[] args) { System.out.println(Long.signum(-10)); }
From source file:org.isoron.uhabits.models.Streak.java
public int compareLonger(Streak other) { if (this.getLength() != other.getLength()) return Long.signum(this.getLength() - other.getLength()); return Long.signum(this.getEnd() - other.getEnd()); }
From source file:org.isoron.uhabits.models.Streak.java
public int compareNewer(Streak other) { return Long.signum(this.getEnd() - other.getEnd()); }
From source file:org.ast.labs.calview.model.Checkmark.java
public int compareNewer(Checkmark other) { return Long.signum(this.getTimestamp() - other.getTimestamp()); }
From source file:br.com.hslife.orcamento.entity.EntityPersistence.java
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result/*from w w w . ja v a2 s . c o m*/ + Long.signum(getId() == null ? 0 : getId() ^ (getId() == null ? 1 : getId() >>> 32)); return result; }
From source file:org.ast.labs.calview.model.Score.java
public int compareNewer(Score other) { return Long.signum(this.getTimestamp() - other.getTimestamp()); }
From source file:org.waveprotocol.wave.examples.fedone.common.HashedVersion.java
/** * {@inheritDoc}//from www.jav a 2 s .co m * * Lexicographic comparison of version and historyHash. */ @Override public int compareTo(HashedVersion other) { return version != other.version ? Long.signum(version - other.version) : compare(historyHash, other.historyHash); }
From source file:org.dkpro.lab.storage.filesystem.FileSystemStorageService.java
@Override public List<TaskContextMetadata> getContexts() { List<TaskContextMetadata> contexts = new ArrayList<TaskContextMetadata>(); for (File child : storageRoot.listFiles()) { if (new File(child, METADATA_KEY).exists()) { contexts.add(retrieveBinary(child.getName(), METADATA_KEY, new TaskContextMetadata())); }//ww w . ja v a 2 s. com } Collections.sort(contexts, new Comparator<TaskContextMetadata>() { @Override public int compare(TaskContextMetadata aO1, TaskContextMetadata aO2) { return Long.signum(aO2.getEnd() - aO1.getEnd()); } }); return contexts; }
From source file:ch.algotrader.accounting.PositionTrackerImpl.java
/** * processes a transaction on an existing position * * @return a pair containing the profit and profit percentage *///w ww. j av a 2s . co m @Override public TradePerformanceVO processTransaction(Position position, Transaction transaction) { // get old values long oldQty = position.getQuantity(); double oldCost = position.getCost().doubleValue(); double oldRealizedPL = position.getRealizedPL().doubleValue(); double oldAvgPrice = position.getAveragePriceDouble(); // get transaction values long qty = transaction.getQuantity(); double price = transaction.getPrice().doubleValue(); double totalCharges = transaction.getTotalChargesDouble(); double contractSize = transaction.getSecurity().getSecurityFamily().getContractSize(); // calculate opening and closing quantity long closingQty = MathUtils.sign(oldQty) != MathUtils.sign(qty) ? Math.min(Math.abs(oldQty), Math.abs(qty)) * MathUtils.sign(qty) : 0; long openingQty = MathUtils.sign(oldQty) == MathUtils.sign(qty) ? qty : qty - closingQty; // calculate new values long newQty = oldQty + qty; double newCost = oldCost + openingQty * contractSize * price; double newRealizedPL = oldRealizedPL; // handle a previously non-closed position (aldAvgPrice is Double.NaN for a previously closed position) if (closingQty != 0) { newCost += closingQty * contractSize * oldAvgPrice; newRealizedPL += closingQty * contractSize * (oldAvgPrice - price); } // handle commissions if (openingQty != 0) { newCost += totalCharges * openingQty / qty; } if (closingQty != 0) { newRealizedPL -= totalCharges * closingQty / qty; } // calculate profit and profitPct TradePerformanceVO tradePerformance = null; if (Long.signum(position.getQuantity()) * Long.signum(transaction.getQuantity()) == -1) { double cost, value; if (Math.abs(transaction.getQuantity()) <= Math.abs(position.getQuantity())) { cost = position.getCost().doubleValue() * Math.abs((double) transaction.getQuantity() / (double) position.getQuantity()); value = transaction.getNetValueDouble(); } else { cost = position.getCost().doubleValue(); value = transaction.getNetValueDouble() * Math.abs((double) position.getQuantity() / (double) transaction.getQuantity()); } double profit = value - cost; double profitPct = Direction.LONG.equals(position.getDirection()) ? ((value - cost) / cost) : ((cost - value) / cost); tradePerformance = new TradePerformanceVO(profit, profitPct, profit > 0); } // set values position.setQuantity(newQty); position.setCost(RoundUtil.getBigDecimal(newCost)); position.setRealizedPL(RoundUtil.getBigDecimal(newRealizedPL)); return tradePerformance; }
From source file:org.trpr.platform.batch.impl.spring.admin.repository.MapJobInstanceDao.java
public List<JobInstance> getJobInstances(String jobName, int start, int count) { List<JobInstance> result = new ArrayList<JobInstance>(); for (JobInstance instance : jobInstances) { if (instance.getJobName().equals(jobName)) { result.add(instance);/*from w w w . j a v a 2 s .com*/ } } Collections.sort(result, new Comparator<JobInstance>() { // sort by ID descending public int compare(JobInstance o1, JobInstance o2) { return Long.signum(o2.getId() - o1.getId()); } }); int startIndex = Math.min(start, result.size()); int endIndex = Math.min(start + count, result.size()); return result.subList(startIndex, endIndex); }