Here you can find the source of addLeadingZeros(String deweyCallNum)
Parameter | Description |
---|---|
deweyCallNum | a parameter |
public static String addLeadingZeros(String deweyCallNum)
//package com.java2s; public class Main { /**// w w w.ja v a 2 s . c om * adds leading zeros to a dewey call number, when they're missing. * * @param deweyCallNum * @return the dewey call number with leading zeros */ public static String addLeadingZeros(String deweyCallNum) { String result = deweyCallNum; String b4Cutter = getPortionBeforeCutter(deweyCallNum); // TODO: could call Utils.normalizeFloat(b4Cutter.trim(), 3, -1); // but still need to add back part after cutter String b4dec = null; int decIx = b4Cutter.indexOf("."); if (decIx >= 0) b4dec = deweyCallNum.substring(0, decIx).trim(); else b4dec = b4Cutter.trim(); if (b4dec != null) { switch (b4dec.length()) { case 1: result = "00" + deweyCallNum; break; case 2: result = "0" + deweyCallNum; } } return result; } /** * return the portion of the call number string that occurs before the * Cutter, NOT including any class suffixes occuring before the cutter */ public static final String getPortionBeforeCutter(String callnum) { // cutter is a single letter followed by digits. // there may be a space before a cutter // there should be a period, which is followed by a single letter // the period is sometimes missing // For Dewey callnumber, there may be a slash instead of a cutter, // or there might be NO cutter String beginCutterRegex = "( +|(\\.[A-Z])| */)"; String[] pieces = callnum.split(beginCutterRegex); if (pieces.length == 0 || pieces[0] == null || pieces[0].length() == 0) return null; else return pieces[0].trim(); } }