Java 类org.apache.lucene.document.NumberTools 实例源码

项目:spacewalk    文件:MatchingField.java   
/**
 *
 * @return value most responsible for this document being a match
 */
public String getFieldValue() {
    String fieldName = getFieldName();
    Field f = doc.getField(fieldName);
    if (f == null) {
        StringBuffer sb = new StringBuffer();
        sb.append("[length=" + terms.length + ";  ");
        for (Object o : terms) {
            sb.append(o + ", ");
        }
        sb.append("]");
        log.info("Unable to get matchingFieldValue for field : " + fieldName +
                " with query: " + query + ", and terms = " + sb.toString());
        log.info("Document = " + doc);
        return "";
    }
    String value = f.stringValue();
    if (needNumberToolsAdjust.containsKey(fieldName)) {
        Long temp = NumberTools.stringToLong(value);
        value = temp.toString();
    }
    return value;
}
项目:GeoprocessingAppstore    文件:DoubleField.java   
/**
 * Reverts an indexable String back to a double value.
 * @param value the indexable string to revert
 * @return the double value
 */
protected static Double doubleFromIndexableString(String value, int precision) {
  try {
    long lValue = NumberTools.stringToLong(value);
    long lConversionFactor = (long)Math.pow((double)10,(double)precision);
    return (double)lValue / lConversionFactor;
  } catch (NumberFormatException e) {
    return null;
  }
}
项目:GeoprocessingAppstore    文件:DoubleField.java   
/**
 * Converts a double value to a String that can be indexed for search.
 * @param value the value to convert
 * @return the indexable string
 */
protected static String doubleToIndexableString(Double value, int precision) {
  if (value == null) {
    return null;
  } else {
    long lConversionFactor = (long)Math.pow((double)10,(double)precision);
    long lValue = Math.round(lConversionFactor * value);
    return NumberTools.longToString(lValue);
  }
}
项目:GeoprocessingAppstore    文件:LongField.java   
/**
 * Reverts an indexable String back to a long value.
 * @param value the indexable string to revert
 * @return the long value
 */
protected static Long longFromIndexableString(String value) {
  try {
    long lValue = NumberTools.stringToLong(value);
    return lValue;
  } catch (NumberFormatException e) {
    return null;
  }
}
项目:GeoprocessingAppstore    文件:LongField.java   
/**
 * Converts a long value to a String that can be indexed for search.
 * @param value the value to convert
 * @return the indexable string
 */
protected static String longToIndexableString(Long value) {
  if (value == null) {
    return null;
  } else {
    return NumberTools.longToString(value);
  }
}
项目:spacewalk    文件:NGramQueryParser.java   
/**
 * This will look to see if "part1" or "part2" are strings of all digits,
 * if they are, then they will be converted to a lexicographically safe string
 * representation, then passed into the inherited getRangeQuery().  This is needed when
 * comparing something like "4" to be less than "10".
 * If the strings don't fit the pattern of all digits, then they get passed through
 * to the inherited getRangeQuery().
 */
protected Query getRangeQuery(String field,
        String part1,
        String part2,
        boolean inclusive) throws ParseException {
    if (isDate(part1) && isDate(part2)) {
        if (log.isDebugEnabled()) {
            log.debug("Detected passed in terms are dates, creating " +
                "ConstantScoreRangeQuery(" + field + ", " + part1 + ", " +
                part2 + ", " + inclusive + ", " + inclusive);
        }
        return new ConstantScoreRangeQuery(field, part1, part2, inclusive,
                inclusive);
    }
    String newPart1 = part1;
    String newPart2 = part2;
    String regEx = "(\\d)*";
    Pattern pattern = Pattern.compile(regEx);
    Matcher matcher1 = pattern.matcher(part1);
    Matcher matcher2 = pattern.matcher(part2);
    if (matcher1.matches() && matcher2.matches()) {
        newPart1 = NumberTools.longToString(Long.parseLong(part1));
        newPart2 = NumberTools.longToString(Long.parseLong(part2));
        if (log.isDebugEnabled()) {
            log.debug("NGramQueryParser.getRangeQuery() Converted " + part1 + " to " +
                newPart1 + ", Converted " + part2 + " to " + newPart2);
        }
    }
    return super.getRangeQuery(field, newPart1, newPart2, inclusive);
}
项目:spacewalk    文件:Server.java   
/**
 * @param cpuBogoMIPSIn the cpuBogoMIPS to set
 */
public void setCpuBogoMIPS(String cpuBogoMIPSIn) {
    if (cpuBogoMIPSIn != null) {
        Float f = Float.parseFloat(cpuBogoMIPSIn);
        this.cpuBogoMIPS = NumberTools.longToString(f.longValue());
    }
    else {
        this.cpuBogoMIPS = null;
    }
}
项目:spacewalk    文件:Server.java   
/**
 * @param cpuMHzIn the cpuMHz to set
 */
public void setCpuMHz(String cpuMHzIn) {
    if (cpuMHzIn != null) {
        this.cpuMHz = NumberTools.longToString(Long.parseLong(cpuMHzIn));
    }
    else {
        this.cpuMHz = null;
    }
}
项目:spacewalk    文件:Server.java   
/**
 * @param cpuNumberOfCpusIn the cpuNumberOfCpus to set
 */
public void setCpuNumberOfCpus(String cpuNumberOfCpusIn) {
    if (cpuNumberOfCpusIn != null) {
        this.cpuNumberOfCpus =
            NumberTools.longToString(Long.parseLong(cpuNumberOfCpusIn));
    }
    else {
        this.cpuNumberOfCpus = null;
    }
}
项目:spacewalk    文件:Server.java   
/**
 * @param ramIn the ram to set
 */
public void setRam(String ramIn) {
    if (ramIn != null) {
        this.ram = NumberTools.longToString(Long.parseLong(ramIn));
    }
    else {
        this.ram = null;
    }
}
项目:spacewalk    文件:Server.java   
/**
 * @param swapIn the swap to set
 */
public void setSwap(String swapIn) {
    if (swapIn != null) {
        this.swap = NumberTools.longToString(Long.parseLong(swapIn));
    }
    else {
        this.swap = null;
    }
}
项目:usgin-geoportal    文件:DoubleField.java   
/**
 * Reverts an indexable String back to a double value.
 * @param value the indexable string to revert
 * @return the double value
 */
protected static Double doubleFromIndexableString(String value, int precision) {
  try {
    long lValue = NumberTools.stringToLong(value);
    long lConversionFactor = (long)Math.pow((double)10,(double)precision);
    return (double)lValue / lConversionFactor;
  } catch (NumberFormatException e) {
    return null;
  }
}
项目:usgin-geoportal    文件:DoubleField.java   
/**
 * Converts a double value to a String that can be indexed for search.
 * @param value the value to convert
 * @return the indexable string
 */
protected static String doubleToIndexableString(Double value, int precision) {
  if (value == null) {
    return null;
  } else {
    long lConversionFactor = (long)Math.pow((double)10,(double)precision);
    long lValue = Math.round(lConversionFactor * value);
    return NumberTools.longToString(lValue);
  }
}
项目:usgin-geoportal    文件:LongField.java   
/**
 * Reverts an indexable String back to a long value.
 * @param value the indexable string to revert
 * @return the long value
 */
protected static Long longFromIndexableString(String value) {
  try {
    long lValue = NumberTools.stringToLong(value);
    return lValue;
  } catch (NumberFormatException e) {
    return null;
  }
}
项目:usgin-geoportal    文件:LongField.java   
/**
 * Converts a long value to a String that can be indexed for search.
 * @param value the value to convert
 * @return the indexable string
 */
protected static String longToIndexableString(Long value) {
  if (value == null) {
    return null;
  } else {
    return NumberTools.longToString(value);
  }
}