Example usage for java.util List equals

List of usage examples for java.util List equals

Introduction

In this page you can find the example usage for java.util List equals.

Prototype

boolean equals(Object o);

Source Link

Document

Compares the specified object with this list for equality.

Usage

From source file:ubic.gemma.loader.expression.geo.GeoConverterImpl.java

/**
 * Sanity check./*from   ww w  . j a  v a 2 s. c om*/
 * 
 * @param datasetSamples
 */
private void sanityCheckQuantitationTypes(List<GeoSample> datasetSamples) {
    List<String> reference = new ArrayList<String>();

    // Choose a reference that is populated ...
    boolean expectingData = true;
    for (GeoSample sample : datasetSamples) {
        if (sample.hasUsableData()) {
            reference = sample.getColumnNames();
            if (!reference.isEmpty())
                break;
        } else {
            expectingData = false;
        }
    }

    if (!expectingData) {
        log.warn("Not expecting any data, so quantitation type checking is skipped.");
        return;
    }

    if (reference.isEmpty()) {
        throw new IllegalStateException("None of the samples have any quantitation type names");
    }

    boolean someDidntMatch = false;
    String lastError = "";
    for (GeoSample sample : datasetSamples) {
        List<String> columnNames = sample.getColumnNames();

        assert !columnNames.isEmpty();

        if (!reference.equals(columnNames)) {

            StringBuilder buf = new StringBuilder();
            buf.append("\nSample " + sample.getGeoAccession() + ":");
            for (String string : columnNames) {
                buf.append(" " + string);
            }
            buf.append("\nReference " + datasetSamples.iterator().next().getGeoAccession() + ":");
            for (String string : reference) {
                buf.append(" " + string);
            }
            someDidntMatch = true;

            lastError = "*** Sample quantitation type names do not match: " + buf.toString();
            log.debug(lastError);
        }
    }
    if (someDidntMatch) {
        log.warn("Samples do not have consistent quantification type names. Last error was: " + lastError);
    }
}

From source file:com.ciphertool.genetics.algorithms.mutation.GroupMutationAlgorithmTest.java

@Test
public void testMutateRandomGeneGroup() {
    MockKeylessChromosome mockKeylessChromosome = new MockKeylessChromosome();
    List<MockGene> originalGenes = new ArrayList<>();

    MockGene mockGene1 = new MockGene();
    mockGene1.addSequence(new MockSequence("g"));
    mockGene1.addSequence(new MockSequence("e"));
    mockGene1.addSequence(new MockSequence("o"));
    mockGene1.addSequence(new MockSequence("r"));
    mockGene1.addSequence(new MockSequence("g"));
    mockGene1.addSequence(new MockSequence("e"));
    mockKeylessChromosome.addGene(mockGene1);
    originalGenes.add(mockGene1);/*w ww .  ja v  a  2 s . c  o m*/

    MockGene mockGene2 = new MockGene();
    mockGene2.addSequence(new MockSequence("b"));
    mockGene2.addSequence(new MockSequence("e"));
    mockGene2.addSequence(new MockSequence("l"));
    mockGene2.addSequence(new MockSequence("d"));
    mockGene2.addSequence(new MockSequence("e"));
    mockGene2.addSequence(new MockSequence("n"));
    mockKeylessChromosome.addGene(mockGene2);
    originalGenes.add(mockGene2);

    MockGene mockGene3 = new MockGene();
    mockGene3.addSequence(new MockSequence("i"));
    mockGene3.addSequence(new MockSequence("s"));
    mockKeylessChromosome.addGene(mockGene3);
    originalGenes.add(mockGene3);

    MockGene mockGene4 = new MockGene();
    mockGene4.addSequence(new MockSequence("a"));
    mockGene4.addSequence(new MockSequence("w"));
    mockGene4.addSequence(new MockSequence("e"));
    mockGene4.addSequence(new MockSequence("s"));
    mockGene4.addSequence(new MockSequence("o"));
    mockGene4.addSequence(new MockSequence("m"));
    mockGene4.addSequence(new MockSequence("e"));
    mockKeylessChromosome.addGene(mockGene4);
    originalGenes.add(mockGene4);

    final MockGene mockGeneOfSize3 = new MockGene();
    mockGeneOfSize3.addSequence(new MockSequence("x"));
    mockGeneOfSize3.addSequence(new MockSequence("y"));
    mockGeneOfSize3.addSequence(new MockSequence("z"));

    MockGene mockGeneOfSize2 = new MockGene();
    mockGeneOfSize2.addSequence(new MockSequence("v"));
    mockGeneOfSize2.addSequence(new MockSequence("w"));

    MockGene mockGeneOfSize1 = new MockGene();
    mockGeneOfSize1.addSequence(new MockSequence("u"));

    when(geneDaoMock.findRandomGene(same(mockKeylessChromosome))).thenAnswer(new Answer<MockGene>() {
        public MockGene answer(InvocationOnMock invocation) throws Throwable {
            return mockGeneOfSize3.clone();
        }
    });
    when(geneDaoMock.findRandomGeneOfLength(same(mockKeylessChromosome), eq(2))).thenReturn(mockGeneOfSize2);
    when(geneDaoMock.findRandomGeneOfLength(same(mockKeylessChromosome), eq(1))).thenReturn(mockGeneOfSize1);

    List<Integer> availableIndices = new ArrayList<Integer>();
    availableIndices.add(0);
    availableIndices.add(1);
    availableIndices.add(2);
    availableIndices.add(3);
    int originalAvailableIndicesSize = availableIndices.size();
    groupMutationAlgorithm.mutateRandomGeneGroup(mockKeylessChromosome, availableIndices, 2);

    assertFalse(originalGenes.equals(mockKeylessChromosome.getGenes()));
    assertTrue(originalAvailableIndicesSize > availableIndices.size());
    assertEquals(21, mockKeylessChromosome.actualSize().intValue());

    int indicesRemoved = 0;
    for (Integer availableIndex : availableIndices) {
        assertTrue(
                originalGenes.contains(mockKeylessChromosome.getGenes().get(availableIndex - indicesRemoved)));
        mockKeylessChromosome.removeGene(availableIndex - indicesRemoved);
        indicesRemoved++;
    }

    assertTrue(mockKeylessChromosome.getGenes().size() > 0);
    int mockChromosomeSizeMinusOne = mockKeylessChromosome.getGenes().size() - 1;
    for (int i = 0; i < mockChromosomeSizeMinusOne; i++) {
        assertEquals(mockGeneOfSize3, mockKeylessChromosome.getGenes().get(i));
    }

    Gene lastGene = mockKeylessChromosome.getGenes().get(mockKeylessChromosome.getGenes().size() - 1);
    switch (((VariableLengthGene) lastGene).size()) {
    case 3:
        assertEquals(mockGeneOfSize3, lastGene);
        break;
    case 2:
        assertEquals(mockGeneOfSize2, lastGene);
        break;
    case 1:
        assertEquals(mockGeneOfSize1, lastGene);
        break;
    }

    verify(geneDaoMock, atLeastOnce()).findRandomGene(same(mockKeylessChromosome));
    verify(geneDaoMock, atMost(4)).findRandomGene(same(mockKeylessChromosome));
    verify(geneDaoMock, atMost(1)).findRandomGeneOfLength(same(mockKeylessChromosome), anyInt());
    verifyZeroInteractions(logMock);
}

From source file:org.talend.designer.core.ui.editor.process.Process.java

/**
 * /*from   ww  w  .  j  ava2  s .  co m*/
 * DOC yexiaowei Comment method "sortNodes".
 * 
 * @param nodes
 * @return
 */
protected List<INode> sortNodes(List<INode> nodes) {

    if (nodes == null || nodes.size() <= 1) {
        return nodes;
    }

    List<INode> res = new ArrayList<INode>();

    List<List<INode>> mainStart = new ArrayList<List<INode>>();

    List<List<INode>> notMainStart = new ArrayList<List<INode>>();

    List<INode> starts = new ArrayList<INode>();

    for (INode node : nodes) {
        if (node.isStart() || node.isSubProcessStart()) {
            starts.add(node);
        }
    }

    for (INode node : starts) {
        List<INode> branch = new ArrayList<INode>();
        branch.add(node);
        findTargetAll(branch, node);
        if (node.isStart() && node.isSubProcessStart()) {
            mainStart.add(branch);
        } else {
            notMainStart.add(branch);
        }

    }

    // Must sort the mainStart first...
    List<List<INode>> tempStart = new ArrayList<List<INode>>();
    tempStart.addAll(mainStart);
    for (List<INode> preview : mainStart) {
        for (List<INode> now : mainStart) {
            if (!preview.equals(now) && now.contains(preview.get(0))) {
                tempStart.remove(preview);
                tempStart.add(tempStart.indexOf(now) + 1, preview);
            }
        }
    }

    for (List<INode> branch : tempStart) {
        for (INode n : branch) {
            if (!res.contains(n)) {
                res.add(n);
            }
        }

        for (List<INode> ns : notMainStart) {

            for (INode node : ns) {
                if (branch.contains(node)) {
                    for (INode nodeadd : ns) {
                        if (!res.contains(nodeadd)) {
                            res.add(nodeadd);
                        }
                        break;
                    }
                }
            }

        }
    }
    return res;
}

From source file:com.dianping.maven.plugin.tools.misc.scanner.ServiceScannerTest.java

@Test
public void test() {
    List<String> expected = Arrays
            .asList(new String[] { "http://service.dianping.com/groupService/eventService_1.0.0",
                    "http://service.dianping.com/groupService/eventTypeService_1.0.0",
                    "http://service.dianping.com/groupService/eventNoteService_1.0.0",
                    "http://service.dianping.com/groupService/eventUserService_1.0.0",
                    "http://service.dianping.com/groupService/groupUserService_1.0.0",
                    "http://service.dianping.com/groupService/groupUserHonorTitleService_1.0.0",
                    "http://service.dianping.com/groupService/groupUserScoreLevelService_1.0.0",
                    "http://service.dianping.com/groupService/groupService_1.0.0",
                    "http://service.dianping.com/groupService/groupLinkService_1.0.0",
                    "http://service.dianping.com/groupService/groupNoteTypeService_1.0.0",
                    "http://service.dianping.com/groupService/groupTypeApplyService_1.0.0",
                    "http://service.dianping.com/groupService/groupCategoryService_1.0.0",
                    "http://service.dianping.com/groupService/groupRecommendService_1.0.0",
                    "http://service.dianping.com/groupService/groupMedalService_1.0.0",
                    "http://service.dianping.com/groupService/userGroupInfoService_1.0.0",
                    "http://service.dianping.com/groupService/groupNoteService_1.0.0",
                    "http://service.dianping.com/groupService/groupNoteScoreLogService_1.0.0",
                    "http://service.dianping.com/groupService/groupOperateLogService_1.0.0",
                    "http://service.dianping.com/groupService/groupDCashLogService_1.0.0",
                    "http://service.dianping.com/groupService/groupFollowNoteService_1.0.0",
                    "http://service.dianping.com/groupService/groupSurveyService_1.0.0",
                    "http://service.dianping.com/groupService/groupSurveyMemberService_1.0.0",
                    "http://service.dianping.com/groupService/groupbackService_1.0.0",
                    "http://service.dianping.com/groupService/groupRoleService_1.0.0",
                    "http://service.dianping.com/groupService/groupPicService_1.0.0",
                    "http://service.dianping.com/groupService/groupUserScoreDailyLogService_1.0.0",
                    "http://service.dianping.com/groupService/groupUserScoreSumService_1.0.0",
                    "http://service.dianping.com/groupService/eventShopService_1.0.0",
                    "http://service.dianping.com/groupService/groupIndexService_1.0.0",
                    "http://service.dianping.com/groupService/groupNoteCountService_1.0.0",
                    "http://service.dianping.com/groupService/groupCheckInActivityService_1.0.0",
                    "http://service.dianping.com/groupService/noteVerifyFeedbackService_1.0.0",
                    "http://service.dianping.com/groupService/eventFollowNoteService_1.0.0",
                    "http://service.dianping.com/groupService/groupQAUserService_1.0.0",
                    "http://service.dianping.com/groupService/groupSetService_1.0.0",
                    "http://service.dianping.com/groupService/groupQAFollowNoteService_1.0.0",
                    "http://service.dianping.com/groupService/groupQANoteService_1.0.0",
                    "http://service.dianping.com/groupService/groupNoteHideContentService_1.0.0",
                    "http://service.dianping.com/groupService/groupNoteShopService_1.0.0",
                    "http://service.dianping.com/groupService/groupConfigurationService_1.0.0",
                    "http://service.dianping.com/groupService/userGoldService_1.0.0",
                    "http://service.dianping.com/groupService/userGoldDetailService_1.0.0",
                    "http://service.dianping.com/groupService/groupFollowNoteExtInfoService_1.0.0",
                    "http://service.dianping.com/groupService/userGoldExchangeService_1.0.0",
                    "http://service.dianping.com/groupService/groupNoteExtInfoService_1.0.0",
                    "http://service.dianping.com/groupService/hotNoteService_1.0.0",
                    "http://service.dianping.com/groupService/goldEggService_1.0.0" });
    Scanner<String> scanner = new ServiceScanner();
    Assert.assertTrue(/*from  ww w .ja  v  a2  s. c o m*/
            expected.equals(scanner.scan(FileUtils.toFile(this.getClass().getResource("service.xml")))));
}

From source file:mondrian.rolap.RolapSchemaLoader.java

RolapLevel createLevel(RolapCube cube, RolapHierarchy hierarchy, RolapSchema.PhysRelation relation, int depth,
        MondrianDef.Level xmlLevel) {
    final String levelName = first(xmlLevel.name, xmlLevel.attribute);
    if (hierarchy.levelList.get(levelName) != null) {
        getHandler().error(MondrianResource.instance().HierarchyLevelNamesNotUnique
                .ex(hierarchy.getUniqueName(), levelName), xmlLevel, null);
    }// w w  w.j  a v a 2 s  .  c  o  m

    if (xmlLevel.attribute == null) {
        getHandler().error("Attribute 'attribute' is required", xmlLevel, "attribute");
        return null;
    }

    final RolapDimension dimension = hierarchy.getDimension();
    RolapAttribute attribute = dimension.attributeMap.get(xmlLevel.attribute);
    if (attribute == null) {
        getHandler().error(
                "Attribute '" + xmlLevel.attribute + "' not found in Dimension '" + dimension.getName() + "'",
                xmlLevel, "attribute");
        return null;
    }

    final RolapAttribute parentAttribute;
    if (xmlLevel.parentAttribute != null) {
        parentAttribute = dimension.attributeMap.get(xmlLevel.parentAttribute);
        if (parentAttribute == null) {
            getHandler().error("Unknown parent attribute ''", xmlLevel, "parentAttribute");
        }
    } else {
        parentAttribute = null;
    }

    // Order-by columns only need to sort within parent. Therefore if this
    // is not the first level of the hierarchy maybe we can trim the list.
    List<RolapSchema.PhysColumn> orderByList = new ArrayList<RolapSchema.PhysColumn>(
            attribute.getOrderByList());
    if (!hierarchy.levelList.isEmpty()) {
        orderByList.removeAll(Util.last(hierarchy.levelList).getOrderByList());
    }
    if (orderByList.equals(attribute.getOrderByList())) {
        orderByList = attribute.getOrderByList(); // save some memory
    }

    final RolapClosure closure = createClosure(cube, relation, xmlLevel, hierarchy);

    final RolapLevel level = new RolapLevel(hierarchy, levelName, toBoolean(xmlLevel.visible, true), depth,
            attribute, parentAttribute, orderByList, xmlLevel.nullParentValue, closure,
            RolapLevel.HideMemberCondition.valueOf(xmlLevel.hideMemberIf),
            createLarder(Util.makeFqName(hierarchy, levelName) + ".level", xmlLevel.getAnnotations(),
                    xmlLevel.name, xmlLevel.caption, xmlLevel.description).build(),
            resourceMap);
    validator.putXml(level, xmlLevel);
    return level;
}

From source file:com.ciphertool.genetics.algorithms.mutation.GroupMutationAlgorithmTest.java

@Test
public void testMutateChromosome() {
    groupMutationAlgorithm.setMaxMutationsPerChromosome(MAX_MUTATIONS);

    MockKeylessChromosome mockKeylessChromosome = new MockKeylessChromosome();
    List<MockGene> originalGenes = new ArrayList<>();

    MockGene mockGene1 = new MockGene();
    mockGene1.addSequence(new MockSequence("g"));
    mockGene1.addSequence(new MockSequence("e"));
    mockGene1.addSequence(new MockSequence("o"));
    mockGene1.addSequence(new MockSequence("r"));
    mockGene1.addSequence(new MockSequence("g"));
    mockGene1.addSequence(new MockSequence("e"));
    mockKeylessChromosome.addGene(mockGene1);
    originalGenes.add(mockGene1);/*from  w w  w . j av a2 s.c o  m*/

    MockGene mockGene2 = new MockGene();
    mockGene2.addSequence(new MockSequence("b"));
    mockGene2.addSequence(new MockSequence("e"));
    mockGene2.addSequence(new MockSequence("l"));
    mockGene2.addSequence(new MockSequence("d"));
    mockGene2.addSequence(new MockSequence("e"));
    mockGene2.addSequence(new MockSequence("n"));
    mockKeylessChromosome.addGene(mockGene2);
    originalGenes.add(mockGene2);

    MockGene mockGene3 = new MockGene();
    mockGene3.addSequence(new MockSequence("i"));
    mockGene3.addSequence(new MockSequence("s"));
    mockKeylessChromosome.addGene(mockGene3);
    originalGenes.add(mockGene3);

    MockGene mockGene4 = new MockGene();
    mockGene4.addSequence(new MockSequence("r"));
    mockGene4.addSequence(new MockSequence("e"));
    mockGene4.addSequence(new MockSequence("a"));
    mockGene4.addSequence(new MockSequence("l"));
    mockGene4.addSequence(new MockSequence("l"));
    mockGene4.addSequence(new MockSequence("y"));
    mockKeylessChromosome.addGene(mockGene4);
    originalGenes.add(mockGene4);

    MockGene mockGene5 = new MockGene();
    mockGene5.addSequence(new MockSequence("j"));
    mockGene5.addSequence(new MockSequence("u"));
    mockGene5.addSequence(new MockSequence("s"));
    mockGene5.addSequence(new MockSequence("t"));
    mockKeylessChromosome.addGene(mockGene5);
    originalGenes.add(mockGene5);

    MockGene mockGene6 = new MockGene();
    mockGene6.addSequence(new MockSequence("a"));
    mockGene6.addSequence(new MockSequence("w"));
    mockGene6.addSequence(new MockSequence("e"));
    mockGene6.addSequence(new MockSequence("s"));
    mockGene6.addSequence(new MockSequence("o"));
    mockGene6.addSequence(new MockSequence("m"));
    mockGene6.addSequence(new MockSequence("e"));
    mockKeylessChromosome.addGene(mockGene6);
    originalGenes.add(mockGene6);

    final MockGene mockGeneOfSize3 = new MockGene();
    mockGeneOfSize3.addSequence(new MockSequence("x"));
    mockGeneOfSize3.addSequence(new MockSequence("y"));
    mockGeneOfSize3.addSequence(new MockSequence("z"));

    MockGene mockGeneOfSize2 = new MockGene();
    mockGeneOfSize2.addSequence(new MockSequence("v"));
    mockGeneOfSize2.addSequence(new MockSequence("w"));

    MockGene mockGeneOfSize1 = new MockGene();
    mockGeneOfSize1.addSequence(new MockSequence("u"));

    when(geneDaoMock.findRandomGene(same(mockKeylessChromosome))).thenAnswer(new Answer<MockGene>() {
        public MockGene answer(InvocationOnMock invocation) throws Throwable {
            return mockGeneOfSize3.clone();
        }
    });
    when(geneDaoMock.findRandomGeneOfLength(same(mockKeylessChromosome), eq(2)))
            .thenReturn(mockGeneOfSize2.clone());
    when(geneDaoMock.findRandomGeneOfLength(same(mockKeylessChromosome), eq(1)))
            .thenReturn(mockGeneOfSize1.clone());

    groupMutationAlgorithm.mutateChromosome(mockKeylessChromosome);

    assertFalse(originalGenes.equals(mockKeylessChromosome.getGenes()));
    assertEquals(31, mockKeylessChromosome.actualSize().intValue());

    verify(geneDaoMock, atLeastOnce()).findRandomGene(same(mockKeylessChromosome));
    verify(geneDaoMock, atMost(2)).findRandomGeneOfLength(same(mockKeylessChromosome), anyInt());
    verifyZeroInteractions(logMock);
}

From source file:org.jahia.services.templates.ModuleInstallationHelper.java

public void templatesSynchro(final JCRNodeWrapper source, final JCRNodeWrapper destinationNode,
        JCRSessionWrapper session, Map<String, List<String>> references, boolean doUpdate, boolean doChildren)
        throws RepositoryException {
    if ("j:acl".equals(destinationNode.getName())) {
        return;/*from   w  w  w .java 2s  .  co m*/
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Synchronizing node : " + destinationNode.getPath() + ", update=" + doUpdate + "/children="
                + doChildren);
    }

    session.checkout(destinationNode);

    final Map<String, String> uuidMapping = session.getUuidMapping();

    ExtendedNodeType[] mixin = source.getMixinNodeTypes();
    List<ExtendedNodeType> destMixin = Arrays.asList(destinationNode.getMixinNodeTypes());
    for (ExtendedNodeType aMixin : mixin) {
        if (!destMixin.contains(aMixin)) {
            destinationNode.addMixin(aMixin.getName());
        }
    }

    uuidMapping.put(source.getIdentifier(), destinationNode.getIdentifier());

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

    if (doUpdate) {
        if (source.hasProperty(Constants.JCR_LANGUAGE) && (!destinationNode.hasProperty(Constants.JCR_LANGUAGE)
                || (!destinationNode.getProperty(Constants.JCR_LANGUAGE).getString()
                        .equals(source.getProperty(Constants.JCR_LANGUAGE).getString())))) {
            destinationNode.setProperty(Constants.JCR_LANGUAGE,
                    source.getProperty(Constants.JCR_LANGUAGE).getString());
        }

        PropertyIterator props = source.getProperties();

        while (props.hasNext()) {
            Property property = props.nextProperty();
            names.add(property.getName());
            try {
                if (!property.getDefinition().isProtected()
                        && !Constants.forbiddenPropertiesToCopy.contains(property.getName())) {
                    if (property.getType() == PropertyType.REFERENCE
                            || property.getType() == PropertyType.WEAKREFERENCE) {
                        if (property.getDefinition().isMultiple() && (property.isMultiple())) {
                            if (!destinationNode.hasProperty(property.getName()) || !Arrays.equals(
                                    destinationNode.getProperty(property.getName()).getValues(),
                                    property.getValues())) {
                                destinationNode.setProperty(property.getName(), new Value[0]);
                                Value[] values = property.getValues();
                                for (Value value : values) {
                                    keepReference(destinationNode, references, property, value.getString());
                                }
                            }
                        } else {
                            if (!destinationNode.hasProperty(property.getName()) || !destinationNode
                                    .getProperty(property.getName()).getValue().equals(property.getValue())) {
                                keepReference(destinationNode, references, property,
                                        property.getValue().getString());
                            }
                        }
                    } else if (property.getDefinition().isMultiple() && (property.isMultiple())) {
                        if (!destinationNode.hasProperty(property.getName())
                                || !Arrays.equals(destinationNode.getProperty(property.getName()).getValues(),
                                        property.getValues())) {
                            destinationNode.setProperty(property.getName(), property.getValues());
                        }
                    } else if (!destinationNode.hasProperty(property.getName()) || !destinationNode
                            .getProperty(property.getName()).getValue().equals(property.getValue())) {
                        destinationNode.setProperty(property.getName(), property.getValue());
                    }
                }
            } catch (Exception e) {
                logger.warn("Unable to copy property '" + property.getName() + "'. Skipping.", e);
            }
        }

        PropertyIterator pi = destinationNode.getProperties();
        while (pi.hasNext()) {
            JCRPropertyWrapper oldChild = (JCRPropertyWrapper) pi.next();
            if (!oldChild.getDefinition().isProtected()) {
                if (!names.contains(oldChild.getName()) && !oldChild.getName().equals("j:published")
                        && !oldChild.getName().equals(Constants.JAHIA_MODULE_TEMPLATE)
                        && !oldChild.getName().equals("j:sourceTemplate")) {
                    oldChild.remove();
                }
            }
        }

        mixin = destinationNode.getMixinNodeTypes();
        for (NodeType aMixin : mixin) {
            if (!source.isNodeType(aMixin.getName())) {
                destinationNode.removeMixin(aMixin.getName());
            }
        }
    }

    NodeIterator ni = source.getNodes();

    names.clear();

    while (ni.hasNext()) {
        JCRNodeWrapper child = (JCRNodeWrapper) ni.next();
        boolean isPageNode = child.isNodeType("jnt:page");

        if (doChildren) {
            names.add(child.getName());

            boolean newNode = false;
            JCRNodeWrapper node;
            if (destinationNode.hasNode(child.getName())) {
                node = destinationNode.getNode(child.getName());
            } else {
                node = destinationNode.addNode(child.getName(), child.getPrimaryNodeTypeName());
                newNode = true;
            }
            templatesSynchro(child, node, session, references, newNode, doChildren && (!isPageNode || newNode));
        }
    }
    if (doUpdate) {
        List<String> destNames = new ArrayList<String>();
        ni = destinationNode.getNodes();
        while (ni.hasNext()) {
            JCRNodeWrapper oldChild = (JCRNodeWrapper) ni.next();
            destNames.add(oldChild.getName());
        }
        if (destinationNode.getPrimaryNodeType().hasOrderableChildNodes() && !names.equals(destNames)) {
            Collections.reverse(names);
            String previous = null;
            for (String name : names) {
                destinationNode.orderBefore(name, previous);
                previous = name;
            }
        }
    }
}

From source file:org.cloudifysource.rest.controllers.ServiceController.java

/**
 * For each puInstance - send the templates folder.
 *
 * @param templatesFolder//  ww  w .j  a  v  a2s . c  o  m
 *            .
 * @param expectedTemplates
 *            The expected templates to add.
 * @param addedTemplatesByHost
 *            a map updates by this method to specify the failed to add templates for each instance.
 * @param failedToAddTemplatesByHost
 *            a map updates by this method to specify the failed to add templates for each instance.
 */
private void sendAddTemplatesToRestInstances(final File templatesFolder, final List<String> expectedTemplates,
        final Map<String, List<String>> addedTemplatesByHost,
        final Map<String, Map<String, String>> failedToAddTemplatesByHost) {

    // get the instances
    final ProcessingUnitInstance[] instances = admin.getProcessingUnits()
            .waitFor("rest", RestUtils.TIMEOUT_IN_SECOND, TimeUnit.SECONDS).getInstances();
    logger.log(Level.INFO, "[sendAddTemplatesToRestInstances] - sending templates folder to " + instances.length
            + " instances.");

    // send the templates folder to each rest instance (except the local
    // one)
    for (final ProcessingUnitInstance puInstance : instances) {
        final String hostAddress = puInstance.getMachine().getHostAddress();
        final String host = puInstance.getMachine().getHostName() + "/" + hostAddress;
        Map<String, Object> response;
        try {
            // send the post request
            response = executePostRestRequest(templatesFolder, puInstance, "/service/templates/internal");
        } catch (final Exception e) {
            logger.log(Level.WARNING, "[sendAddTemplatesToRestInstances] - failed to execute http request to "
                    + host + ". Error: " + e, e);
            final Map<String, String> expectedMap = new HashMap<String, String>();
            for (final String expectedTemplate : expectedTemplates) {
                expectedMap.put(expectedTemplate, e.getMessage());
            }
            failedToAddTemplatesByHost.put(host, expectedMap);
            continue;
        }
        // update maps
        @SuppressWarnings("unchecked")
        final Map<String, String> failedMap = (Map<String, String>) response.get(FAILED_TO_ADD_TEMPLATES_KEY);
        if (!failedMap.isEmpty()) {
            failedToAddTemplatesByHost.put(host, failedMap);
        }
        @SuppressWarnings("unchecked")
        final List<String> addedTemplates = (List<String>) response.get(SUCCESSFULLY_ADDED_TEMPLATES_KEY);
        if (!addedTemplates.isEmpty()) {
            addedTemplatesByHost.put(host, addedTemplates);
        }
        // validate response list and
        if (!expectedTemplates.equals(addedTemplates)) {
            logger.log(Level.WARNING, "[sendAddTemplatesToRestInstances] - failed to add templates to " + host
                    + ", expected: " + expectedTemplates.toString() + ", actual: " + addedTemplates.toString());
        }
        logger.log(Level.INFO, "[sendAddTemplatesToRestInstances] - successfully added " + addedTemplates.size()
                + " templates to " + host + ": " + addedTemplates);
    }
}

From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.instruments.commands.configuration.UploadControllerOS.java

/***********************************************************************************************
 * Upload the specified data to the AVR Controller's Bootloader.
 * Optionally fill the unused code memory with 0xff.
 * Capture the version number of the bootloader.
 *
 * @param target/* w ww  . jav  a 2 s .  c om*/
 * @param broadcastaddress
 * @param data
 * @param fillunused
 * @param logentries
 * @param errors
 *
 * @return ResponseMessageStatus
 */

private static ResponseMessageStatus uploadToAVRBootloader(final TargetCPU target,
        final String broadcastaddress, final List<Byte> data, final boolean fillunused,
        final List<String> logentries, final List<String> errors) {
    final String SOURCE = "UploadControllerOS.uploadToAVRBootloader() ";
    final int RETRY_COUNT = 5;
    final byte COMMAND_IDENTIFY = 0x49; // ASCII 'I'
    final byte COMMAND_PROGRAM = 0x50; // ASCII 'P'
    final byte COMMAND_ACK = 0x41; // ASCII 'A'
    final byte COMMAND_NACK = 0x4e; // ASCII 'N'
    UDPClient clientUDP;
    ResponseMessageStatus responseMessageStatus;

    clientUDP = null;
    responseMessageStatus = ResponseMessageStatus.SUCCESS;

    try {
        final String strHostname;
        final InetAddress inetAddress;
        List<Byte> listPayload;
        byte[] arrayResponse;

        // Set up the UDPClient
        // Note that UDP requests are often restricted to the current subnet
        strHostname = broadcastaddress;
        inetAddress = InetAddress.getByName(strHostname);

        // SocketException
        clientUDP = new UDPClient(inetAddress, target.getLocalPort(), target.getRemotePort(),
                target.getTimeoutMillis());
        clientUDP.getSocket().setBroadcast(true);

        // The host program transmits an 'identify' packet to kick off communication with any devices in bootloader mode
        // The MAC address in this packet is all zeroes meaning any bootloader should respond
        // I <0x00> <0x00> <0x00> <0x00> <0x00> <0x00>
        listPayload = new ArrayList<Byte>(7);
        listPayload.add(COMMAND_IDENTIFY);
        listPayload.add((byte) 0x00);
        listPayload.add((byte) 0x00);
        listPayload.add((byte) 0x00);
        listPayload.add((byte) 0x00);
        listPayload.add((byte) 0x00);
        listPayload.add((byte) 0x00);

        // Prepare to get the Bootloader Version
        logentries.clear();

        // Send the packet, do NOT call UDPClient.connect() !
        // If the payload is longer than the maximum reliable length of a UDP Datagram
        // (8192) bytes then an IOException is thrown
        clientUDP.send(ArrayUtils.toPrimitive(listPayload.toArray(new Byte[listPayload.size()])));

        // The host then waits for timeout for any/all devices in bootloader mode to respond
        // This method blocks until a UDP Datagram is received
        // This Command is being executed on its own SwingWorker, so this doesn't matter...
        // IOException
        arrayResponse = clientUDP.receive();

        // The devices respond with an 'acknowledge' packet and its MAC address
        // There are additional data giving more details about the target processor
        // A <6 bytes Target MAC> <ChipFlashPageSize> <ProcessorID> <VersionNumber>
        // Ideally the host should capture all responses and allow the user to select which device to program,
        // at the moment this host simply uses the first (and normally only) response.

        if ((arrayResponse != null) && (arrayResponse.length > 0)) {
            final int INDEX_ACK = 0;
            final int INDEX_MAC_ADDRESS = 1;
            final int INDEX_PAGE_SIZE = 7;
            final int INDEX_PACKET_NUMBER = 7;
            final int INDEX_ID = 8;
            final int INDEX_VERSION = 9;
            final byte[] arrayMAC;
            final List<Byte> listMAC;
            final int intChipFlashPageSize;
            final byte byteProcessorID;
            final byte byteVersion;

            LOGGER.debug(LOADER_PROPERTIES.isStarinetDebug(),
                    "[identify_response=" + Utilities.byteArrayToSpacedHex(arrayResponse) + "]");

            // Read the MAC address of the responder, and convert to a List
            arrayMAC = ArrayUtils.subarray(arrayResponse, INDEX_MAC_ADDRESS, INDEX_MAC_ADDRESS + 6);
            listMAC = new ArrayList<Byte>(6);

            for (int intMACIndex = 0; intMACIndex < 6; intMACIndex++) {
                listMAC.add(arrayMAC[intMACIndex]);
            }

            // ChipFlashPageSize
            intChipFlashPageSize = arrayResponse[INDEX_PAGE_SIZE] << 4;

            // ProcessorID
            byteProcessorID = arrayResponse[INDEX_ID];

            // Version Number (did not exist prior to v1.1)
            if (arrayResponse.length > INDEX_VERSION) {
                byteVersion = arrayResponse[INDEX_VERSION];
            } else {
                byteVersion = 0x00;
            }
            logentries.add(Utilities.byteToTwoHexString(byteVersion));

            // Check that we have exactly the right target
            if ((byteProcessorID == target.getID()) && (intChipFlashPageSize == target.getPagesize())) {
                // Now program the data in PageSize packets
                if ((data != null) && (!data.isEmpty())) {
                    final int intSizeOfLastPacket;
                    final int intPacketCount;
                    boolean boolSuccessfulPacket;

                    // Record the Codesize (before padding) as the second entry
                    logentries.add(Integer.toString(data.size()));

                    // Fill the unused bytes in the code memory if requested
                    if (fillunused) {
                        while (data.size() < target.getCodesize()) {
                            data.add(target.getFill());
                        }
                    }

                    // Only now do we know the page size required for this processor
                    // Pad the data List to be multiple of PageSize bytes
                    intSizeOfLastPacket = data.size() % intChipFlashPageSize;

                    if ((intSizeOfLastPacket != intChipFlashPageSize) && (data.size() < target.getCodesize())) {
                        for (int intPadding = 0; ((intPadding < (intChipFlashPageSize - intSizeOfLastPacket))
                                && (data.size() < target.getCodesize())); intPadding++) {
                            data.add(target.getFill());
                        }
                    }

                    // Calculate the number of packets to send
                    intPacketCount = data.size() / intChipFlashPageSize;
                    boolSuccessfulPacket = true;

                    for (int intPacketIndex = 0; ((intPacketIndex < intPacketCount)
                            && (boolSuccessfulPacket)); intPacketIndex++) {
                        final int intPacketAddress;
                        boolean boolKeepRetrying;

                        intPacketAddress = intPacketIndex * intChipFlashPageSize;

                        // The program packet is made up as follows:
                        // P
                        // <6 bytes Dest MAC>
                        // <PacketNumber>
                        // <TargetAddressMSB>
                        // <TargetAddressLSB>
                        // <DataBytesLengthMSB>
                        // <DataBytesLengthLSB>
                        // <DataBytes>
                        // Code words in DataBytes are sent little-endian, i.e. LSB first
                        // but that order will have been set during compilation to create the HEX file

                        listPayload = new ArrayList<Byte>(12 + intChipFlashPageSize);

                        // Program Command 'P'
                        listPayload.add(COMMAND_PROGRAM);

                        // MAC Address
                        listPayload.addAll(listMAC);

                        // PacketNumber
                        listPayload.add((byte) intPacketIndex);

                        // Target Address MSB, LSB
                        listPayload.add((byte) ((intPacketAddress & 0xff00) >> 8));
                        listPayload.add((byte) ((intPacketAddress & 0x00ff)));

                        // DataBytesLength MSB, LSB
                        listPayload.add((byte) ((intChipFlashPageSize & 0xff00) >> 8));
                        listPayload.add((byte) ((intChipFlashPageSize & 0x00ff)));

                        // DataBytes
                        listPayload.addAll(
                                data.subList(intPacketAddress, intPacketAddress + intChipFlashPageSize));

                        LOGGER.debug(LOADER_PROPERTIES.isStarinetDebug(),
                                "[send] [packet_index=" + intPacketIndex + "] [packet_address="
                                        + intPacketAddress + "] [pagesize=" + intChipFlashPageSize + "]");
                        LOGGER.debug(LOADER_PROPERTIES.isStarinetDebug(), HexFileHelper.dumpHex(listPayload,
                                intPacketAddress, HexFileHelper.DUMP_BYTES_PER_LINE));
                        boolKeepRetrying = true;

                        // Start the retry loop
                        for (int intRetryIndex = 0; ((intRetryIndex < RETRY_COUNT)
                                && (boolKeepRetrying)); intRetryIndex++) {
                            // Send the packet to the remote Port
                            clientUDP.send(
                                    ArrayUtils.toPrimitive(listPayload.toArray(new Byte[listPayload.size()])));

                            // Wait here for Ack or Nack
                            arrayResponse = clientUDP.receive();

                            if ((arrayResponse != null) && (arrayResponse.length > 0)) {
                                // Was it an Ack or Nack from the correct MAC address?
                                // A
                                // <6 bytes Source MAC>
                                // <PacketNumber>

                                LOGGER.debug(LOADER_PROPERTIES.isStarinetDebug(), "[program_response="
                                        + Utilities.byteArrayToSpacedHex(arrayResponse) + "]");

                                // See if it was an Ack
                                if ((arrayResponse.length >= 8) && (COMMAND_ACK == arrayResponse[INDEX_ACK])) {
                                    final byte[] arrayAckMAC;
                                    final List<Byte> listAckMAC;

                                    // Read the MAC address in the Ack
                                    arrayAckMAC = ArrayUtils.subarray(arrayResponse, INDEX_MAC_ADDRESS,
                                            INDEX_MAC_ADDRESS + 6);
                                    listAckMAC = new ArrayList<Byte>(6);

                                    for (int intMACIndex = 0; intMACIndex < 6; intMACIndex++) {
                                        listAckMAC.add(arrayAckMAC[intMACIndex]);
                                    }

                                    // Check the the MAC address is correct
                                    if (listMAC.equals(listAckMAC)) {
                                        // Check the packet number
                                        if (arrayResponse[INDEX_PACKET_NUMBER] == (byte) intPacketIndex) {
                                            // Success, so stop the retry loop and carry on
                                            boolKeepRetrying = false;
                                            boolSuccessfulPacket = true;
                                        } else {
                                            // Faulty packet index, so retry?
                                            boolKeepRetrying = true;
                                            boolSuccessfulPacket = false;
                                            errors.add(METADATA_TARGET_STARINET + METADATA_ACTION_REQUEST_UDP
                                                    + METADATA_RESULT + "Faulty Packet Index, Retry [index="
                                                    + arrayResponse[7] + TERMINATOR);
                                        }
                                    } else {
                                        // Faulty MAC address, so retry
                                        boolKeepRetrying = true;
                                        boolSuccessfulPacket = false;
                                        errors.add(METADATA_TARGET_STARINET + METADATA_ACTION_REQUEST_UDP
                                                + METADATA_RESULT + "Faulty MAC Address, Retry [index="
                                                + intRetryIndex + TERMINATOR);
                                    }
                                } else if (COMMAND_NACK == arrayResponse[INDEX_ACK]) {
                                    // A Nack must always cause a retry
                                    boolKeepRetrying = true;
                                    boolSuccessfulPacket = false;
                                    errors.add(METADATA_TARGET_STARINET + METADATA_ACTION_REQUEST_UDP
                                            + METADATA_RESULT + "NACK Packet, Retry [index=" + intRetryIndex
                                            + TERMINATOR);
                                } else {
                                    // An unknown packet type, so give up
                                    boolKeepRetrying = false;
                                    boolSuccessfulPacket = false;
                                    responseMessageStatus = ResponseMessageStatus.PREMATURE_TERMINATION;
                                    errors.add(METADATA_TARGET_STARINET + METADATA_ACTION_REQUEST_UDP
                                            + METADATA_RESULT + "Unknown packet type ("
                                            + arrayResponse[INDEX_ACK] + ")" + TERMINATOR);
                                }
                            } else {
                                // A fatal error, since no Ack or Nack packet, so no sense in retrying again
                                boolKeepRetrying = false;
                                boolSuccessfulPacket = false;
                                responseMessageStatus = ResponseMessageStatus.PREMATURE_TERMINATION;
                                errors.add(
                                        METADATA_TARGET_STARINET + METADATA_ACTION_REQUEST_UDP + METADATA_RESULT
                                                + "Program Acknowledge was empty or NULL" + TERMINATOR);
                            }
                        }
                    }
                } else {
                    // Record the Codesize (before padding) as the second entry
                    logentries.add("0");

                    responseMessageStatus = ResponseMessageStatus.PREMATURE_TERMINATION;
                    errors.add(METADATA_TARGET_STARINET + METADATA_ACTION_REQUEST_UDP + METADATA_RESULT
                            + "No data to transmit" + TERMINATOR);
                }
            } else {
                responseMessageStatus = ResponseMessageStatus.PREMATURE_TERMINATION;
                errors.add(METADATA_TARGET_STARINET + METADATA_ACTION_REQUEST_UDP + METADATA_RESULT
                        + "Invalid AVR ProcessorID or PageSize [id=" + byteProcessorID + "] [pagesize="
                        + intChipFlashPageSize + TERMINATOR);
            }
        } else {
            responseMessageStatus = ResponseMessageStatus.PREMATURE_TERMINATION;
            errors.add(METADATA_TARGET_STARINET + METADATA_ACTION_REQUEST_UDP + METADATA_RESULT
                    + "Identify Acknowledge was empty or NULL" + TERMINATOR);
        }
    }

    catch (IndexOutOfBoundsException exception) {
        responseMessageStatus = ResponseMessageStatus.PREMATURE_TERMINATION;
        errors.add(METADATA_TARGET_STARINET + METADATA_ACTION_REQUEST_UDP + METADATA_EXCEPTION
                + ObservatoryInstrumentDAOInterface.ERROR_ARRAY_INDEX + TERMINATOR + SPACE + METADATA_MESSAGE
                + exception.getMessage() + TERMINATOR);
    }

    catch (PortUnreachableException exception) {
        responseMessageStatus = ResponseMessageStatus.PREMATURE_TERMINATION;
        errors.add(METADATA_TARGET_STARINET + METADATA_ACTION_REQUEST_UDP + METADATA_EXCEPTION
                + ObservatoryInstrumentDAOInterface.ERROR_PORT + TERMINATOR + SPACE + METADATA_MESSAGE
                + exception.getMessage() + TERMINATOR);
    }

    catch (SocketException exception) {
        responseMessageStatus = ResponseMessageStatus.PREMATURE_TERMINATION;
        errors.add(METADATA_TARGET_STARINET + METADATA_ACTION_REQUEST_UDP + METADATA_EXCEPTION
                + ObservatoryInstrumentDAOInterface.ERROR_SOCKET + TERMINATOR + SPACE + METADATA_MESSAGE
                + exception.getMessage() + TERMINATOR);
    }

    catch (IllegalArgumentException exception) {
        responseMessageStatus = ResponseMessageStatus.PREMATURE_TERMINATION;
        errors.add(METADATA_TARGET_STARINET + METADATA_ACTION_REQUEST_UDP + METADATA_EXCEPTION
                + ObservatoryInstrumentDAOInterface.ERROR_PARSE_INPUT + TERMINATOR + SPACE + METADATA_MESSAGE
                + exception.getMessage() + TERMINATOR);
    }

    catch (SecurityException exception) {
        responseMessageStatus = ResponseMessageStatus.PREMATURE_TERMINATION;
        errors.add(METADATA_TARGET_STARINET + METADATA_ACTION_REQUEST_UDP + METADATA_EXCEPTION
                + ObservatoryInstrumentDAOInterface.ERROR_SECURITY + TERMINATOR + SPACE + METADATA_MESSAGE
                + exception.getMessage() + TERMINATOR);
    }

    catch (UnknownHostException exception) {
        responseMessageStatus = ResponseMessageStatus.PREMATURE_TERMINATION;
        errors.add(METADATA_TARGET_STARINET + METADATA_ACTION_REQUEST_UDP + METADATA_EXCEPTION
                + ObservatoryInstrumentDAOInterface.ERROR_UNKNOWN_HOST + TERMINATOR + SPACE + METADATA_MESSAGE
                + exception.getMessage() + TERMINATOR);
    }

    catch (SocketTimeoutException exception) {
        responseMessageStatus = ResponseMessageStatus.PREMATURE_TERMINATION;
        errors.add(METADATA_TARGET_STARINET + METADATA_ACTION_REQUEST_UDP + METADATA_EXCEPTION
                + ObservatoryInstrumentDAOInterface.ERROR_TIMEOUT + TERMINATOR + SPACE + METADATA_MESSAGE
                + exception.getMessage() + TERMINATOR);
    }

    catch (IllegalBlockingModeException exception) {
        responseMessageStatus = ResponseMessageStatus.PREMATURE_TERMINATION;
        errors.add(METADATA_TARGET_STARINET + METADATA_ACTION_REQUEST_UDP + METADATA_EXCEPTION
                + ObservatoryInstrumentDAOInterface.ERROR_ILLEGAL_MODE + TERMINATOR + SPACE + METADATA_MESSAGE
                + exception.getMessage() + TERMINATOR);
    }

    catch (IOException exception) {
        responseMessageStatus = ResponseMessageStatus.PREMATURE_TERMINATION;
        errors.add(METADATA_TARGET_STARINET + METADATA_ACTION_REQUEST_UDP + METADATA_EXCEPTION
                + ObservatoryInstrumentDAOInterface.ERROR_IO + TERMINATOR + SPACE + METADATA_MESSAGE
                + exception.getMessage() + TERMINATOR);
    }

    finally {
        // Make sure that the Socket is released
        if (clientUDP != null) {
            clientUDP.close();
        }
    }

    return (responseMessageStatus);
}

From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java

private void sort(ArrayList<String> l, String objectName, String type, String pattern, String order,
        boolean stopOnFailure, final Object[] customError) {

    for (int i = 0; i < l.size(); i++) {
        // System.out.println(l.get(i));

        if (l.get(i).equals("")) {
            l.set(i, " ");
        }/* w w  w . ja v a 2 s . c  o m*/
    }

    System.out.println("Unsorted ArrayList in Java : " + l);
    System.out.println("Order :" + order);
    System.out.println("Pattern :" + pattern);
    System.out.println("Type :" + type);
    List<String> listOrg = new ArrayList<String>();

    for (int i = 0; i < l.size(); i++) {
        listOrg.add(l.get(i).toString());
    }

    //////////////////////////////////////////////////////////////////////////

    if (type.equals("string")) {

        if ("ascending".equals(order) && "alphabetically".equals(pattern)) {

            //System.out.println("list"+l);
            //Collections.sort(l, ALPHA_ORDER); 
            Collections.sort(l, String.CASE_INSENSITIVE_ORDER);
            //System.out.println("Ordered list"+l);

            if (l.equals(listOrg)) {
                // System.out.println("In ascending Order alphabetically" );

                reportresult(true, "CHECK SORTING :", "PASSED",
                        "Check sorting command : Element " + objectName + " sorted");

            } else {
                //  System.out.println("Not in ascending Order alphabetically" );
                if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");

                } else {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");

                }

            }

        } else if ("descending".equals(order) && "alphabetically".equals(pattern)) {

            // Collections.sort(l, ALPHA_ORDER);
            Collections.sort(l, String.CASE_INSENSITIVE_ORDER);

            //System.out.println("Ordered list"+l);
            List<String> listDes = new ArrayList<String>();
            for (int i = l.size() - 1; i >= 0; i--) {
                // System.out.println(l.get(i).toString());
                //String s = (String) l.get( i ) ;
                listDes.add(l.get(i).toString());
            }

            //System.out.println("Ordered list"+listDes);
            if (listDes.equals(listOrg)) {
                //System.out.println("In descending Order alphabetically" );

                reportresult(true, "CHECK SORTING :", "PASSED",
                        "Check sorting command : Element " + objectName + " sorted");

            } else {
                //System.out.println("Not in descending Order alphabetically" );
                if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                } else {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                }

            }
        } else if ("ascending".equals(order) && "1Aa".equals(pattern)) {

            Collections.sort(l, DiffSort.diffNaturalOrder1Aa);
            //Collections.sort(l);

            //System.out.println("Ordered list"+l);
            if (l.equals(listOrg)) {
                //System.out.println("In Ascending Order 1Aa" );

                reportresult(true, "CHECK SORTING :", "PASSED",
                        "Check sorting command : Element " + objectName + " sorted");

            } else {
                //System.out.println("Not in Ascending Order 1Aa" );
                if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                } else {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                }

            }

        } else if ("descending".equals(order) && "1Aa".equals(pattern)) {

            Collections.sort(l, DiffSort.diffNaturalOrder1Aa);

            List<String> listDes = new ArrayList<String>();
            for (int i = l.size() - 1; i >= 0; i--) {
                // System.out.println(l.get(i).toString());
                //String s = (String) l.get( i ) ;
                listDes.add(l.get(i).toString());
            }

            //System.out.println("Ordered list"+listDes);
            if (listDes.equals(listOrg)) {
                //System.out.println("In Descending Order 1Aa" );

                reportresult(true, "CHECK SORTING :", "PASSED",
                        "Check sorting command : Element " + objectName + " sorted");

            } else {
                //System.out.println("Not in Descending Order 1Aa" );
                if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");

                } else {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");

                }

            }

        } else if ("ascending".equals(order) && "Aa1".equals(pattern)) {
            Collections.sort(l, DiffSort.diffNaturalOrderAa1);

            //System.out.println("Ordered list"+l);
            if (l.equals(listOrg)) {
                //System.out.println("In Ascending Order Aa1" );

                reportresult(true, "CHECK SORTING :", "PASSED",
                        "Check sorting command : Element " + objectName + " sorted");

            } else {
                //System.out.println("Not in Ascending Order Aa1" );
                if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");

                } else {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");

                }

            }

        } else if ("descending".equals(order) && "Aa1".equals(pattern)) {
            Collections.sort(l, DiffSort.diffNaturalOrderAa1);

            List<String> listDes = new ArrayList<String>();
            for (int i = l.size() - 1; i >= 0; i--) {
                // System.out.println(l.get(i).toString());
                //String s = (String) l.get( i ) ;
                listDes.add(l.get(i).toString());
            }

            //System.out.println("Ordered list"+listDes);
            if (listDes.equals(listOrg)) {
                //System.out.println("In Descending Order Aa1" );

                reportresult(true, "CHECK SORTING :", "PASSED",
                        "Check sorting command : Element " + objectName + " sorted");

            } else {
                //  System.out.println("Not in Descending Order Aa1" );
                if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");

                } else {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");

                }

            }

        } else if ("ascending".equals(order) && "aA1".equals(pattern)) {
            Collections.sort(l, DiffSort.diffNaturalOrderaA1);

            //System.out.println("Ordered list"+l);
            if (l.equals(listOrg)) {
                // System.out.println("In Ascending Order aA1" );

                reportresult(true, "CHECK SORTING :", "PASSED",
                        "Check sorting command : Element " + objectName + " sorted");

            } else {
                // System.out.println("Not in Ascending Order aA1" );
                if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");

                } else {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");

                }

            }

        } else if ("descending".equals(order) && "aA1".equals(pattern)) {
            Collections.sort(l, DiffSort.diffNaturalOrderaA1);

            List<String> listDes = new ArrayList<String>();
            for (int i = l.size() - 1; i >= 0; i--) {
                // System.out.println(l.get(i).toString());
                //String s = (String) l.get( i ) ;
                listDes.add(l.get(i).toString());
            }

            //System.out.println("Ordered list"+listDes);
            if (listDes.equals(listOrg)) {
                // System.out.println("In Descending Order aA1" );

                reportresult(true, "CHECK SORTING :", "PASSED",
                        "Check sorting command : Element " + objectName + " sorted");

            } else {
                //System.out.println("Not in Descending Order aA1" );
                if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");

                } else {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");

                }

            }

        } else {
            if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) {
                reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                        " Custom Error :" + generateCustomError(customError)
                                + " System generated Error : CHECK SORTING command  : Element (" + objectName
                                + ") not sorted");
                checkTrue(false, stopOnFailure,
                        " Custom Error :" + generateCustomError(customError)
                                + " System generated Error : CHECK SORTING command  : Element (" + objectName
                                + ") not sorted");

            } else {
                reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                        "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                checkTrue(false, stopOnFailure,
                        "CHECK SORTING command  : Element (" + objectName + ") not sorted");

            }
        }

        /////////////////////////////////////////////////////////////////////////////////////////
    } else if (type.equals("numeric")) {
        List<Double> DoublelistOrg = new ArrayList<Double>();
        List<Double> DoublelistTemp = new ArrayList<Double>();
        try {
            for (int i = 0; i < l.size(); i++) {
                // System.out.println(l.get(i));       Rs    
                String temp = l.get(i).replace(",", "");
                temp = temp.replace("", "");
                temp = temp.replace("Rs", "");
                temp = temp.replace("$", "");
                temp = temp.replace("", "");
                // System.out.println(temp);

                double value = Double.parseDouble(temp);
                DoublelistOrg.add(value);
                DoublelistTemp.add(value);

            }
        } catch (Exception e) {
            // e.printStackTrace();
            reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                    "CHECK SORTING command  : Element (" + type + ") not match");
            checkTrue(false, stopOnFailure, "CHECK SORTING command  : Element (" + type + ") not match");
        }

        // System.out.println(DoublelistOrg);

        if (order.equals("ascending")) {
            Collections.sort(DoublelistTemp);

            if (DoublelistTemp.equals(DoublelistOrg)) {
                // System.out.println("ascending");
                reportresult(true, "CHECK SORTING :", "PASSED",
                        "Check sorting command : Element " + objectName + " sorted");
            } else {
                //System.out.println("Not ascending"); 

                if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                } else {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                }

            }

        } else if (order.equals("descending")) {
            Collections.sort(DoublelistTemp);
            Collections.reverse(DoublelistTemp);

            if (DoublelistTemp.equals(DoublelistOrg)) {
                //  System.out.println("descending");
                reportresult(true, "CHECK SORTING :", "PASSED",
                        "Check sorting command : Element " + objectName + " sorted");
            } else {
                // System.out.println("Not descending"); 
                if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                } else {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                }

            }

        } else {
            reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                    "CHECK SORTING command  : Element (" + order + ") not match");
            checkTrue(false, stopOnFailure, "CHECK SORTING command  : Element (" + order + ") not match");
        }

    } else if (type.equals("date")) {
        List<Date> datelistOrg = new ArrayList<Date>();
        List<Date> datelistTemp = new ArrayList<Date>();
        try {
            for (int i = 0; i < l.size(); i++) {
                // System.out.println(l.get(i));       Rs    
                SimpleDateFormat formatter = new SimpleDateFormat(pattern);
                String tempDate = l.get(i);
                //  System.out.println(l.get(i));

                Date date = formatter.parse(tempDate);
                // System.out.println(date);
                //System.out.println(formatter.format(date));
                datelistOrg.add(date);
                datelistTemp.add(date);
            }
        } catch (Exception e) {
            // e.printStackTrace();
            reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                    "CHECK SORTING command  : Element (" + type + ") not match");
            checkTrue(false, stopOnFailure, "CHECK SORTING command  : Element (" + type + ") not match");
        }

        //System.out.println( datelistOrg);

        if (order.equals("ascending")) {
            Collections.sort(datelistTemp);

            if (datelistTemp.equals(datelistOrg)) {
                // System.out.println("ascending");
                reportresult(true, "CHECK SORTING :", "PASSED",
                        "Check sorting command : Element " + objectName + " sorted");
            } else {
                //System.out.println("Not ascending"); 
                if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                } else {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                }

            }

        } else if (order.equals("descending")) {
            Collections.sort(datelistTemp);
            Collections.reverse(datelistTemp);

            if (datelistTemp.equals(datelistOrg)) {
                //  System.out.println("descending");
                reportresult(true, "CHECK SORTING :", "PASSED",
                        "Check sorting command : Element " + objectName + " sorted");
            } else {
                // System.out.println("Not descending"); 
                if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                } else {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                }

            }

        } else {
            reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                    "CHECK SORTING command  : Element (" + order + ") not match");
            checkTrue(false, stopOnFailure, "CHECK SORTING command  : Element (" + order + ") not match");
        }

    } else {
        reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                "CHECK SORTING command  : Type (" + type + ") not match");
        checkTrue(false, stopOnFailure, "CHECK SORTING command  : Type (" + type + ") not match");
    }
}