Converts representation of the given value using type conversation rules
between JCR type of this column and Elasticsearch core type of this column.

@param value value to be converted.
@return converted value.
12223
protected Object columnValue(Object value) {
        switch (type) {
            case PATH:
            case NAME:
            case STRING:
            case REFERENCE:
            case SIMPLEREFERENCE:
            case WEAKREFERENCE:
            case URI:
                return valueFactories.getStringFactory().create(value);
            case DATE :
                return ((DateTime) value).getMilliseconds();
            default :
                return value;
        }
    }
908705
public int valueToIndex(Object value)
    {
        if (value != null)
            if (!(value instanceof String))
                value = value.toString();
        if ((m_record != null) && (m_strIndexValue != null))
        {
            try   {
                FieldTable table = m_record.getTable();
                for (int iIndex = 0; ; iIndex++)
                {
                    if (table.get(iIndex) == null)  // I use get, so the index matches the index of JComboBox
                        break;
                    FieldInfo field = m_record.getField(m_strIndexValue);
                    if (field == null)
                        field = m_record.getField(0);
                    String strValue = field.getString();
                    if ((strValue != null) && (strValue.length() > 0))
                        if (strValue.equals(value))
                            return iIndex + 1;
                }
            } catch (Exception ex)  {
                ex.printStackTrace();
            }
        }
        else
        {
            this.setSelectedItem(value);
            if (this.getSelectedIndex() != -1)
                return this.getSelectedIndex();
        }
        return 0;
    }
531180
protected Object cast(Object value) {
        switch (type) {
            case STRING :
               return valueFactories.getStringFactory().create(value);
            case LONG :
                return valueFactories.getLongFactory().create(value);
            case NAME :
                return valueFactories.getNameFactory().create(value);
            case PATH :
                return valueFactories.getPathFactory().create(value);
            case DATE :
                return valueFactories.getDateFactory().create(value);
            case BOOLEAN :
                return valueFactories.getBooleanFactory().create(value);
            case URI :
                return valueFactories.getUriFactory().create(value);
            case REFERENCE :
                return valueFactories.getReferenceFactory().create(value);
            case SIMPLEREFERENCE :
                return valueFactories.getSimpleReferenceFactory().create(value);
            case WEAKREFERENCE :
                return valueFactories.getWeakReferenceFactory().create(value);
            default :
                return value;
        }
    }
1069832
private String getDataType(final Value value) {
        if (value instanceof BigDecimalValue) {
            return DataType.TYPE_NUMERIC_BIGDECIMAL;
        } else if (value instanceof BigIntegerValue) {
            return DataType.TYPE_NUMERIC_BIGINTEGER;
        } else if (value instanceof BooleanValue) {
            return DataType.TYPE_BOOLEAN;
        } else if (value instanceof ByteValue) {
            return DataType.TYPE_NUMERIC_BYTE;
        } else if (value instanceof DateValue) {
            return DataType.TYPE_DATE;
        } else if (value instanceof DoubleValue) {
            return DataType.TYPE_NUMERIC_DOUBLE;
        } else if (value instanceof FloatValue) {
            return DataType.TYPE_NUMERIC_FLOAT;
        } else if (value instanceof IntegerValue) {
            return DataType.TYPE_NUMERIC_INTEGER;
        } else if (value instanceof LongValue) {
            return DataType.TYPE_NUMERIC_LONG;
        } else if (value instanceof ShortValue) {
            return DataType.TYPE_NUMERIC_SHORT;
        } else if (value instanceof EnumValue) {
            return DataType.TYPE_COMPARABLE;
        }

        return DataType.TYPE_STRING;
    }
1081000
public <T> T convert(Type type, Object value, T defaultValue) throws ConvertException {
		return convert(type, value, defaultValue, true);
	}
215512
def convert(self, value, _type):
        
        return self.type_convertors.get(_type, lambda x: x)(value)
1029758
public static SassValue convertToSassValue(Object value) {
    if (null == value) {
      return SassNull.SINGLETON;
    }

    if (value instanceof SassValue) {
      return (SassValue) value;
    }

    Class cls = value.getClass();

    if (isaBoolean(cls)) {
      return new SassBoolean((Boolean) value);
    }

    if (isaNumber(cls)) {
      return new SassNumber(((Number) value).doubleValue(), "");
    }

    if (isaString(cls) || isaCharacter(cls)) {
      return new SassString(value.toString());
    }

    if (value instanceof Collection) {
      return new SassList(
          ((Collection<?>) value)
              .stream()
              .map(TypeUtils::convertToSassValue)
              .collect(Collectors.toList())
      );
    }

    if (value instanceof Map) {
      return ((Map<?, ?>) value).entrySet()
          .stream()
          .collect(Collectors.toMap(
              entry -> entry.getKey().toString(),
              entry -> TypeUtils.convertToSassValue(entry.getValue()),
              (origin, duplicate) -> origin,
              SassMap::new
          ));
    }

    if (value instanceof Throwable) {
      Throwable throwable = (Throwable) value;
      StringWriter stringWriter = new StringWriter();
      PrintWriter printWriter = new PrintWriter(stringWriter);

      String message = throwable.getMessage();
      if (StringUtils.isNotEmpty(message)) {
        printWriter.append(message).append(System.lineSeparator());
      }
      throwable.printStackTrace(printWriter);

      return new SassError(stringWriter.toString());
    }

    return new SassError(
        String.format(
            "Could not convert object of type %s into a sass value",
            value.getClass().toString()
        )
    );
  }
767569
public static Object convertToJava(Value value) {
        switch (value.getType()) {
            case STRING:
                return ((StringValue) value).get();
            case BOOLEAN:
                return ((BooleanValue) value).get();
            case NUMBER:
                return ((NumberValue) value).get();
            case DATE:
                return ((DateValue) value).get();
            case NIL:
                return null;
            case OBJECT:
                return value.get();
        }
        throw new CommandExecutionException("Could not convert value " + value + " to an equivalent Java object");
    }
1023650
private Object convert(Object value, Class type) {

		Object convertedObject = null;

		if (type.equals(String.class)) {

			// strings can be returned immediately
			return value.toString();

		} else if (value instanceof Number) {

			Number number = (Number) value;

			if (type.equals(Integer.class) || type.equals(Integer.TYPE)) {
				return number.intValue();

			} else if (type.equals(Long.class) || type.equals(Long.TYPE)) {
				return number.longValue();

			} else if (type.equals(Double.class) || type.equals(Double.TYPE)) {
				return number.doubleValue();

			} else if (type.equals(Float.class) || type.equals(Float.TYPE)) {
				return number.floatValue();

			} else if (type.equals(Short.class) || type.equals(Integer.TYPE)) {
				return number.shortValue();

			} else if (type.equals(Byte.class) || type.equals(Byte.TYPE)) {
				return number.byteValue();

			}

		} else if (value instanceof List) {

			return value;

		} else if (value instanceof Map) {
			return value;
		}

		// fallback
		try {

			Method valueOf = type.getMethod("valueOf", String.class);
			if (valueOf != null) {

				convertedObject = valueOf.invoke(null, value.toString());

			} else {

				logger.warn("Unable to find static valueOf method for type {}", type);
			}

		} catch (Throwable t) {

			logger.warn("Unable to deserialize value {} of type {}, Class has no static valueOf method.", new Object[]{value, type});
		}

		return convertedObject;
	}
883978
@Override public Object transform(Object value) {
        if (value == null) {
            return value;
        } else if (value instanceof Boolean) {
            return value;
        } else if (value instanceof String) {
            return value;
        } else if (value instanceof Number) {
            return InternalUtils.toBigDecimal((Number)value);
        } else if (value instanceof byte[]) {
            return value;
        } else if (value instanceof ByteBuffer) {
            return copyBytesFrom((ByteBuffer)value);
        } else if (value instanceof Set) {
            @SuppressWarnings("unchecked")
            Set<Object> set = (Set<Object>) value;
            if (set.size() == 0)
                return value;
            Object element = set.iterator().next();
            if (element instanceof String) {
                return value;
            } else if (element instanceof BigDecimal) {
                return value;
            } else if (element instanceof Number) {
                @SuppressWarnings("unchecked")
                Set<Number> in = (Set<Number>) value;
                Set<BigDecimal> out = new LinkedHashSet<BigDecimal>(set.size());
                for (Number n : in)
                    out.add(InternalUtils.toBigDecimal(n));
                return out;
            } else if (element instanceof byte[]) {
                return value;
            } else if (element instanceof ByteBuffer) {
                @SuppressWarnings("unchecked")
                Set<ByteBuffer> bs = (Set<ByteBuffer>) value;
                Set<byte[]> out = new LinkedHashSet<byte[]>(bs.size());
                for (ByteBuffer bb: bs)
                    out.add(copyBytesFrom(bb));
                return out;
            } else {
                throw new UnsupportedOperationException("element type: "
                        + element.getClass());
            }
        } else if (value instanceof List) {
            @SuppressWarnings("unchecked")
            List<Object> in = (List<Object>) value;
            if (in.size() == 0)
                return in;
            List<Object> out = new ArrayList<Object>();
            for (Object v : in)
                out.add(transform(v));
            return out;
        } else if (value instanceof Map) {
            @SuppressWarnings("unchecked")
            Map<String, Object> in = (Map<String, Object>) value;
            if (in.size() == 0)
                return in;
            Map<String, Object> out = new LinkedHashMap<String, Object>(in.size());
            for (Map.Entry<String, Object> e : in.entrySet())
                out.put(e.getKey(), transform(e.getValue()));
            return out;
        } else {
            throw new UnsupportedOperationException("value type: "
                    + value.getClass());
        }
    }
980189
public static CmsSearchFieldMappingType valueOf(String value) {

        if (CmsStringUtil.isEmptyOrWhitespaceOnly(value)) {
            return null;
        }
        value = value.trim().toLowerCase();
        if (STR_CONTENT.equals(value)) {
            return CONTENT;
        } else if (STR_PROPERTY.equals(value)) {
            return PROPERTY;
        } else if (STR_PROPERTY_SEARCH.equals(value)) {
            return PROPERTY_SEARCH;
        } else if (STR_ITEM.equals(value)) {
            return ITEM;
        } else if (STR_DYNAMIC.equals(value)) {
            return DYNAMIC;
        } else if (STR_ATTRIBUTE.equals(value)) {
            return ATTRIBUTE;
        }
        return null;
    }
1323297
protected Collection<?> convertInternal(Object value) {
		final Collection<Object> collection = CollectionUtil.create(TypeUtil.getClass(this.collectionType));
		return CollUtil.addAll(collection, value, this.elementType);
	}
234112
protected final Object convert(Class targetType, String value) {
        Converter converter = Stapler.lookupConverter(targetType);
        if (converter==null)
            throw new IllegalArgumentException("Unable to convert to "+targetType);

        return converter.convert(targetType,value);
    }
956334
@SuppressWarnings({ "unchecked", "rawtypes" })
    public static Object convert(Object value, Class<?> type) {
        if (value == null || type == null || type.isAssignableFrom(value.getClass())) {
            return value;
        }
        if (value instanceof String) {
            String string = (String) value;
            if (char.class.equals(type) || Character.class.equals(type)) {
                if (string.length() != 1) {
                    throw new IllegalArgumentException(String.format("can not convert String(%s) to char!" +
                        " when convert String to char, the String must only 1 char.", string));
                }
                return string.charAt(0);
            } else if (type.isEnum()) {
                return Enum.valueOf((Class<Enum>) type, string);
            } else if (type == BigInteger.class) {
                return new BigInteger(string);
            } else if (type == BigDecimal.class) {
                return new BigDecimal(string);
            } else if (type == Short.class || type == short.class) {
                return Short.valueOf(string);
            } else if (type == Integer.class || type == int.class) {
                return Integer.valueOf(string);
            } else if (type == Long.class || type == long.class) {
                return Long.valueOf(string);
            } else if (type == Double.class || type == double.class) {
                return new Double(string);
            } else if (type == Float.class || type == float.class) {
                return new Float(string);
            } else if (type == Byte.class || type == byte.class) {
                return Byte.valueOf(string);
            } else if (type == Boolean.class || type == boolean.class) {
                return Boolean.valueOf(string);
            } else if (type == Date.class || type == java.sql.Date.class || type == java.sql.Time.class ||
                type == java.sql.Timestamp.class) {
                try {
                    if (type == Date.class) {
                        return DateUtils.strToDate(string, DateUtils.DATE_FORMAT_TIME);
                    } else if (type == java.sql.Date.class) {
                        return new java.sql.Date(DateUtils.strToLong(string));
                    } else if (type == java.sql.Timestamp.class) {
                        return new java.sql.Timestamp(DateUtils.strToLong(string));
                    } else {
                        return new java.sql.Time(DateUtils.strToLong(string));
                    }
                } catch (ParseException e) {
                    throw new IllegalStateException("Failed to parse date " + value + " by format " +
                        DateUtils.DATE_FORMAT_TIME + ", cause: " + e.getMessage(), e);
                }
            } else if (type == Class.class) {
                return ClassTypeUtils.getClass((String) value);
            }
        } else if (value instanceof Number) {
            Number number = (Number) value;
            if (type == byte.class || type == Byte.class) {
                return number.byteValue();
            } else if (type == short.class || type == Short.class) {
                return number.shortValue();
            } else if (type == int.class || type == Integer.class) {
                return number.intValue();
            } else if (type == long.class || type == Long.class) {
                return number.longValue();
            } else if (type == float.class || type == Float.class) {
                return number.floatValue();
            } else if (type == double.class || type == Double.class) {
                return number.doubleValue();
            } else if (type == BigInteger.class) {
                return BigInteger.valueOf(number.longValue());
            } else if (type == BigDecimal.class) {
                return BigDecimal.valueOf(number.doubleValue());
            } else if (type == Date.class) {
                return new Date(number.longValue());
            } else if (type == java.sql.Date.class) {
                return new java.sql.Date(number.longValue());
            } else if (type == java.sql.Time.class) {
                return new java.sql.Time(number.longValue());
            } else if (type == java.sql.Timestamp.class) {
                return new java.sql.Timestamp(number.longValue());
            }
        } else if (value instanceof Collection) {
            Collection collection = (Collection) value;
            if (type.isArray()) {
                int length = collection.size();
                Object array = Array.newInstance(type.getComponentType(), length);
                int i = 0;
                for (Object item : collection) {
                    Array.set(array, i++, item);
                }
                return array;
            } else if (!type.isInterface()) {
                try {
                    Collection result = (Collection) type.newInstance();
                    result.addAll(collection);
                    return result;
                } catch (Throwable ignore) { // NOPMD
                }
            } else if (type == List.class) {
                return new ArrayList<Object>(collection);
            } else if (type == Set.class) {
                return new HashSet<Object>(collection);
            }
        } else if (value.getClass().isArray() && Collection.class.isAssignableFrom(type)) {
            Collection collection;
            if (!type.isInterface()) {
                try {
                    collection = (Collection) type.newInstance();
                } catch (Throwable e) {
                    collection = new ArrayList<Object>();
                }
            } else if (type == Set.class) {
                collection = new HashSet<Object>();
            } else {
                collection = new ArrayList<Object>();
            }
            int length = Array.getLength(value);
            for (int i = 0; i < length; i++) {
                collection.add(Array.get(value, i));
            }
            return collection;
        }
        return value;
    }
164139
public static Object convertExample(String value, String type) {
        if (value == null) {
            return null;
        }

        try {
            switch (type) {
                case "integer":
                    return Integer.valueOf(value);
                case "number":
                    return Float.valueOf(value);
                case "boolean":
                    return Boolean.valueOf(value);
                case "string":
                    return value;
                default:
                    return value;
            }
        } catch (NumberFormatException e) {
            throw new RuntimeException(String.format("Value '%s' cannot be converted to '%s'", value, type), e);
        }
    }
1198386
@Override
	public T convert(ResponseBody value) throws IOException {
		try {
			return (T) binderContext.parse(value.byteStream(), clazz);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} finally {
			value.close();
		}
	}
1020766
public static <T> T convert(Type type, Object value, T defaultValue) throws ConvertException {
		return ConverterRegistry.getInstance().convert(type, value, defaultValue);
	}