Example usage for java.lang Float NaN

List of usage examples for java.lang Float NaN

Introduction

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

Prototype

float NaN

To view the source code for java.lang Float NaN.

Click Source Link

Document

A constant holding a Not-a-Number (NaN) value of type float .

Usage

From source file:com.frank.search.solr.core.query.Criteria.java

/**
 * Crates new {@link Criteria.Predicate} with trailing {@code ~}
 *
 * @param s
 * @return
 */
public Criteria fuzzy(String s) {
    return fuzzy(s, Float.NaN);
}

From source file:gdsc.core.utils.MedianWindowDLLFloat.java

/**
 * Compute the median for the input data using a range of time points. The first time point added is t=0. Time
 * points after that have a positive index. The maximum allowed index is the data length-1
 * //from   ww  w . j  a v a 2s .c  o  m
 * @param start
 * @param end
 * @return the median
 */
public float getMedian(int start, int end) {
    end = FastMath.min(data.length - 1, Math.abs(end));
    start = FastMath.max(0, Math.abs(start));

    final int length = end - start + 1;
    if (length == 0)
        return Float.NaN;

    // Find the head of the list
    Data head = median;
    while (head.s != null)
        head = head.s;

    // Create a list of the data using only the desired time points
    Data[] list = new Data[length];

    // Extract the data into a list. This should be sorted.
    int i = 0;
    while (head != null) {
        final int age = (data.length + head.i - t) % data.length;
        if (age >= start && age <= end)
            list[i++] = head;
        head = head.g;
    }

    return (list[(list.length - 1) / 2].v + list[list.length / 2].v) * 0.5f;
}

From source file:io.github.protino.codewatch.ui.ProjectDetailsFragment.java

private void displayData() {
    setUpBarChart();/*from  w ww  . ja v a2s .c o  m*/

    setUpPieChart(pieChartLanguages, project.getLanguageList(), LANGUAGE_CHART_ID);
    setUpPieChart(pieChartEditors, project.getEditorPaiList(), EDITORS_CHART_ID);
    setUpPieChart(pieChartOs, project.getOsPairList(), OS_CHART_ID);

    setUpOnExpandRecyclerView(languagesListview, LANGUAGE_CHART_ID);
    setUpOnExpandRecyclerView(editorsListView, EDITORS_CHART_ID);
    setUpOnExpandRecyclerView(osListview, OS_CHART_ID);

    pieChartLanguages.animateXY(1500, 1500);
    pieChartEditors.animateXY(1500, 1500);
    pieChartOs.animateXY(1500, 1500);

    setListeners();

    isExpandedMap.clear();
    if (languageHighlightedEntryX != null) {
        pieChartLanguages.highlightValue(new Highlight(languageHighlightedEntryX, Float.NaN, 0), true);
    }

    if (editorHighlightedEntryX != null) {
        pieChartEditors.highlightValue(new Highlight(editorHighlightedEntryX, Float.NaN, 0), true);
    }

    if (osHighlightedEntryX != null) {
        pieChartOs.highlightValue(new Highlight(osHighlightedEntryX, Float.NaN, 0), true);
    }
}

From source file:org.codelibs.fess.api.gsa.GsaApiManager.java

protected void processSearchRequest(final HttpServletRequest request, final HttpServletResponse response,
        final FilterChain chain) {
    final SearchService searchService = ComponentUtil.getComponent(SearchService.class);
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final boolean xmlDtd = OUTPUT_XML.equals(request.getParameter("output"));

    if (!fessConfig.isAcceptedSearchReferer(request.getHeader("referer"))) {
        writeXmlResponse(99, xmlDtd, StringUtil.EMPTY, "Referer is invalid.");
        return;// w w w  . j  av a 2 s  .  c om
    }

    int status = 0;
    String errMsg = StringUtil.EMPTY;
    String query = null;
    final StringBuilder buf = new StringBuilder(1000);
    request.setAttribute(Constants.SEARCH_LOG_ACCESS_TYPE, Constants.SEARCH_LOG_ACCESS_TYPE_GSA);
    try {
        final SearchRenderData data = new SearchRenderData();
        final GsaRequestParams params = new GsaRequestParams(request, fessConfig);
        query = params.getQuery();
        searchService.search(params, data, OptionalThing.empty());
        final String execTime = data.getExecTime();
        final long allRecordCount = data.getAllRecordCount();
        final List<Map<String, Object>> documentItems = data.getDocumentItems();

        final List<String> getFields = new ArrayList<>();
        // meta tags should be returned
        final String getFieldsParam = request.getParameter("getfields");
        if (StringUtil.isNotBlank(getFieldsParam)) {
            getFields.addAll(Arrays.asList(getFieldsParam.split("\\.")));
        }
        final StringBuilder requestUri = new StringBuilder(request.getRequestURI());
        if (request.getQueryString() != null) {
            requestUri.append("?").append(request.getQueryString());
        }
        final String uriQueryString = requestUri.toString();
        // Input/Output encoding
        final String ie = request.getCharacterEncoding();
        final String oe = "UTF-8";
        // IP address
        final String ip = ComponentUtil.getViewHelper().getClientIp(request);

        buf.append("<TM>");
        buf.append(execTime);
        buf.append("</TM>");
        buf.append("<Q>");
        buf.append(escapeXml(query));
        buf.append("</Q>");
        for (final Entry<String, String[]> entry : request.getParameterMap().entrySet()) {
            final String[] values = entry.getValue();
            if (values == null) {
                continue;
            }
            final String key = entry.getKey();
            if ("sort".equals(key)) {
                continue;
            }
            for (final String value : values) {
                appendParam(buf, key, value);
            }
        }
        appendParam(buf, "ie", ie);
        if (request.getParameter("oe") == null) {
            appendParam(buf, "oe", oe);
        }
        final String[] langs = params.getLanguages();
        if (langs.length > 0) {
            appendParam(buf, "inlang", langs[0]);
            appendParam(buf, "ulang", langs[0]);
        }
        appendParam(buf, "ip", ip);
        appendParam(buf, "access", "p");
        appendParam(buf, "sort", params.getSortParam(), params.getSortParam());
        appendParam(buf, "entqr", "3");
        appendParam(buf, "entqrm", "0");
        appendParam(buf, "wc", "200");
        appendParam(buf, "wc_mc", "1");
        if (!documentItems.isEmpty()) {
            buf.append("<RES SN=\"");
            buf.append(data.getCurrentStartRecordNumber());
            buf.append("\" EN=\"");
            buf.append(data.getCurrentEndRecordNumber());
            buf.append("\">");
            buf.append("<M>");
            buf.append(allRecordCount);
            buf.append("</M>");
            if (data.isExistPrevPage() || data.isExistNextPage()) {
                buf.append("<NB>");
                if (data.isExistPrevPage()) {
                    long s = data.getCurrentStartRecordNumber() - data.getPageSize() - 1;
                    if (s < 0) {
                        s = 0;
                    }
                    buf.append("<PU>");
                    buf.append(escapeXml(uriQueryString.replaceFirst("start=([0-9]+)", "start=" + s)));
                    buf.append("</PU>");
                }
                if (data.isExistNextPage()) {
                    buf.append("<NU>");
                    buf.append(escapeXml(uriQueryString.replaceFirst("start=([0-9]+)",
                            "start=" + data.getCurrentEndRecordNumber())));
                    buf.append("</NU>");
                }
                buf.append("</NB>");
            }
            long recordNumber = data.getCurrentStartRecordNumber();
            for (final Map<String, Object> document : documentItems) {
                buf.append("<R N=\"");
                buf.append(recordNumber);
                buf.append("\">");
                final String url = DocumentUtil.getValue(document, fessConfig.getIndexFieldUrl(), String.class);
                document.put("UE", url);
                document.put("U", URLDecoder.decode(url, Constants.UTF_8));
                document.put("T", DocumentUtil.getValue(document, fessConfig.getResponseFieldContentTitle(),
                        String.class));
                final float score = DocumentUtil.getValue(document, Constants.SCORE, Float.class, Float.NaN);
                int rk = 10;
                if (!Float.isNaN(score)) {
                    if (score < 0.0) {
                        rk = 0;
                    } else if (score > 1.0) {
                        rk = 10;
                    } else {
                        rk = (int) (score * 10.0);
                    }
                }
                document.put("RK", rk);
                document.put("S", DocumentUtil.getValue(document,
                        fessConfig.getResponseFieldContentDescription(), String.class, StringUtil.EMPTY));
                final String lang = DocumentUtil.getValue(document, fessConfig.getIndexFieldLang(),
                        String.class);
                if (StringUtil.isNotBlank(lang)) {
                    document.put("LANG", lang);
                    document.remove(fessConfig.getIndexFieldLang());
                }
                final String gsaMetaPrefix = fessConfig.getQueryGsaMetaPrefix();
                for (final Map.Entry<String, Object> entry : document.entrySet()) {
                    final String name = entry.getKey();
                    if (StringUtil.isNotBlank(name) && entry.getValue() != null
                            && fessConfig.isGsaResponseFields(name)) {
                        if (name.startsWith(gsaMetaPrefix)) {
                            final String tagName = name.replaceFirst("^" + gsaMetaPrefix, StringUtil.EMPTY);
                            if (getFields.contains(tagName)) {
                                buf.append("<MT N=\"");
                                buf.append(tagName);
                                buf.append("\" V=\"");
                                buf.append(escapeXml(entry.getValue()));
                                buf.append("\"/>");
                            }
                        } else {
                            final String tagName = name;
                            buf.append('<');
                            buf.append(tagName);
                            buf.append('>');
                            buf.append(escapeXml(entry.getValue()));
                            buf.append("</");
                            buf.append(tagName);
                            buf.append('>');
                        }
                    }
                }
                buf.append("<ENT_SOURCE>").append(escapeXml("FESS")).append("</ENT_SOURCE>");
                String lastModified = DocumentUtil.getValue(document, fessConfig.getIndexFieldLastModified(),
                        String.class);
                if (StringUtil.isBlank(lastModified)) {
                    lastModified = StringUtil.EMPTY;
                }
                lastModified = lastModified.split("T")[0];
                buf.append("<FS NAME=\"date\" VALUE=\"").append(escapeXml(lastModified)).append("\"/>");

                buf.append("<HAS>");
                buf.append("<L/>");
                buf.append("<C SZ=\"");
                buf.append(DocumentUtil.getValue(document, fessConfig.getIndexFieldContentLength(), Long.class,
                        Long.valueOf(0)).longValue() / 1000);
                document.remove(fessConfig.getIndexFieldContentLength());
                buf.append("k\" CID=\"");
                buf.append(DocumentUtil.getValue(document, fessConfig.getIndexFieldDocId(), String.class));
                document.remove(fessConfig.getIndexFieldDocId());
                buf.append("\" ENC=\"");
                final String charsetField = fessConfig.getQueryGsaIndexFieldCharset();
                String charset = DocumentUtil.getValue(document, charsetField, String.class);
                document.remove(charsetField);
                if (StringUtil.isBlank(charset)) {
                    final String contentTypeField = fessConfig.getQueryGsaIndexFieldContentType();
                    charset = DocumentUtil.getValue(document, contentTypeField, String.class);
                    document.remove(contentTypeField);
                    if (StringUtil.isNotBlank(charset)) {
                        final Matcher m = Pattern.compile(".*;\\s*charset=(.+)").matcher(charset);
                        if (m.matches()) {
                            charset = m.group(1);
                        }
                    }
                    if (StringUtil.isBlank(charset)) {
                        charset = Constants.UTF_8;
                    }
                }
                buf.append(charset);
                buf.append("\"/>");
                buf.append("</HAS>");
                buf.append("</R>");
                recordNumber++;
            }
            buf.append("</RES>");
        }
    } catch (final Exception e) {
        status = 1;
        errMsg = e.getMessage();
        if (errMsg == null) {
            errMsg = e.getClass().getName();
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Failed to process a search request.", e);
        }
        if (e instanceof InvalidAccessTokenException) {
            final InvalidAccessTokenException iate = (InvalidAccessTokenException) e;
            response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
            response.setHeader("WWW-Authenticate", "Bearer error=\"" + iate.getType() + "\"");
        }
    }

    writeXmlResponse(status, xmlDtd, buf.toString(), errMsg);
}

From source file:pcgen.cdom.facet.analysis.ChallengeRatingFacet.java

/**
 * Returns the ChallengeRating provided solely by the given Class of the
 * Player Character identified by the given CharID.
 * /*from  w  ww  .java 2s .c om*/
 * @param id
 *            The CharID representing the Player Character
 * @param cl
 *            The PCClass for which the class Challenge Rating should be
 *            calculated
 * @return the Challenge Rating provided solely by the given Class of the
 *         Player Character identified by the given CharID
 */
private Float calcClassCR(CharID id, PCClass cl) {
    Formula cr = cl.get(FormulaKey.CR);
    if (cr == null) {
        /*
         * TODO I don't like the fact that this method is accessing the
         * ClassTypes and using one of those to set one of its variables. In
         * theory, we should have a ClassType that triggers CR that is not a
         * TYPE, but a unique token. See this thread:
         * http://tech.groups.yahoo.com/group/pcgen_experimental/message/10778
         */
        ClassType aClassType = SettingsHandler.getGame().getClassTypeByName(cl.getClassType());
        if (aClassType != null) {
            String crf = aClassType.getCRFormula();
            if ("NONE".equalsIgnoreCase(crf)) {
                return Float.NaN;
            } else if (!"0".equals(crf)) {
                cr = FormulaFactory.getFormulaFor(crf);
            }
        } else {
            // For migration purposes, if CLASSTYPE is not set, 
            // use old method to determine the class type from TYPE. 
            for (Type type : cl.getTrueTypeList(false)) {
                aClassType = SettingsHandler.getGame().getClassTypeByName(type.toString());
                if (aClassType != null) {
                    String crf = aClassType.getCRFormula();
                    if ("NONE".equalsIgnoreCase(crf)) {
                        return Float.NaN;
                    } else if (!"0".equals(crf)) {
                        cr = FormulaFactory.getFormulaFor(crf);
                    }
                }
            }
        }
    }

    return cr == null ? 0 : formulaResolvingFacet.resolve(id, cr, cl.getQualifiedKey()).floatValue();
}

From source file:net.myrrix.online.ServerRecommender.java

@Override
public void ingest(Reader reader) throws TasteException {
    // See also InputFilesReader
    BufferedReader buffered = IOUtils.buffer(reader);
    try {/*from   ww w . j a va 2s  .c o  m*/

        int lines = 0;
        int badLines = 0;
        String line;
        while ((line = buffered.readLine()) != null) {

            if (badLines > 100) { // Crude check
                throw new IOException("Too many bad lines; aborting");
            }

            lines++;

            if (line.isEmpty() || line.charAt(0) == '#') {
                continue;
            }

            Iterator<String> it = DELIMITER.split(line).iterator();

            long userID = Long.MIN_VALUE;
            String itemTag = null;
            long itemID = Long.MIN_VALUE;
            String userTag = null;
            float value;
            try {

                String userIDString = it.next();
                if (userIDString.startsWith("\"")) {
                    itemTag = userIDString.substring(1, userIDString.length() - 1);
                } else {
                    userID = Long.parseLong(userIDString);
                }

                String itemIDString = it.next();
                if (itemIDString.startsWith("\"")) {
                    userTag = itemIDString.substring(1, itemIDString.length() - 1);
                } else {
                    itemID = Long.parseLong(itemIDString);
                }

                if (it.hasNext()) {
                    String valueToken = it.next();
                    value = valueToken.isEmpty() ? Float.NaN : LangUtils.parseFloat(valueToken);
                } else {
                    value = 1.0f;
                }

            } catch (NoSuchElementException ignored) {
                log.warn("Ignoring line with too few columns: '{}'", line);
                badLines++;
                continue;
            } catch (IllegalArgumentException iae) { // includes NumberFormatException
                if (lines == 1) {
                    log.info("Ignoring header line: '{}'", line);
                } else {
                    log.warn("Ignoring unparseable line: '{}'", line);
                    badLines++;
                }
                continue;
            }

            boolean remove = Float.isNaN(value);

            if (itemTag != null) {

                if (userTag != null) {
                    log.warn("Two tags not allowed: '{}'", line);
                    badLines++;
                    continue;
                }

                if (!remove) {
                    setItemTag(itemTag, itemID, value, true);
                }
                // else ignore? no support for remove tag yet

            } else if (userTag != null) {

                if (!remove) {
                    setUserTag(userID, userTag, value, true);
                }
                // else ignore? no support for remove tag yet

            } else {

                if (remove) {
                    removePreference(userID, itemID, true);
                } else {
                    setPreference(userID, itemID, value, true);
                }

            }

            if (lines % 1000000 == 0) {
                log.info("Finished {} lines", lines);
            }
        }
        generationManager.bulkDone();

    } catch (IOException ioe) {
        throw new TasteException(ioe);
    }
}

From source file:Main.java

public static boolean isUndefined(float value) {
    return Float.compare(value, Float.NaN) == 0;
}

From source file:Main.java

public static float getFloat(Object value) {
    if (value == null) {
        return Float.NaN;
    }/*from   ww w.  j  a  va2s.  com*/
    String temp = value.toString().trim();
    if (temp.endsWith("px")) {
        temp = temp.substring(0, temp.indexOf("px"));
    }
    float result = Float.NaN;
    try {
        result = Float.parseFloat(temp);
    } catch (NumberFormatException e) {
    }
    return result;
}

From source file:org.caleydo.core.util.impute.KNNImpute.java

private void updateCenter(Gene center, float[] values, int n) {
    float[] data = center.data;
    for (int i = 0; i < samples; ++i)
        data[i] = values[i] / n;/*from   w  ww.j  av  a  2  s.co m*/
    Arrays.fill(values, Float.NaN); // reset
}

From source file:com.gyz.androidopensamples.vlayout.VLayoutActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_vlayout_main);

    mFirstText = (TextView) findViewById(R.id.first);
    mLastText = (TextView) findViewById(R.id.last);
    mCountText = (TextView) findViewById(R.id.count);
    mTotalOffsetText = (TextView) findViewById(R.id.total_offset);

    final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.main_view);

    findViewById(R.id.jump).setOnClickListener(new View.OnClickListener() {
        @Override//ww  w.  j  a  v a 2  s  . c o  m
        public void onClick(View v) {
            EditText position = (EditText) findViewById(R.id.position);
            if (!TextUtils.isEmpty(position.getText())) {
                try {
                    int pos = Integer.parseInt(position.getText().toString());
                    recyclerView.scrollToPosition(pos);
                } catch (Exception e) {
                    Log.e("VlayoutActivity", e.getMessage(), e);
                }
            } else {
                recyclerView.requestLayout();
            }
        }
    });

    final VirtualLayoutManager layoutManager = new VirtualLayoutManager(this);

    recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int scrollState) {

        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int i, int i2) {
            mFirstText.setText("First: " + layoutManager.findFirstVisibleItemPosition());
            mLastText.setText(
                    "Existing: " + MainViewHolder.existing + " Created: " + MainViewHolder.createdTimes);
            mCountText.setText("Count: " + recyclerView.getChildCount());
            mTotalOffsetText.setText("Total Offset: " + layoutManager.getOffsetToStart());
        }
    });

    recyclerView.setLayoutManager(layoutManager);

    // layoutManager.setReverseLayout(true);

    RecyclerView.ItemDecoration itemDecoration = new RecyclerView.ItemDecoration() {
        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            int position = ((LayoutParams) view.getLayoutParams()).getViewPosition();
            outRect.set(4, 4, 4, 4);
        }
    };

    final RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool();

    recyclerView.setRecycledViewPool(viewPool);

    // recyclerView.addItemDecoration(itemDecoration);

    viewPool.setMaxRecycledViews(0, 20);

    final DelegateAdapter delegateAdapter = new DelegateAdapter(layoutManager, true);

    recyclerView.setAdapter(delegateAdapter);

    List<DelegateAdapter.Adapter> adapters = new LinkedList<>();

    if (BANNER_LAYOUT) {
        adapters.add(new SubAdapter(this, new LinearLayoutHelper(), 1) {

            @Override
            public void onViewRecycled(MainViewHolder holder) {
                if (holder.itemView instanceof ViewPager) {
                    ((ViewPager) holder.itemView).setAdapter(null);
                }
            }

            @Override
            public MainViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                if (viewType == 1) {
                    return new MainViewHolder(LayoutInflater.from(VLayoutActivity.this)
                            .inflate(R.layout.view_pager, parent, false));
                }

                return super.onCreateViewHolder(parent, viewType);
            }

            @Override
            public int getItemViewType(int position) {
                return 1;
            }

            @Override
            protected void onBindViewHolderWithOffset(MainViewHolder holder, int position, int offsetTotal) {

            }

            @Override
            public void onBindViewHolder(MainViewHolder holder, int position) {
                if (holder.itemView instanceof ViewPager) {
                    ViewPager viewPager = (ViewPager) holder.itemView;

                    viewPager.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 200));

                    // from position to get adapter
                    viewPager.setAdapter(new PagerAdapter(this, viewPool));
                }
            }
        });
    }

    if (FLOAT_LAYOUT) {
        FloatLayoutHelper layoutHelper = new FloatLayoutHelper();
        layoutHelper.setAlignType(FixLayoutHelper.BOTTOM_RIGHT);
        layoutHelper.setDefaultLocation(100, 400);
        LayoutParams layoutParams = new LayoutParams(150, 150);
        adapters.add(new SubAdapter(this, layoutHelper, 1, layoutParams));
    }

    if (LINEAR_LAYOUT) {
        LinearLayoutHelper layoutHelper1 = new LinearLayoutHelper();
        layoutHelper1.setAspectRatio(2.0f);
        LinearLayoutHelper layoutHelper2 = new LinearLayoutHelper();
        layoutHelper2.setAspectRatio(4.0f);
        layoutHelper2.setDividerHeight(10);
        layoutHelper2.setMargin(10, 30, 10, 10);
        layoutHelper2.setPadding(10, 30, 10, 10);
        layoutHelper2.setBgColor(0xFFF5A623);
        adapters.add(new SubAdapter(this, layoutHelper1, 1));
        adapters.add(new SubAdapter(this, layoutHelper2, 6) {

            @Override
            public void onBindViewHolder(MainViewHolder holder, int position) {
                if (position % 2 == 0) {
                    LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300);
                    layoutParams.mAspectRatio = 5;
                    holder.itemView.setLayoutParams(layoutParams);
                }
            }
        });
    }

    if (STICKY_LAYOUT) {
        StickyLayoutHelper layoutHelper = new StickyLayoutHelper();
        layoutHelper.setOffset(100);
        layoutHelper.setAspectRatio(4);
        adapters.add(new SubAdapter(this, layoutHelper, 1,
                new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100)));
    }

    if (SINGLE_LAYOUT) {
        SingleLayoutHelper layoutHelper = new SingleLayoutHelper();
        layoutHelper.setBgColor(Color.rgb(135, 225, 90));
        layoutHelper.setAspectRatio(4);
        layoutHelper.setMargin(10, 20, 10, 20);
        layoutHelper.setPadding(10, 10, 10, 10);
        adapters.add(new SubAdapter(this, layoutHelper, 1,
                new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100)));
    }

    if (COLUMN_LAYOUT) {
        ColumnLayoutHelper layoutHelper = new ColumnLayoutHelper();
        layoutHelper.setBgColor(0xff00f0f0);
        layoutHelper.setWeights(new float[] { 40.0f, Float.NaN, 40 });
        adapters.add(new SubAdapter(this, layoutHelper, 5) {

            @Override
            public void onBindViewHolder(MainViewHolder holder, int position) {
                if (position == 0) {
                    LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300);
                    layoutParams.mAspectRatio = 4;
                    holder.itemView.setLayoutParams(layoutParams);
                }
            }

        });
    }

    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper();
        helper.setBgColor(0xff876384);
        helper.setAspectRatio(4.0f);
        helper.setColWeights(new float[] { 40f, 45f });
        helper.setMargin(10, 20, 10, 20);
        helper.setPadding(10, 10, 10, 10);
        adapters.add(new SubAdapter(this, helper, 2));
    }

    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper();
        helper.setBgColor(0xffef8ba3);
        helper.setAspectRatio(2.0f);
        helper.setColWeights(new float[] { 40f });
        helper.setRowWeight(30f);
        helper.setMargin(10, 20, 10, 20);
        helper.setPadding(10, 10, 10, 10);
        adapters.add(new SubAdapter(this, helper, 4) {
            @Override
            public void onBindViewHolder(MainViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                LayoutParams lp = (LayoutParams) holder.itemView.getLayoutParams();
                if (position == 0) {
                    lp.rightMargin = 1;
                } else if (position == 1) {

                } else if (position == 2) {
                    lp.topMargin = 1;
                    lp.rightMargin = 1;
                }
            }
        });
    }

    if (ONEN_LAYOUT) {
        adapters.add(new SubAdapter(this, new OnePlusNLayoutHelper(), 0));
        OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper();
        helper.setBgColor(0xff87e543);
        helper.setAspectRatio(1.8f);
        helper.setColWeights(new float[] { 33.33f, 50f, 40f });
        helper.setMargin(10, 20, 10, 20);
        helper.setPadding(10, 10, 10, 10);
        LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
        adapters.add(new SubAdapter(this, helper, 3, lp) {
            @Override
            public void onBindViewHolder(MainViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                LayoutParams lp = (LayoutParams) holder.itemView.getLayoutParams();
                if (position == 0) {
                    lp.rightMargin = 1;
                }
            }
        });
    }

    if (COLUMN_LAYOUT) {
        adapters.add(new SubAdapter(this, new ColumnLayoutHelper(), 0));
        adapters.add(new SubAdapter(this, new ColumnLayoutHelper(), 4));
    }

    if (FIX_LAYOUT) {
        FixLayoutHelper layoutHelper = new FixLayoutHelper(10, 10);
        adapters.add(new SubAdapter(this, layoutHelper, 0));

        layoutHelper = new FixLayoutHelper(FixLayoutHelper.TOP_RIGHT, 20, 20);

        adapters.add(new SubAdapter(this, layoutHelper, 1) {
            @Override
            public void onBindViewHolder(MainViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                LayoutParams layoutParams = new LayoutParams(200, 200);
                holder.itemView.setLayoutParams(layoutParams);
            }
        });
    }

    if (STICKY_LAYOUT) {
        StickyLayoutHelper layoutHelper = new StickyLayoutHelper(false);
        adapters.add(new SubAdapter(this, layoutHelper, 0));
        layoutHelper = new StickyLayoutHelper(false);
        layoutHelper.setOffset(100);
        adapters.add(new SubAdapter(this, layoutHelper, 3,
                new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100)));
    }

    if (GRID_LAYOUT) {
        GridLayoutHelper layoutHelper = new GridLayoutHelper(2);
        layoutHelper.setMargin(7, 0, 7, 0);
        layoutHelper.setWeights(new float[] { 46.665f });
        layoutHelper.setHGap(3);
        adapters.add(new SubAdapter(this, layoutHelper, 2));

        layoutHelper = new GridLayoutHelper(4);
        layoutHelper.setWeights(new float[] { 20f, 26.665f });
        layoutHelper.setMargin(7, 0, 7, 0);
        layoutHelper.setHGap(3);
        adapters.add(new SubAdapter(this, layoutHelper, 8));
    }

    if (GRID_LAYOUT) {
        adapters.add(new SubAdapter(this, new GridLayoutHelper(4), 0));

        GridLayoutHelper helper = new GridLayoutHelper(4);
        helper.setAspectRatio(4f);
        //helper.setColWeights(new float[]{40, 20, 30, 30});
        // helper.setMargin(0, 10, 0, 10);
        helper.setGap(10);
        adapters.add(new SubAdapter(this, helper, 80) {
            @Override
            public void onBindViewHolder(MainViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                LayoutParams lp = (LayoutParams) holder.itemView.getLayoutParams();
                // lp.bottomMargin = 1;
                // lp.rightMargin = 1;
            }
        });
    }

    if (FIX_LAYOUT) {
        adapters.add(new SubAdapter(this, new ScrollFixLayoutHelper(20, 20), 1) {
            @Override
            public void onBindViewHolder(MainViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                LayoutParams layoutParams = new LayoutParams(200, 200);
                holder.itemView.setLayoutParams(layoutParams);
            }
        });
    }

    if (LINEAR_LAYOUT)
        adapters.add(new SubAdapter(this, new LinearLayoutHelper(), 10));

    if (GRID_LAYOUT) {
        GridLayoutHelper helper = new GridLayoutHelper(3);
        helper.setMargin(0, 10, 0, 10);
        adapters.add(new SubAdapter(this, helper, 3));
    }

    if (STAGGER_LAYOUT) {
        // adapters.add(new SubAdapter(this, new StaggeredGridLayoutHelper(2, 0), 0));
        final StaggeredGridLayoutHelper helper = new StaggeredGridLayoutHelper(2, 10);
        helper.setMargin(20, 10, 10, 10);
        helper.setPadding(10, 10, 20, 10);
        helper.setBgColor(0xFF86345A);
        adapters.add(new SubAdapter(this, helper, 27) {
            @Override
            public void onBindViewHolder(MainViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 200);
                if (position % 2 == 0) {
                    layoutParams.mAspectRatio = 1.0f;
                } else {
                    layoutParams.height = 340 + position % 7 * 20;
                }
                holder.itemView.setLayoutParams(layoutParams);
            }
        });
    }

    if (COLUMN_LAYOUT) {
        // adapters.add(new SubAdapter(this, new ColumnLayoutHelper(), 3));
    }

    if (GRID_LAYOUT) {
        // adapters.add(new SubAdapter(this, new GridLayoutHelper(4), 24));
    }

    delegateAdapter.setAdapters(adapters);

    final Handler mainHandler = new Handler(Looper.getMainLooper());

    trigger = new Runnable() {
        @Override
        public void run() {
            // recyclerView.scrollToPosition(22);
            // recyclerView.getAdapter().notifyDataSetChanged();
            recyclerView.requestLayout();
            // mainHandler.postDelayed(trigger, 1000);
        }
    };

    mainHandler.postDelayed(trigger, 1000);
}