List of usage examples for java.util LinkedHashMap putAll
void putAll(Map<? extends K, ? extends V> m);
From source file:com.android.tradefed.testtype.suite.TfSuiteRunner.java
/** * Internal load configuration. Load configuration, expand sub suite runners and track cycle * inclusion to prevent infinite recursion. * * @param parentConfig the name of the config being loaded. * @param graph the directed graph tracking inclusion. * @return a map of module name and the configuration associated. *//*from w w w. ja v a2 s . co m*/ private LinkedHashMap<String, IConfiguration> loadTests(String parentConfig, DirectedGraph<String> graph) { LinkedHashMap<String, IConfiguration> configMap = new LinkedHashMap<String, IConfiguration>(); IConfigurationFactory configFactory = ConfigurationFactory.getInstance(); // TODO: Do a better job searching for configs. // We do not load config from environment, they should be inside the testsDir of the build // info. List<String> configs = configFactory.getConfigList(mSuitePrefix, false); if (getBuildInfo() instanceof IDeviceBuildInfo) { IDeviceBuildInfo deviceBuildInfo = (IDeviceBuildInfo) getBuildInfo(); File testsDir = deviceBuildInfo.getTestsDir(); if (testsDir != null) { if (mAdditionalTestsZip != null) { CLog.d("Extract general-tests.zip (%s) to tests directory.", mAdditionalTestsZip); ZipFile zip = null; try { zip = new ZipFile(mAdditionalTestsZip); ZipUtil2.extractZip(zip, testsDir); } catch (IOException e) { RuntimeException runtimeException = new RuntimeException( String.format("IO error (%s) when unzipping general-tests.zip", e.toString()), e); throw runtimeException; } finally { StreamUtil.close(zip); } } CLog.d("Loading extra test configs from the tests directory: %s", testsDir.getAbsolutePath()); List<File> extraTestCasesDirs = Arrays.asList(testsDir); configs.addAll(ConfigurationUtil.getConfigNamesFromDirs(mSuitePrefix, extraTestCasesDirs)); } } // Sort configs to ensure they are always evaluated and added in the same order. Collections.sort(configs); for (String configName : configs) { try { IConfiguration testConfig = configFactory.createConfigurationFromArgs(new String[] { configName }); if (testConfig.getConfigurationDescription().getSuiteTags().contains(mSuiteTag)) { // In case some sub-config are suite too, we expand them to avoid weirdness // of modules inside modules. if (parentConfig != null) { graph.addEdge(parentConfig, configName); if (!graph.isDag()) { CLog.e("%s", graph); throw new RuntimeException(String.format( "Circular configuration detected: %s has been included " + "several times.", configName)); } } LinkedHashMap<String, IConfiguration> expandedConfig = expandTestSuites(configName, testConfig, graph); configMap.putAll(expandedConfig); } } catch (ConfigurationException | NoClassDefFoundError e) { // Do not print the stack it's too verbose. CLog.e("Configuration '%s' cannot be loaded, ignoring.", configName); } } return configMap; }
From source file:org.apache.nifi.cluster.manager.impl.WebClusterManager.java
public ClusterStatusHistoryDTO getProcessorStatusHistory(final String processorId, final Date startDate, final Date endDate, final int preferredDataPoints) { final List<NodeStatusHistoryDTO> nodeHistories = new ArrayList<>(); StatusHistoryDTO lastStatusHistory = null; final Set<MetricDescriptor<?>> processorDescriptors = new LinkedHashSet<>(); final Map<Date, List<StatusSnapshot>> snapshotsToAggregate = new TreeMap<>(); for (final Node node : getRawNodes()) { final ComponentStatusRepository statusRepository = componentMetricsRepositoryMap.get(node.getNodeId()); if (statusRepository == null) { continue; }//from w w w . j a v a 2s .com final StatusHistory statusHistory = statusRepository.getProcessorStatusHistory(processorId, startDate, endDate, preferredDataPoints); if (statusHistory == null) { continue; } processorDescriptors.addAll(statusRepository.getProcessorMetricDescriptors()); // record the status history (last) to get the component details for use later final StatusHistoryDTO statusHistoryDto = createStatusHistoryDto(statusHistory); lastStatusHistory = statusHistoryDto; final NodeStatusHistoryDTO nodeHistory = new NodeStatusHistoryDTO(); nodeHistory.setStatusHistory(statusHistoryDto); nodeHistory.setNode(createNodeDTO(node)); nodeHistories.add(nodeHistory); // collect all of the snapshots to aggregate for (final StatusSnapshot snapshot : statusHistory.getStatusSnapshots()) { final Date normalizedDate = normalizeStatusSnapshotDate(snapshot.getTimestamp(), componentStatusSnapshotMillis); List<StatusSnapshot> snapshots = snapshotsToAggregate.get(normalizedDate); if (snapshots == null) { snapshots = new ArrayList<>(); snapshotsToAggregate.put(normalizedDate, snapshots); } snapshots.add(snapshot); } } // Aggregate the snapshots final List<StatusSnapshotDTO> aggregatedSnapshotDtos = aggregate(snapshotsToAggregate); // get the details for this component from the last status history final LinkedHashMap<String, String> clusterStatusHistoryDetails = new LinkedHashMap<>(); clusterStatusHistoryDetails.putAll(lastStatusHistory.getDetails()); final StatusHistoryDTO clusterStatusHistory = new StatusHistoryDTO(); clusterStatusHistory.setGenerated(new Date()); clusterStatusHistory.setFieldDescriptors(StatusHistoryUtil.createFieldDescriptorDtos(processorDescriptors)); clusterStatusHistory.setDetails(clusterStatusHistoryDetails); clusterStatusHistory.setStatusSnapshots(aggregatedSnapshotDtos); final ClusterStatusHistoryDTO history = new ClusterStatusHistoryDTO(); history.setGenerated(new Date()); history.setNodeStatusHistory(nodeHistories); history.setClusterStatusHistory(clusterStatusHistory); return history; }
From source file:org.apache.nifi.cluster.manager.impl.WebClusterManager.java
public ClusterStatusHistoryDTO getConnectionStatusHistory(final String connectionId, final Date startDate, final Date endDate, final int preferredDataPoints) { final List<NodeStatusHistoryDTO> nodeHistories = new ArrayList<>(); StatusHistoryDTO lastStatusHistory = null; final Set<MetricDescriptor<?>> connectionDescriptors = new LinkedHashSet<>(); final Map<Date, List<StatusSnapshot>> snapshotsToAggregate = new TreeMap<>(); for (final Node node : getRawNodes()) { final ComponentStatusRepository statusRepository = componentMetricsRepositoryMap.get(node.getNodeId()); if (statusRepository == null) { continue; }/*from w w w. j ava 2s. c o m*/ final StatusHistory statusHistory = statusRepository.getConnectionStatusHistory(connectionId, startDate, endDate, preferredDataPoints); if (statusHistory == null) { continue; } final StatusHistoryDTO statusHistoryDto = createStatusHistoryDto(statusHistory); // record the status history (last) to get the componet details for use later lastStatusHistory = statusHistoryDto; connectionDescriptors.addAll(statusRepository.getConnectionMetricDescriptors()); final NodeStatusHistoryDTO nodeHistory = new NodeStatusHistoryDTO(); nodeHistory.setStatusHistory(statusHistoryDto); nodeHistory.setNode(createNodeDTO(node)); nodeHistories.add(nodeHistory); // collect all of the snapshots to aggregate for (final StatusSnapshot snapshot : statusHistory.getStatusSnapshots()) { final Date normalizedDate = normalizeStatusSnapshotDate(snapshot.getTimestamp(), componentStatusSnapshotMillis); List<StatusSnapshot> snapshots = snapshotsToAggregate.get(normalizedDate); if (snapshots == null) { snapshots = new ArrayList<>(); snapshotsToAggregate.put(normalizedDate, snapshots); } snapshots.add(snapshot); } } // Aggregate the snapshots final List<StatusSnapshotDTO> aggregatedSnapshotDtos = aggregate(snapshotsToAggregate); // get the details for this component from the last status history final LinkedHashMap<String, String> clusterStatusHistoryDetails = new LinkedHashMap<>(); clusterStatusHistoryDetails.putAll(lastStatusHistory.getDetails()); final StatusHistoryDTO clusterStatusHistory = new StatusHistoryDTO(); clusterStatusHistory.setGenerated(new Date()); clusterStatusHistory .setFieldDescriptors(StatusHistoryUtil.createFieldDescriptorDtos(connectionDescriptors)); clusterStatusHistory.setDetails(clusterStatusHistoryDetails); clusterStatusHistory.setStatusSnapshots(aggregatedSnapshotDtos); final ClusterStatusHistoryDTO history = new ClusterStatusHistoryDTO(); history.setGenerated(new Date()); history.setNodeStatusHistory(nodeHistories); history.setClusterStatusHistory(clusterStatusHistory); return history; }
From source file:org.apache.nifi.cluster.manager.impl.WebClusterManager.java
public ClusterStatusHistoryDTO getProcessGroupStatusHistory(final String processGroupId, final Date startDate, final Date endDate, final int preferredDataPoints) { final List<NodeStatusHistoryDTO> nodeHistories = new ArrayList<>(); StatusHistoryDTO lastStatusHistory = null; final Set<MetricDescriptor<?>> processGroupDescriptors = new LinkedHashSet<>(); final Map<Date, List<StatusSnapshot>> snapshotsToAggregate = new TreeMap<>(); for (final Node node : getRawNodes()) { final ComponentStatusRepository statusRepository = componentMetricsRepositoryMap.get(node.getNodeId()); if (statusRepository == null) { continue; }/*w w w.j ava2s.c o m*/ final StatusHistory statusHistory = statusRepository.getProcessGroupStatusHistory(processGroupId, startDate, endDate, preferredDataPoints); if (statusHistory == null) { continue; } final StatusHistoryDTO statusHistoryDto = createStatusHistoryDto(statusHistory); // record the status history (last) to get the componet details for use later lastStatusHistory = statusHistoryDto; processGroupDescriptors.addAll(statusRepository.getProcessGroupMetricDescriptors()); final NodeStatusHistoryDTO nodeHistory = new NodeStatusHistoryDTO(); nodeHistory.setStatusHistory(statusHistoryDto); nodeHistory.setNode(createNodeDTO(node)); nodeHistories.add(nodeHistory); // collect all of the snapshots to aggregate for (final StatusSnapshot snapshot : statusHistory.getStatusSnapshots()) { final Date normalizedDate = normalizeStatusSnapshotDate(snapshot.getTimestamp(), componentStatusSnapshotMillis); List<StatusSnapshot> snapshots = snapshotsToAggregate.get(normalizedDate); if (snapshots == null) { snapshots = new ArrayList<>(); snapshotsToAggregate.put(normalizedDate, snapshots); } snapshots.add(snapshot); } } // Aggregate the snapshots final List<StatusSnapshotDTO> aggregatedSnapshotDtos = aggregate(snapshotsToAggregate); // get the details for this component from the last status history final LinkedHashMap<String, String> clusterStatusHistoryDetails = new LinkedHashMap<>(); clusterStatusHistoryDetails.putAll(lastStatusHistory.getDetails()); final StatusHistoryDTO clusterStatusHistory = new StatusHistoryDTO(); clusterStatusHistory.setGenerated(new Date()); clusterStatusHistory.setDetails(clusterStatusHistoryDetails); clusterStatusHistory .setFieldDescriptors(StatusHistoryUtil.createFieldDescriptorDtos(processGroupDescriptors)); clusterStatusHistory.setStatusSnapshots(aggregatedSnapshotDtos); final ClusterStatusHistoryDTO history = new ClusterStatusHistoryDTO(); history.setGenerated(new Date()); history.setNodeStatusHistory(nodeHistories); history.setClusterStatusHistory(clusterStatusHistory); return history; }
From source file:org.apache.nifi.cluster.manager.impl.WebClusterManager.java
public ClusterStatusHistoryDTO getRemoteProcessGroupStatusHistory(final String remoteGroupId, final Date startDate, final Date endDate, final int preferredDataPoints) { final List<NodeStatusHistoryDTO> nodeHistories = new ArrayList<>(); StatusHistoryDTO lastStatusHistory = null; final Set<MetricDescriptor<?>> remoteProcessGroupDescriptors = new LinkedHashSet<>(); final Map<Date, List<StatusSnapshot>> snapshotsToAggregate = new TreeMap<>(); for (final Node node : getRawNodes()) { final ComponentStatusRepository statusRepository = componentMetricsRepositoryMap.get(node.getNodeId()); if (statusRepository == null) { continue; }// w ww . j a va 2 s. c o m final StatusHistory statusHistory = statusRepository.getRemoteProcessGroupStatusHistory(remoteGroupId, startDate, endDate, preferredDataPoints); if (statusHistory == null) { continue; } final StatusHistoryDTO statusHistoryDto = createStatusHistoryDto(statusHistory); // record the status history (last) to get the componet details for use later lastStatusHistory = statusHistoryDto; remoteProcessGroupDescriptors.addAll(statusRepository.getRemoteProcessGroupMetricDescriptors()); final NodeStatusHistoryDTO nodeHistory = new NodeStatusHistoryDTO(); nodeHistory.setStatusHistory(statusHistoryDto); nodeHistory.setNode(createNodeDTO(node)); nodeHistories.add(nodeHistory); // collect all of the snapshots to aggregate for (final StatusSnapshot snapshot : statusHistory.getStatusSnapshots()) { final Date normalizedDate = normalizeStatusSnapshotDate(snapshot.getTimestamp(), componentStatusSnapshotMillis); List<StatusSnapshot> snapshots = snapshotsToAggregate.get(normalizedDate); if (snapshots == null) { snapshots = new ArrayList<>(); snapshotsToAggregate.put(normalizedDate, snapshots); } snapshots.add(snapshot); } } // Aggregate the snapshots final List<StatusSnapshotDTO> aggregatedSnapshotDtos = aggregate(snapshotsToAggregate); // get the details for this component from the last status history final LinkedHashMap<String, String> clusterStatusHistoryDetails = new LinkedHashMap<>(); clusterStatusHistoryDetails.putAll(lastStatusHistory.getDetails()); final StatusHistoryDTO clusterStatusHistory = new StatusHistoryDTO(); clusterStatusHistory.setGenerated(new Date()); clusterStatusHistory.setDetails(clusterStatusHistoryDetails); clusterStatusHistory .setFieldDescriptors(StatusHistoryUtil.createFieldDescriptorDtos(remoteProcessGroupDescriptors)); clusterStatusHistory.setStatusSnapshots(aggregatedSnapshotDtos); final ClusterStatusHistoryDTO history = new ClusterStatusHistoryDTO(); history.setGenerated(new Date()); history.setNodeStatusHistory(nodeHistories); history.setClusterStatusHistory(clusterStatusHistory); return history; }
From source file:org.apache.asterix.optimizer.rules.subplan.InlineSubplanInputForNestedTupleSourceRule.java
private Pair<Boolean, LinkedHashMap<LogicalVariable, LogicalVariable>> applySpecialFlattening( Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { SubplanOperator subplanOp = (SubplanOperator) opRef.getValue(); Mutable<ILogicalOperator> inputOpRef = subplanOp.getInputs().get(0); LinkedHashMap<LogicalVariable, LogicalVariable> replacedVarMap = new LinkedHashMap<>(); // Recursively applies this rule to the nested plan of the subplan operator, // for the case where there are nested subplan operators within {@code subplanOp}. Pair<Boolean, LinkedHashMap<LogicalVariable, LogicalVariable>> result = rewriteSubplanOperator( subplanOp.getNestedPlans().get(0).getRoots().get(0), context); ILogicalOperator inputOpBackup = inputOpRef.getValue(); // Gets live variables and covering variables from the subplan's input operator. Pair<ILogicalOperator, Set<LogicalVariable>> primaryOpAndVars = EquivalenceClassUtils .findOrCreatePrimaryKeyOpAndVariables(inputOpBackup, false, context); ILogicalOperator inputOp = primaryOpAndVars.first; Set<LogicalVariable> primaryKeyVars = primaryOpAndVars.second; inputOpRef.setValue(inputOp);/*from w w w . j a va 2 s .co m*/ Set<LogicalVariable> liveVars = new HashSet<>(); VariableUtilities.getLiveVariables(inputOp, liveVars); Pair<Set<LogicalVariable>, Mutable<ILogicalOperator>> notNullVarsAndTopJoinRef = SubplanFlatteningUtil .inlineLeftNtsInSubplanJoin(subplanOp, context); if (notNullVarsAndTopJoinRef.first == null) { inputOpRef.setValue(inputOpBackup); return new Pair<>(false, replacedVarMap); } Set<LogicalVariable> notNullVars = notNullVarsAndTopJoinRef.first; Mutable<ILogicalOperator> topJoinRef = notNullVarsAndTopJoinRef.second; // Creates a group-by operator. List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> groupByList = new ArrayList<Pair<LogicalVariable, Mutable<ILogicalExpression>>>(); List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> groupByDecorList = new ArrayList<Pair<LogicalVariable, Mutable<ILogicalExpression>>>(); GroupByOperator groupbyOp = new GroupByOperator(groupByList, groupByDecorList, subplanOp.getNestedPlans()); for (LogicalVariable coverVar : primaryKeyVars) { LogicalVariable newVar = context.newVar(); groupByList.add(new Pair<>(newVar, new MutableObject<>(new VariableReferenceExpression(coverVar)))); // Adds variables for replacements in ancestors. replacedVarMap.put(coverVar, newVar); } for (LogicalVariable liveVar : liveVars) { if (primaryKeyVars.contains(liveVar)) { continue; } groupByDecorList.add(new Pair<>(null, new MutableObject<>(new VariableReferenceExpression(liveVar)))); } groupbyOp.getInputs().add(new MutableObject<>(topJoinRef.getValue())); if (!notNullVars.isEmpty()) { // Adds a select operator into the nested plan for group-by to remove tuples with NULL on {@code assignVar}, i.e., // subplan input tuples that are filtered out within a subplan. List<Mutable<ILogicalExpression>> nullCheckExprRefs = new ArrayList<>(); for (LogicalVariable notNullVar : notNullVars) { Mutable<ILogicalExpression> filterVarExpr = new MutableObject<>( new VariableReferenceExpression(notNullVar)); List<Mutable<ILogicalExpression>> args = new ArrayList<>(); args.add(filterVarExpr); List<Mutable<ILogicalExpression>> argsForNotFunction = new ArrayList<>(); argsForNotFunction.add(new MutableObject<>(new ScalarFunctionCallExpression( FunctionUtil.getFunctionInfo(AsterixBuiltinFunctions.IS_MISSING), args))); nullCheckExprRefs.add(new MutableObject<>(new ScalarFunctionCallExpression( FunctionUtil.getFunctionInfo(AsterixBuiltinFunctions.NOT), argsForNotFunction))); } Mutable<ILogicalExpression> selectExprRef = nullCheckExprRefs.size() > 1 ? new MutableObject<>(new ScalarFunctionCallExpression( FunctionUtil.getFunctionInfo(AsterixBuiltinFunctions.AND), nullCheckExprRefs)) : nullCheckExprRefs.get(0); SelectOperator selectOp = new SelectOperator(selectExprRef, false, null); topJoinRef.setValue(selectOp); selectOp.getInputs() .add(new MutableObject<>(new NestedTupleSourceOperator(new MutableObject<>(groupbyOp)))); } else { // The original join operator in the Subplan is a left-outer join. // Therefore, no null-check variable is injected and no SelectOperator needs to be added. topJoinRef.setValue(new NestedTupleSourceOperator(new MutableObject<>(groupbyOp))); } opRef.setValue(groupbyOp); OperatorManipulationUtil.computeTypeEnvironmentBottomUp(groupbyOp, context); VariableUtilities.substituteVariables(groupbyOp, result.second, context); replacedVarMap.putAll(result.second); return new Pair<>(true, replacedVarMap); }
From source file:com.gp.cong.logisoft.lcl.report.LclAllBLPdfCreator.java
public PdfPTable appendChargesAndCommodity() throws Exception { LclBlAcDAO lclBlAcDAO = new LclBlAcDAO(); List<LclBlPiece> lclBlPiecesList = lclbl.getLclFileNumber().getLclBlPieceList(); List<LclBlAc> chargeList = lclBlAcDAO.getLclCostByFileNumberAsc(lclbl.getFileNumberId()); PdfPTable chargeTable = new PdfPTable(6); PdfPCell chargeCell = null;//www. j a v a 2 s .c om chargeTable.setWidths(new float[] { 3.8f, 1.5f, .8f, 3.8f, 1.5f, .8f }); chargeTable.setWidthPercentage(100f); Paragraph p = null; this.total_ar_amount = 0.00; this.total_ar_col_amount = 0.00; this.total_ar_ppd_amount = 0.00; List<LinkedHashMap<String, PdfPCell>> listChargeMap = null; LinkedHashMap<String, PdfPCell> chargeMap = null; if ("BOTH".equalsIgnoreCase(billType)) { listChargeMap = this.getTotalChargesList(chargeList, lclBlPiecesList); } else { chargeMap = this.getTotalCharges(chargeList, lclBlPiecesList); } LclBlAc blAC = lclBlAcDAO.manualChargeValidate(lclbl.getFileNumberId(), "OCNFRT", false); if (lclBlPiecesList != null && lclBlPiecesList.size() > 0 && blAC != null) { BigDecimal CFT = BigDecimal.ZERO, LBS = BigDecimal.ZERO; LclBlPiece lclBlPiece = (LclBlPiece) lclBlPiecesList.get(0); if (blAC.getRatePerUnitUom() != null) { CFT = blAC.getRatePerUnitUom().equalsIgnoreCase("FRV") ? blAC.getRatePerVolumeUnit() : BigDecimal.ZERO; LBS = blAC.getRatePerUnitUom().equalsIgnoreCase("FRW") ? blAC.getRatePerWeightUnit() : BigDecimal.ZERO; } if (CFT != BigDecimal.ZERO || LBS != BigDecimal.ZERO) { StringBuilder cbmValues = new StringBuilder(); if (CFT != BigDecimal.ZERO && lclBlPiece.getActualVolumeImperial() != null) { cbmValues.append(NumberUtils .convertToThreeDecimalhash(lclBlPiece.getActualVolumeImperial().doubleValue())); } if (LBS != BigDecimal.ZERO && lclBlPiece.getActualWeightImperial() != null) { cbmValues.append(NumberUtils .convertToThreeDecimalhash(lclBlPiece.getActualWeightImperial().doubleValue())); } if (null != blAC.getArAmount() && blAC.getArAmount().toString().equalsIgnoreCase(OCNFRT_Total)) { if (CFT == BigDecimal.ZERO) { cbmValues.append(" LBS @ ").append(LBS).append(" PER 100 LBS @ ") .append(blAC.getArAmount()); } else { cbmValues.append(" CFT @ ").append(CFT).append(" PER CFT @").append(blAC.getArAmount()); } chargeCell = new PdfPCell(); chargeCell.setBorder(0); chargeCell.setColspan(6); chargeTable.addCell(chargeCell); chargeCell = new PdfPCell(); chargeCell.setBorder(0); chargeCell.setColspan(6); p = new Paragraph(2f, "" + cbmValues.toString().toUpperCase(), totalFontQuote); p.add(new Paragraph(2f, null != lclBlPiece && null != lclBlPiece.getCommodityType() ? " Commodity# " + lclBlPiece.getCommodityType().getCode() : " Commodity#", totalFontQuote)); p.setAlignment(Element.ALIGN_LEFT); chargeCell.addElement(p); chargeTable.addCell(chargeCell); } } } this.OCNFRT_Total = ""; LinkedHashMap<String, PdfPCell> left_chargeMap = new LinkedHashMap<String, PdfPCell>(); LinkedHashMap<String, PdfPCell> right_chargeMap = new LinkedHashMap<String, PdfPCell>(); if ("BOTH".equalsIgnoreCase(billType) && listChargeMap != null && !listChargeMap.isEmpty()) { if (listChargeMap.size() > 1) { if (listChargeMap.get(0).size() > 6 || listChargeMap.get(1).size() > 6) { chargeMap = new LinkedHashMap<String, PdfPCell>(); chargeMap.putAll(listChargeMap.get(0)); chargeMap.putAll(listChargeMap.get(1)); int count = 0, size = chargeMap.size() / 2 <= 6 ? 6 : chargeMap.size() / 2; for (String key : chargeMap.keySet()) { if (count++ < size) { left_chargeMap.put(key, chargeMap.get(key)); } else { right_chargeMap.put(key, chargeMap.get(key)); } } } else { left_chargeMap.putAll(listChargeMap.get(0)); right_chargeMap.putAll(listChargeMap.get(1)); } } else { int count = 0, size = listChargeMap.get(0).size() / 2 <= 6 ? 6 : listChargeMap.get(0).size() / 2; for (String key : listChargeMap.get(0).keySet()) { if (count++ < size) { left_chargeMap.put(key, listChargeMap.get(0).get(key)); } else { right_chargeMap.put(key, listChargeMap.get(0).get(key)); } } } } else if (chargeMap != null && !chargeMap.isEmpty()) { int count = 0, size = chargeMap.size() / 2 <= 6 ? 6 : chargeMap.size() / 2; for (String key : chargeMap.keySet()) { if (count++ < size) { left_chargeMap.put(key, chargeMap.get(key)); } else { right_chargeMap.put(key, chargeMap.get(key)); } } } if (!left_chargeMap.isEmpty()) { String chargeDesc = null; PdfPTable innner_chargeTable = new PdfPTable(2); innner_chargeTable.setWidthPercentage(100f); PdfPCell inner_chargeCell = null; chargeCell = new PdfPCell(); chargeCell.setBorder(0); chargeCell.setColspan(3); chargeCell.setBorderWidthRight(0.6f); chargeCell.setPadding(0); innner_chargeTable = new PdfPTable(2); innner_chargeTable.setWidths(new float[] { 5f, 3f }); if (!left_chargeMap.isEmpty()) { for (String key : left_chargeMap.keySet()) { inner_chargeCell = new PdfPCell(); inner_chargeCell.setBorder(0); inner_chargeCell.setPaddingLeft(-15); chargeDesc = key.substring(key.indexOf("#") + 1, key.indexOf("$")); inner_chargeCell.addElement(new Paragraph(7f, "" + chargeDesc, totalFontQuote)); innner_chargeTable.addCell(inner_chargeCell); inner_chargeCell = new PdfPCell(); inner_chargeCell.setBorder(0); inner_chargeCell = left_chargeMap.get(key); innner_chargeTable.addCell(inner_chargeCell); } } chargeCell.addElement(innner_chargeTable); chargeTable.addCell(chargeCell); chargeCell = new PdfPCell(); chargeCell.setBorder(0); chargeCell.setColspan(3); chargeCell.setPadding(0); innner_chargeTable = new PdfPTable(2); innner_chargeTable.setWidths(new float[] { 5f, 3f }); if (!left_chargeMap.isEmpty()) { for (String key : right_chargeMap.keySet()) { inner_chargeCell = new PdfPCell(); inner_chargeCell.setBorder(0); inner_chargeCell.setPaddingLeft(-15); chargeDesc = key.substring(key.indexOf("#") + 1, key.indexOf("$")); inner_chargeCell.addElement(new Paragraph(7f, "" + chargeDesc, totalFontQuote)); innner_chargeTable.addCell(inner_chargeCell); inner_chargeCell = new PdfPCell(); inner_chargeCell.setBorder(0); inner_chargeCell = right_chargeMap.get(key); innner_chargeTable.addCell(inner_chargeCell); } } chargeCell.addElement(innner_chargeTable); chargeTable.addCell(chargeCell); } else { this.total_ar_amount = 0.00; this.total_ar_ppd_amount = 0.00; this.total_ar_col_amount = 0.00; } String acctNo = ""; String billToParty = ""; if (CommonFunctions.isNotNull(lclbl.getBillToParty()) && CommonUtils.isNotEmpty(lclbl.getBillToParty())) { if (lclbl.getBillToParty().equalsIgnoreCase("T") && CommonFunctions.isNotNull(lclbl.getThirdPartyAcct())) { billToParty = "THIRD PARTY"; acctNo = lclbl.getThirdPartyAcct().getAccountno(); } else if (lclbl.getBillToParty().equalsIgnoreCase("S") && CommonFunctions.isNotNull(lclbl.getShipAcct())) { billToParty = "SHIPPER"; acctNo = lclbl.getShipAcct().getAccountno(); } else if (lclbl.getBillToParty().equalsIgnoreCase("F") && CommonFunctions.isNotNull(lclbl.getFwdAcct())) { billToParty = "FORWARDER"; acctNo = lclbl.getFwdAcct().getAccountno(); } else if (lclbl.getBillToParty().equalsIgnoreCase("A") && CommonFunctions.isNotNull(lclbl.getAgentAcct())) { billToParty = "AGENT"; if (lclBooking.getBookingType().equals("T") && lclbl.getLclFileNumber().getLclBookingImport().getExportAgentAcctNo() != null) { acctNo = lclbl.getLclFileNumber().getLclBookingImport().getExportAgentAcctNo().getAccountno(); } else if (lclBooking.getAgentAcct() != null) { acctNo = lclBooking.getAgentAcct().getAccountno(); } else { acctNo = lclbl.getAgentAcct().getAccountno(); } } } if ("BOTH".equalsIgnoreCase(billType)) { if (this.total_ar_ppd_amount != 0.00 || this.total_ar_col_amount != 0.00) { if (this.total_ar_ppd_amount != 0.00) { if (CommonFunctions.isNotNullOrNotEmpty(ppdBillToSet) && ppdBillToSet.size() == 1) { for (String billTo : ppdBillToSet) { arBillToParty = billTo; break; } if (arBillToParty.equalsIgnoreCase("T")) { billToParty = "THIRD PARTY"; acctNo = null != lclbl.getThirdPartyAcct() ? lclbl.getThirdPartyAcct().getAccountno() : acctNo; } else if (arBillToParty.equalsIgnoreCase("S")) { acctNo = null != lclbl.getShipAcct() ? lclbl.getShipAcct().getAccountno() : acctNo; billToParty = "SHIPPER"; } else if (arBillToParty.equalsIgnoreCase("F")) { billToParty = "FORWARDER"; acctNo = null != lclbl.getFwdAcct() ? lclbl.getFwdAcct().getAccountno() : acctNo; } } else { acctNo = null; } chargeCell = new PdfPCell(); chargeCell.setBorder(0); chargeCell.setColspan(2); p = new Paragraph(7f, "T O T A L (USA)", totalFontQuote); p.setAlignment(Element.ALIGN_LEFT); chargeCell.addElement(p); chargeTable.addCell(chargeCell); chargeCell = new PdfPCell(); chargeCell.setColspan(4); chargeCell.setBorder(0); if (null != acctNo) { p = new Paragraph(7f, "$" + NumberUtils.convertToTwoDecimal(this.total_ar_ppd_amount) + " PPD " + billToParty + "-" + acctNo, totalFontQuote); } else { p = new Paragraph(7f, "$" + NumberUtils.convertToTwoDecimal(this.total_ar_ppd_amount) + " PPD ", totalFontQuote); } p.setAlignment(Element.ALIGN_LEFT); chargeCell.addElement(p); chargeTable.addCell(chargeCell); } if (this.total_ar_col_amount != 0.00) { String colAcctNo = ""; if (lclBooking.getBookingType().equals("T") && lclbl.getLclFileNumber().getLclBookingImport().getExportAgentAcctNo() != null) { colAcctNo = lclbl.getLclFileNumber().getLclBookingImport().getExportAgentAcctNo() .getAccountno(); } else if (lclBooking.getAgentAcct() != null) { colAcctNo = lclBooking.getAgentAcct().getAccountno(); } else if (lclbl.getAgentAcct() != null) { colAcctNo = lclbl.getAgentAcct().getAccountno(); } chargeCell = new PdfPCell(); chargeCell.setBorder(0); chargeCell.setColspan(2); if (this.total_ar_ppd_amount == 0.00) { p = new Paragraph(7f, "T O T A L (USA)", totalFontQuote); } else { p = new Paragraph(7f, "", totalFontQuote); } p.setAlignment(Element.ALIGN_LEFT); chargeCell.addElement(p); chargeTable.addCell(chargeCell); chargeCell = new PdfPCell(); chargeCell.setColspan(4); chargeCell.setBorder(0); p = new Paragraph(7f, "$" + NumberUtils.convertToTwoDecimal(this.total_ar_col_amount) + " COL AGENT-" + colAcctNo, totalFontQuote); p.setAlignment(Element.ALIGN_LEFT); chargeCell.addElement(p); chargeTable.addCell(chargeCell); } NumberFormat numberFormat = new DecimalFormat("###,###,##0.000"); if (this.total_ar_ppd_amount != 0.00) { String totalString1 = numberFormat.format(this.total_ar_ppd_amount).replaceAll(",", ""); int indexdot = totalString1.indexOf("."); String beforeDecimal = totalString1.substring(0, indexdot); String afterDecimal = totalString1.substring(indexdot + 1, totalString1.length()); chargeCell = new PdfPCell(); chargeCell.setColspan(6); chargeCell.setBorder(0); p = new Paragraph(7f, "" + ConvertNumberToWords.convert(Integer.parseInt(beforeDecimal)) + " DOLLARS AND " + StringUtils.removeEnd(afterDecimal, "0") + " CENTS", totalFontQuote); chargeCell.setHorizontalAlignment(Element.ALIGN_CENTER); chargeCell.addElement(p); chargeTable.addCell(chargeCell); } if (this.total_ar_col_amount != 0.00) { String totalString1 = numberFormat.format(this.total_ar_col_amount).replaceAll(",", ""); int indexdot = totalString1.indexOf("."); String beforeDecimal = totalString1.substring(0, indexdot); String afterDecimal = totalString1.substring(indexdot + 1, totalString1.length()); chargeCell = new PdfPCell(); chargeCell.setColspan(6); chargeCell.setBorder(0); p = new Paragraph(7f, "" + ConvertNumberToWords.convert(Integer.parseInt(beforeDecimal)) + " DOLLARS AND " + StringUtils.removeEnd(afterDecimal, "0") + " CENTS", totalFontQuote); chargeCell.setHorizontalAlignment(Element.ALIGN_CENTER); chargeCell.addElement(p); chargeTable.addCell(chargeCell); } } } else if (this.total_ar_amount != 0.00) { chargeCell = new PdfPCell(); chargeCell.setBorder(0); chargeCell.setColspan(2); chargeCell.setPaddingTop(8f); p = new Paragraph(7f, "T O T A L (USA)", totalFontQuote); p.setAlignment(Element.ALIGN_LEFT); chargeCell.addElement(p); chargeTable.addCell(chargeCell); chargeCell = new PdfPCell(); chargeCell.setColspan(4); chargeCell.setBorder(0); chargeCell.setPaddingTop(8f); p = new Paragraph(7f, "$" + NumberUtils.convertToTwoDecimal(this.total_ar_amount) + " " + billType + " " + billToParty + "-" + acctNo, totalFontQuote); p.setAlignment(Element.ALIGN_LEFT); chargeCell.addElement(p); chargeTable.addCell(chargeCell); NumberFormat numberFormat = new DecimalFormat("###,###,##0.000"); String totalString1 = numberFormat.format(this.total_ar_amount).replaceAll(",", ""); int indexdot = totalString1.indexOf("."); String beforeDecimal = totalString1.substring(0, indexdot); String afterDecimal = totalString1.substring(indexdot + 1, totalString1.length()); chargeCell = new PdfPCell(); chargeCell.setColspan(6); chargeCell.setBorder(0); p = new Paragraph(7f, "" + ConvertNumberToWords.convert(Integer.parseInt(beforeDecimal)) + " DOLLARS AND " + StringUtils.removeEnd(afterDecimal, "0") + " CENTS", totalFontQuote); chargeCell.setHorizontalAlignment(Element.ALIGN_CENTER); chargeCell.addElement(p); chargeTable.addCell(chargeCell); } chargeCell = new PdfPCell(); chargeCell.setBorder(0); chargeCell.setColspan(4); p = new Paragraph(5f, "" + sailDateFormat, totalFontQuote); p.setAlignment(Element.ALIGN_LEFT); chargeCell.addElement(p); chargeTable.addCell(chargeCell); chargeCell = new PdfPCell(); chargeCell.setColspan(5); chargeCell.setBorder(0); chargeTable.addCell(chargeCell); chargeCell = new PdfPCell(); chargeCell.setColspan(3); chargeCell.setBorder(0); chargeCell.setRowspan(3); String fdPodValue = null; if (agencyInfo != null && CommonUtils.isNotEmpty(agencyInfo[2])) { fdPodValue = agencyInfo[2]; } else if (CommonFunctions.isNotNull(lclbl.getFinalDestination()) && CommonFunctions.isNotNull(lclbl.getFinalDestination().getCountryId()) && CommonFunctions.isNotNull(lclbl.getFinalDestination().getCountryId().getCodedesc())) { fdPodValue = lclbl.getFinalDestination().getUnLocationName() + "," + lclbl.getFinalDestination().getCountryId().getCodedesc(); } p = new Paragraph(7f, fdPodValue != null ? fdPodValue.toUpperCase() : podValues.toUpperCase(), totalFontQuote); p.setAlignment(Element.ALIGN_LEFT); chargeCell.addElement(p); chargeTable.addCell(chargeCell); chargeCell = new PdfPCell(); chargeCell.setBorder(0); chargeCell.setColspan(3); p = new Paragraph(5f, "UNIT# " + unitNumber, headingblackBoldFont); p.setAlignment(Element.ALIGN_LEFT); chargeCell.addElement(p); chargeTable.addCell(chargeCell); chargeCell = new PdfPCell(); chargeCell.setBorder(0); chargeCell.setColspan(3); chargeCell.setPaddingTop(2f); p = new Paragraph(5f, "SEAL# " + sealOut, headingblackBoldFont); p.setAlignment(Element.ALIGN_LEFT); chargeCell.addElement(p); chargeTable.addCell(chargeCell); chargeCell = new PdfPCell(); chargeCell.setBorder(0); chargeCell.setColspan(3); chargeCell.setPaddingTop(2f); p = new Paragraph(5f, "CONTROL-VOY# " + voyageNumber, totalFontQuote); p.setAlignment(Element.ALIGN_LEFT); chargeCell.addElement(p); chargeTable.addCell(chargeCell); String emailId = ""; StringBuilder agentDetails = new StringBuilder(); //Agent Details String agentAcctNo = ""; if ("Y".equalsIgnoreCase(altAgentKey)) { agentAcctNo = CommonUtils.isNotEmpty(altAgentValue) ? altAgentValue : ""; } else if (lclbl.getAgentAcct() != null) { agentAcctNo = (agencyInfo != null && CommonUtils.isNotEmpty(agencyInfo[0])) ? agencyInfo[0] : lclbl.getAgentAcct().getAccountno(); } if (CommonUtils.isNotEmpty(agentAcctNo)) { CustAddress custAddress = new CustAddressDAO().findPrimeContact(agentAcctNo); if (CommonFunctions.isNotNull(custAddress)) { if (CommonFunctions.isNotNull(custAddress.getAcctName())) { agentDetails.append(custAddress.getAcctName()).append(" "); } if (CommonFunctions.isNotNull(custAddress.getPhone())) { agentDetails.append("Phone: ").append(custAddress.getPhone()).append("\n"); } else { agentDetails.append("\n"); } if (CommonFunctions.isNotNull(custAddress.getCoName())) { agentDetails.append(custAddress.getCoName()).append("\n"); } if (CommonFunctions.isNotNull(custAddress.getAddress1())) { agentDetails.append(custAddress.getAddress1().replace(", ", "\n")).append("\n"); } if (CommonFunctions.isNotNull(custAddress.getCity1())) { agentDetails.append(custAddress.getCity1()); } if (CommonFunctions.isNotNull(custAddress.getState())) { agentDetails.append(" ").append(custAddress.getState()); } if (CommonFunctions.isNotNull(custAddress.getEmail1())) { emailId = custAddress.getEmail1(); } } } BigDecimal PrintInvoiceValue = null; if (lclbl.getPortOfDestination() != null) { boolean schnum = new LCLPortConfigurationDAO().getSchnumValue(lclbl.getPortOfDestination().getId()); if (schnum) { BigDecimal printInvoice = lclbl.getInvoiceValue(); Long fileId = lclbl.getFileNumberId(); if (!CommonUtils.isEmpty(printInvoice) && !CommonUtils.isEmpty(fileId)) { PrintInvoiceValue = printInvoice; } } } chargeCell = new PdfPCell(); chargeCell.setBorder(2); chargeCell.setColspan(6); chargeCell.setPadding(0f); PdfPTable agent_Contact_Table = new PdfPTable(3); agent_Contact_Table.setWidthPercentage(100f); agent_Contact_Table.setWidths(new float[] { 2.3f, 1.7f, 1.8f }); PdfPCell agent_Contact_cell = new PdfPCell(); agent_Contact_cell.setBorder(0); agent_Contact_cell.setBorderWidthTop(1f); agent_Contact_cell.setBorderWidthLeft(1f); agent_Contact_cell.setBorderWidthBottom(0.06f); agent_Contact_cell.setBorderWidthRight(1f); p = new Paragraph(7f, "To Pick Up Freight Please Contact: ", blackContentNormalFont); p.setAlignment(Element.ALIGN_LEFT); agent_Contact_cell.addElement(p); agent_Contact_Table.addCell(agent_Contact_cell); agent_Contact_cell = new PdfPCell(); agent_Contact_cell.setBorder(0); agent_Contact_cell.setColspan(2); agent_Contact_cell.setBorderWidthTop(1f); agent_Contact_cell.setPaddingBottom(2f); p = new Paragraph(7f, "Email: " + emailId.toLowerCase(), totalFontQuote); p.setAlignment(Element.ALIGN_LEFT); agent_Contact_cell.addElement(p); agent_Contact_Table.addCell(agent_Contact_cell); agent_Contact_cell = new PdfPCell(); agent_Contact_cell.setColspan(2); agent_Contact_cell.setBorder(0); agent_Contact_cell.setBorderWidthLeft(1f); p = new Paragraph(7f, "" + agentDetails.toString(), totalFontQuote); p.setAlignment(Element.ALIGN_LEFT); agent_Contact_cell.addElement(p); agent_Contact_Table.addCell(agent_Contact_cell); agent_Contact_cell = new PdfPCell(); agent_Contact_cell.setBorder(0); agent_Contact_cell.setPaddingTop(27f); p = new Paragraph(7f, "" + agentAcctNo, totalFontQuote); p.setAlignment(Element.ALIGN_RIGHT); agent_Contact_cell.addElement(p); agent_Contact_Table.addCell(agent_Contact_cell); agent_Contact_cell = new PdfPCell(); agent_Contact_cell.setBorder(0); agent_Contact_cell.setColspan(3); agent_Contact_cell.setBorderWidthLeft(1f); StringBuilder builder = new StringBuilder(); builder.append(PrintInvoiceValue != null ? "Value of Goods:USD $" + PrintInvoiceValue : ""); p = new Paragraph(3f, "" + builder.toString(), totalFontQuote); p.setAlignment(Element.ALIGN_RIGHT); agent_Contact_cell.addElement(p); agent_Contact_Table.addCell(agent_Contact_cell); chargeCell.addElement(agent_Contact_Table); chargeTable.addCell(chargeCell); return chargeTable; }