List of usage examples for org.apache.commons.lang3 StringUtils repeat
public static String repeat(final char ch, final int repeat)
From source file:org.ohdsi.webapi.service.FeasibilityService.java
private String getInclusionRuleTreemapData(int id, int inclusionRuleCount, Source source) { String resultsTableQualifier = source.getTableQualifier(SourceDaimon.DaimonType.Results); String smulationResultsQuery = String.format( "select inclusion_rule_mask, person_count from %s.feas_study_result where study_id = %d", resultsTableQualifier, id);/* ww w.java2s .c om*/ String translatedSql = SqlTranslate.translateSql(smulationResultsQuery, "sql server", source.getSourceDialect(), SessionUtils.sessionId(), resultsTableQualifier); // [0] is the inclusion rule bitmask, [1] is the count of the match List<Long[]> items = this.getSourceJdbcTemplate(source).query(translatedSql, simulationResultItemMapper); Map<Integer, List<Long[]>> groups = new HashMap<>(); for (Long[] item : items) { int bitsSet = countSetBits(item[0]); if (!groups.containsKey(bitsSet)) { groups.put(bitsSet, new ArrayList<Long[]>()); } groups.get(bitsSet).add(item); } StringBuilder treemapData = new StringBuilder("{\"name\" : \"Everyone\", \"children\" : ["); List<Integer> groupKeys = new ArrayList<Integer>(groups.keySet()); Collections.sort(groupKeys); Collections.reverse(groupKeys); int groupCount = 0; // create a nested treemap data where more matches (more bits set in string) appear higher in the hierarchy) for (Integer groupKey : groupKeys) { if (groupCount > 0) { treemapData.append(","); } treemapData.append(String.format("{\"name\" : \"Group %d\", \"children\" : [", groupKey)); int groupItemCount = 0; for (Long[] groupItem : groups.get(groupKey)) { if (groupItemCount > 0) { treemapData.append(","); } //sb_treemap.Append("{\"name\": \"" + cohort_identifer + "\", \"size\": " + cohorts[cohort_identifer].ToString() + "}"); treemapData.append(String.format("{\"name\": \"%s\", \"size\": %d}", formatBitMask(groupItem[0], inclusionRuleCount), groupItem[1])); groupItemCount++; } groupCount++; } treemapData.append(StringUtils.repeat("]}", groupCount + 1)); return treemapData.toString(); }
From source file:org.ohdsi.webapi.service.IRAnalysisService.java
private String getStrataTreemapData(int analysisId, int targetId, int outcomeId, int inclusionRuleCount, Source source) {// w ww . jav a2 s . c om String resultsTableQualifier = source.getTableQualifier(SourceDaimon.DaimonType.Results); String analysisResultsQuery = String.format( "select strata_mask, person_count, time_at_risk, cases from %s.ir_analysis_result where analysis_id = %d and target_id = %d and outcome_id = %d", resultsTableQualifier, analysisId, targetId, outcomeId); String translatedSql = SqlTranslate.translateSql(analysisResultsQuery, "sql server", source.getSourceDialect(), SessionUtils.sessionId(), resultsTableQualifier); // [0] is the inclusion rule bitmask, [1] is the count of the match List<StratifyReportItem> items = this.getSourceJdbcTemplate(source).query(translatedSql, stratifyResultsMapper); Map<Integer, List<StratifyReportItem>> groups = new HashMap<>(); for (StratifyReportItem item : items) { int bitsSet = countSetBits(item.bits); if (!groups.containsKey(bitsSet)) { groups.put(bitsSet, new ArrayList<StratifyReportItem>()); } groups.get(bitsSet).add(item); } StringBuilder treemapData = new StringBuilder("{\"name\" : \"Everyone\", \"children\" : ["); List<Integer> groupKeys = new ArrayList<>(groups.keySet()); Collections.sort(groupKeys); Collections.reverse(groupKeys); int groupCount = 0; // create a nested treemap data where more matches (more bits set in string) appear higher in the hierarchy) for (Integer groupKey : groupKeys) { if (groupCount > 0) { treemapData.append(","); } treemapData.append(String.format("{\"name\" : \"Group %d\", \"children\" : [", groupKey)); int groupItemCount = 0; for (StratifyReportItem groupItem : groups.get(groupKey)) { if (groupItemCount > 0) { treemapData.append(","); } //sb_treemap.Append("{\"name\": \"" + cohort_identifer + "\", \"size\": " + cohorts[cohort_identifer].ToString() + "}"); treemapData.append( String.format("{\"name\": \"%s\", \"size\": %d, \"cases\": %d, \"timeAtRisk\": %d }", formatBitMask(groupItem.bits, inclusionRuleCount), groupItem.totalPersons, groupItem.cases, groupItem.timeAtRisk)); groupItemCount++; } groupCount++; } treemapData.append(StringUtils.repeat("]}", groupCount + 1)); return treemapData.toString(); }
From source file:org.omnaest.utils.structure.map.MapUtils.java
/** * Prints out a given {@link Map} using {@link String#valueOf(Object)} and all submaps indented to a new column.<br> * <br>/*from ww w . j av a 2s . co m*/ * Example:<br> * * <pre> * -+ * |-- valueDouble=1.234 * |-+ testClassCopy * | |-- valueDouble=5.678 * | |-- testClassCopy=null * | |-- privateField=privateValue0.16433438667207334 * | |-+ future * | | |-- countDownLatch=java.util.concurrent.CountDownLatch@1f4384c2[Count = 1] * | | |-- shouldCancel=false * | | |-- isCancelled=false * | | |-- value=null * | | |-- clazz=org.omnaest.utils.structure.element.FutureSimple * </pre> * * @param printStream * @param map */ public static void printMapHierarchical(final PrintStream printStream, @SuppressWarnings("rawtypes") Map map) { // class MapPrinter { @SuppressWarnings("rawtypes") public void printMap(Map map, int indentation) { if (map != null) { String indentationString = StringUtils.repeat(" |", indentation / 2); printStream.append(indentation == 0 ? indentationString + "-+\n" : ""); for (Object key : map.keySet()) { // Object value = map.get(key); // if (value instanceof Map) { // printStream.append(indentationString + " |-+ " + String.valueOf(key) + "\n"); this.printMap((Map) value, indentation + 2); } else { // printStream.append(indentationString + " |-- " + String.valueOf(key) + "=" + String.valueOf(map.get(key)) + "\n"); } } printStream.append(indentationString + "\n"); } } } // new MapPrinter().printMap(map, 0); }
From source file:org.opencb.cellbase.app.cli.variant.annotation.CellBaseWSVariantAnnotator.java
private Variant getGenomicVariant(Variant variant) { if (variant.getAlternate().equals(".")) { // reference positions are not variants return null; } else {/*from ww w . j a va2 s . c o m*/ String ref; // large deletion if (variant.getAlternate().equals("<DEL>")) { // .get("_") because studyId and fileId are empty strings when VariantSource is initialized at readInputFile int end = Integer.valueOf(variant.getSourceEntries().get("_").getAttributes().get("END")); ref = StringUtils.repeat("N", end - variant.getStart()); return new Variant(variant.getChromosome(), variant.getStart(), ref, variant.getAlternate().equals("") ? "-" : variant.getAlternate()); // TODO: structural variants are not yet properly handled. Implement and remove this patch asap } else if (variant.getAlternate().startsWith("<") || (variant.getAlternate().length() > 1 && variant.getReference().length() > 1)) { return null; } else { ref = variant.getReference().equals("") ? "-" : variant.getReference(); return new Variant(variant.getChromosome(), variant.getStart(), ref, variant.getAlternate().equals("") ? "-" : variant.getAlternate()); } } }
From source file:org.opencb.cellbase.lib.db.VariantAnnotationCalculatorTest.java
private int getVcfAnnotationBatch(VcfRawReader vcfReader, VariantAnnotationCalculator variantAnnotationDBAdaptor, Set<AnnotationComparisonObject> uvaAnnotationSet) { QueryResult queryResult = null;/*from ww w . j a v a 2s.co m*/ String pos; String ref; String cellbaseRef; String alt; String cellbaseAlt; String SoNameToTest; List<VcfRecord> vcfRecordList = vcfReader.read(1000); int ensemblPos; int processedVariants = 0; for (VcfRecord vcfRecord : vcfRecordList) { // boolean isSnv = false; // Short deletion if (vcfRecord.getReference().length() > 1) { ref = vcfRecord.getReference().substring(1); cellbaseRef = vcfRecord.getReference().substring(1); alt = "-"; cellbaseAlt = ""; ensemblPos = vcfRecord.getPosition() + 1; int end = getEndFromInfoField(vcfRecord); if (end == -1) { if (ref.length() > 1) { pos = (vcfRecord.getPosition() + 1) + "-" + (vcfRecord.getPosition() + ref.length()); } else { pos = Integer.toString(vcfRecord.getPosition() + 1); } } else { pos = (vcfRecord.getPosition() + 1) + "-" + end; } // Alternate length may be > 1 if it contains <DEL> } else if (vcfRecord.getAlternate().length() > 1) { // Large deletion if (vcfRecord.getAlternate().equals("<DEL>")) { ensemblPos = vcfRecord.getPosition() + 1; int end = getEndFromInfoField(vcfRecord); pos = (vcfRecord.getPosition() + 1) + "-" + end; ref = StringUtils.repeat("N", end - vcfRecord.getPosition()); cellbaseRef = StringUtils.repeat("N", end - vcfRecord.getPosition()); alt = "-"; cellbaseAlt = ""; // Short insertion } else { ensemblPos = vcfRecord.getPosition() + 1; ref = "-"; cellbaseRef = ""; alt = vcfRecord.getAlternate().substring(1); cellbaseAlt = vcfRecord.getAlternate().substring(1); pos = vcfRecord.getPosition() + "-" + (vcfRecord.getPosition() + 1); } // SNV } else { ref = vcfRecord.getReference(); cellbaseRef = vcfRecord.getReference(); alt = vcfRecord.getAlternate(); cellbaseAlt = vcfRecord.getAlternate(); ensemblPos = vcfRecord.getPosition(); pos = Integer.toString(ensemblPos); // isSnv = true; } // TODO: Remove this if as refactoring implements consequence types for other variant types // if(isSnv) { processedVariants++; try { queryResult = variantAnnotationDBAdaptor.getAllConsequenceTypesByVariant( new Variant(vcfRecord.getChromosome(), ensemblPos, cellbaseRef, cellbaseAlt), new QueryOptions()); } catch (Exception e) { System.out.println("new Variant = " + new Variant(vcfRecord.getChromosome(), ensemblPos, cellbaseRef, cellbaseAlt)); e.printStackTrace(); System.exit(1); } int i; List<ConsequenceType> consequenceTypeList = (List<ConsequenceType>) queryResult.getResult(); for (i = 0; i < consequenceTypeList.size(); i++) { for (SequenceOntologyTerm soTerm : consequenceTypeList.get(i).getSequenceOntologyTerms()) { if (soTerm.getName().equals("2KB_upstream_gene_variant")) { SoNameToTest = "upstream_gene_variant"; } else if (soTerm.getName().equals("2KB_downstream_gene_variant")) { SoNameToTest = "downstream_gene_variant"; } else { SoNameToTest = soTerm.getName(); } uvaAnnotationSet.add(new AnnotationComparisonObject(vcfRecord.getChromosome(), pos, alt, consequenceTypeList.get(i).getEnsemblGeneId() == null ? "-" : consequenceTypeList.get(i).getEnsemblGeneId(), consequenceTypeList.get(i).getEnsemblTranscriptId() == null ? "-" : consequenceTypeList.get(i).getEnsemblTranscriptId(), consequenceTypeList.get(i).getBiotype() == null ? "-" : consequenceTypeList.get(i).getBiotype(), SoNameToTest)); } } } // } return processedVariants; // return vcfRecordList.size(); }
From source file:org.opencb.cellbase.mongodb.db.VariantAnnotationMongoDBAdaptorTest.java
private int getVcfAnnotationBatch(VcfRawReader vcfReader, VariantAnnotationDBAdaptor variantAnnotationDBAdaptor, Set<AnnotationComparisonObject> uvaAnnotationSet) { QueryResult queryResult = null;//from ww w. j av a2 s . c o m String pos; String ref; String alt; String SoNameToTest; List<VcfRecord> vcfRecordList = vcfReader.read(1000); int ensemblPos; for (VcfRecord vcfRecord : vcfRecordList) { // Short deletion if (vcfRecord.getReference().length() > 1) { ref = vcfRecord.getReference().substring(1); alt = "-"; ensemblPos = vcfRecord.getPosition() + 1; int end = getEndFromInfoField(vcfRecord); if (end == -1) { if (ref.length() > 1) { pos = (vcfRecord.getPosition() + 1) + "-" + (vcfRecord.getPosition() + ref.length()); } else { pos = Integer.toString(vcfRecord.getPosition() + 1); } } else { pos = (vcfRecord.getPosition() + 1) + "-" + end; } // Alternate length may be > 1 if it contains <DEL> } else if (vcfRecord.getAlternate().length() > 1) { // Large deletion if (vcfRecord.getAlternate().equals("<DEL>")) { ensemblPos = vcfRecord.getPosition() + 1; int end = getEndFromInfoField(vcfRecord); pos = (vcfRecord.getPosition() + 1) + "-" + end; ref = StringUtils.repeat("N", end - vcfRecord.getPosition()); alt = "-"; // Short insertion } else { ensemblPos = vcfRecord.getPosition() + 1; ref = "-"; alt = vcfRecord.getAlternate().substring(1); pos = vcfRecord.getPosition() + "-" + (vcfRecord.getPosition() + 1); } // SNV } else { ref = vcfRecord.getReference(); alt = vcfRecord.getAlternate(); ensemblPos = vcfRecord.getPosition(); pos = Integer.toString(ensemblPos); } try { queryResult = variantAnnotationDBAdaptor.getAllConsequenceTypesByVariant( new GenomicVariant(vcfRecord.getChromosome(), ensemblPos, ref, alt), new QueryOptions()); } catch (Exception e) { System.out.println("new GenomicVariant = " + new GenomicVariant(vcfRecord.getChromosome(), ensemblPos, ref, alt)); System.exit(1); } int i; List<ConsequenceType> consequenceTypeList = (List<ConsequenceType>) queryResult.getResult(); for (i = 0; i < consequenceTypeList.size(); i++) { for (ConsequenceType.ConsequenceTypeEntry soTerm : consequenceTypeList.get(i).getSoTerms()) { if (soTerm.getSoName().equals("2KB_upstream_gene_variant")) { SoNameToTest = "upstream_gene_variant"; } else if (soTerm.getSoName().equals("2KB_downstream_gene_variant")) { SoNameToTest = "downstream_gene_variant"; } else { SoNameToTest = soTerm.getSoName(); } uvaAnnotationSet.add(new AnnotationComparisonObject(vcfRecord.getChromosome(), pos, alt, consequenceTypeList.get(i).getEnsemblGeneId() == null ? "-" : consequenceTypeList.get(i).getEnsemblGeneId(), consequenceTypeList.get(i).getEnsemblTranscriptId() == null ? "-" : consequenceTypeList.get(i).getEnsemblTranscriptId(), consequenceTypeList.get(i).getBiotype() == null ? "-" : consequenceTypeList.get(i).getBiotype(), SoNameToTest)); } } } return vcfRecordList.size(); }
From source file:org.opencb.opencga.storage.core.variant.io.VariantVcfDataWriter.java
/** * Get bases from reference sequence./*from w w w. j a va 2s . co m*/ * @param chromosome Chromosome. * @param from Start ( inclusive) position. * @param to End (exclusive) position. * @return String Reference sequence of length to - from. */ private String getReferenceBase(String chromosome, Integer from, Integer to) { int length = to - from; if (length < 0) { throw new IllegalStateException( "Sequence length is negative: chromosome " + chromosome + " from " + from + " to " + to); } return StringUtils.repeat('N', length); // current return default base TODO load reference sequence }
From source file:org.opendaylight.releng.autorelease.autonotes.service.RstService.java
/** * Load RST content.//www. j a v a 2 s. co m */ public void execute() { LogUtils.step("Start loading rst"); try { StringBuilder builder = new StringBuilder(); String header = this.controller.getPropertyService().getProperties().getProperty(HEADER); header = header.replace("#####NICKNAME", this.controller.getPropertyService().getProperties().getProperty(NICKNAME)); header = header.replace("#####PREVIOUS", this.controller.getPropertyService().getProperties().getProperty(PREVIOUS)); header = header.replace("#####CURRENT", this.controller.getPropertyService().getProperties().getProperty(CURRENT)); builder.append(header + "\n\n"); Release release = this.controller.getReleaseService().getRelease(); for (ReleaseProject releaseProject : release.getUnchangedProjects()) { builder.append("* " + releaseProject.getProject().getName() + "\n"); } builder.append("\n"); for (ReleaseProject releaseProject : release.getChangedProjects()) { String projectSubsectionMarker = StringUtils.repeat("-", releaseProject.getProject().getName().length()); builder.append(releaseProject.getProject().getName() + "\n" + projectSubsectionMarker + "\n"); for (Commit commit : releaseProject.getCommits()) { Pattern replace = Pattern .compile(this.controller.getPropertyService().getProperties().getProperty(BUG_TAG) + "([0-9]{4})"); Matcher matcher = replace.matcher(commit.getCommitText()); String replacement = "`BUG-$1 <" + this.controller.getPropertyService().getProperties().getProperty(BUG_URL) + "$1>`_"; String commitText = matcher.replaceAll(replacement); String commitAdoc = "* " + "`" + commit.getId() + " <" + commit.getUrl() + ">`_ " + commitText + "\n"; builder.append(commitAdoc); LogUtils.step("Adoc: " + commitAdoc); } builder.append("\n"); } String adoc = builder.toString(); File file = new File(this.controller.getPropertyService().getProperties().getProperty(RST_FILE)); FileUtils.writeStringToFile(file, adoc); } catch (Exception e) { LogUtils.log(e); } LogUtils.step("Completed loading rst"); }
From source file:org.opendaylight.sfc.scfvpprenderer.processors.VppClassifierProcessor.java
private byte[] ipv6AddressNoZoneToArray(final String address) { byte[] retval = new byte[16]; //splits address and add ommited zeros for easier parsing List<String> segments = Arrays.asList(address.split(":")).stream() .map(segment -> StringUtils.repeat('0', 4 - segment.length()) + segment) .collect(Collectors.toList()); byte index = 0; for (String segment : segments) { String firstPart = segment.substring(0, 2); String secondPart = segment.substring(2); //first part should be ommited if ("00".equals(firstPart)) { index++;//w w w . j av a2 s . c om } else { retval[index++] = ((byte) Short.parseShort(firstPart, 16)); } retval[index++] = ((byte) Short.parseShort(secondPart, 16)); } return retval; }
From source file:org.opendaylight.sfc.scfvpprenderer.processors.VppClassifierProcessor.java
private Pair<HexString> getMaskAndMatch(Matches matches) { int maskLength = 0; String mask = new String(""); String match = new String(""); if (matches == null) { return null; }//from w ww . j ava 2s.co m if (matches.getAceType() instanceof AceEth) { AceEth eth = (AceEth) matches.getAceType(); if (eth.getDestinationMacAddress() != null) { mask = mask + "ff:ff:ff:ff:ff:ff"; match = match + eth.getDestinationMacAddress().getValue(); } else { mask = mask + "00:00:00:00:00:00"; match = match + "00:00:00:00:00:00"; } if (eth.getSourceMacAddress() != null) { mask = mask + ":ff:ff:ff:ff:ff:ff"; match = match + ":" + eth.getSourceMacAddress().getValue(); } else { mask = mask + ":00:00:00:00:00:00"; match = match + ":00:00:00:00:00:00"; } maskLength += 12; } else if (matches.getAceType() instanceof AceIp) { mask = mask + "00:00:00:00:00:00:00:00:00:00:00:00"; match = match + "00:00:00:00:00:00:00:00:00:00:00:00"; maskLength += 12; AceIp aceip = (AceIp) matches.getAceType(); if (aceip.getAceIpVersion() instanceof AceIpv4) { //Ethernet Type mask = mask + ":ff:ff"; match = match + ":08:00"; maskLength += 2; //Transport Type mask = mask + ":00:00:00:00:00:00:00:00:00:ff:00:00"; match = match + String.format(":00:00:00:00:00:00:00:00:00:%1$02x:00:00", aceip.getProtocol()); maskLength += 12; //L3: IPv4 AceIpv4 ipv4 = (AceIpv4) aceip.getAceIpVersion(); Ipv4Prefix src = ipv4.getSourceIpv4Network(); if (src != null) { byte[] retval = ipv4AddressPrefixToBytes(src); for (int i = 0; i < 4; i++) { if (retval[i] == 0) { mask = mask + ":00"; } else { mask = mask + ":ff"; } } match = match + String.format(":%1$02x:%2$02x:%3$02x:%4$02x", retval[0], retval[1], retval[2], retval[3]); } else { mask = mask + ":00:00:00:00"; match = match + ":00:00:00:00"; } maskLength += 4; Ipv4Prefix dst = ipv4.getDestinationIpv4Network(); if (dst != null) { byte[] retval = ipv4AddressPrefixToBytes(dst); for (int i = 0; i < 4; i++) { if (retval[i] == 0) { mask = mask + ":00"; } else { mask = mask + ":ff"; } } match = match + String.format(":%1$02x:%2$02x:%3$02x:%4$02x", retval[0], retval[1], retval[2], retval[3]); } else { mask = mask + ":00:00:00:00"; match = match + ":00:00:00:00"; } maskLength += 4; } else if (aceip.getAceIpVersion() instanceof AceIpv6) { //Ethernet Type mask = mask + ":ff:ff"; match = match + ":86:dd"; maskLength += 2; //Transport Type mask = mask + ":00:00:00:00:00:00:ff:00"; match = match + String.format(":00:00:00:00:00:00:%1$02x:00", aceip.getProtocol()); maskLength += 8; //L3: IPv6 AceIpv6 ipv6 = (AceIpv6) aceip.getAceIpVersion(); Ipv6Prefix src = ipv6.getSourceIpv6Network(); if (src != null) { byte[] retval = ipv6AddressPrefixToBytes(src); mask = mask + ":ff:ff:ff:ff:ff:ff:ff:ff::ff:ff:ff:ff:ff:ff:ff:ff"; match = match + String.format( ":%1$02x:%2$02x:%3$02x:%4$02x:%5$02x:%6$02x:%7$02x:%8$02x:%9$02x:%10$02x:%11$02x:%12$02x:%13$02x:%14$02x:%15$02x:%16$02x", retval[0], retval[1], retval[2], retval[3], retval[4], retval[5], retval[6], retval[7], retval[8], retval[9], retval[10], retval[11], retval[12], retval[13], retval[14], retval[15]); } else { mask = mask + ":00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00"; match = match + ":00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00"; } maskLength += 16; Ipv6Prefix dst = ipv6.getDestinationIpv6Network(); if (dst != null) { byte[] retval = ipv6AddressPrefixToBytes(dst); mask = mask + ":ff:ff:ff:ff:ff:ff:ff:ff::ff:ff:ff:ff:ff:ff:ff:ff"; match = match + String.format( ":%1$02x:%2$02x:%3$02x:%4$02x:%5$02x:%6$02x:%7$02x:%8$02x:%9$02x:%10$02x:%11$02x:%12$02x:%13$02x:%14$02x:%15$02x:%16$02x", retval[0], retval[1], retval[2], retval[3], retval[4], retval[5], retval[6], retval[7], retval[8], retval[9], retval[10], retval[11], retval[12], retval[13], retval[14], retval[15]); } else { mask = mask + ":00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00"; match = match + ":00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00"; } maskLength += 16; } if (aceip.getProtocol() != null) { aceip.getProtocol(); Integer srcPort = null; Integer dstPort = null; if (aceip.getSourcePortRange() != null && aceip.getSourcePortRange().getLowerPort() != null && aceip.getSourcePortRange().getLowerPort().getValue() != null && aceip.getSourcePortRange().getLowerPort().getValue() != 0) { srcPort = aceip.getSourcePortRange().getLowerPort().getValue(); } if (aceip.getDestinationPortRange() != null && aceip.getDestinationPortRange().getLowerPort() != null && aceip.getDestinationPortRange().getLowerPort().getValue() != null && aceip.getDestinationPortRange().getLowerPort().getValue() != 0) { dstPort = aceip.getDestinationPortRange().getLowerPort().getValue(); } // don't support port range if (srcPort != null) { mask = mask + ":ff:ff"; match = match + String.format(":%1$02x:%2$02x", srcPort.intValue() & 0xFF00, srcPort.intValue() & 0x00FF); } else { mask = mask + ":00:00"; match = match + ":00:00"; } maskLength += 2; if (dstPort != null) { mask = mask + ":ff:ff"; match = match + String.format(":%1$02x:%2$02x", dstPort.intValue() & 0xFF00, dstPort.intValue() & 0x00FF); } else { mask = mask + ":00:00"; match = match + ":00:00"; } maskLength += 2; } } if (maskLength == 0) { return null; } else { if (maskLength % 16 != 0) { int padLength = 16 - maskLength % 16; mask = mask + StringUtils.repeat(":00", padLength); match = match + StringUtils.repeat(":00", padLength); } return new Pair(new HexString(mask), new HexString(match)); } }