Example usage for java.lang Float isNaN

List of usage examples for java.lang Float isNaN

Introduction

In this page you can find the example usage for java.lang Float isNaN.

Prototype

public static boolean isNaN(float v) 

Source Link

Document

Returns true if the specified number is a Not-a-Number (NaN) value, false otherwise.

Usage

From source file:com.tmall.wireless.tangram3.dataparser.concrete.Card.java

@Nullable
public final LayoutHelper getLayoutHelper() {

    LayoutHelper helper = convertLayoutHelper(mLayoutHelper);

    // bind style to helper
    if (style != null && helper != null) {
        helper.setZIndex(style.zIndex);//www.  j ava2s.  co m

        if (helper instanceof BaseLayoutHelper) {
            BaseLayoutHelper baseHelper = (BaseLayoutHelper) helper;
            baseHelper.setBgColor(style.bgColor);
            if (!TextUtils.isEmpty(style.bgImgUrl)) {
                if (serviceManager != null && serviceManager.getService(CardSupport.class) != null) {
                    final CardSupport support = serviceManager.getService(CardSupport.class);
                    baseHelper.setLayoutViewBindListener(new BindListener(style) {
                        @Override
                        public void onBind(View layoutView, BaseLayoutHelper baseLayoutHelper) {
                            support.onBindBackgroundView(layoutView, Card.this);
                        }
                    });
                    baseHelper.setLayoutViewUnBindListener(new UnbindListener(style) {
                        @Override
                        public void onUnbind(View layoutView, BaseLayoutHelper baseLayoutHelper) {
                            support.onUnbindBackgroundView(layoutView, Card.this);
                        }
                    });
                } else {
                    baseHelper.setLayoutViewBindListener(new BindListener(style));
                    baseHelper.setLayoutViewUnBindListener(new UnbindListener(style));
                }
            } else {
                baseHelper.setLayoutViewBindListener(null);
                baseHelper.setLayoutViewUnBindListener(null);
            }

            if (!Float.isNaN(style.aspectRatio)) {
                // ((BaseLayoutHelper) helper).setAspectRatio(style.aspectRatio);
            }

        }

        if (helper instanceof FixAreaLayoutHelper) {
            FixAreaLayoutHelper fixHelper = (FixAreaLayoutHelper) helper;
            boolean hasCustomAnimatorHelper = false;
            if (serviceManager != null && serviceManager.getService(CardSupport.class) != null) {
                CardSupport support = serviceManager.getService(CardSupport.class);
                FixAreaLayoutHelper.FixViewAnimatorHelper viewAnimatorHelper = support
                        .onGetFixViewAppearAnimator(Card.this);
                if (viewAnimatorHelper != null) {
                    hasCustomAnimatorHelper = true;
                    fixHelper.setFixViewAnimatorHelper(viewAnimatorHelper);
                }
            }
            if (!hasCustomAnimatorHelper) {
                final int duration = style.extras != null
                        ? style.extras.getIntValue(Style.KEY_ANIMATION_DURATION)
                        : 0;
                if (duration > 0) {
                    fixHelper.setFixViewAnimatorHelper(new FixAreaLayoutHelper.FixViewAnimatorHelper() {
                        @Override
                        public ViewPropertyAnimator onGetFixViewAppearAnimator(View fixView) {
                            int height = fixView.getMeasuredHeight();
                            fixView.setTranslationY(-height);
                            return fixView.animate().translationYBy(height).setDuration(duration);
                        }

                        @Override
                        public ViewPropertyAnimator onGetFixViewDisappearAnimator(View fixView) {
                            int height = fixView.getMeasuredHeight();
                            return fixView.animate().translationYBy(-height).setDuration(duration);
                        }
                    });
                }
            }
        }

        if (helper instanceof MarginLayoutHelper) {
            ((MarginLayoutHelper) helper).setMargin(style.margin[Style.MARGIN_LEFT_INDEX],
                    style.margin[Style.MARGIN_TOP_INDEX], style.margin[Style.MARGIN_RIGHT_INDEX],
                    style.margin[Style.MARGIN_BOTTOM_INDEX]);
            ((MarginLayoutHelper) helper).setPadding(style.padding[Style.MARGIN_LEFT_INDEX],
                    style.padding[Style.MARGIN_TOP_INDEX], style.padding[Style.MARGIN_RIGHT_INDEX],
                    style.padding[Style.MARGIN_BOTTOM_INDEX]);
        }
    }

    if (mRetainLayout) {
        mLayoutHelper = helper;
    }

    return helper;
}

From source file:edu.cmu.lti.oaqa.knn4qa.apps.DataPointWrapper.java

@Override
public void run() {

    try {//w ww .j  a  v a2  s . c  om
        mAppRef.logger.info("Thread id=" + mThreadId + " is created, the total # of threads " + mThreadQty);

        CandidateProvider candProvider = mAppRef.mCandProviders[mThreadId];

        boolean addRankScores = mAppRef.mInMemExtrFinal != null && mAppRef.mInMemExtrFinal.addRankScores();

        for (int iq = 0; iq < mAppRef.mQueries.size(); ++iq)
            if (iq % mThreadQty == mThreadId) {
                Map<String, String> docFields = null;
                String docText = mAppRef.mQueries.get(iq);

                // 1. Parse a query
                try {
                    docFields = XmlHelper.parseXMLIndexEntry(docText);
                } catch (Exception e) {
                    mAppRef.logger.error("Parsing error, offending DOC:\n" + docText);
                    throw new Exception("Parsing error.");
                }

                String queryID = docFields.get(CandidateProvider.ID_FIELD_NAME);

                // 2. Obtain results
                long start = System.currentTimeMillis();

                CandidateInfo qres = candProvider.getCandidates(iq, docFields, mAppRef.mMaxCandRet);
                CandidateEntry[] resultsAll = qres.mEntries;

                long end = System.currentTimeMillis();
                long searchTimeMS = end - start;

                mAppRef.logger.info(String.format(
                        "Obtained results for the query # %d queryId='%s' thread ID=%d, the search took %d ms, we asked for max %d entries got %d",
                        iq, queryID, mThreadId, searchTimeMS, mAppRef.mMaxCandRet, resultsAll.length));

                mAppRef.mQueryTimeStat.addValue(searchTimeMS);
                mAppRef.mNumRetStat.addValue(qres.mNumFound);

                ArrayList<String> allDocIds = new ArrayList<String>();

                for (int rank = 0; rank < resultsAll.length; ++rank) {
                    CandidateEntry e = resultsAll[rank];
                    allDocIds.add(e.mDocId);
                    if (addRankScores)
                        e.mOrigRank = rank;
                }

                // allDocFeats will be first created by an intermediate re-ranker (if it exists).
                // If there is a final re-ranker, it will overwrite previously created features.
                Map<String, DenseVector> allDocFeats = null;
                Integer maxNumRet = mAppRef.mMaxNumRet;

                // 3. If necessary carry out an intermediate re-ranking
                if (mAppRef.mInMemExtrInterm != null) {
                    // Compute features once for all documents using an intermediate re-ranker
                    start = System.currentTimeMillis();
                    allDocFeats = mAppRef.mInMemExtrInterm.getFeatures(allDocIds, docFields);

                    DenseVector intermModelWeights = mAppRef.mModelInterm;

                    for (int rank = 0; rank < resultsAll.length; ++rank) {
                        CandidateEntry e = resultsAll[rank];
                        DenseVector feat = allDocFeats.get(e.mDocId);
                        e.mScore = (float) feat.dot(intermModelWeights);
                        if (Float.isNaN(e.mScore)) {
                            if (Float.isNaN(e.mScore)) {
                                mAppRef.logger.info("DocId=" + e.mDocId + " queryId=" + queryID);
                                mAppRef.logger.info("NAN scores, feature vector:");
                                mAppRef.logger.info(feat.toString());
                                mAppRef.logger.info("NAN scores, feature weights:");
                                mAppRef.logger.info(intermModelWeights.toString());
                                throw new Exception("NAN score encountered (intermediate reranker)!");
                            }
                        }
                    }
                    Arrays.sort(resultsAll);
                    // We may now need to update allDocIds and resultsAll to include only top-maxNumRet entries!
                    if (resultsAll.length > maxNumRet) {
                        allDocIds = new ArrayList<String>();
                        CandidateEntry resultsAllTrunc[] = Arrays.copyOf(resultsAll, maxNumRet);
                        resultsAll = resultsAllTrunc;
                        for (int rank = 0; rank < resultsAll.length; ++rank)
                            allDocIds.add(resultsAll[rank].mDocId);
                    }
                    end = System.currentTimeMillis();
                    long rerankIntermTimeMS = end - start;
                    mAppRef.logger.info(String.format(
                            "Intermediate-feature generation & re-ranking for the query # %d queryId='%s' thread ID=%d, took %d ms",
                            iq, queryID, mThreadId, rerankIntermTimeMS));
                    mAppRef.mIntermRerankTimeStat.addValue(rerankIntermTimeMS);
                }

                // 4. If QRELs are specified, we need to save results only for subsets that return a relevant entry. 
                //    Let's see what's the rank of the highest ranked entry. 
                //    If, e.g., the rank is 10, then we discard subsets having less than top-10 entries.
                int minRelevRank = Integer.MAX_VALUE;
                if (mAppRef.mQrels != null) {
                    for (int rank = 0; rank < resultsAll.length; ++rank) {
                        CandidateEntry e = resultsAll[rank];
                        String label = mAppRef.mQrels.get(queryID, e.mDocId);
                        if (CandidateProvider.isRelevLabel(label, 1)) {
                            e.mIsRelev = true;
                            minRelevRank = rank;
                            break;
                        }
                    }
                } else {
                    minRelevRank = 0;
                }

                // 5. If the final re-ranking model is specified, let's re-rank again and save all the results
                if (mAppRef.mInMemExtrFinal != null) {
                    if (allDocIds.size() > maxNumRet) {
                        throw new RuntimeException(
                                "Bug: allDocIds.size()=" + allDocIds.size() + " > maxNumRet=" + maxNumRet);
                    }
                    // Compute features once for all documents using a final re-ranker
                    start = System.currentTimeMillis();
                    allDocFeats = mAppRef.mInMemExtrFinal.getFeatures(allDocIds, docFields);
                    if (addRankScores) {
                        addScoresAndRanks(allDocFeats, resultsAll);
                    }

                    Ranker modelFinal = mAppRef.mModelFinal;

                    if (modelFinal != null) {
                        DataPointWrapper featRankLib = new DataPointWrapper();
                        for (int rank = 0; rank < resultsAll.length; ++rank) {
                            CandidateEntry e = resultsAll[rank];
                            DenseVector feat = allDocFeats.get(e.mDocId);
                            // It looks like eval is thread safe in RankLib 2.5.
                            featRankLib.assign(feat);
                            e.mScore = (float) modelFinal.eval(featRankLib);
                            if (Float.isNaN(e.mScore)) {
                                if (Float.isNaN(e.mScore)) {
                                    mAppRef.logger.info("DocId=" + e.mDocId + " queryId=" + queryID);
                                    mAppRef.logger.info("NAN scores, feature vector:");
                                    mAppRef.logger.info(feat.toString());
                                    throw new Exception("NAN score encountered (intermediate reranker)!");
                                }
                            }
                        }
                    }

                    end = System.currentTimeMillis();
                    long rerankFinalTimeMS = end - start;
                    mAppRef.logger.info(String.format(
                            "Final-feature generation & re-ranking for the query # %d queryId='%s' thread ID=%d, final. reranking took %d ms",
                            iq, queryID, mThreadId, rerankFinalTimeMS));
                    mAppRef.mFinalRerankTimeStat.addValue(rerankFinalTimeMS);
                }

                /* 
                 * After computing scores based on the final model, elements need to be resorted.
                 * However, this needs to be done *SEPARATELY* for each of the subset of top-K results.
                 */

                for (int k = 0; k < mAppRef.mNumRetArr.size(); ++k) {
                    int numRet = mAppRef.mNumRetArr.get(k);
                    if (numRet >= minRelevRank) {
                        CandidateEntry resultsCurr[] = Arrays.copyOf(resultsAll,
                                Math.min(numRet, resultsAll.length));
                        Arrays.sort(resultsCurr);
                        synchronized (mWriteLock) {
                            mAppRef.procResults(queryID, docFields, resultsCurr, numRet, allDocFeats);
                        }
                    }
                }
            }

        mAppRef.logger.info("Thread id=" + mThreadId + " finished!");
    } catch (Exception e) {
        e.printStackTrace();
        System.err.println("Unhandled exception: " + e + " ... exiting");
        System.exit(1);
    }
}

From source file:Armadillo.Analytics.Base.Precision.java

/**
 * Returns true if both arguments are NaN or if they are equal as defined
 * by {@link #equals(float,float,int) equals(x, y, maxUlps)}.
 *
 * @param x first value/*from  ww w .  j  ava2  s  . c  o  m*/
 * @param y second value
 * @param maxUlps {@code (maxUlps - 1)} is the number of floating point
 * values between {@code x} and {@code y}.
 * @return {@code true} if both arguments are NaN or if there are less than
 * {@code maxUlps} floating point values between {@code x} and {@code y}.
 * @since 2.2
 */
public static boolean equalsIncludingNaN(float x, float y, int maxUlps) {
    return (Float.isNaN(x) && Float.isNaN(y)) || equals(x, y, maxUlps);
}

From source file:routines.system.BigDataParserUtils.java

public static String parseTo_String(float input) {
    if (Float.isNaN(input)) {
        return null;
    }/*from  ww  w . java  2  s.  c  o m*/
    return String.valueOf(input);
}

From source file:net.myrrix.common.math.MatrixUtils.java

/**
 * @param M matrix to print//from  www .j a  v  a 2s.  c o m
 * @return a print-friendly rendering of a sparse matrix. Not useful for wide matrices.
 */
public static String matrixToString(FastByIDMap<FastByIDFloatMap> M) {
    StringBuilder result = new StringBuilder();
    long[] colKeys = unionColumnKeysInOrder(M);
    appendWithPadOrTruncate("", result);
    for (long colKey : colKeys) {
        result.append('\t');
        appendWithPadOrTruncate(colKey, result);
    }
    result.append("\n\n");
    long[] rowKeys = keysInOrder(M);
    for (long rowKey : rowKeys) {
        appendWithPadOrTruncate(rowKey, result);
        FastByIDFloatMap row = M.get(rowKey);
        for (long colKey : colKeys) {
            result.append('\t');
            float value = row.get(colKey);
            if (Float.isNaN(value)) {
                appendWithPadOrTruncate("", result);
            } else {
                appendWithPadOrTruncate(value, result);
            }
        }
        result.append('\n');
    }
    result.append('\n');
    return result.toString();
}

From source file:gdsc.smlm.engine.FitWorker.java

/**
 * Locate all the peaks in the image specified by the fit job
 * <p>/*from   w  w  w .  j a  v a  2s . com*/
 * WARNING: The FitWorker fits a sub-region of the data for each maxima. It then updates the FitResult parameters
 * with an offset reflecting the position. The initialParameters are not updated with this offset unless configured.
 * 
 * @param job
 *            The fit job
 */
public void run(FitJob job) {
    final long start = System.nanoTime();
    job.start();
    this.slice = job.slice;

    // Used for debugging
    //if (logger == null) logger = new gdsc.fitting.logging.ConsoleLogger();

    // Crop to the ROI
    bounds = job.bounds;
    int width = bounds.width;
    int height = bounds.height;
    borderLimitX = width - border;
    borderLimitY = height - border;
    data = job.data;

    FitParameters params = job.getFitParameters();
    this.endT = (params != null) ? params.endT : -1;

    Spot[] spots = indentifySpots(job, width, height, params);

    if (spots.length == 0) {
        finish(job, start);
        return;
    }

    fittedBackground = 0;

    allocateArrays(spots.length);

    // Always get the noise and store it with the results.
    boolean updatedNoise = false;
    if (params != null && !Float.isNaN(params.noise)) {
        noise = params.noise;
        updatedNoise = true;
    } else if (calculateNoise) {
        noise = estimateNoise(data, width, height, config.getNoiseMethod());
        updatedNoise = true;
    }
    if (updatedNoise)
        fitConfig.setNoise(noise);

    // Get the background
    if (params != null && !Float.isNaN(params.background)) {
        background = params.background;
    } else {
        background = estimateBackground(width, height);
    }

    //System.out.printf("Slice %d : Noise = %g\n", slice, noise);
    if (logger != null)
        logger.info("Slice %d: Noise = %f : Background = %f", slice, noise, background);

    ResultFilter filter = null;

    if (params != null && params.fitTask == FitTask.MAXIMA_IDENITIFICATION) {
        final float sd0 = (float) fitConfig.getInitialPeakStdDev0();
        final float sd1 = (float) fitConfig.getInitialPeakStdDev1();
        ImageExtractor ie = new ImageExtractor(data, width, height);
        double[] region = null;
        for (int n = 0; n < spots.length; n++) {
            // Find the background using the perimeter of the data.
            // TODO - Perhaps the Gaussian Fitter should be used to produce the initial estimates but no actual fit done.
            // This would produce coords using the centre-of-mass.
            final int x = spots[n].x;
            final int y = spots[n].y;
            Rectangle regionBounds = ie.getBoxRegionBounds(x, y, fitting);
            region = ie.crop(regionBounds, region);
            final float b = (float) Gaussian2DFitter.getBackground(region, regionBounds.width,
                    regionBounds.height, 1);

            // Offset the coords to the centre of the pixel. Note the bounds will be added later.
            // Subtract the background to get the amplitude estimate then convert to signal.
            final float amplitude = spots[n].intensity - ((relativeIntensity) ? 0 : b);
            final float signal = (float) (amplitude * 2.0 * Math.PI * sd0 * sd1);
            final float[] peakParams = new float[] { b, signal, 0, x + 0.5f, y + 0.5f, sd0, sd1 };
            final int index = y * width + x;
            sliceResults.add(createResult(bounds.x + x, bounds.y + y, data[index], 0, noise, peakParams, null));
        }
    } else {
        // Perform the Gaussian fit
        int success = 0;

        // Track failures
        int[] failed = new int[spots.length];
        int failedCount = 0;

        // Allow the results to be filtered for certain peaks
        if (params != null && params.filter != null) {
            // TODO - Check if this works.
            filter = new DistanceResultFilter(params.filter, params.distanceThreshold, spots.length);
            //filter = new OptimumDistanceResultFilter(params.filter, params.distanceThreshold, maxIndices.length);
        }

        // Extract each peak and fit individually until N consecutive failures
        ImageExtractor ie = new ImageExtractor(data, width, height);
        double[] region = null;
        for (int n = 0, failures = 0; n < spots.length && !finished; n++) {
            failures++;

            final int x = spots[n].x;
            final int y = spots[n].y;
            final int index = y * width + x;

            Rectangle regionBounds = ie.getBoxRegionBounds(x, y, fitting);
            region = ie.crop(regionBounds, region);

            if (logger != null)
                logger.info("Fitting %d:%d [%d,%d]", slice, n + 1, x + bounds.x, y + bounds.y);

            FitResult fitResult = fit(gf, region, regionBounds, spots, n);
            job.setFitResult(n, fitResult);

            // Q. Should we add the regionBounds offset here to the params and initialParams in the FitResult?

            // Check fit result
            if (fitResult.getStatus() == FitStatus.OK) {
                double[] peakParams = fitResult.getParameters();
                convertParameters(peakParams);

                double[] peakParamsDev = null;
                if (fitConfig.isComputeDeviations()) {
                    peakParamsDev = fitResult.getParameterStdDev();
                    if (peakParamsDev != null)
                        convertParameters(peakParamsDev);
                }

                int npeaks = addResults(sliceResults, n, x, y, bounds, regionBounds, peakParams, peakParamsDev,
                        data[index], fitResult.getError(), noise);

                // Add to filtered output results
                if (filter != null && npeaks != 0) {
                    // Check all result peaks for the distance to the filter positions
                    PeakResult[] results = new PeakResult[npeaks];
                    for (int i = sliceResults.size(); npeaks-- > 0;) {
                        results[npeaks] = sliceResults.get(--i);
                    }
                    filter.filter(fitResult, index, results);
                }

                // Q. Should this be a failure if the npeaks == 0 (i.e. outside the border; was a duplicate)
                // or if the filter removed a peak?
                // At the moment just let the fitting continue until real failures occur.
                failures = 0;
                success++;
            } else {
                // Add to filtered output results
                if (filter != null) {
                    // Check the start position for the distance to the filter positions
                    filter.filter(fitResult, index, x + 0.5f, y + 0.5f);
                }

                // Add the failed jobs to a list.
                failed[failedCount++] = n;

                if (updateInitialParameters)
                    // Update the coordinates for failed fits
                    updateCoordinates(regionBounds, fitResult.getParameters());
            }

            if (updateInitialParameters)
                // Update the initial coordinates
                updateCoordinates(regionBounds, fitResult.getInitialParameters());

            if (config.getFailuresLimit() != 0 && failures >= config.getFailuresLimit())
                break;
        }

        if (logger != null)
            logger.info("Slice %d: %d / %d", slice, success, spots.length);
    }

    float offsetx = bounds.x;
    float offsety = bounds.y;

    if (params != null && params.getOffset() != null) {
        offsetx += params.getOffset()[0];
        offsety += params.getOffset()[1];
    }

    // Add the ROI bounds to the fitted peaks
    for (PeakResult result : sliceResults) {
        result.params[Gaussian2DFunction.X_POSITION] += offsetx;
        result.params[Gaussian2DFunction.Y_POSITION] += offsety;
    }

    // Check if only selected peaks should be added to the results
    if (filter != null) {
        filter.finalise();
        job.setResults(filter.getResults());
        job.setIndices(filter.getMaxIndices());

        for (int i = 0; i < filter.getFilteredCount(); i++)
            job.setFitResult(i, filter.getFitResults()[i]);

        this.results.addAll(filter.getResults());
    } else {
        this.results.addAll(sliceResults);
    }

    finish(job, start);
}

From source file:Vector3f.java

/**
 * Returns <code>true</code> if vector is {@link Float#NEGATIVE_INFINITY},
 * {@link Float#POSITIVE_INFINITY} or {@link Float#NaN}
 * @return  <code>true</code> if vector is {@link Float#NEGATIVE_INFINITY},
 * {@link Float#POSITIVE_INFINITY} or {@link Float#NaN}.
 *///from   w w  w  .  j  a v a 2  s.c om
public boolean isInvalid() {
    return Float.isInfinite(x) || Float.isInfinite(y) || Float.isInfinite(z) || Float.isNaN(x) || Float.isNaN(y)
            || Float.isNaN(z);
}

From source file:com.neophob.sematrix.core.jmx.PixelControllerStatus.java

/**
 * Gets the average buffer value.//from ww w  .  j  a  v a 2 s  . c o  m
 *
 * @param circularFifoBuffer the circular fifo buffer
 * @return returns average value of all buffer entries
 */
private static float getAverageBufferValue(CircularFifoBuffer circularFifoBuffer) {
    // handle null instance
    if (circularFifoBuffer == null) {
        return 0f;
    }
    // calculate sum of all buffer values
    float bufferSum = 0f;
    @SuppressWarnings("rawtypes")
    Iterator iterator = circularFifoBuffer.iterator();
    while (iterator.hasNext()) {
        bufferSum += (Long) iterator.next();
    }
    // return average value
    float result = bufferSum / circularFifoBuffer.size();
    if (Float.isNaN(result)) {
        result = 0f;
    }
    return result;
}

From source file:com.frank.search.solr.core.QueryParserBase.java

/**
 * Creates query string representation of a single critiera
 *
 * @param part/*from  ww  w .j  a v a2  s.  co  m*/
 * @return
 */
protected String createQueryFragmentForCriteria(Criteria part) {
    Criteria criteria = (Criteria) part;
    StringBuilder queryFragment = new StringBuilder();
    boolean singeEntryCriteria = (criteria.getPredicates().size() == 1);
    if (criteria instanceof QueryStringHolder) {
        return ((QueryStringHolder) criteria).getQueryString();
    }

    String fieldName = getNullsafeFieldName(criteria.getField());
    if (criteria.isNegating()) {
        fieldName = NOT + fieldName;
    }
    if (!StringUtils.isEmpty(fieldName) && !containsFunctionCriteria(criteria.getPredicates())) {
        queryFragment.append(fieldName);
        queryFragment.append(DELIMINATOR);
    }

    // no criteria given is defaulted to not null
    if (criteria.getPredicates().isEmpty()) {
        queryFragment.append("[* TO *]");
        return queryFragment.toString();
    }

    if (!singeEntryCriteria) {
        queryFragment.append("(");
    }

    CriteriaQueryStringValueProvider valueProvider = new CriteriaQueryStringValueProvider(criteria);
    while (valueProvider.hasNext()) {
        queryFragment.append(valueProvider.next());
        if (valueProvider.hasNext()) {
            queryFragment.append(CRITERIA_VALUE_SEPERATOR);
        }
    }

    if (!singeEntryCriteria) {
        queryFragment.append(")");
    }
    if (!Float.isNaN(criteria.getBoost())) {
        queryFragment.append(BOOST + criteria.getBoost());
    }

    return queryFragment.toString();
}

From source file:eu.itesla_project.modelica_export.records.GeneratorRecord.java

@Override
public void createRecord(ModExportContext modContext, DDBManager ddbManager, SimulatorInst simulator) {
    if (!Float.isNaN(this.busInfo.getBus().getV()) && this.busInfo.isConnected()) {
        if (super.isCorrect()) {
            if (!busInfo.isConnected()) {
                this.addValue(StaticData.COMMENT);
            }//from w  ww .j  a  va2s . co m
            if (super.getModelicaType() != null) {
                this.addValue(super.getModelicaType() + StaticData.WHITE_SPACE);
            } else {
                if (!isInyection) {
                    this.addValue(DEFAULT_GEN_TYPE + StaticData.WHITE_SPACE);
                } else {
                    this.addValue(DEFAULT_GEN_LOAD_TYPE + StaticData.WHITE_SPACE);
                }
            }
            this.addValue(super.getModelicaName());
            this.addValue(" (");
            this.addValue(StaticData.NEW_LINE);
            //If it is a generator or injection it will have different parameters
            if ((iidmgenParameters != null) && (!iidmgenParameters.isEmpty())) {
                for (int i = 0; i < iidmgenParameters.size() - 1; i++) {
                    if (!busInfo.isConnected()) {
                        this.addValue(StaticData.COMMENT);
                    }
                    if (iidmgenParameters.get(i).getName().equals(PsseFixedData.Mbase) && this.changedMbse) {
                        this.addValue("\t " + iidmgenParameters.get(i).getName() + " = "
                                + iidmgenParameters.get(i).getValue()
                                + ", // Mbase has been changed: Mbase > SQRT(P^2 + Q^2)");
                    } else {
                        this.addValue("\t " + iidmgenParameters.get(i).getName() + " = "
                                + iidmgenParameters.get(i).getValue() + ", ");
                    }
                    this.addValue(StaticData.NEW_LINE);
                }
                if (!busInfo.isConnected()) {
                    this.addValue(StaticData.COMMENT);
                }
                if (isInyection) {
                    this.addValue("\t " + iidmgenParameters.get(iidmgenParameters.size() - 1).getName() + " = "
                            + iidmgenParameters.get(iidmgenParameters.size() - 1).getValue());
                } else if ((genParameters != null) && (!genParameters.isEmpty())) {
                    if (iidmgenParameters.get(iidmgenParameters.size() - 1).getName()
                            .equals(PsseFixedData.Mbase) && this.changedMbse) {
                        this.addValue("\t " + iidmgenParameters.get(iidmgenParameters.size() - 1).getName()
                                + " = " + iidmgenParameters.get(iidmgenParameters.size() - 1).getValue()
                                + ", // Mbase has been changed: Mbase > SQRT(P^2 + Q^2)");
                    } else {
                        this.addValue("\t " + iidmgenParameters.get(iidmgenParameters.size() - 1).getName()
                                + " = " + iidmgenParameters.get(iidmgenParameters.size() - 1).getValue() + ",");
                    }
                }
                this.addValue(StaticData.NEW_LINE);
            }
            if (!isInyection) {
                if ((genParameters != null) && (!genParameters.isEmpty())) {
                    for (int i = 0; i < genParameters.size() - 1; i++) {
                        if (!busInfo.isConnected()) {
                            this.addValue(StaticData.COMMENT);
                        }
                        this.addValue("\t " + genParameters.get(i).getName() + " = "
                                + genParameters.get(i).getValue() + ",");
                        this.addValue(StaticData.NEW_LINE);
                    }
                    if (!busInfo.isConnected()) {
                        this.addValue(StaticData.COMMENT);
                    }
                    this.addValue("\t " + genParameters.get(genParameters.size() - 1).getName() + " = "
                            + genParameters.get(genParameters.size() - 1).getValue());
                    this.addValue(StaticData.NEW_LINE);
                }
            }
            if (!this.busInfo.isConnected()) {
                this.addValue(StaticData.COMMENT);
            }
            this.addValue("\t " + EurostagFixedData.ANNOT);
            genParameters = null;
            iidmgenParameters = null;
        } else {
            _log.error(this.getModelicaName() + " not added to grid model.");
        }
    } else {
        _log.warn("Generator " + this.getModelicaName() + " disconnected.");
        this.addValue(StaticData.COMMENT + " Generator " + this.getModelicaName() + " disconnected.");
    }
}