Example usage for java.lang Character isDigit

List of usage examples for java.lang Character isDigit

Introduction

In this page you can find the example usage for java.lang Character isDigit.

Prototype

public static boolean isDigit(int codePoint) 

Source Link

Document

Determines if the specified character (Unicode code point) is a digit.

Usage

From source file:net.o3s.beans.registering.RegisteringBean.java

/**
  * Check if a the string is a valid rfid
  * @param s String to check/*from   w ww .  j a va2 s.c  o m*/
  * @return true if the string is numeric
  */
 public boolean isValidRfid(String s) {
     if (s == null)
         return false;

     if (s.length() == 0) {
         return false;
     }

     if (s.length() != IEntityLabel.RFID_SIZE) {
         return false;
     }

     for (int i = 0; i < s.length(); i++) {
         if (!Character.isDigit(s.charAt(i))) {
             return false;
         }
     }

     return true;

 }

From source file:TypeConversionHelper.java

/**
 * Convenience method to convert a String containing numbers (separated by assorted
 * characters) into an int array. The separators can be ' '  '-'  ':'  '.'  ',' etc.
 * @param str The String/*from  w ww  .j a  v a  2s.c  o  m*/
 * @return The int array
 */
private static int[] convertStringToIntArray(String str) {
    if (str == null) {
        return null;
    }

    int[] values = null;
    ArrayList list = new ArrayList();

    int start = -1;
    for (int i = 0; i < str.length(); i++) {
        if (start == -1 && Character.isDigit(str.charAt(i))) {
            start = i;
        }
        if (start != i && start >= 0) {
            if (!Character.isDigit(str.charAt(i))) {
                list.add(new Integer(str.substring(start, i)));
                start = -1;
            }
        }
    }

    if (list.size() > 0) {
        values = new int[list.size()];
        Iterator iter = list.iterator();
        int n = 0;
        while (iter.hasNext()) {
            values[n++] = ((Integer) iter.next()).intValue();
        }
    }
    return values;
}

From source file:de.micromata.genome.gwiki.utils.html.Html2WikiFilter.java

@Override
public void endElement(QName element, Augmentations augs) throws XNIException {
    flushText();/*from  w w  w  . j av  a2s .com*/
    String en = element.rawname.toLowerCase();
    if (handleMacroTransformerEnd(element, augs) == true) {
        super.endElement(element, augs);
        return;
    }
    List<GWikiFragment> frags;

    if (handleAutoCloseTag(en) == true) {
        ; // nothing
    } else if (en.length() == 2 && en.charAt(0) == 'h' && Character.isDigit(en.charAt(1)) == true) {
        frags = parseContext.popFragList();
        GWikiFragmentHeading lfh = (GWikiFragmentHeading) parseContext.lastFragment();
        lfh.addChilds(frags);
    } else if (en.equals("p") == true) {
        GWikiFragment top = parseContext.peekFragStack(); // p with attributes
        if (top instanceof GWikiMacroFragment
                && ((GWikiMacroFragment) top).getMacro() instanceof GWikiHtmlBodyPTagMacro) {
            parseContext.popFragStack();
            frags = parseContext.popFragList();
            ((GWikiMacroFragment) top).getAttrs().setChildFragment(new GWikiFragmentChildContainer(frags));
            parseContext.addFragment(top);
        } else {
            if (hasPreviousBr() == false) {
                parseContext.addFragment(getNlFragement(new GWikiFragmentP()));
            } else {
                parseContext.addFragment(getNlFragement(new GWikiFragmentBr()));
            }
        }
    } else if (en.equals("ul") == true || en.equals("ol") == true) {
        if (liStack.isEmpty() == false && liStack.peek().equals(en) == true) {
            liStack.pop();
        }
        frags = parseContext.popFragList();
        GWikiFragmentList lf = (GWikiFragmentList) parseContext.lastFragment();
        lf.addChilds(frags);
    } else if (en.equals("li") == true) {
        frags = parseContext.popFragList();
        GWikiFragmentLi li = (GWikiFragmentLi) parseContext.lastFragment();
        li.addChilds(frags);
    } else if (isSimpleWordDeco(en, null) == true) {
        frags = parseContext.popFragList();
        GWikiFragmentTextDeco fragDeco = new GWikiFragmentTextDeco(simpleTextDecoMap.get(en).charAt(0),
                "<" + en + ">", "</" + en + ">", frags);
        fragDeco.setRequireMacroSyntax(requireTextDecoMacroSyntax(fragDeco));
        parseContext.addFragment(fragDeco);
    } else if (en.equals("img") == true) {

    } else if (en.equals("a") == true) {
        finalizeLink();

    } else if (en.equals("table") == true) {
        endTable();
    } else if (en.equals("tr") == true) {
        endTr();
    } else if (en.equals("th") == true) {
        endTdTh();
    } else if (en.equals("td") == true) {
        endTdTh();
    } else if (en.equals("code") == true) {
        endCode();
    } else if (en.equals("span") == true && handleSpanEnd() == true) {
        // nothing

    } else if (supportedHtmlTags.contains(en) == true) {
        frags = parseContext.popFragList();
        GWikiMacroFragment maf = (GWikiMacroFragment) parseContext.lastFragment();
        if (maf != null) {
            maf.getAttrs().setChildFragment(new GWikiFragmentChildContainer(frags));
        } else {
            throw new RuntimeException("No fragment set on end tag: " + en);
        }
    } else {

        // GWikiLog.note("Unhandled end tag: " + en);
    }
    super.endElement(element, augs);
}

From source file:com.legstar.cob2xsd.XsdDataItem.java

/**
 * Turn a COBOL name to an XSD element name.
 * <p/>//from   w w w  .j a  va 2s. c  om
 * COBOL names look ugly in XML schema. They are often uppercased and use
 * hyphens extensively. XML schema names they will have to be transformed
 * later to java identifiers so we try to get as close as possible to a
 * naming convention that suits XML Schema as well as Java.
 * <p>
 * So we remove hyphens. We lower case all characters which are not word
 * breakers. Word breakers are hyphens and numerics. This creates Camel
 * style names. Element names customarily start with a lowercase character.
 * <p/>
 * COBOL FILLERs are a particular case because there might be more than one
 * in the same parent group. So what we do is systematically append the
 * COBOL source line number so that these become unique names.
 * <p/>
 * COBOL names can start with a digit which is illegal for XML element
 * names. In this case we prepend a "C" character.
 * <p/>
 * Since Enterprise COBOL V4R1, underscores can be used (apart from first
 * character). We treat them as hyphens here, they are not propagated to the
 * XSD name but are used as word breakers.
 * <p/>
 * Once an element name is identified, we make sure it is unique among
 * siblings within the same parent.
 * 
 * @param cobolDataItem the original COBOL data item
 * @param nonUniqueCobolNames a list of non unique COBOL names used to
 *            detect name collisions
 * @param model the translator options
 * @param parent used to resolve potential name conflict
 * @param order order within parent to disambiguate siblings
 * @return an XML schema element name
 */
public static String formatElementName(final CobolDataItem cobolDataItem,
        final List<String> nonUniqueCobolNames, final Cob2XsdModel model, final XsdDataItem parent,
        final int order) {

    String cobolName = getXmlCompatibleCobolName(cobolDataItem.getCobolName());
    if (cobolName.equalsIgnoreCase("FILLER")) {
        String filler = (model.elementNamesStartWithUppercase()) ? "Filler" : "filler";
        return filler + cobolDataItem.getSrceLine();
    }

    StringBuilder sb = new StringBuilder();
    boolean wordBreaker = (model.elementNamesStartWithUppercase()) ? true : false;
    for (int i = 0; i < cobolName.length(); i++) {
        char c = cobolName.charAt(i);
        if (c != '-' && c != '_') {
            if (Character.isDigit(c)) {
                sb.append(c);
                wordBreaker = true;
            } else {
                if (wordBreaker) {
                    sb.append(Character.toUpperCase(c));
                } else {
                    sb.append(Character.toLowerCase(c));
                }
                wordBreaker = false;
            }
        } else {
            wordBreaker = true;
        }
    }

    String elementName = sb.toString();
    if (parent != null) {
        int siblingsWithSameName = 0;
        for (CobolDataItem child : parent.getCobolChildren()) {
            if (child.getCobolName().equals(cobolDataItem.getCobolName())) {
                siblingsWithSameName++;
            }
        }
        if (siblingsWithSameName > 1) {
            elementName += order;
        }
    }

    return elementName;
}

From source file:com.android.tools.lint.checks.GradleDetector.java

private static boolean isNumberString(@Nullable String s) {
    if (s == null || s.isEmpty()) {
        return false;
    }/*from   w  ww. java2 s .c  om*/
    for (int i = 0, n = s.length(); i < n; i++) {
        if (!Character.isDigit(s.charAt(i))) {
            return false;
        }
    }

    return true;
}

From source file:edu.cornell.mannlib.vitro.webapp.dao.jena.IndividualDaoJena.java

public String getUnusedURI(Individual individual) throws InsertException {
    String errMsg = null;//  w  ww. ja  va2  s  . com
    String namespace = null;
    String uri = null;
    boolean uriIsGood = false;

    if (individual == null || (individual.getURI() != null && individual.getURI().startsWith(DEFAULT_NAMESPACE))
            || individual.getNamespace() == null || individual.getNamespace().length() == 0
            || DEFAULT_NAMESPACE.equals(individual.getNamespace())) {
        //we always want local names like n23423 for the default namespace
        namespace = DEFAULT_NAMESPACE;
        uri = null;
        log.debug("Setting namespace to default namespace " + DEFAULT_NAMESPACE + " and uri is null");
        log.debug("Individual : " + individual + " - URI: " + individual.getURI() + " - namespace -"
                + individual.getNamespace() + "- ");
    } else if (individual.getURI() != null) {
        errMsg = getWebappDaoFactory().checkURI(individual.getURI());
        if (errMsg == null) {
            uriIsGood = true;
            uri = individual.getURI();
        } else {
            throw new InsertException(errMsg);
        }
        log.debug("Individual URI not null " + individual.getURI()
                + " and uriIsGood is true and uri set to individual uri");
    } else {
        namespace = individual.getNamespace();
        if (namespace == null || namespace.length() == 0)
            namespace = DEFAULT_NAMESPACE;
        String localName = individual.getName();
        log.debug("Namespace " + namespace + " -localname=" + localName);
        /* try to use the specified namespace and local name */
        if (localName != null) {
            log.debug("Local name not equal to null so replacing characters, etc.");
            localName = localName.replaceAll("\\W", "");
            localName = localName.replaceAll(":", "");
            if (localName.length() > 2) {
                if (Character.isDigit(localName.charAt(0))) {
                    localName = "n" + localName;
                }
                uri = namespace + localName;
                errMsg = getWebappDaoFactory().checkURI(uri);
                if (errMsg == null)
                    uriIsGood = true;
                else
                    throw new InsertException(errMsg);
                log.debug("uriIsGood is true and uri is " + uri);
            }
        }
        /* else try namespace + n2343 */
    }

    int attempts = 0;

    while (uriIsGood == false && attempts < 30) {
        log.debug("While loop: Uri is good false, attempt=" + attempts);
        String localName = "n" + random.nextInt(Math.min(Integer.MAX_VALUE, (int) Math.pow(2, attempts + 13)));
        uri = namespace + localName;
        log.debug("Trying URI " + uri);
        errMsg = getWebappDaoFactory().checkURI(uri);
        if (errMsg != null)
            uri = null;
        else
            uriIsGood = true;
        attempts++;
    }

    if (uri == null)
        throw new InsertException("Could not create URI for individual: " + errMsg);
    log.debug("Using URI" + uri);
    return uri;
}

From source file:com.insprise.common.lang.StringUtilities.java

/**
  * Checks whether the given string represents an integer.
  * @param str//from w  ww  .ja  v  a 2  s. com
  * @param trimFirst true to trim the string first.
  * @return
  */
 public static boolean isInteger(String str, boolean trimFirst) {
     if (str == null) {
         return false;
     }
     if (trimFirst) {
         str = str.trim();
     }
     if (str.length() == 0) {
         return false;
     }
     for (int i = 0; i < str.length(); i++) {
         if (!(Character.isDigit(str.charAt(i)) || (i == 0 && (str.charAt(i) == '-') || str.charAt(i) == '+'))) {
             return false;
         }
     }
     return true;
 }

From source file:com.prowidesoftware.swift.model.field.Field.java

private static String getNumber(final String fieldName) {
    if (fieldName != null) {
        final StringBuilder sb = new StringBuilder();
        for (int i = 0; i < fieldName.length(); i++) {
            final char c = fieldName.charAt(i);
            if (Character.isDigit(c)) {
                sb.append(c);/* w  w w  .j  av  a2s .c  om*/
            }
        }
        if (sb.length() > 0) {
            return sb.toString();
        }
    }
    return null;
}

From source file:com.aurel.track.exchange.msProject.exchange.MsProjectExchangeBL.java

/**
 * Get the time span fields into a map/*from  ww w  . ja  va  2s .  c o m*/
 *
 * @param str
 * @return
 */
private static Map<String, Double> getTimeSpanFields(String str) {
    Map<String, Double> timeUnitsMap = new HashMap<String, Double>();
    if (str == null || str.charAt(0) != MSPROJECT_TIME_UNITS.START_CHAR) {
        return timeUnitsMap;
    }
    StringBuilder stringBuffer = new StringBuilder(str.substring(1));
    StringBuilder gatherUnitValue = new StringBuilder();
    boolean isMinute = false;
    for (int i = 0; i < stringBuffer.length(); i++) {
        char c = stringBuffer.charAt(i);
        if (Character.isDigit(c)) {
            gatherUnitValue.append(c);
        } else {
            if (c == MSPROJECT_TIME_UNITS.TIME_SEPARATOR) {
                isMinute = true;
                continue;
            }
            if (c == MSPROJECT_TIME_UNITS.MINUTE_OR_MONTH) {
                if (isMinute) {
                    timeUnitsMap.put(MSPROJECT_TIME_UNITS.MINUTE, Double.valueOf(gatherUnitValue.toString()));
                } else {
                    timeUnitsMap.put(MSPROJECT_TIME_UNITS.MONTH, Double.valueOf(gatherUnitValue.toString()));
                }
            } else {
                timeUnitsMap.put(Character.toString(c), Double.valueOf(gatherUnitValue.toString()));
            }
            gatherUnitValue = new StringBuilder();
        }
    }
    return timeUnitsMap;
}

From source file:eu.tango.energymodeller.datasourceclient.SlurmDataSourceAdaptor.java

/**
 * This reads in the GresUsed string, this string represents Generic
 * Resource Scheduling (GRES). Usually either GPUs or Intel Many Integrated
 * Core (MIC) processors/*from   ww  w . j  a v  a2s.co  m*/
 *
 * @param values The parsed list of metrics.
 * @param measurement The measurement to add the metrics to
 * @param clock The timestamp for the new metric values
 * @return The newly adjusted measurement
 */
private HostMeasurement readGresUsedString(String[] values, HostMeasurement measurement, long clock) {
    String gresString = getValue("GresUsed", values);
    if (gresString.isEmpty()) {
        return measurement;
    }
    String[] gresStringSplit = gresString.split(",");
    for (String dataItem : gresStringSplit) {
        boolean gpu = dataItem.contains("gpu");
        boolean mic = dataItem.contains("mic");
        String[] dataItemSplit = dataItem.split(":");
        String gpuUsed = "";
        for (String item : dataItemSplit) {
            if (!item.isEmpty() && Character.isDigit(item.charAt(0))) {
                try (Scanner scanner = new Scanner(item).useDelimiter("[^\\d]+")) {
                    int used = scanner.nextInt();
                    gpuUsed = used + "";
                }
                break;
            }
        }
        if (gpu) {
            measurement.addMetric(new MetricValue(KpiList.GPU_USED, KpiList.GPU_USED, gpuUsed, clock));
        } else if (mic) {
            measurement.addMetric(new MetricValue(KpiList.MIC_USED, KpiList.MIC_USED, gpuUsed, clock));
        }

    }
    return measurement;
}