Example usage for java.math BigInteger intValue

List of usage examples for java.math BigInteger intValue

Introduction

In this page you can find the example usage for java.math BigInteger intValue.

Prototype

public int intValue() 

Source Link

Document

Converts this BigInteger to an int .

Usage

From source file:org.alfresco.opencmis.CMISConnector.java

public ObjectList getObjectRelationships(NodeRef nodeRef, RelationshipDirection relationshipDirection,
        String typeId, String filter, Boolean includeAllowableActions, BigInteger maxItems,
        BigInteger skipCount) {
    ObjectListImpl result = new ObjectListImpl();
    result.setHasMoreItems(false);//from  ww  w. j  a  va  2 s  . c om
    result.setNumItems(BigInteger.ZERO);
    result.setObjects(new ArrayList<ObjectData>());

    if (nodeRef.getStoreRef().getProtocol().equals(VersionBaseModel.STORE_PROTOCOL)) {
        // relationships from and to versions are not preserved
        return result;
    }

    // get relationships
    List<AssociationRef> assocs = new ArrayList<AssociationRef>();
    if (relationshipDirection == RelationshipDirection.SOURCE
            || relationshipDirection == RelationshipDirection.EITHER) {
        assocs.addAll(nodeService.getTargetAssocs(nodeRef, RegexQNamePattern.MATCH_ALL));
    }
    if (relationshipDirection == RelationshipDirection.TARGET
            || relationshipDirection == RelationshipDirection.EITHER) {
        assocs.addAll(nodeService.getSourceAssocs(nodeRef, RegexQNamePattern.MATCH_ALL));
    }

    int skip = (skipCount == null ? 0 : skipCount.intValue());
    int max = (maxItems == null ? Integer.MAX_VALUE : maxItems.intValue());
    int counter = 0;
    boolean hasMore = false;

    if (max > 0) {
        // filter relationships that not map the CMIS domain model
        for (AssociationRef assocRef : assocs) {
            TypeDefinitionWrapper assocTypeDef = getOpenCMISDictionaryService()
                    .findAssocType(assocRef.getTypeQName());
            if (assocTypeDef == null || getType(assocRef.getSourceRef()) == null
                    || getType(assocRef.getTargetRef()) == null) {
                continue;
            }

            if ((typeId != null) && !assocTypeDef.getTypeId().equals(typeId)) {
                continue;
            }

            counter++;

            if (skip > 0) {
                skip--;
                continue;
            }

            max--;
            if (max > 0) {
                try {
                    result.getObjects()
                            .add(createCMISObject(createNodeInfo(assocRef), filter, includeAllowableActions,
                                    IncludeRelationships.NONE, RENDITION_NONE, false, false/*, cmisVersion*/));
                } catch (CmisObjectNotFoundException e) {
                    // ignore objects that have not been found (perhaps because their type is unknown to CMIS)
                }
            } else {
                hasMore = true;
            }
        }
    }

    result.setNumItems(BigInteger.valueOf(counter));
    result.setHasMoreItems(hasMore);

    return result;
}

From source file:spade.reporter.Audit.java

/**
 * Converts syscall args: 'a0', 'a1', 'a2', and 'a3' from hexadecimal values to decimal values
 * /*ww w.j a  v a 2  s  . com*/
 * Conversion done based on the length of the hex value string. If length <= 8 then integer else a long.
 * If length > 16 then truncated to long.
 * 
 * Done so to avoid the issue of incorrectly fitting a small negative (i.e. int) value into a big (i.e. long) value
 * causing a wrong interpretation of bits.
 * 
 * @param eventData map that contains the above-mentioned args keys and values
 * @param time time of the event
 * @param eventId id of the event
 * @param syscall syscall of the event
 */
private void convertArgsHexToDec(Map<String, String> eventData, String time, String eventId, SYSCALL syscall) {
    String[] argKeys = { AuditEventReader.ARG0, AuditEventReader.ARG1, AuditEventReader.ARG2,
            AuditEventReader.ARG3 };
    for (String argKey : argKeys) {
        String hexArgValue = eventData.get(argKey);
        if (hexArgValue != null) {
            int hexArgValueLength = hexArgValue.length();
            try {
                BigInteger bigInt = new BigInteger(hexArgValue, 16);
                String argValueString = null;
                if (hexArgValueLength <= 8) {
                    int argInt = bigInt.intValue();
                    argValueString = Integer.toString(argInt);
                } else { // greater than 8
                    if (hexArgValueLength > 16) {
                        log(Level.SEVERE, "Truncated value for '" + argKey + "': '" + hexArgValue
                                + "'. Too big for 'long' datatype", null, time, eventId, syscall);
                    }
                    long argLong = bigInt.longValue();
                    argValueString = Long.toString(argLong);
                }
                eventData.put(argKey, argValueString);
            } catch (Exception e) {
                log(Level.SEVERE, "Non-numerical value for '" + argKey + "': '" + hexArgValue + "'", e, time,
                        eventId, syscall);
            }
        } else {
            log(Level.SEVERE, "NULL value for '" + argKey + "'", null, time, eventId, syscall);
        }
    }
}

From source file:org.alfresco.opencmis.CMISConnector.java

/**
 * Returns content changes.//w ww. j  ava2 s.  com
 */
public ObjectList getContentChanges(Holder<String> changeLogToken, BigInteger maxItems) {
    final ObjectListImpl result = new ObjectListImpl();
    result.setObjects(new ArrayList<ObjectData>());

    EntryIdCallback changeLogCollectingCallback = new EntryIdCallback(true) {
        @Override
        public boolean handleAuditEntry(Long entryId, String user, long time,
                Map<String, Serializable> values) {
            result.getObjects().addAll(createChangeEvents(time, values));
            return super.handleAuditEntry(entryId, user, time, values);
        }
    };

    Long from = null;
    if ((changeLogToken != null) && (changeLogToken.getValue() != null)) {
        try {
            from = Long.parseLong(changeLogToken.getValue());
        } catch (NumberFormatException e) {
            throw new CmisInvalidArgumentException("Invalid change log token: " + changeLogToken);
        }
    }

    AuditQueryParameters params = new AuditQueryParameters();
    params.setApplicationName(CMIS_CHANGELOG_AUDIT_APPLICATION);
    params.setForward(true);
    params.setFromId(from);

    int maxResults = (maxItems == null ? 0 : maxItems.intValue());
    maxResults = (maxResults < 1 ? 0 : maxResults + 1);

    auditService.auditQuery(changeLogCollectingCallback, params, maxResults);

    String newChangeLogToken = null;
    if (maxResults > 0) {
        if (result.getObjects().size() >= maxResults) {
            StringBuilder clt = new StringBuilder();
            newChangeLogToken = (from == null ? clt.append(maxItems.intValue() + 1).toString()
                    : clt.append(from.longValue() + maxItems.intValue()).toString());
            result.getObjects().remove(result.getObjects().size() - 1).getId();
            result.setHasMoreItems(true);
        } else {
            result.setHasMoreItems(false);
        }
    }

    if (changeLogToken != null) {
        changeLogToken.setValue(newChangeLogToken);
    }

    return result;
}

From source file:com.turborep.turbotracker.banking.service.BankingServiceImpl.java

@Override
public int getRecordChartsCount(ArrayList<?> theTransactionDetails, Integer moAccount) throws BankingException {
    StringBuilder aStringBuilder = new StringBuilder("");
    if (theTransactionDetails != null) {
        if (theTransactionDetails.get(0) != "" && theTransactionDetails.get(0) != null) {
            aStringBuilder.append("WHERE moAccountID =" + theTransactionDetails.get(0) + "");
        }// w w w.  j av a  2  s  . co  m
        if (theTransactionDetails.get(1) != "" && theTransactionDetails.get(1) != null
                && theTransactionDetails.get(2) != "" && theTransactionDetails.get(2) != null) {
            String aTranDateString = theTransactionDetails.get(1).toString();
            String aTranToDateString = theTransactionDetails.get(2).toString();
            String[] aTranSactionDate = aTranDateString.split("%2F");
            String[] aTranSactionToDate = aTranToDateString.split("%2F");
            String aFromTranDate = aTranSactionDate[2] + "-" + aTranSactionDate[0] + "-" + aTranSactionDate[1];
            String aToTranDate = aTranSactionToDate[2] + "-" + aTranSactionToDate[0] + "-"
                    + aTranSactionToDate[1];
            aStringBuilder.append(" AND date(TransactionDate) >= '" + aFromTranDate
                    + "' AND date(TransactionDate) <= '" + aToTranDate + "'");
        }
        if (theTransactionDetails.get(3) != "" && theTransactionDetails.get(3) != null) {
            aStringBuilder.append(" AND moTransactionTypeID =").append(theTransactionDetails.get(3));
        }
        if (theTransactionDetails.get(4) != "" && theTransactionDetails.get(4) != null) {
            aStringBuilder.append(" AND moTransactionTypeID =").append(theTransactionDetails.get(4));
        }
        if (theTransactionDetails.get(5) != "" && theTransactionDetails.get(5) != null) {
            aStringBuilder.append(" AND moTransactionTypeID =").append(theTransactionDetails.get(5));
        }
        if (theTransactionDetails.get(6) != "" && theTransactionDetails.get(6) != null) {
            aStringBuilder.append(" AND moTransactionTypeID =").append(theTransactionDetails.get(6));
        }
        if (theTransactionDetails.get(7) != "" && theTransactionDetails.get(7) != null) {
            aStringBuilder.append(" AND moTransactionTypeID =").append(theTransactionDetails.get(7));
        }
    } else {
        aStringBuilder.append("WHERE moAccountID =" + moAccount + "");
    }

    String aTransactionCountStr = "SELECT COUNT(moTransactionID) FROM moTransaction " + aStringBuilder;
    Session aSession = null;
    BigInteger aTotalCount = null;
    itsLogger.info("aTransactionCountStr==" + aTransactionCountStr);
    try {
        // Retrieve session from Hibernate
        aSession = itsSessionFactory.openSession();
        Query aQuery = aSession.createSQLQuery(aTransactionCountStr);
        List<?> aList = aQuery.list();
        aTotalCount = (BigInteger) aList.get(0);
    } catch (Exception e) {
        BankingException aBankingException = new BankingException(e.getMessage(), e);
        throw aBankingException;
    } finally {
        aSession.flush();
        aSession.close();
        aTransactionCountStr = null;
    }
    return aTotalCount.intValue();
}

From source file:com.turborep.turbotracker.banking.service.BankingServiceImpl.java

@Override
public BigInteger rePrintChecksInsert(Motransaction motrans, BigInteger startId, BigInteger endId,
        BigInteger chekcNo, Integer yearID, Integer periodID, String username) throws BankingException {
    itsLogger.debug("moTransaction Update");

    Session aSession = null;/*from  ww w .j  a v a2s.  c  o  m*/

    /*
     * Description: MoAccountID is Added to check#. 
     * Table:glLinkage
     * Reason: fetching Purpose
     */
    BigInteger startId1 = new BigInteger(motrans.getMoAccountId() + "" + startId);
    BigInteger endId1 = new BigInteger(motrans.getMoAccountId() + "" + endId);

    GlTransaction aGlTransaction = null;
    GlTransaction bGlTransaction = null;
    GlTransaction theGlTransaction = null;
    String updateQuery = null;
    //int newCheckValue = chekcNo.intValue();
    BigInteger referenceValue = chekcNo;
    int k = 0;
    try {
        Coledgersource aColedgersource = new Coledgersource();

        Cofiscalperiod aCofiscalperiod = accountingCyclesService.getCurrentPeriod(periodID);
        Cofiscalyear aCofiscalyear = accountingCyclesService.getCurrentYear(yearID);
        aColedgersource = gltransactionService.getColedgersourceDetail("WC");

        updateQuery = "SELECT distinct(glTransactionId),vebillID FROM glLinkage WHERE STATUS=0 AND coLedgerSourceId = "
                + aColedgersource.getCoLedgerSourceId() + " and vebillID  BETWEEN  " + startId1 + " AND "
                + endId1;
        itsLogger.info("Query : " + updateQuery);

        itsLogger.info("MoAccountID:---->" + motrans.getMoAccountId());

        aSession = itsSessionFactory.openSession();
        Query insQuery = aSession.createSQLQuery(updateQuery);
        Iterator<?> theIterator = insQuery.list().iterator();
        Transaction aSearchInsert = aSession.beginTransaction();
        ArrayList<GlTransaction> glTransactionList = new ArrayList<GlTransaction>();
        while (theIterator.hasNext()) {
            k++;
            aGlTransaction = new GlTransaction();
            theGlTransaction = new GlTransaction();
            Object[] aObj = (Object[]) theIterator.next();
            aGlTransaction = (GlTransaction) aSession.get(GlTransaction.class, ((Integer) aObj[0]));

            bGlTransaction = new GlTransaction();
            bGlTransaction.setBankClosingBalance(aGlTransaction.getBankClosingBalance());
            bGlTransaction.setBankOpeningBalance(aGlTransaction.getBankOpeningBalance());
            bGlTransaction.setCoAccountDesc(aGlTransaction.getCoAccountDesc());
            bGlTransaction.setCoAccountId(aGlTransaction.getCoAccountId());
            bGlTransaction.setCoAccountNumber(aGlTransaction.getCoAccountNumber());

            bGlTransaction.setCoFiscalPeriodId(aCofiscalperiod.getCoFiscalPeriodId());
            bGlTransaction.setpStartDate(aCofiscalperiod.getStartDate());
            bGlTransaction.setpEndDate(aCofiscalperiod.getEndDate());
            bGlTransaction.setPeriod(aCofiscalperiod.getPeriod());

            bGlTransaction.setCoFiscalYearId(aCofiscalyear.getCoFiscalYearId());
            bGlTransaction.setyStartDate(aCofiscalyear.getStartDate());
            bGlTransaction.setyStartDate(aCofiscalyear.getEndDate());
            bGlTransaction.setFyear(aCofiscalyear.getFiscalYear());

            bGlTransaction.setEntrydate(new Date());
            bGlTransaction.setEnteredBy(username);
            bGlTransaction.setTransactionDate(motrans.getTransactionDate());

            bGlTransaction.setHiddenstatus(aGlTransaction.getHiddenstatus());
            bGlTransaction.setJournalDesc(aGlTransaction.getJournalDesc());
            bGlTransaction.setJournalId(aGlTransaction.getJournalId());
            bGlTransaction.setOldcoAccountId(aGlTransaction.getOldcoAccountId());
            bGlTransaction.setOldcoAccountNumber(aGlTransaction.getOldcoAccountNumber());
            bGlTransaction.setStatus(aGlTransaction.getStatus());
            bGlTransaction.setTransactionDesc(aGlTransaction.getTransactionDesc());
            bGlTransaction.setPoNumber(referenceValue + "");
            bGlTransaction.setDebit(aGlTransaction.getDebit());
            bGlTransaction.setCredit(aGlTransaction.getCredit());
            glTransactionList.add(bGlTransaction);

            if (k % 2 == 0) {
                referenceValue = referenceValue.add(BigInteger.ONE);

                GlRollback glRollback = new GlRollback();
                glRollback.setVeBillID((Integer) aObj[1]);
                glRollback.setCoLedgerSourceID(aColedgersource.getCoLedgerSourceId());
                glRollback.setPeriodID(periodID);
                glRollback.setYearID(yearID);
                glRollback.setTransactionDate(motrans.getTransactionDate());

                gltransactionService.rollBackGlTransaction(glRollback);
            }
            itsLogger.info("Reference Val: " + referenceValue);
        }
        for (int a = 0; a < glTransactionList.size(); a++) {
            GlTransaction cGlTransaction = new GlTransaction();
            cGlTransaction = glTransactionList.get(a);
            Integer glID = 0;
            glID = (Integer) aSession.save(cGlTransaction);
            glLinkageInsert(aColedgersource, glID, Integer.parseInt(cGlTransaction.getPoNumber()),
                    motrans.getMoAccountId());

        }

        aSearchInsert.commit();

    } catch (Exception e) {
        itsLogger.error(e.getMessage(), e);
        BankingException aBankingException = new BankingException(e.getMessage(), e);
        throw aBankingException;
    } finally {
        aSession.flush();
        aSession.close();
        updateQuery = null;
    }

    String aCustomerQry = "SELECT * FROM moTransaction WHERE  CAST(reference AS UNSIGNED) BETWEEN " + startId
            + " AND " + endId + " AND moAccountID=" + motrans.getMoAccountId();
    itsLogger.info("Query : " + aCustomerQry);
    Motransaction aMotransaction = null;
    Motransaction aMotransactionUpdate = null;
    MoAccount aMoAccount = null;
    Query theQuery = null;
    BigInteger newCheckValue = chekcNo;
    try {
        aSession = itsSessionFactory.openSession();
        Query aQuery = aSession.createSQLQuery(aCustomerQry);
        Iterator<?> aIterator = aQuery.list().iterator();
        Transaction aSearchInsert = aSession.beginTransaction();
        while (aIterator.hasNext()) {
            aMotransaction = new Motransaction();
            Object[] aObj = (Object[]) aIterator.next();
            aMotransaction.setMoTransactionId((Integer) aObj[0]);
            aMotransactionUpdate = (Motransaction) aSession.get(Motransaction.class,
                    aMotransaction.getMoTransactionId());
            theQuery = aSession.createQuery(
                    "From VeBillPaymentHistory where checkNo='" + aMotransactionUpdate.getReference() + "'");
            List aList = theQuery.list();
            for (int n = 0; n < aList.size(); n++) {
                VeBillPaymentHistory objph = (VeBillPaymentHistory) aList.get(n);
                VeBillPaymentHistory objvbillph = (VeBillPaymentHistory) aSession
                        .get(VeBillPaymentHistory.class, objph.getPaymentHistoryID());
                objvbillph.setCheckNo(newCheckValue + "");
                aSession.save(objvbillph);
            }
            aMotransactionUpdate.setReference(newCheckValue + "");
            aSession.update(aMotransactionUpdate);
            newCheckValue = newCheckValue.add(BigInteger.ONE);
            itsLogger.info("New Check Val: " + newCheckValue);
            aMoAccount = new MoAccount();
            aMoAccount = (MoAccount) aSession.get(MoAccount.class, motrans.getMoAccountId());
            aMoAccount.setNextCheckNumber(newCheckValue.intValue());
            aSession.update(aMotransactionUpdate);

        }
        aSearchInsert.commit();
    } catch (Exception e) {
        itsLogger.error(e.getMessage(), e);
        BankingException aBankingException = new BankingException(e.getMessage(), e);
        throw aBankingException;
    }

    /*Session bSession = null;
    String InsertQry = "INSERT INTO motransaction " +
    "(rxMasterID,rxAddressID,coAccountID,moAccountId,TransactionDate," +
    "moTransactionTypeID,CheckType,reference,Description,void,reconciled," +
    "temprec,printed,amount,directdeposit) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
    Motransaction aSearchList = new Motransaction();
    try {
               
       bSession = itsSessionFactory.openSession();
       Transaction aSearchInsert = bSession.beginTransaction();
       Query aQuery = bSession.createSQLQuery(InsertQry);
       for (int i = 0; i < aQueryList.size(); i++) {
    aSearchList = (Motransaction) aQueryList.get(i);
    aQuery.setInteger(1, aSearchList.getRxMasterId());
    aQuery.setInteger(2, aSearchList.getRxAddressId());
    aQuery.setInteger(3, aSearchList.getCoAccountId());
    aQuery.setInteger(4, aSearchList.getMoAccountId());
    aQuery.setDate(5, aSearchList.getTransactionDate());
    aQuery.setInteger(6, aSearchList.getMoTransactionTypeId());
    aQuery.setInteger(7, aSearchList.getCheckType());
    aQuery.setString(8, newCheckValue+"");
    aQuery.setString(9, aSearchList.getDescription());
    aQuery.setInteger(10, aSearchList.getVoid_());
    aQuery.setInteger(11, aSearchList.getReconciled());
    aQuery.setInteger(12, aSearchList.getTempRec());
    aQuery.setInteger(13, aSearchList.getPrinted());
    aQuery.setBigDecimal(14, aSearchList.getAmount());
    aQuery.setInteger(15, aSearchList.getDirectDeposit());
            
    bSession.save(aQuery);
    if (i % 100 == 0) {
       aSession.flush();
       aSession.clear();
       Session aTransdetailSession = itsSessionFactory.openSession();
       Transaction aTransaction;
       try {
          aTransaction = aTransdetailSession.beginTransaction();
          aTransaction.begin();
          aTransdetailSession.delete(aSearchList);
          aTransaction.commit();
       } catch (Exception excep) {
          itsLogger.error(excep.getMessage(), excep);
          BankingException aBankingException = new BankingException(excep.getMessage(), excep);
          throw aBankingException;
       } finally {
          aTransdetailSession.flush();
          aTransdetailSession.close();
       }
    }
            
       }
       aSearchInsert.commit();
    } catch (Exception e) {
       itsLogger.error(e.getMessage(), e);
       BankingException aBankingException = new BankingException(e.getMessage(), e);
       throw aBankingException;
    }*/
    finally {
        aSession.flush();
        aSession.close();
        aCustomerQry = null;
    }
    return newCheckValue;
}

From source file:com.udojava.evalex.Expression.java

/**
 * Creates a new expression instance from an expression string with a given
 * default match context./*from   www .ja v  a  2s .co  m*/
 *
 * @param expression The expression. E.g. <code>"2.4*sin(3)/(2-4)"</code> or
 *                   <code>"sin(y)>0 & max(z, 3)>3"</code>
 */
public Expression(String expression, LinkedList<String> hist, Variables vars) {
    this.history = hist;
    this.expression = expression;

    mainVars = vars;

    addOperator(new Operator("+", 20, true, "Addition") {
        @Override
        public MyComplex eval(MyComplex v1, MyComplex v2) {
            if (v1.type == ValueType.ARRAY) {
                MyComplex vo = new MyComplex(v1.list);
                vo.list.add(v2);
                return vo;
            }
            return v1.add(v2);
        }
    });

    addOperator(new Operator("-", 20, true, "Subtraction") {
        @Override
        public MyComplex eval(MyComplex v1, MyComplex v2) {
            if (v1.type == ValueType.ARRAY) {
                MyComplex vo = new MyComplex(v1.list);
                vo.list.removeIf(o -> o.equals(v2));
                return vo;
            }
            return v1.subtract(v2);
        }
    });
    addOperator(new Operator("*", 30, true, "Real number multiplication") {
        @Override
        public MyComplex eval(MyComplex v1, MyComplex v2) {
            return v1.multiply(v2);
        }
    });
    addOperator(new Operator("/", 30, true, "Real number division") {
        @Override
        public MyComplex eval(MyComplex v1, MyComplex v2) {
            return v1.divide(v2);
        }
    });
    addOperator(new Operator("%", 30, true, "Remainder of integer division") {
        @Override
        public MyComplex eval(MyComplex v1, MyComplex v2) {
            double r = v1.real % v2.real;
            return new MyComplex(r);
        }
    });
    addOperator(
            new Operator("^", 40, false, "Exponentation. See: https://en.wikipedia.org/wiki/Exponentiation") {
                @Override
                public MyComplex eval(MyComplex v1, MyComplex v2) {
                    return v1.pow(v2);
                }
            });
    addOperator(new Operator("&&", 4, false, "Logical AND. Evaluates to 1 if both operands are not 0") {
        @Override
        public MyComplex eval(MyComplex v1, MyComplex v2) {
            boolean b1 = (v1.real == 0.0 && v2.real == 0.0);
            return new MyComplex(b1 ? 1 : 0);
        }
    });

    addOperator(new Operator("||", 2, false, "Logical OR. Evaluates to 0 if both operands are 0") {
        @Override
        public MyComplex eval(MyComplex v1, MyComplex v2) {
            boolean b1 = (v1.real == 0.0 && v2.real == 0.0);
            return new MyComplex(b1 ? 0 : 1);
        }
    });

    addOperator(new Operator(">", 10, false,
            "Greater than. See: See: https://en.wikipedia.org/wiki/Inequality_(mathematics)") {
        @Override
        public MyComplex eval(MyComplex v1, MyComplex v2) {
            if (v1.type == ValueType.REAL && v2.type == ValueType.REAL) {
                return new MyComplex(v1.real > v2.real ? 1 : 0);
            } else {
                return new MyComplex(v1.abs() > v2.abs() ? 1 : 0);
            }
        }
    });

    addOperator(new Operator(">=", 10, false, "Greater or equal") {
        @Override
        public MyComplex eval(MyComplex v1, MyComplex v2) {
            if (v1.type == ValueType.REAL && v2.type == ValueType.REAL) {
                return new MyComplex(v1.real >= v2.real ? 1 : 0);
            } else {
                return new MyComplex(v1.abs() >= v2.abs() ? 1 : 0);
            }
        }
    });

    addOperator(new Operator("<", 10, false,
            "Less than. See: https://en.wikipedia.org/wiki/Inequality_(mathematics)") {
        @Override
        public MyComplex eval(MyComplex v1, MyComplex v2) {
            if (v1.type == ValueType.REAL && v2.type == ValueType.REAL) {
                return new MyComplex(v1.real < v2.real ? 1 : 0);
            } else {
                return new MyComplex(v1.abs() < v2.abs() ? 1 : 0);
            }
        }
    });

    addOperator(new Operator("<=", 10, false, "less or equal") {
        @Override
        public MyComplex eval(MyComplex v1, MyComplex v2) {
            if (v1.type == ValueType.REAL && v2.type == ValueType.REAL) {
                return new MyComplex(v1.real <= v2.real ? 1 : 0);
            } else {
                return new MyComplex(v1.abs() <= v2.abs() ? 1 : 0);
            }
        }
    });

    addOperator(new Operator("->", 7, false, "Set variable v to new value ") {
        @Override
        public MyComplex eval(MyComplex v1, MyComplex v2) {
            if (v1 instanceof PitDecimal) {
                PitDecimal target = (PitDecimal) v1;
                String s = target.getVarToken();
                setVariable(s, v2);
                return v2;
            }
            throw new ExpressionException("LHS not variable");
        }
    });

    addOperator(new Operator("=", 7, false, "Equality") {
        @Override
        public MyComplex eval(MyComplex v1, MyComplex v2) {
            if (v1.type == ValueType.REAL && v2.type == ValueType.REAL) {
                return new MyComplex(v1.real == v2.real ? 1 : 0);
            } else {
                return new MyComplex(v1.abs() == v2.abs() ? 1 : 0);
            }
        }
    });

    addOperator(new Operator("!=", 7, false,
            "Inequality. See: https://en.wikipedia.org/wiki/Inequality_(mathematics)") {
        @Override
        public MyComplex eval(MyComplex v1, MyComplex v2) {
            if (v1.type == ValueType.REAL && v2.type == ValueType.REAL) {
                return new MyComplex(v1.real != v2.real ? 1 : 0);
            } else {
                return new MyComplex(v1.abs() != v2.abs() ? 1 : 0);
            }
        }
    });
    addOperator(
            new Operator("or", 7, false, "Bitwise OR. See: https://en.wikipedia.org/wiki/Logical_disjunction") {
                @Override
                public MyComplex eval(MyComplex v1, MyComplex v2) {
                    return new MyComplex((long) v1.real | (long) v2.real);
                }
            });
    addOperator(new Operator("and", 7, false,
            "Bitwise AND. See: https://en.wikipedia.org/wiki/Logical_conjunction") {
        @Override
        public MyComplex eval(MyComplex v1, MyComplex v2) {
            return new MyComplex((long) v1.real & (long) v2.real);
        }
    });
    addOperator(new Operator("xor", 7, false, "Bitwise XOR, See: https://en.wikipedia.org/wiki/Exclusive_or") {
        @Override
        public MyComplex eval(MyComplex v1, MyComplex v2) {
            return new MyComplex((long) v1.real ^ (long) v2.real);
        }
    });

    addOperator(new Operator("!", 50, true, "Factorial. See https://en.wikipedia.org/wiki/Factorial") {
        public BigInteger factorial(long n) {
            BigInteger factorial = BigInteger.ONE;
            for (long i = 1; i <= n; i++) {
                factorial = factorial.multiply(BigInteger.valueOf(i));
            }
            return factorial;
        }

        @Override
        public MyComplex eval(MyComplex v1, MyComplex v2) {
            BigInteger fact = factorial((long) v1.real);
            return new MyComplex(fact, BigInteger.ZERO);
        }
    });

    addOperator(new Operator("~", 8, false, "Bitwise negation") {
        @Override
        public MyComplex eval(MyComplex v1, MyComplex v2) {
            BigInteger bi = v2.toBigIntegerReal();
            int c = bi.bitLength();
            if (c == 0) {
                return new MyComplex(1);
            }
            for (int s = 0; s < c; s++) {
                bi = bi.flipBit(s);
            }
            return new MyComplex(bi);
        }
    });

    addOperator(new Operator("shl", 8, false, "Left Bit shift") {
        @Override
        public MyComplex eval(MyComplex v1, MyComplex v2) {
            return new MyComplex((long) v1.real << (long) v2.real);
        }
    });

    addOperator(new Operator("shr", 8, false, "Right bit shift") {
        @Override
        public MyComplex eval(MyComplex v1, MyComplex v2) {
            return new MyComplex((long) v1.real >>> (long) v2.real);
        }
    });

    addFunction(new Function("NOT", 1, "evaluates to 0 if argument != 0") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            boolean zero = parameters.get(0).abs() == 0;
            return new MyComplex(zero ? 1 : 0);
        }
    });

    addFunction(new Function("RND", 2, "Give random number in the range between first and second argument") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            double low = parameters.get(0).real;
            double high = parameters.get(1).real;
            return new MyComplex(low + Math.random() * (high - low));
        }
    });

    MersenneTwister mers = new MersenneTwister(System.nanoTime());

    addFunction(new Function("MRS", 0, "Mersenne twister random generator") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            return new MyComplex(mers.nextDouble());
        }
    });

    addFunction(new Function("BIN", 2, "Binomial Coefficient 'n choose k'") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            int n = (int) parameters.get(0).real;
            int k = (int) parameters.get(1).real;
            double d = CombinatoricsUtils.binomialCoefficientDouble(n, k);
            return new MyComplex(d);
        }
    });
    addFunction(new Function("STIR", 2,
            "Stirling number of 2nd kind: http://mathworld.wolfram.com/StirlingNumberoftheSecondKind.html") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            int n = (int) parameters.get(0).real;
            int k = (int) parameters.get(1).real;
            double d = CombinatoricsUtils.stirlingS2(n, k);
            return new MyComplex(d);
        }
    });

    addFunction(new Function("SIN", 1, "Sine function") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            return parameters.get(0).sin();
        }
    });
    addFunction(new Function("COS", 1, "Cosine function") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            return parameters.get(0).cos();
        }
    });
    addFunction(new Function("TAN", 1, "Tangent") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            return parameters.get(0).tan();
        }
    });
    addFunction(new Function("ASIN", 1, "Reverse Sine") { // added by av
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            return parameters.get(0).asin();
        }
    });
    addFunction(new Function("ACOS", 1, "Reverse Cosine") { // added by av
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            return parameters.get(0).acos();
        }
    });
    addFunction(new Function("ATAN", 1, "Reverse Tangent") { // added by av
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            return parameters.get(0).atan();
        }
    });
    addFunction(new Function("SINH", 1, "Hyperbolic Sine") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            return parameters.get(0).sinh();
        }
    });
    addFunction(new Function("COSH", 1, "Hyperbolic Cosine") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            return parameters.get(0).cosh();
        }
    });
    addFunction(new Function("TANH", 1, "Hyperbolic Tangent") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            return parameters.get(0).tanh();
        }
    });
    addFunction(new Function("RAD", 1, "Transform degree to radian") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            double d = Math.toRadians(parameters.get(0).real);
            return new MyComplex(d);
        }
    });
    addFunction(new Function("DEG", 1, "Transform radian to degree") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            double d = Math.toDegrees(parameters.get(0).real);
            return new MyComplex(d);
        }
    });
    addFunction(new Function("MAX", -1, "Find the biggest value in a list") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            MyComplex save = new MyComplex(Double.MIN_VALUE);
            if (parameters.size() == 0) {
                throw new ExpressionException("MAX requires at least one parameter");
            }
            //                if (parameters.get(0).type == ValueType.ARRAY)
            //                    parameters = parameters.get(0).list;
            if (parameters.get(0).type == ValueType.COMPLEX) {
                for (MyComplex parameter : parameters) {
                    if (parameter.abs() > save.abs()) {
                        save = parameter;
                    }
                }
                save.type = ValueType.COMPLEX;
            } else {
                for (MyComplex parameter : parameters) {
                    if (parameter.real > save.real) {
                        save = parameter;
                    }
                }
                save.type = ValueType.REAL;
            }
            return save;
        }
    });
    ///////////////////////////////////////////////////////
    addFunction(new Function("IF", 3, "Conditional: give param3 if param1 is 0, otherwise param2") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            if (parameters.get(0).real == 0.0) {
                return parameters.get(2);
            }
            return parameters.get(1);
        }
    });

    addFunction(new Function("PERC", 2, "Get param1 percent of param2") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            return parameters.get(0).divide(new MyComplex(100)).multiply(parameters.get(1));
        }
    });

    addFunction(new Function("PER", 2, "How many percent is param1 of param2") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            return parameters.get(0).multiply(new MyComplex(100)).divide(parameters.get(1));
        }
    });

    addFunction(new Function("H", 1, "Evaluate _history element") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            int i = (int) parameters.get(0).real;
            Expression ex = new Expression(history.get(i), history, mainVars);
            return ex.eval();
        }
    });

    addFunction(new Function("MERS", 1, "Calculate Mersenne Number") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            MyComplex p = parameters.get(0);
            return new MyComplex(2).pow(p).subtract(new MyComplex(1));
        }
    });

    addFunction(new Function("GCD", 2, "Find greatest common divisor of 2 values") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            double a = parameters.get(0).real;
            double b = parameters.get(1).real;
            long r = ArithmeticUtils.gcd((long) a, (long) b);
            return new MyComplex(r);
        }
    });
    addFunction(new Function("LCM", 2, "Find least common multiple of 2 values") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            double a = parameters.get(0).real;
            double b = parameters.get(1).real;
            long r = ArithmeticUtils.lcm((long) a, (long) b);
            return new MyComplex(r);
        }
    });
    addFunction(new Function("AMEAN", -1, "Arithmetic mean of a set of values") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            if (parameters.size() == 0) {
                throw new ExpressionException("MEAN requires at least one parameter");
            }
            Mean m = new Mean();
            double[] d = MyComplex.getRealArray(parameters);
            double d2 = m.evaluate(d);
            return new MyComplex(d2);
        }
    });
    //        addFunction(new Function("BYT", -1,
    //                "Value from sequence of bytes")
    //        {
    //            @Override
    //            public MyComplex eval (List<MyComplex> parameters)
    //            {
    //                if (parameters.size() == 0)
    //                {
    //                    return MyComplex.ZERO;
    //                }
    //                BigInteger res = BigInteger.ZERO;
    //                for (MyComplex parameter : parameters)
    //                {
    //                    if (parameter.intValue() < 0 || parameter.intValue() > 255)
    //                    {
    //                        throw new ExpressionException("not a byte value");
    //                    }
    //                    res = res.shiftLeft(8);
    //                    res = res.or(parameter.toBigInteger());
    //                }
    //                return new MyComplex(res, BigInteger.ZERO);
    //            }
    //        });
    addFunction(new Function("SEQ", 3, "Generate Sequence p1=start, p2=step, p3=count") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            double start = parameters.get(0).real;
            ArrayList<MyComplex> arr = new ArrayList<>();
            for (int s = 0; s < (int) (parameters.get(2).real); s++) {
                arr.add(new MyComplex(start));
                start += parameters.get(1).real;
            }
            return new MyComplex(arr);
        }
    });

    addFunction(new Function("PROD", -1, "Product of real values") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            Product p = new Product();
            double[] d = MyComplex.getRealArray(parameters);
            return new MyComplex(p.evaluate(d));
        }
    });

    addFunction(new Function("SUM", -1, "Sum of values") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            Sum p = new Sum();
            double[] d = MyComplex.getRealArray(parameters);
            return new MyComplex(p.evaluate(d));
        }
    });

    addFunction(new Function("ANG", 1, "Angle phi of complex number in radians") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            double b = parameters.get(0).angle();
            return new MyComplex(b);
        }
    });

    addFunction(new Function("IM", 1, "Get imaginary part") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            return new MyComplex(parameters.get(0).imaginary);
        }
    });

    addFunction(new Function("RE", 1, "Get real part") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            return new MyComplex(parameters.get(0).real);
        }
    });

    addFunction(new Function("POL", 2, "Make complex number from polar coords. angle is first arg") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            double angle = parameters.get(0).real;
            double len = parameters.get(1).real;
            Complex c = ComplexUtils.polar2Complex(len, angle);
            return new MyComplex(c);
        }
    });

    addFunction(new Function("GMEAN", -1, "Geometric mean of a set of values") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            if (parameters.size() == 0) {
                throw new ExpressionException("MEAN requires at least one parameter");
            }
            GeometricMean m = new GeometricMean();
            double[] d = MyComplex.getRealArray(parameters);
            double d2 = m.evaluate(d);
            return new MyComplex(d2);
        }
    });

    addFunction(new Function("HMEAN", -1, "Harmonic mean of a set of values") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            if (parameters.size() == 0) {
                throw new ExpressionException("MEAN requires at least one parameter");
            }
            MyComplex res = new MyComplex(0);
            int num = 0;
            for (MyComplex parameter : parameters) {
                res = res.add(new MyComplex(1).divide(parameter));
                num++;
            }
            res = new MyComplex(res.abs());
            return new MyComplex(num).divide(res);
        }
    });

    addFunction(new Function("VAR", -1, "Variance of a set of values") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            if (parameters.size() == 0) {
                throw new ExpressionException("MEAN requires at least one parameter");
            }
            double[] arr = new double[parameters.size()];
            for (int s = 0; s < parameters.size(); s++) {
                arr[s] = parameters.get(s).real;
            }
            return new MyComplex(variance(arr));
        }
    });

    addFunction(new Function("NPR", 1, "Next prime number greater or equal the argument") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            return new MyComplex(nextPrime((int) parameters.get(0).real));
        }
    });

    addFunction(new Function("NSWP", 1, "Swap nibbles") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            BigInteger bi = parameters.get(0).toBigIntegerReal();
            String s = bi.toString(16);
            s = new StringBuilder(s).reverse().toString();
            return new MyComplex(new BigInteger(s, 16), BigInteger.ZERO);
        }
    });

    addFunction(new Function("BSWP", 1, "Swap bytes") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            BigInteger bi = parameters.get(0).toBigIntegerReal();
            String s = bi.toString(16);
            while (s.length() % 4 != 0) {
                s = s + "0";
            }
            if (bi.intValue() < 256) {
                s = "00" + s;
            }
            s = Misc.reverseHex(s);
            return new MyComplex(new BigInteger(s, 16), BigInteger.ZERO);
        }
    });

    addFunction(new Function("PYT", 2,
            "Pythagoras's result = sqrt(param1^2+param2^2) https://en.wikipedia.org/wiki/Pythagorean_theorem") {
        @Override
        public MyComplex eval(List<MyComplex> par) {
            double a = par.get(0).real;
            double b = par.get(1).real;
            return new MyComplex(Math.sqrt(a * a + b * b));
        }
    });

    addFunction(new Function("FIB", 1, "Fibonacci number") {
        // --Commented out by Inspection (2/19/2017 7:46 PM):private final Operator exp = operators.get("^");

        @Override
        public MyComplex eval(List<MyComplex> par) {
            return Misc.iterativeFibonacci((int) par.get(0).real);
        }
    });

    ///////////////////////////////////////////////

    addFunction(new Function("MIN", -1, "Find the smallest in a list of values") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            MyComplex save = new MyComplex(Double.MAX_VALUE);
            if (parameters.size() == 0) {
                throw new ExpressionException("MAX requires at least one parameter");
            }
            if (parameters.get(0).type == ValueType.COMPLEX) {
                for (MyComplex parameter : parameters) {
                    if (parameter.abs() < save.abs()) {
                        save = parameter;
                    }
                }
                save.type = ValueType.COMPLEX;
            } else {
                for (MyComplex parameter : parameters) {
                    if (parameter.real < save.real) {
                        save = parameter;
                    }
                }
                save.type = ValueType.REAL;
            }
            return save;
        }
    });
    addFunction(new Function("ABS", 1, "Get absolute value of a number") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            return new MyComplex(parameters.get(0).abs());
        }
    });
    addFunction(new Function("LN", 1, "Logarithm base e of the argument") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            double d = Math.log(parameters.get(0).real);
            return new MyComplex(d);
        }
    });
    addFunction(new Function("LOG", 1, "Logarithm base 10 of the argument") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            double d = Math.log10(parameters.get(0).real);
            return new MyComplex(d);
        }
    });
    addFunction(new Function("FLOOR", 1, "Rounds DOWN to nearest Integer") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            double d = Math.floor(parameters.get(0).real);
            return new MyComplex(d);
        }
    });
    addFunction(new Function("CEIL", 1, "Rounds UP to nearest Integer") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            double d = Math.ceil(parameters.get(0).real);
            return new MyComplex(d);
        }
    });
    addFunction(new Function("ROU", 1, "Rounds to nearest Integer") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            int d = (int) (parameters.get(0).real + 0.5);
            return new MyComplex(d);
        }
    });
    addFunction(new Function("SQRT", 1, "Square root") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            MyComplex p = parameters.get(0);
            if (p.type == ValueType.REAL) {
                return new MyComplex(Math.sqrt(p.real));
            }
            return p.sqrt();
        }
    });
    addFunction(new Function("ARR", -1, "Create array") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            return new MyComplex(parameters);
        }
    });
    addFunction(new Function("POLY", -1, "Treat array as Polynom") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            double[] d = MyComplex.getRealArray(parameters);
            PolynomialFunction p = new PolynomialFunction(d);
            return new MyComplex(p);
        }
    });
    addFunction(new Function("DRVE", -1, "Make derivative of polynomial") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            PolynomialFunction p;
            if (parameters.get(0).isPoly()) {
                p = new PolynomialFunction(parameters.get(0).getRealArray());
            } else {
                double[] d = MyComplex.getRealArray(parameters);
                p = new PolynomialFunction(d);
            }
            return new MyComplex(p.polynomialDerivative());
        }
    });
    addFunction(new Function("ADRVE", -1, "Make antiderivative of polynomial. Constant is always zero") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            PolynomialFunction p;
            if (parameters.get(0).isPoly()) {
                p = new PolynomialFunction(parameters.get(0).getRealArray());
            } else {
                double[] d = MyComplex.getRealArray(parameters);
                p = new PolynomialFunction(d);
            }
            return new MyComplex(Misc.antiDerive(p));
        }
    });

    addFunction(new Function("PVAL", 2, "Compute value of polynom for the given argument.") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            if (parameters.get(0).isPoly()) {
                PolynomialFunction p = new PolynomialFunction(parameters.get(0).getRealArray());
                double v = p.value(parameters.get(1).real);
                return new MyComplex(v);
            }
            throw new ExpressionException("first arg must be polynomial");
        }
    });

    addFunction(new Function("INTGR", 3, "Numerical integration") {
        @Override
        public MyComplex eval(List<MyComplex> parameters) {
            if (parameters.get(0).isPoly()) {
                PolynomialFunction p = new PolynomialFunction(parameters.get(0).getRealArray());
                double start = parameters.get(1).real;
                double end = parameters.get(2).real;
                SimpsonIntegrator si = new SimpsonIntegrator();
                double d = si.integrate(1000, p, start, end);
                return new MyComplex(d);
            }
            throw new ExpressionException("first arg must be polynomial");
        }
    });

}