Example usage for org.apache.commons.lang ArrayUtils toString

List of usage examples for org.apache.commons.lang ArrayUtils toString

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils toString.

Prototype

public static String toString(Object array) 

Source Link

Document

Outputs an array as a String, treating null as an empty array.

Usage

From source file:edu.harvard.iq.dataverse.ingest.tabulardata.impl.plugins.sav.SAVFileReader.java

void decodeRecordType3and4(BufferedInputStream stream) throws IOException {
    dbgLog.fine("decodeRecordType3and4(): start");
    Map<String, Map<String, String>> valueLabelTable = new LinkedHashMap<String, Map<String, String>>();

    int safteyCounter = 0;
    while (true) {
        try {//  w  w  w . ja  v a 2 s  . c o  m
            if (stream == null) {
                throw new IllegalArgumentException("stream == null!");
            }
            // this secton may not exit so first check the 4-byte header value
            //if (stream.markSupported()){
            stream.mark(1000);
            //}
            // 3.0 check the first 4 bytes
            byte[] headerCode = new byte[LENGTH_RECORD_TYPE3_CODE];

            int nbytes_rt3 = stream.read(headerCode, 0, LENGTH_RECORD_TYPE3_CODE);
            // to-do check against nbytes
            //printHexDump(headerCode, "RT3 header test");
            ByteBuffer bb_header_code = ByteBuffer.wrap(headerCode, 0, LENGTH_RECORD_TYPE3_CODE);
            if (isLittleEndian) {
                bb_header_code.order(ByteOrder.LITTLE_ENDIAN);
            }

            int intRT3test = bb_header_code.getInt();
            dbgLog.fine("header test value: RT3=" + intRT3test);
            if (intRT3test != 3) {
                //if (stream.markSupported()){
                dbgLog.fine("iteration=" + safteyCounter);

                // We have encountered a record that's not type 3. This means we've
                // processed all the type 3/4 record pairs. So we want to rewind
                // the stream and return -- so that the appropriate record type
                // reader can be called on it.
                // But before we return, we need to save all the value labels
                // we have found:
                //smd.setValueLabelTable(valueLabelTable);
                assignValueLabels(valueLabelTable);

                stream.reset();
                return;
                //}
            }
            // 3.1 how many value-label pairs follow
            byte[] number_of_labels = new byte[LENGTH_RT3_HOW_MANY_LABELS];

            int nbytes_3_1 = stream.read(number_of_labels);
            if (nbytes_3_1 == 0) {
                throw new IOException("RT 3: reading recordType3.1: no byte was read");
            }
            ByteBuffer bb_number_of_labels = ByteBuffer.wrap(number_of_labels, 0, LENGTH_RT3_HOW_MANY_LABELS);
            if (isLittleEndian) {
                bb_number_of_labels.order(ByteOrder.LITTLE_ENDIAN);
            }

            int numberOfValueLabels = bb_number_of_labels.getInt();
            dbgLog.fine("number of value-label pairs=" + numberOfValueLabels);

            ByteBuffer[] tempBB = new ByteBuffer[numberOfValueLabels];

            String valueLabel[] = new String[numberOfValueLabels];

            for (int i = 0; i < numberOfValueLabels; i++) {

                // read 8-byte as value          
                byte[] value = new byte[LENGTH_RT3_VALUE];
                int nbytes_3_value = stream.read(value);

                if (nbytes_3_value == 0) {
                    throw new IOException("RT 3: reading recordType3 value: no byte was read");
                }
                // note these 8 bytes are interpreted later
                // currently no information about which variable's (=> type unknown)
                ByteBuffer bb_value = ByteBuffer.wrap(value, 0, LENGTH_RT3_VALUE);
                if (isLittleEndian) {
                    bb_value.order(ByteOrder.LITTLE_ENDIAN);
                }
                tempBB[i] = bb_value;
                dbgLog.fine("bb_value=" + Hex.encodeHex(bb_value.array()));
                /*
                 double valueD = bb_value.getDouble();                
                 dbgLog.fine("value="+valueD);
                 */
                // read 1st byte as unsigned integer = label_length

                // read label_length byte as label
                byte[] labelLengthByte = new byte[LENGTH_RT3_LABEL_LENGTH];

                int nbytes_3_label_length = stream.read(labelLengthByte);

                // add check-routine here
                dbgLog.fine("labelLengthByte" + Hex.encodeHex(labelLengthByte));
                dbgLog.fine("label length = " + labelLengthByte[0]);
                // the net-length of a value label is saved as
                // unsigned byte; however, the length is less than 127
                // byte should be ok
                int rawLabelLength = labelLengthByte[0] & 0xFF;
                dbgLog.fine("rawLabelLength=" + rawLabelLength);
                // -1 =>1-byte already read
                int labelLength = getSAVobsAdjustedBlockLength(rawLabelLength + 1) - 1;
                byte[] valueLabelBytes = new byte[labelLength];
                int nbytes_3_value_label = stream.read(valueLabelBytes);

                // ByteBuffer bb_label = ByteBuffer.wrap(valueLabel,0,labelLength);
                valueLabel[i] = StringUtils.stripEnd(
                        new String(Arrays.copyOfRange(valueLabelBytes, 0, rawLabelLength), defaultCharSet),
                        " ");
                dbgLog.fine(i + "-th valueLabel=" + valueLabel[i] + "<-");

            } // iter rt3

            dbgLog.fine("end of RT3 block");
            dbgLog.fine("start of RT4 block");

            // 4.0 check the first 4 bytes
            byte[] headerCode4 = new byte[LENGTH_RECORD_TYPE4_CODE];

            int nbytes_rt4 = stream.read(headerCode4, 0, LENGTH_RECORD_TYPE4_CODE);

            if (nbytes_rt4 == 0) {
                throw new IOException("RT4: reading recordType4 value: no byte was read");
            }

            //printHexDump(headerCode4, "RT4 header test");
            ByteBuffer bb_header_code_4 = ByteBuffer.wrap(headerCode4, 0, LENGTH_RECORD_TYPE4_CODE);
            if (isLittleEndian) {
                bb_header_code_4.order(ByteOrder.LITTLE_ENDIAN);
            }

            int intRT4test = bb_header_code_4.getInt();
            dbgLog.fine("header test value: RT4=" + intRT4test);

            if (intRT4test != 4) {
                throw new IOException("RT 4: reading recordType4 header: no byte was read");
            }

            // 4.1 read the how-many-variables bytes
            byte[] howManyVariablesfollow = new byte[LENGTH_RT4_HOW_MANY_VARIABLES];

            int nbytes_rt4_1 = stream.read(howManyVariablesfollow, 0, LENGTH_RT4_HOW_MANY_VARIABLES);

            ByteBuffer bb_howManyVariablesfollow = ByteBuffer.wrap(howManyVariablesfollow, 0,
                    LENGTH_RT4_HOW_MANY_VARIABLES);
            if (isLittleEndian) {
                bb_howManyVariablesfollow.order(ByteOrder.LITTLE_ENDIAN);
            }

            int howManyVariablesRT4 = bb_howManyVariablesfollow.getInt();
            dbgLog.fine("how many variables follow: RT4=" + howManyVariablesRT4);

            int length_indicies = LENGTH_RT4_VARIABLE_INDEX * howManyVariablesRT4;
            byte[] variableIdicesBytes = new byte[length_indicies];

            int nbytes_rt4_2 = stream.read(variableIdicesBytes, 0, length_indicies);

            // !!!!! Caution: variableIndex in RT4 starts from 1 NOT ** 0 **
            int[] variableIndex = new int[howManyVariablesRT4];
            int offset = 0;
            for (int i = 0; i < howManyVariablesRT4; i++) {

                ByteBuffer bb_variable_index = ByteBuffer.wrap(variableIdicesBytes, offset,
                        LENGTH_RT4_VARIABLE_INDEX);
                offset += LENGTH_RT4_VARIABLE_INDEX;

                if (isLittleEndian) {
                    bb_variable_index.order(ByteOrder.LITTLE_ENDIAN);
                }

                variableIndex[i] = bb_variable_index.getInt();
                dbgLog.fine(i + "-th variable index number=" + variableIndex[i]);
            }

            dbgLog.fine("variable index set=" + ArrayUtils.toString(variableIndex));
            dbgLog.fine("subtract 1 from variableIndex for getting a variable info");

            boolean isNumeric = OBSwiseTypelList.get(variableIndex[0] - 1) == 0 ? true : false;

            Map<String, String> valueLabelPair = new LinkedHashMap<String, String>();
            if (isNumeric) {
                // numeric variable
                dbgLog.fine("processing of a numeric value-label table");
                for (int j = 0; j < numberOfValueLabels; j++) {
                    valueLabelPair.put(doubleNumberFormatter.format(tempBB[j].getDouble()), valueLabel[j]);
                }
            } else {
                // String variable
                dbgLog.fine("processing of a string value-label table");
                for (int j = 0; j < numberOfValueLabels; j++) {
                    valueLabelPair.put(
                            StringUtils.stripEnd(new String((tempBB[j].array()), defaultCharSet), " "),
                            valueLabel[j]);
                }
            }

            dbgLog.fine("valueLabePair=" + valueLabelPair);
            dbgLog.fine("key variable's (raw) index =" + variableIndex[0]);

            valueLabelTable.put(OBSIndexToVariableName.get(variableIndex[0] - 1), valueLabelPair);

            dbgLog.fine("valueLabelTable=" + valueLabelTable);

            // create a mapping table that finds the key variable for this mapping table
            String keyVariableName = OBSIndexToVariableName.get(variableIndex[0] - 1);
            for (int vn : variableIndex) {
                valueVariableMappingTable.put(OBSIndexToVariableName.get(vn - 1), keyVariableName);
            }

            dbgLog.fine("valueVariableMappingTable:\n" + valueVariableMappingTable);
        } catch (IOException ex) {
            //ex.printStackTrace();
            throw ex;
        }

        safteyCounter++;
        if (safteyCounter >= 1000000) {
            break;
        }
    } //while

    ///smd.setValueLabelTable(valueLabelTable);
    assignValueLabels(valueLabelTable);

    dbgLog.fine("***** decodeRecordType3and4(): end *****");
}

From source file:com.ikanow.infinit.e.api.config.source.SourceHandler.java

private static String allowCommunityRegex(String userIdStr, String communityIdStr) {
    if (communityIdStr.startsWith("*")) {
        String[] communityIdStrs = SocialUtils.getCommunityIds(userIdStr, communityIdStr);
        if (1 == communityIdStrs.length) {
            communityIdStr = communityIdStrs[0];
        } else {/*from   w  ww  .jav  a  2 s.c  o  m*/
            throw new RuntimeException("Invalid community pattern, matched " + communityIdStrs.length
                    + " communities: " + ArrayUtils.toString(communityIdStrs));
        }
    }
    return communityIdStr;
}

From source file:it.grid.storm.config.Configuration.java

@Override
public String toString() {

    StringBuilder configurationStringBuilder = new StringBuilder();
    try {//from w  w w.java  2 s.c  o  m
        // This class methods
        Method methods[] = Configuration.instance.getClass().getDeclaredMethods();

        // This class fields
        Field[] fields = Configuration.instance.getClass().getDeclaredFields();
        HashMap<String, String> methodKeyMap = new HashMap<String, String>();
        for (Field field : fields) {
            String fieldName = field.getName();
            if (fieldName.endsWith("KEY") && field.getType().equals(String.class)) {
                // from a field like GROUP_TAPE_WRITE_BUFFER_KEY =
                // "tape.buffer.group.write"
                // puts in the map the pair
                // <getgrouptapewritebuffer,tape.buffer.group.write>
                String mapKey = "get"
                        + fieldName.substring(0, fieldName.lastIndexOf("_")).replaceAll("_", "").toLowerCase();
                if (methodKeyMap.containsKey(mapKey)) {
                    String value = methodKeyMap.get(mapKey);
                    methodKeyMap.put(mapKey, value + " , " + (String) field.get(Configuration.instance));
                } else {
                    methodKeyMap.put(mapKey, (String) field.get(Configuration.instance));
                }
            }
        }

        Object field = null;
        Object[] dummyArray = new Object[0];
        for (Method method : methods) {
            /*
             * with method.getModifiers() == 1 we check that the method is public
             * (otherwise he can request real parameters)
             */
            if (method.getName().substring(0, 3).equals("get") && (!method.getName().equals("getInstance"))
                    && method.getModifiers() == 1) {
                field = method.invoke(Configuration.instance, dummyArray);
                if (field.getClass().isArray()) {
                    field = ArrayUtils.toString(field);
                }
                String value = methodKeyMap.get(method.getName().toLowerCase());
                if (value == null) {
                    configurationStringBuilder.insert(0,
                            "!! Unable to find method " + method.getName() + " in methode key map!");
                } else {
                    configurationStringBuilder.append("Property " + value + " : ");
                }
                if (field.getClass().equals(String.class)) {
                    field = '\'' + ((String) field) + '\'';
                }
                configurationStringBuilder.append(method.getName() + "() == " + field.toString() + "\n");
            }
        }
        return configurationStringBuilder.toString();
    } catch (Exception e) {
        if (e.getClass().isAssignableFrom(java.lang.reflect.InvocationTargetException.class)) {
            configurationStringBuilder.insert(0,
                    "!!! Cannot do toString! Got an Exception: " + e.getCause() + "\n");
        } else {
            configurationStringBuilder.insert(0, "!!! Cannot do toString! Got an Exception: " + e + "\n");
        }
        return configurationStringBuilder.toString();
    }
}

From source file:com.novartis.opensource.yada.YADARequest.java

/**
 * A utility method for pretty-printing debug info in the form like:
 * <p>/*w ww . j  a va 2  s  .  c om*/
 * {@code Set [name] to [string,string...]}
 * </p>
 * @param name a parameter name
 * @param strings the parameter value
 * @return a formatted string
 */
@SuppressWarnings("static-method")
private String getFormattedDebugString(String name, String[] strings) {
    String sSet = "Set [" + name + "]";
    String sVal = "[" + ArrayUtils.toString(strings) + "]";
    return String.format("%25s to %s", sSet, sVal);
}

From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.sav.SAVFileReader.java

void decodeRecordTypeDataUnCompressed(BufferedInputStream stream) throws IOException {
    dbgLog.fine("***** decodeRecordTypeDataUnCompressed(): start *****");

    if (stream == null) {
        throw new IllegalArgumentException("decodeRecordTypeDataUnCompressed: stream == null!");
    }//from  ww  w  .j  a va 2 s.  c o  m

    Map<String, String> formatCategoryTable = new LinkedHashMap<String, String>();

    // 
    // set-up tab file

    PrintWriter pwout = createOutputWriter(stream);

    boolean hasStringVarContinuousBlock = obsNonVariableBlockSet.size() > 0 ? true : false;
    dbgLog.fine("hasStringVarContinuousBlock=" + hasStringVarContinuousBlock);

    int ii = 0;

    int OBS = LENGTH_SAV_OBS_BLOCK;
    int nOBS = OBSUnitsPerCase;

    dbgLog.fine("OBSUnitsPerCase=" + OBSUnitsPerCase);

    int caseIndex = 0;

    dbgLog.fine("printFormatTable:\n" + printFormatTable);

    dbgLog.fine("printFormatNameTable:\n" + printFormatNameTable);
    variableFormatTypeList = new String[varQnty];

    for (int i = 0; i < varQnty; i++) {
        variableFormatTypeList[i] = SPSSConstants.FORMAT_CATEGORY_TABLE
                .get(printFormatTable.get(variableNameList.get(i)));
        dbgLog.fine("i=" + i + "th variableFormatTypeList=" + variableFormatTypeList[i]);
        formatCategoryTable.put(variableNameList.get(i), variableFormatTypeList[i]);
    }
    dbgLog.fine("variableFormatType:\n" + Arrays.deepToString(variableFormatTypeList));
    dbgLog.fine("formatCategoryTable:\n" + formatCategoryTable);

    // contents (variable) checker concering decimals
    variableTypeFinal = new int[varQnty];
    Arrays.fill(variableTypeFinal, 0);

    int numberOfDecimalVariables = 0;

    List<String> casewiseRecordForTabFile = new ArrayList<String>();
    String[] caseWiseDateFormatForUNF = null;
    List<String> casewiseRecordForUNF = new ArrayList<String>();

    // missing values are written to the tab-delimited file by
    // using the default or user-specified missing-value  strings;
    // however, to calculate UNF/summary statistics,
    // classes for these calculations require their specific 
    // missing values that differ from the above missing-value
    // strings; therefore, after row data for the tab-delimited 
    // file are written, missing values in a row are changed to
    // UNF/summary-statistics-OK ones.

    // data-storage object for sumStat
    dataTable2 = new Object[varQnty][caseQnty];
    // storage of date formats to pass to UNF   
    dateFormats = new String[varQnty][caseQnty];

    try {
        for (int i = 0;; i++) { // case-wise loop

            byte[] buffer = new byte[OBS * nOBS];

            int nbytesuc = stream.read(buffer);

            StringBuilder sb_stringStorage = new StringBuilder("");

            for (int k = 0; k < nOBS; k++) {
                int offset = OBS * k;

                // uncompressed case
                // numeric missing value == sysmis
                // FF FF FF FF FF FF eF FF(little endian)
                // string missing value
                // 20 20 20 20 20 20 20 20
                // cf: compressed case 
                // numeric type:sysmis == 0xFF
                // string type: missing value == 0xFE
                // 

                boolean isNumeric = OBSwiseTypelList.get(k) == 0 ? true : false;

                if (isNumeric) {
                    dbgLog.finer(k + "-th variable is numeric");
                    // interprete as double
                    ByteBuffer bb_double = ByteBuffer.wrap(buffer, offset, LENGTH_SAV_OBS_BLOCK);
                    if (isLittleEndian) {
                        bb_double.order(ByteOrder.LITTLE_ENDIAN);
                    }
                    //char[] hexpattern =
                    String dphex = new String(Hex.encodeHex(
                            Arrays.copyOfRange(bb_double.array(), offset, offset + LENGTH_SAV_OBS_BLOCK)));
                    dbgLog.finer("dphex=" + dphex);

                    if ((dphex.equals("ffffffffffffefff")) || (dphex.equals("ffefffffffffffff"))) {
                        //casewiseRecordForTabFile.add(systemMissingValue);
                        // add the numeric missing value
                        dbgLog.fine("SAV Reader: adding: Missing Value (numeric)");
                        casewiseRecordForTabFile.add(MissingValueForTextDataFileNumeric);
                    } else {
                        Double ddatum = bb_double.getDouble();
                        dbgLog.fine("SAV Reader: adding: ddatum=" + ddatum);

                        // add this non-missing-value numeric datum
                        casewiseRecordForTabFile.add(doubleNumberFormatter.format(ddatum));
                    }

                } else {
                    dbgLog.finer(k + "-th variable is string");
                    // string case
                    // strip space-padding
                    // do not trim: string might have spaces within it
                    // the missing value (hex) for a string variable is:
                    // "20 20 20 20 20 20 20 20"

                    String strdatum = new String(
                            Arrays.copyOfRange(buffer, offset, (offset + LENGTH_SAV_OBS_BLOCK)),
                            defaultCharSet);
                    dbgLog.finer("str_datum=" + strdatum);
                    // add this non-missing-value string datum 
                    casewiseRecordForTabFile.add(strdatum);

                } // if isNumeric

            } // k-loop

            // String-variable's continuous block exits:
            if (hasStringVarContinuousBlock) {
                // continuous blocks: string case
                // concatenating process
                //dbgLog.fine("concatenating process starts");

                //dbgLog.fine("casewiseRecordForTabFile(before)="+casewiseRecordForTabFile);
                //dbgLog.fine("casewiseRecordForTabFile(before:size)="+casewiseRecordForTabFile.size());

                StringBuilder sb = new StringBuilder("");
                int firstPosition = 0;

                Set<Integer> removeJset = new HashSet<Integer>();
                for (int j = 0; j < nOBS; j++) {
                    dbgLog.finer("j=" + j + "-th type =" + OBSwiseTypelList.get(j));
                    if (OBSwiseTypelList.get(j) == -1) {
                        // String continued fount at j-th 
                        // look back the j-1 
                        firstPosition = j - 1;
                        int lastJ = j;
                        String concatanated = null;

                        removeJset.add(j);
                        sb.append(casewiseRecordForTabFile.get(j - 1));
                        sb.append(casewiseRecordForTabFile.get(j));
                        for (int jc = 1;; jc++) {
                            if (OBSwiseTypelList.get(j + jc) != -1) {
                                // j is the end unit of this string variable
                                concatanated = sb.toString();
                                sb.setLength(0);
                                lastJ = j + jc;
                                break;
                            } else {
                                sb.append(casewiseRecordForTabFile.get(j + jc));
                                removeJset.add(j + jc);
                            }
                        }
                        casewiseRecordForTabFile.set(j - 1, concatanated);

                        //out.println(j-1+"th concatanated="+concatanated);
                        j = lastJ - 1;

                    } // end-of-if: continuous-OBS only
                } // end of loop-j

                List<String> newDataLine = new ArrayList<String>();

                for (int jl = 0; jl < casewiseRecordForTabFile.size(); jl++) {
                    //out.println("jl="+jl+"-th datum =["+casewiseRecordForTabFile.get(jl)+"]");

                    if (!removeJset.contains(jl)) {
                        newDataLine.add(casewiseRecordForTabFile.get(jl));
                    }
                }

                dbgLog.fine("new casewiseRecordForTabFile=" + newDataLine);
                dbgLog.fine("new casewiseRecordForTabFile(size)=" + newDataLine.size());

                casewiseRecordForTabFile = newDataLine;

            } // end-if: stringContinuousVar-exist case

            for (int el = 0; el < casewiseRecordForTabFile.size(); el++) {
                casewiseRecordForUNF.add(casewiseRecordForTabFile.get(el));
            }

            caseWiseDateFormatForUNF = new String[casewiseRecordForTabFile.size()];

            caseIndex++;
            dbgLog.finer("caseIndex=" + caseIndex);
            for (int k = 0; k < casewiseRecordForTabFile.size(); k++) {

                if (variableTypelList.get(k) > 0) {
                    // String variable case: set to  -1
                    variableTypeFinal[k] = -1;

                    // See my comments for this padding removal logic
                    // in the "compressed" method -- L.A.

                    String paddRemoved = StringUtils.stripEnd(casewiseRecordForTabFile.get(k).toString(), null);
                    // TODO: clean this up.  For now, just make sure that strings contain at least one blank space.
                    if (paddRemoved.equals("")) {
                        paddRemoved = " ";
                    }

                    casewiseRecordForUNF.set(k, paddRemoved);
                    casewiseRecordForTabFile.set(k,
                            "\"" + paddRemoved.replaceAll("\"", Matcher.quoteReplacement("\\\"")) + "\"");

                    // end of String var case

                } else {
                    // numeric var case
                    if (casewiseRecordForTabFile.get(k).equals(MissingValueForTextDataFileNumeric)) {
                        casewiseRecordForUNF.set(k, null);
                    }

                } // end of variable-type check

                if (casewiseRecordForTabFile.get(k) != null
                        && !casewiseRecordForTabFile.get(k).equals(MissingValueForTextDataFileNumeric)) {

                    // to do date conversion
                    String variableFormatType = variableFormatTypeList[k];
                    dbgLog.finer("k=" + k + "th variable format=" + variableFormatType);

                    int formatDecimalPointPosition = formatDecimalPointPositionList.get(k);

                    if (variableFormatType.equals("date")) {
                        dbgLog.finer("date case");

                        long dateDatum = Long.parseLong(casewiseRecordForTabFile.get(k).toString()) * 1000L
                                - SPSS_DATE_OFFSET;

                        String newDatum = sdf_ymd.format(new Date(dateDatum));
                        dbgLog.finer("k=" + k + ":" + newDatum);
                        caseWiseDateFormatForUNF[k] = sdf_ymd.toPattern();

                        casewiseRecordForTabFile.set(k, newDatum);
                        casewiseRecordForUNF.set(k, newDatum);
                        //formatCategoryTable.put(variableNameList.get(k), "date");
                    } else if (variableFormatType.equals("time")) {
                        dbgLog.finer("time case:DTIME or DATETIME or TIME");
                        //formatCategoryTable.put(variableNameList.get(k), "time");

                        if (printFormatTable.get(variableNameList.get(k)).equals("DTIME")) {

                            if (casewiseRecordForTabFile.get(k).toString().indexOf(".") < 0) {
                                long dateDatum = Long.parseLong(casewiseRecordForTabFile.get(k).toString())
                                        * 1000L - SPSS_DATE_BIAS;
                                String newDatum = sdf_dhms.format(new Date(dateDatum));
                                // Note: DTIME is not a complete date, so we don't save a date format with it
                                dbgLog.finer("k=" + k + ":" + newDatum);
                                casewiseRecordForTabFile.set(k, newDatum);
                                casewiseRecordForUNF.set(k, newDatum);
                            } else {
                                // decimal point included
                                String[] timeData = casewiseRecordForTabFile.get(k).toString().split("\\.");

                                dbgLog.finer(StringUtils.join(timeData, "|"));
                                long dateDatum = Long.parseLong(timeData[0]) * 1000L - SPSS_DATE_BIAS;
                                StringBuilder sb_time = new StringBuilder(sdf_dhms.format(new Date(dateDatum)));

                                if (formatDecimalPointPosition > 0) {
                                    sb_time.append("." + timeData[1].substring(0, formatDecimalPointPosition));
                                }

                                dbgLog.finer("k=" + k + ":" + sb_time.toString());
                                casewiseRecordForTabFile.set(k, sb_time.toString());
                                casewiseRecordForUNF.set(k, sb_time.toString());
                            }
                        } else if (printFormatTable.get(variableNameList.get(k)).equals("DATETIME")) {

                            if (casewiseRecordForTabFile.get(k).toString().indexOf(".") < 0) {
                                long dateDatum = Long.parseLong(casewiseRecordForTabFile.get(k).toString())
                                        * 1000L - SPSS_DATE_OFFSET;
                                String newDatum = sdf_ymdhms.format(new Date(dateDatum));
                                caseWiseDateFormatForUNF[k] = sdf_ymdhms.toPattern();
                                dbgLog.finer("k=" + k + ":" + newDatum);
                                casewiseRecordForTabFile.set(k, newDatum);
                                casewiseRecordForUNF.set(k, newDatum);
                            } else {
                                // decimal point included
                                String[] timeData = casewiseRecordForTabFile.get(k).toString().split("\\.");

                                //dbgLog.finer(StringUtils.join(timeData, "|"));
                                long dateDatum = Long.parseLong(timeData[0]) * 1000L - SPSS_DATE_OFFSET;
                                StringBuilder sb_time = new StringBuilder(
                                        sdf_ymdhms.format(new Date(dateDatum)));
                                //dbgLog.finer(sb_time.toString());

                                if (formatDecimalPointPosition > 0) {
                                    sb_time.append("." + timeData[1].substring(0, formatDecimalPointPosition));
                                }
                                caseWiseDateFormatForUNF[k] = sdf_ymdhms.toPattern()
                                        + (formatDecimalPointPosition > 0 ? ".S" : "");
                                dbgLog.finer("k=" + k + ":" + sb_time.toString());
                                casewiseRecordForTabFile.set(k, sb_time.toString());
                                casewiseRecordForUNF.set(k, sb_time.toString());
                            }
                        } else if (printFormatTable.get(variableNameList.get(k)).equals("TIME")) {
                            if (casewiseRecordForTabFile.get(k).toString().indexOf(".") < 0) {
                                long dateDatum = Long.parseLong(casewiseRecordForTabFile.get(k).toString())
                                        * 1000L;
                                String newDatum = sdf_hms.format(new Date(dateDatum));
                                caseWiseDateFormatForUNF[k] = sdf_hms.toPattern();
                                dbgLog.finer("k=" + k + ":" + newDatum);
                                casewiseRecordForTabFile.set(k, newDatum);
                                casewiseRecordForUNF.set(k, newDatum);
                            } else {
                                // decimal point included
                                String[] timeData = casewiseRecordForTabFile.get(k).toString().split("\\.");

                                //dbgLog.finer(StringUtils.join(timeData, "|"));
                                long dateDatum = Long.parseLong(timeData[0]) * 1000L;
                                StringBuilder sb_time = new StringBuilder(sdf_hms.format(new Date(dateDatum)));
                                //dbgLog.finer(sb_time.toString());

                                if (formatDecimalPointPosition > 0) {
                                    sb_time.append("." + timeData[1].substring(0, formatDecimalPointPosition));
                                }
                                caseWiseDateFormatForUNF[k] = this.sdf_hms.toPattern()
                                        + (formatDecimalPointPosition > 0 ? ".S" : "");
                                dbgLog.finer("k=" + k + ":" + sb_time.toString());
                                casewiseRecordForTabFile.set(k, sb_time.toString());
                                casewiseRecordForUNF.set(k, sb_time.toString());
                            }
                        }
                    } else if (variableFormatType.equals("other")) {
                        dbgLog.finer("other non-date/time case");

                        if (printFormatTable.get(variableNameList.get(k)).equals("WKDAY")) {
                            // day of week
                            dbgLog.finer("data k=" + k + ":" + casewiseRecordForTabFile.get(k));
                            dbgLog.finer("data k=" + k + ":" + SPSSConstants.WEEKDAY_LIST
                                    .get(Integer.valueOf(casewiseRecordForTabFile.get(k).toString()) - 1));
                            String newDatum = SPSSConstants.WEEKDAY_LIST
                                    .get(Integer.valueOf(casewiseRecordForTabFile.get(k).toString()) - 1);
                            casewiseRecordForTabFile.set(k, newDatum);
                            casewiseRecordForUNF.set(k, newDatum);
                            dbgLog.finer("wkday:k=" + k + ":" + casewiseRecordForTabFile.get(k));
                        } else if (printFormatTable.get(variableNameList.get(k)).equals("MONTH")) {
                            // month
                            dbgLog.finer("data k=" + k + ":" + casewiseRecordForTabFile.get(k));
                            dbgLog.finer("data k=" + k + ":" + SPSSConstants.MONTH_LIST
                                    .get(Integer.valueOf(casewiseRecordForTabFile.get(k).toString()) - 1));
                            String newDatum = SPSSConstants.MONTH_LIST
                                    .get(Integer.valueOf(casewiseRecordForTabFile.get(k).toString()) - 1);
                            casewiseRecordForTabFile.set(k, newDatum);
                            casewiseRecordForUNF.set(k, newDatum);
                            dbgLog.finer("month:k=" + k + ":" + casewiseRecordForTabFile.get(k));

                        }
                    }
                    // end of date/time block
                } // end: date-time-datum check

            } // end: loop-k(2nd: variablte-wise-check)

            // write to tab file
            if (casewiseRecordForTabFile.size() > 0) {
                pwout.println(StringUtils.join(casewiseRecordForTabFile, "\t"));
            }

            if (casewiseRecordForTabFile.size() > 0) {
                for (int ij = 0; ij < varQnty; ij++) {
                    dataTable2[ij][caseIndex - 1] = casewiseRecordForUNF.get(ij);
                    if (variableFormatTypeList[ij].equals("date")
                            || variableFormatTypeList[ij].equals("time")) {
                        this.dateFormats[ij][caseIndex - 1] = caseWiseDateFormatForUNF[ij];
                    }
                }
            }

            // numeric contents-check
            for (int l = 0; l < casewiseRecordForTabFile.size(); l++) {
                if (variableFormatTypeList[l].equals("date") || variableFormatTypeList[l].equals("time")
                        || printFormatTable.get(variableNameList.get(l)).equals("WKDAY")
                        || printFormatTable.get(variableNameList.get(l)).equals("MONTH")) {
                    variableTypeFinal[l] = -1;
                }

                if (variableTypeFinal[l] == 0) {
                    if (casewiseRecordForTabFile.get(l).toString().indexOf(".") >= 0) {
                        // l-th variable is not integer
                        variableTypeFinal[l] = 1;
                        decimalVariableSet.add(l);
                    }
                }
            }

            // reset the case-wise working objects
            casewiseRecordForTabFile.clear();
            casewiseRecordForUNF.clear();

            if (stream.available() == 0) {
                // reached the end of this file
                // do exit-processing

                dbgLog.fine("***** reached the end of the file at " + ii + "th iteration *****");

                break;
            } // if eof processing
        } //i-loop: case(row) iteration

        // close the writer
        pwout.close();

    } catch (IOException ex) {
        throw ex;
    }

    smd.getFileInformation().put("caseQnty", caseQnty);
    smd.setDecimalVariables(decimalVariableSet);
    smd.setVariableFormatCategory(formatCategoryTable);

    // contents check
    dbgLog.fine("variableType=" + ArrayUtils.toString(variableTypeFinal));
    dbgLog.fine("numberOfDecimalVariables=" + numberOfDecimalVariables);
    dbgLog.fine("decimalVariableSet=" + decimalVariableSet);

    dbgLog.fine("***** decodeRecordTypeDataUnCompressed(): end *****");
}

From source file:net.sourceforge.openutils.mgnlcriteria.tests.CriteriaTestUtils.java

public static void assertNumOfResults(int expected, Collection<Node> result, String search) {
    if (result.size() != expected) {
        List<String> titles = new ArrayList<String>();
        for (Node content : result) {
            titles.add(title(content));//from w w w  .j ava  2 s .  c  om
        }

        Assert.fail("Wrong result when searching for \"" + search + "\", expected " + expected
                + " results, found " + result.size() + ". Pages found: " + ArrayUtils.toString(titles));
    }
}

From source file:net.sourceforge.openutils.mgnlcriteria.tests.CriteriaTestUtils.java

public static void assertUnsortedResults(String[] expected, Collection<Node> result, String search) {
    Arrays.sort(expected);/*w  w  w. j a v a2s. c om*/

    List<String> titles = new ArrayList<String>();

    for (Node content : result) {
        titles.add(title(content));
    }
    Collections.sort(titles);

    if (result.size() != expected.length) {
        Assert.fail("Wrong result when searching for \"" + search + "\", expected " + expected.length
                + " results, found " + result.size() + ". Pages found: " + ArrayUtils.toString(titles));
    }

    Assert.assertEquals(arrayToString(titles.toArray()), arrayToString(expected),
            "Wrong result searching for \"" + search + "\"");

}

From source file:net.sourceforge.openutils.mgnlcriteria.tests.CriteriaTestUtils.java

public static void assertSortedResults(String[] expected, Collection<Node> result, String search) {
    List<String> titles = new ArrayList<String>();
    for (Node content : result) {
        titles.add(title(content));//from www  .j a v a 2s .  c om
    }

    if (result.size() != expected.length) {
        Assert.fail("Wrong result when searching for \"" + search + "\", expected " + expected.length
                + " results, found " + result.size() + ". Pages found: " + ArrayUtils.toString(titles));
    }

    Assert.assertEquals(arrayToString(titles.toArray()), arrayToString(expected),
            "Wrong order searching for \"" + search + "\"");

}

From source file:net.unicon.sakora.impl.csv.CsvCommonHandlerService.java

public void setUserRemoveMode(String userRemoveMode) {
    if (ArrayUtils.contains(URM_VALIDS, userRemoveMode)) {
        this.userRemoveMode = userRemoveMode;
    } else {/*from   w w w . j a v a 2  s.co  m*/
        this.userRemoveMode = URM_DISABLE;
        log.warn("SakoraCSV userRemoveMode (" + userRemoveMode
                + ") is invalid: resetting to default (disable), must match one of these: "
                + ArrayUtils.toString(URM_VALIDS));
    }
}

From source file:net.unicon.sakora.impl.csv.CsvCommonHandlerService.java

/**
 * Allows the current setting to be overridden for the current sync run only
 * @param urm null clears the override, see {@link #userRemoveMode}
 *//*  w ww.ja  va  2  s.  c  om*/
public void overrideUserRemoveMode(String urm) {
    if (ArrayUtils.contains(URM_VALIDS, userRemoveMode) || urm == null) {
        setCurrentSyncVar(USER_REMOVAL_MODE, urm);
        if (urm != null) {
            log.info("Overriding the " + USER_REMOVAL_MODE + " value of " + userRemoveMode + " with " + urm
                    + " for current sync: " + getCurrentSyncRunId());
        }
    } else {
        log.warn("SakoraCSV userRemoveMode override (" + urm
                + ") is invalid: ignoring the override, must match one of these: "
                + ArrayUtils.toString(URM_VALIDS));
    }
}