Example usage for org.apache.commons.lang StringUtils leftPad

List of usage examples for org.apache.commons.lang StringUtils leftPad

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils leftPad.

Prototype

public static String leftPad(String str, int size, String padStr) 

Source Link

Document

Left pad a String with a specified String.

Usage

From source file:stroom.streamstore.server.fs.FileSystemUtil.java

public static String encodeFileName(String fileName) {
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < fileName.length(); i++) {
        char c = fileName.charAt(i);
        if (Character.isLetter(c) || Character.isDigit(c) || c == '.' || c == ' ' || c == '-' || c == '_') {
            builder.append(c);/*from   w w  w.j  a v  a2 s.c  o m*/
        } else {
            builder.append("#");
            builder.append(StringUtils.leftPad(Integer.toHexString(c), 3, '0'));
        }
    }
    return builder.toString();
}

From source file:tasly.greathealth.jd.order.service.impl.JdOrderRetrieveServiceImpl.java

@Override
@Transactional//from  ww w .java 2s .co  m
public Order transformThirdPartyOrder2OmsOrder(final OrderSearchInfo thirdPartyOrder,
        final OrderContext orderContext) throws Exception {
    final OrderIdGeneratorData orderIdGenerator = this.getPersistenceManager()
            .create(OrderIdGeneratorData.class);
    final SimpleDateFormat sf = new SimpleDateFormat(DEFAULT_GENERATE_ID_DATE_FORMAT);
    final String temp = sf.format(new Date());
    orderContext.addProperty(DEFAULT_ORDER_ID_KEY,
            StringUtils.leftPad(String.valueOf(orderIdGenerator.getOrderId()), DEFAULT_ORDER_ID_LEN,
                    DEFAULT_ORDER_ID_PLACEHOLDER) + temp);
    return orderTransformer.transformOrder(thirdPartyOrder, orderContext);
}

From source file:tasly.greathealth.tmall.order.services.impl.OmsOrderRetrieverServiceTmallImpl.java

@Override
@Transactional//from ww  w  .  j a  va  2s .  co  m
public Order transformThirdPartyOrder2OmsOrder(final Trade thirdPartyOrder, final OrderContext orderContext)
        throws Exception {
    final OrderIdGeneratorData orderIdGenerator = this.getPersistenceManager()
            .create(OrderIdGeneratorData.class);
    final SimpleDateFormat sf = new SimpleDateFormat(DEFAULT_GENERATE_ID_DATE_FORMAT);
    final String temp = sf.format(new Date());
    orderContext.addProperty(DEFAULT_ORDER_ID_KEY,
            StringUtils.leftPad(String.valueOf(orderIdGenerator.getOrderId()), DEFAULT_ORDER_ID_LEN,
                    DEFAULT_ORDER_ID_PLACEHOLDER) + temp);
    return orderTransformer.transformOrder(thirdPartyOrder, orderContext);
}

From source file:ubic.gemma.analysis.preprocess.batcheffects.BatchInfoPopulationHelperServiceImpl.java

/**
 * @param batchNum//from   ww w . ja v a 2s.  c  o m
 * @param df
 * @param d
 * @return
 */
private String formatBatchName(int batchNum, DateFormat df, Date d) {
    String batchDateString;
    batchDateString = ExperimentalDesignUtils.BATCH_FACTOR_NAME_PREFIX
            + StringUtils.leftPad(Integer.toString(batchNum), 2, "0") + "_"
            + df.format(DateUtils.truncate(d, Calendar.HOUR));
    return batchDateString;
}

From source file:uk.ac.diamond.scisoft.analysis.processing.operations.ncd.NcdBackgroundSubtractionFromDataOperation.java

/**
 * Get images based on a user selection written in Irakli's format - note the latter number is inclusive (for 0-10, 11 images are selected)
 * @param slice//from  w ww.  j  a va  2s . co m
 * @return
 * @throws Exception
 */
private ILazyDataset getImageSelection(IDataset slice) throws Exception {
    //append ; to fill out the dimensions for image selection
    String selectionString = model.getImageSelectionString();
    int rank = getInputRank().equals(OperationRank.ONE) ? 1 : 2;
    int toAdd = background.getShape().length - rank - model.getImageSelectionString().split(";").length;
    if (toAdd > 0) {
        selectionString = StringUtils.leftPad(selectionString, toAdd + model.getImageSelectionString().length(),
                ";");
    }
    int[] reshaped = Arrays.copyOf(background.getShape(),
            background.getShape().length - slice.getShape().length);
    ArrayList<int[]> sliceList = NcdDataUtils.createSliceList(selectionString, reshaped); //only get image slices, not image data
    ArrayList<int[]> combinations = NcdDataUtils.generateCombinations(sliceList);

    return getByCombinations(background.getSliceView(), combinations);
}

From source file:uk.ac.diamond.scisoft.ncd.reduction.LazyNcdProcessing.java

/**
  * // www. j  ava2  s . co m
  * @param detectorName - name of detector e.g. Pilatus2M
  * @param dimension      - dimension of detector
  * @param filename - file path to io file (processing done in this folder) 
  * @param monitor
  * @throws HDF5Exception 
  */
 public void configure(String detectorName, int dimension, String filename, final IProgressMonitor monitor)
         throws HDF5Exception {
     String[] tmpName = FilenameUtils.getName(filename).split("_");
     monitorFile = tmpName[1];
     detector = detectorName;

     int fapl = H5.H5Pcreate(HDF5Constants.H5P_FILE_ACCESS);
     H5.H5Pset_fclose_degree(fapl, HDF5Constants.H5F_CLOSE_WEAK);
     nxsfile_handle = H5.H5Fopen(filename, HDF5Constants.H5F_ACC_RDWR, fapl);
     H5.H5Pclose(fapl);
     entry_group_id = H5.H5Gopen(nxsfile_handle, "entry1", HDF5Constants.H5P_DEFAULT);

     fapl = H5.H5Pcreate(HDF5Constants.H5P_FILE_ACCESS);
     H5.H5Pset_fclose_degree(fapl, HDF5Constants.H5F_CLOSE_WEAK);
     // Need to use read-only file handle to safely access
     // input data linked into the result file
     inputfile_handle = H5.H5Fopen(filename, HDF5Constants.H5F_ACC_RDONLY, fapl);
     H5.H5Pclose(fapl);
     detector_group_id = H5.H5Gopen(inputfile_handle, "entry1/" + detector, HDF5Constants.H5P_DEFAULT);
     input_data_id = H5.H5Dopen(detector_group_id, "data", HDF5Constants.H5P_DEFAULT);
     boolean exists = H5.H5Lexists(detector_group_id, "errors", HDF5Constants.H5P_DEFAULT);
     if (exists) {
         input_errors_id = H5.H5Dopen(detector_group_id, "errors", HDF5Constants.H5P_DEFAULT);
     }

     input_ids = new DataSliceIdentifiers();
     input_ids.setIDs(detector_group_id, input_data_id);
     input_errors_ids = new DataSliceIdentifiers();
     input_errors_ids.setIDs(detector_group_id, input_errors_id);

     dim = dimension;
     rank = H5.H5Sget_simple_extent_ndims(input_ids.dataspace_id);
     frames = new long[rank];
     H5.H5Sget_simple_extent_dims(input_ids.dataspace_id, frames, null);
     frames_int = (int[]) ConvertUtils.convert(frames, int[].class);

     processing_group_id = NcdNexusUtils.makegroup(entry_group_id, detector + "_processing", Nexus.INST);
     result_group_id = NcdNexusUtils.makegroup(entry_group_id, detector + "_result", Nexus.DATA);

     if (firstFrame != null || lastFrame != null) {
         frameSelection = StringUtils.leftPad("", rank - dim - 1, ";");
         if (firstFrame != null) {
             frameSelection += Integer.toString(firstFrame);
         }
         frameSelection += "-";
         if (lastFrame != null) {
             frameSelection += Integer.toString(lastFrame);
         }
         frameSelection += ";";
     }

     if (frameSelection != null) {
         int sel_group_id = NcdNexusUtils.makegroup(processing_group_id, LazySelection.name, Nexus.DETECT);

         monitor.beginTask(monitorFile + " : Slicing Input Data", IProgressMonitor.UNKNOWN);
         LazySelection selection = new LazySelection(frames_int);
         selection.setFormat(frameSelection);
         selection.setMonitor(monitor);
         DataSliceIdentifiers[] obj_ids = selection.execute(dim, input_ids, input_errors_ids, sel_group_id);

         if (monitor.isCanceled()) {
             return;
         }

         monitor.done();

         input_ids = obj_ids[0];
         input_errors_ids = obj_ids[1];
         H5.H5Sget_simple_extent_dims(input_ids.dataspace_id, frames, null);
         frames_int = (int[]) ConvertUtils.convert(frames, int[].class);
     }

     lazyDetectorResponse = new LazyDetectorResponse(drFile, detector);
     if (flags.isEnableDetectorResponse()) {
         lazyDetectorResponse.setDrFile(drFile);
         lazyDetectorResponse.configure(dimension, frames, entry_group_id, processing_group_id);
     }

     lazySectorIntegration = new LazySectorIntegration();
     if (flags.isEnableSector() && dim == 2) {
         intSector.setAverageArea(false);
         lazySectorIntegration.setIntSector(intSector);
         if (enableMask) {
             lazySectorIntegration.setMask(mask);
         }
         qaxis = calculateQaxisDataset(detector, dim, secFrames, frames);
         if (qaxis != null) {
             lazySectorIntegration.setQaxis(qaxis, qaxisUnit);
             lazySectorIntegration.setCalibrationData(slope, intercept);
             lazySectorIntegration.setCameraLength(cameraLength);
             lazySectorIntegration.setEnergy(energy);
         }
         lazySectorIntegration.setCalculateRadial(flags.isEnableRadial());
         lazySectorIntegration.setCalculateAzimuthal(flags.isEnableAzimuthal());
         lazySectorIntegration.setFast(flags.isEnableFastintegration());
         lazySectorIntegration.configure(dimension, frames, processing_group_id);

         secRank = rank - dim + 1;
         secFrames = lazySectorIntegration.secFrames;
         dimension = 1;
     }

     lazyNormalisation = new LazyNormalisation();
     if (flags.isEnableNormalisation()) {
         lazyNormalisation.setCalibration(calibration);
         lazyNormalisation.setAbsScaling(absScaling);
         lazyNormalisation.setNormChannel(normChannel);
         lazyNormalisation.configure(dimension, flags.isEnableSector() ? secFrames : frames, entry_group_id,
                 processing_group_id);
     }

     lazyBackgroundSubtraction = new LazyBackgroundSubtraction();
     if (flags.isEnableBackground()) {
         if (qaxis != null) {
             lazyBackgroundSubtraction.setQaxis(qaxis, qaxisUnit);
         }
         lazyBackgroundSubtraction.setBgFile(bgFile);
         lazyBackgroundSubtraction.setBgDetector(bgDetector);
         lazyBackgroundSubtraction.setBgScale(bgScaling);
         lazyBackgroundSubtraction.configure(dimension, flags.isEnableSector() ? secFrames : frames,
                 processing_group_id);

         lazyBackgroundSubtraction.preprocess(dimension, frames, frameBatch);
     }

     lazyInvariant = new LazyInvariant();
     if (flags.isEnableInvariant()) {
         lazyInvariant.configure(dimension, flags.isEnableSector() ? secFrames : frames, entry_group_id,
                 processing_group_id);
     }
 }

From source file:util.settings.ColorProperty.java

/**
 * Sets the Color in this Property/*  www.  j  a  v  a 2s .  c  om*/
 * @param color Color
 */
public void setColor(Color color) {
    if (color == mDefaultColor) {
        setProperty(null);
    } else {
        mCachedValue = color;
        String value = UiUtilities.getHTMLColorCode(color)
                + StringUtils.leftPad(Integer.toString(color.getAlpha(), 16), 2, '0');
        setProperty(value);
    }
}

From source file:util.ui.UiUtilities.java

/**
 * returns a color code as used in HTML, e.g. #FF0000 for pure red
 * @param color// ww  w.j  av  a 2 s . c  o m
 * @return HTML color code
 */
public static String getHTMLColorCode(Color color) {
    return '#' + StringUtils.leftPad(Integer.toString(color.getRed(), 16), 2, '0')
            + StringUtils.leftPad(Integer.toString(color.getGreen(), 16), 2, '0')
            + StringUtils.leftPad(Integer.toString(color.getBlue(), 16), 2, '0');
}