Java Type Coerce coerceIntoComboId(Long entityId)

Here you can find the source of coerceIntoComboId(Long entityId)

Description

Coerces numeric entity ids into ids which correctly sorts into a jeditable combo.

License

Open Source License

Parameter

Parameter Description
entityId a parameter

Return

id suitable for combo. never null

Declaration

public static long coerceIntoComboId(Long entityId) 

Method Source Code

//package com.java2s;
/**/*w  w  w .  j a  va  2 s.co m*/
 *     This file is part of the Squashtest platform.
 *     Copyright (C) 2010 - 2016 Henix, henix.fr
 *
 *     See the NOTICE file distributed with this work for additional
 *     information regarding copyright ownership.
 *
 *     This is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU Lesser General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     this software is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU Lesser General Public License for more details.
 *
 *     You should have received a copy of the GNU Lesser General Public License
 *     along with this software.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    private static final int ID_OFFSET = 10;

    /**
     * Coerces numeric entity ids into ids which correctly sorts into a jeditable combo.
     * When "no value" would be represented by a null id and we want it to appear first in the combo, we have to convert
     * it to a numeric which would correctly be sorted and which would not conflict with an existing id.
     * 
     * <strong>Note :</strong> ids coming from frontend have to be coerced back using {@link #coerceIntoEntityId(Long)}
     * 
     * @param entityId
     * @return id suitable for combo. never <code>null</code>
     */
    public static long coerceIntoComboId(Long entityId) {
        if (entityId == null) {
            return 0;
        }
        return entityId + ID_OFFSET;
    }
}

Related

  1. coerce(Object val, Class c)
  2. coerce(Object value, Class clazz)
  3. coerce(Object value, Class clazz)
  4. coerceBool(Object obj)
  5. coerceBool(Object val)
  6. coerceIntoEntityId(Long comboId)
  7. coerceTagValueInt(String tag, Object val)
  8. coerceToDouble(Object o)
  9. coerceToEntrySize(String s)