List of usage examples for java.util BitSet BitSet
public BitSet()
From source file:org.zkoss.poi.ss.format.CellNumberFormatter.java
/** {@inheritDoc} */ public void formatValue(StringBuffer toAppendTo, Object valueObject) { double value = ((Number) valueObject).doubleValue(); value *= scale;/*from w w w.j a va2 s .c o m*/ // For negative numbers: // - If the cell format has a negative number format, this method // is called with a positive value and the number format has // the negative formatting required, e.g. minus sign or brackets. // - If the cell format does not have a negative number format, // this method is called with a negative value and the number is // formatted with a minus sign at the start. boolean negative = value < 0; if (negative) value = -value; // Split out the fractional part if we need to print a fraction double fractional = 0; if (slash != null) { if (improperFraction) { fractional = value; value = 0; } else { fractional = value % 1.0; //noinspection SillyAssignment value = (long) value; } } Set<StringMod> mods = new TreeSet<StringMod>(); StringBuffer output = new StringBuffer(desc); if (exponent != null) { writeScientific(value, output, mods); } else if (improperFraction) { writeFraction(value, null, fractional, output, mods); } else { StringBuffer result = new StringBuffer(); Formatter f = new Formatter(result, locale); //ZSS-68 f.format(locale, printfFmt, value); //ZSS-68 if (numerator == null) { writeFractional(result, output); writeInteger(result, output, integerSpecials, mods, integerCommas, false); } else { writeFraction(value, result, fractional, output, mods); } } // Now strip out any remaining '#'s and add any pending text ... ListIterator<Special> it = specials.listIterator(); Iterator<StringMod> changes = mods.iterator(); StringMod nextChange = (changes.hasNext() ? changes.next() : null); int adjust = 0; BitSet deletedChars = new BitSet(); // records chars already deleted final String groupSeparator = "" + Formatters.getGroupingSeparator(locale); //ZSS-68 while (it.hasNext()) { Special s = it.next(); int adjustedPos = s.pos + adjust; if (!deletedChars.get(s.pos) && output.charAt(adjustedPos) == '#') { output.deleteCharAt(adjustedPos); adjust--; deletedChars.set(s.pos); } while (nextChange != null && s == nextChange.special) { int lenBefore = output.length(); int modPos = s.pos + adjust; int posTweak = 0; switch (nextChange.op) { case StringMod.AFTER: // ignore adding a comma after a deleted char (which was a '#') if (nextChange.toAdd.equals(groupSeparator) && deletedChars.get(s.pos)) //20110321, henrichen@zkoss.org: respect current locale break; posTweak = 1; //noinspection fallthrough case StringMod.BEFORE: output.insert(modPos + posTweak, nextChange.toAdd); break; case StringMod.REPLACE: int delPos = s.pos; // delete starting pos in original coordinates if (!nextChange.startInclusive) { delPos++; modPos++; } // Skip over anything already deleted while (deletedChars.get(delPos)) { delPos++; modPos++; } int delEndPos = nextChange.end.pos; // delete end point in original if (nextChange.endInclusive) delEndPos++; int modEndPos = delEndPos + adjust; // delete end point in current if (modPos < modEndPos) { if (nextChange.toAdd == "") output.delete(modPos, modEndPos); else { char fillCh = nextChange.toAdd.charAt(0); for (int i = modPos; i < modEndPos; i++) output.setCharAt(i, fillCh); } deletedChars.set(delPos, delEndPos); } break; default: throw new IllegalStateException("Unknown op: " + nextChange.op); } adjust += output.length() - lenBefore; if (changes.hasNext()) nextChange = changes.next(); else nextChange = null; } } // Finally, add it to the string if (negative) toAppendTo.append('-'); toAppendTo.append(output); }
From source file:MSUmpire.SpectrumParser.mzXMLParser.java
@Override public ScanCollection GetAllScanCollectionByMSLabel(boolean MS1Included, boolean MS2Included, boolean MS1Peak, boolean MS2Peak, float startTime, float endTime) { ScanCollection scanCollection = InitializeScanCollection(); Logger.getRootLogger()// www . j a v a2 s . c o m .debug("Memory usage before loading scans:" + Math.round( (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1048576) + "MB (" + NoCPUs + " threads)"); // ArrayList<Integer> IncludedScans = new ArrayList<>(); final IntArrayList IncludedScans = new IntArrayList(); for (int ScanNum : MsLevelList.keySet()) { if (MsLevelList.get(ScanNum) == 1 && MS1Included) { IncludedScans.add(ScanNum); } if (MsLevelList.get(ScanNum) == 2 && MS2Included) { IncludedScans.add(ScanNum); } } List<MzXMLthreadUnit> ScanList = null; int StartScanNo = 0; int EndScanNo = 0; StartScanNo = GetStartScan(startTime); EndScanNo = GetEndScan(endTime); // ArrayList<Integer> temp=new ArrayList<>(); final BitSet temp = new BitSet(); // for(int scannum : IncludedScans){ for (int i = 0; i < IncludedScans.size(); ++i) { final int scannum = IncludedScans.get(i); if (scannum >= StartScanNo && scannum <= EndScanNo) { temp.set(scannum, true); } } ScanList = ParseScans(temp); for (MzXMLthreadUnit result : ScanList) { scanCollection.AddScan(result.scan); } ScanList.clear(); ScanList = null; System.gc(); Logger.getRootLogger() .debug("Memory usage after loading scans:" + Math.round( (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1048576) + "MB"); return scanCollection; }
From source file:org.apache.hadoop.hive.ql.optimizer.ConstantPropagateProcFactory.java
private static ExprNodeDesc shortcutFunction(GenericUDF udf, List<ExprNodeDesc> newExprs, Operator<? extends Serializable> op) throws UDFArgumentException { if (udf instanceof GenericUDFOPEqual) { assert newExprs.size() == 2; boolean foundUDFInFirst = false; ExprNodeGenericFuncDesc caseOrWhenexpr = null; if (newExprs.get(0) instanceof ExprNodeGenericFuncDesc) { caseOrWhenexpr = (ExprNodeGenericFuncDesc) newExprs.get(0); if (caseOrWhenexpr.getGenericUDF() instanceof GenericUDFWhen || caseOrWhenexpr.getGenericUDF() instanceof GenericUDFCase) { foundUDFInFirst = true;//from w w w . j a va 2 s .c om } } if (!foundUDFInFirst && newExprs.get(1) instanceof ExprNodeGenericFuncDesc) { caseOrWhenexpr = (ExprNodeGenericFuncDesc) newExprs.get(1); if (!(caseOrWhenexpr.getGenericUDF() instanceof GenericUDFWhen || caseOrWhenexpr.getGenericUDF() instanceof GenericUDFCase)) { return null; } } if (null == caseOrWhenexpr) { // we didn't find case or when udf return null; } GenericUDF childUDF = caseOrWhenexpr.getGenericUDF(); List<ExprNodeDesc> children = caseOrWhenexpr.getChildren(); int i; if (childUDF instanceof GenericUDFWhen) { for (i = 1; i < children.size(); i += 2) { children.set(i, ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPEqual(), Lists.newArrayList(children.get(i), newExprs.get(foundUDFInFirst ? 1 : 0)))); } if (children.size() % 2 == 1) { i = children.size() - 1; children.set(i, ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPEqual(), Lists.newArrayList(children.get(i), newExprs.get(foundUDFInFirst ? 1 : 0)))); } // after constant folding of child expression the return type of UDFWhen might have changed, // so recreate the expression ExprNodeGenericFuncDesc newCaseOrWhenExpr = ExprNodeGenericFuncDesc.newInstance(childUDF, caseOrWhenexpr.getFuncText(), children); return newCaseOrWhenExpr; } else if (childUDF instanceof GenericUDFCase) { for (i = 2; i < children.size(); i += 2) { children.set(i, ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPEqual(), Lists.newArrayList(children.get(i), newExprs.get(foundUDFInFirst ? 1 : 0)))); } if (children.size() % 2 == 0) { i = children.size() - 1; children.set(i, ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPEqual(), Lists.newArrayList(children.get(i), newExprs.get(foundUDFInFirst ? 1 : 0)))); } // after constant folding of child expression the return type of UDFCase might have changed, // so recreate the expression ExprNodeGenericFuncDesc newCaseOrWhenExpr = ExprNodeGenericFuncDesc.newInstance(childUDF, caseOrWhenexpr.getFuncText(), children); return newCaseOrWhenExpr; } else { // cant happen return null; } } if (udf instanceof GenericUDFOPAnd) { final BitSet positionsToRemove = new BitSet(); final List<ExprNodeDesc> notNullExprs = new ArrayList<ExprNodeDesc>(); final List<Integer> notNullExprsPositions = new ArrayList<Integer>(); final List<ExprNodeDesc> compareExprs = new ArrayList<ExprNodeDesc>(); for (int i = 0; i < newExprs.size(); i++) { ExprNodeDesc childExpr = newExprs.get(i); if (childExpr instanceof ExprNodeConstantDesc) { ExprNodeConstantDesc c = (ExprNodeConstantDesc) childExpr; if (Boolean.TRUE.equals(c.getValue())) { // if true, prune it positionsToRemove.set(i); } else { // if false, return false return childExpr; } } else if (childExpr instanceof ExprNodeGenericFuncDesc && ((ExprNodeGenericFuncDesc) childExpr).getGenericUDF() instanceof GenericUDFOPNotNull && childExpr.getChildren().get(0) instanceof ExprNodeColumnDesc) { notNullExprs.add(childExpr.getChildren().get(0)); notNullExprsPositions.add(i); } else if (childExpr instanceof ExprNodeGenericFuncDesc && ((ExprNodeGenericFuncDesc) childExpr).getGenericUDF() instanceof GenericUDFBaseCompare && !(((ExprNodeGenericFuncDesc) childExpr).getGenericUDF() instanceof GenericUDFOPNotEqual) && childExpr.getChildren().size() == 2) { // Try to fold (key <op> 86) and (key is not null) to (key <op> 86) // where <op> can be "=", ">=", "<=", ">", "<". // Note: (key <> 86) and (key is not null) cannot be folded ExprNodeColumnDesc colDesc = ExprNodeDescUtils.getColumnExpr(childExpr.getChildren().get(0)); if (null == colDesc) { colDesc = ExprNodeDescUtils.getColumnExpr(childExpr.getChildren().get(1)); } if (colDesc != null) { compareExprs.add(colDesc); } } } // Try to fold (key = 86) and (key is not null) to (key = 86) for (int i = 0; i < notNullExprs.size(); i++) { for (ExprNodeDesc other : compareExprs) { if (notNullExprs.get(i).isSame(other)) { positionsToRemove.set(notNullExprsPositions.get(i)); break; } } } // Remove unnecessary expressions int pos = 0; int removed = 0; while ((pos = positionsToRemove.nextSetBit(pos)) != -1) { newExprs.remove(pos - removed); pos++; removed++; } if (newExprs.size() == 0) { return new ExprNodeConstantDesc(TypeInfoFactory.booleanTypeInfo, Boolean.TRUE); } if (newExprs.size() == 1) { return newExprs.get(0); } } if (udf instanceof GenericUDFOPOr) { final BitSet positionsToRemove = new BitSet(); for (int i = 0; i < newExprs.size(); i++) { ExprNodeDesc childExpr = newExprs.get(i); if (childExpr instanceof ExprNodeConstantDesc) { ExprNodeConstantDesc c = (ExprNodeConstantDesc) childExpr; if (Boolean.FALSE.equals(c.getValue())) { // if false, prune it positionsToRemove.set(i); } else if (Boolean.TRUE.equals(c.getValue())) { // if true return true return childExpr; } } } int pos = 0; int removed = 0; while ((pos = positionsToRemove.nextSetBit(pos)) != -1) { newExprs.remove(pos - removed); pos++; removed++; } if (newExprs.size() == 0) { return new ExprNodeConstantDesc(TypeInfoFactory.booleanTypeInfo, Boolean.FALSE); } if (newExprs.size() == 1) { return newExprs.get(0); } } if (udf instanceof GenericUDFWhen) { if (!(newExprs.size() == 2 || newExprs.size() == 3)) { // In general, when can have unlimited # of branches, // we currently only handle either 1 or 2 branch. return null; } ExprNodeDesc thenExpr = newExprs.get(1); ExprNodeDesc elseExpr = newExprs.size() == 3 ? newExprs.get(2) : new ExprNodeConstantDesc(newExprs.get(1).getTypeInfo(), null); ExprNodeDesc whenExpr = newExprs.get(0); if (whenExpr instanceof ExprNodeConstantDesc) { Boolean whenVal = (Boolean) ((ExprNodeConstantDesc) whenExpr).getValue(); return (whenVal == null || Boolean.FALSE.equals(whenVal)) ? elseExpr : thenExpr; } if (thenExpr instanceof ExprNodeConstantDesc && elseExpr instanceof ExprNodeConstantDesc) { ExprNodeConstantDesc constThen = (ExprNodeConstantDesc) thenExpr; ExprNodeConstantDesc constElse = (ExprNodeConstantDesc) elseExpr; Object thenVal = constThen.getValue(); Object elseVal = constElse.getValue(); if (thenVal == null) { if (elseVal == null) { // both branches are null. return thenExpr; } else if (op instanceof FilterOperator) { // we can still fold, since here null is equivalent to false. return Boolean.TRUE.equals(elseVal) ? ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPNot(), newExprs.subList(0, 1)) : Boolean.FALSE.equals(elseVal) ? elseExpr : null; } else { // can't do much, expression is not in context of filter, so we can't treat null as equivalent to false here. return null; } } else if (elseVal == null && op instanceof FilterOperator) { return Boolean.TRUE.equals(thenVal) ? whenExpr : Boolean.FALSE.equals(thenVal) ? thenExpr : null; } else if (thenVal.equals(elseVal)) { return thenExpr; } else if (thenVal instanceof Boolean && elseVal instanceof Boolean) { List<ExprNodeDesc> children = new ArrayList<>(); children.add(whenExpr); children.add(new ExprNodeConstantDesc(false)); ExprNodeGenericFuncDesc func = ExprNodeGenericFuncDesc.newInstance(new GenericUDFNvl(), children); if (Boolean.TRUE.equals(thenVal)) { return func; } else { List<ExprNodeDesc> exprs = new ArrayList<>(); exprs.add(func); return ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPNot(), exprs); } } else { return null; } } } if (udf instanceof GenericUDFCase) { // HIVE-9644 Attempt to fold expression like : // where (case ss_sold_date when '1998-01-01' then 1=1 else null=1 end); // where ss_sold_date= '1998-01-01' ; if (!(newExprs.size() == 3 || newExprs.size() == 4)) { // In general case can have unlimited # of branches, // we currently only handle either 1 or 2 branch. return null; } ExprNodeDesc thenExpr = newExprs.get(2); ExprNodeDesc elseExpr = newExprs.size() == 4 ? newExprs.get(3) : new ExprNodeConstantDesc(newExprs.get(2).getTypeInfo(), null); if (thenExpr instanceof ExprNodeConstantDesc && elseExpr instanceof ExprNodeConstantDesc) { ExprNodeConstantDesc constThen = (ExprNodeConstantDesc) thenExpr; ExprNodeConstantDesc constElse = (ExprNodeConstantDesc) elseExpr; Object thenVal = constThen.getValue(); Object elseVal = constElse.getValue(); if (thenVal == null) { if (null == elseVal) { return thenExpr; } else if (op instanceof FilterOperator) { return Boolean.TRUE.equals(elseVal) ? ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPNotEqual(), newExprs.subList(0, 2)) : Boolean.FALSE.equals(elseVal) ? elseExpr : null; } else { return null; } } else if (null == elseVal && op instanceof FilterOperator) { return Boolean.TRUE.equals(thenVal) ? ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPEqual(), newExprs.subList(0, 2)) : Boolean.FALSE.equals(thenVal) ? thenExpr : null; } else if (thenVal.equals(elseVal)) { return thenExpr; } else if (thenVal instanceof Boolean && elseVal instanceof Boolean) { ExprNodeGenericFuncDesc equal = ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPEqual(), newExprs.subList(0, 2)); List<ExprNodeDesc> children = new ArrayList<>(); children.add(equal); children.add(new ExprNodeConstantDesc(false)); ExprNodeGenericFuncDesc func = ExprNodeGenericFuncDesc.newInstance(new GenericUDFNvl(), children); if (Boolean.TRUE.equals(thenVal)) { return func; } else { List<ExprNodeDesc> exprs = new ArrayList<>(); exprs.add(func); return ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPNot(), exprs); } } else { return null; } } } if (udf instanceof GenericUDFUnixTimeStamp) { if (newExprs.size() >= 1) { // unix_timestamp(args) -> to_unix_timestamp(args) return ExprNodeGenericFuncDesc.newInstance(new GenericUDFToUnixTimeStamp(), newExprs); } } return null; }
From source file:com.rockagen.commons.util.CommUtil.java
/** * Create a BitSet instance,start index is 0 * <p>/*from www . j a v a2 s . c o m*/ * example: * </p> * <pre> * byte: 50 * binary: 0b110010 * * +--------+---+---+---+---+---+---+---+---+ * | bits | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | * +--------+---+---+---+---+---+---+---+---+ * | bitset | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +--------+---+---+---+---+---+---+-------+ * * bitSet.toString(): {2, 3, 6} * </pre> * * @param bytes bytes * @return bitSet */ public static BitSet bitSet(byte[] bytes) { if (bytes == null) { return null; } BitSet bit = new BitSet(); int index = 0; for (byte aByte : bytes) { for (int j = 7; j >= 0; j--) { bit.set(index++, (aByte & (1 << j)) >>> j == 1); } } return bit; }
From source file:android.databinding.tool.expr.ExprModelTest.java
private void assertFlags(Expr a, int... flags) { BitSet bitset = new BitSet(); for (int flag : flags) { bitset.set(flag);/* ww w. jav a2s.c o m*/ } assertEquals("flag test for " + a.getUniqueKey(), bitset, a.getShouldReadFlags()); }
From source file:android.databinding.tool.expr.ExprModelTest.java
private void assertFlags(Expr a, Expr... exprs) { BitSet bitSet = a.getShouldReadFlags(); for (Expr expr : exprs) { BitSet clone = (BitSet) bitSet.clone(); clone.and(expr.getInvalidFlags()); assertEquals("should read flags of " + a.getUniqueKey() + " should include " + expr.getUniqueKey(), expr.getInvalidFlags(), clone); }//w ww . j av a2 s . c o m BitSet composite = new BitSet(); for (Expr expr : exprs) { composite.or(expr.getInvalidFlags()); } assertEquals("composite flags should match", composite, bitSet); }
From source file:org.onosproject.teyang.utils.topology.NodeConverter.java
private static Map<Long, ConnectivityMatrix> yang2TeSubsystemNodeConnectivityMatrix(String networkId, String nodeId, ConnectivityMatrices yangMatrices) { Map<Long, ConnectivityMatrix> teCmList = Maps.newHashMap(); List<org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconnectivitymatrix.connectivitymatrices.ConnectivityMatrix> yangMatrix = yangMatrices .connectivityMatrix();//from www . j a va 2 s . co m for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconnectivitymatrix.connectivitymatrices.ConnectivityMatrix cmYang : yangMatrix) { ElementType from = new TeLinkId(Long.valueOf(((String) cmYang.from().tpRef()))); // is this correct? UnderlayAbstractPath underlayPath = null; // ignore List<org.onosproject.tetopology.management.api.link.PathElement> pathElements = Lists.newArrayList(); Boolean loose = false; long longTeNodeId = TeConstants.NIL_LONG_VALUE; if (cmYang != null && cmYang.underlay() != null && cmYang.underlay().primaryPath() != null && cmYang.underlay().primaryPath().pathElement() != null && !cmYang.underlay().primaryPath().pathElement().isEmpty()) { for (PathElement yangPathEl : cmYang.underlay().primaryPath().pathElement()) { ElementType type = null; if (yangPathEl.type() instanceof UnnumberedLink) { String rS = ((UnnumberedLink) (yangPathEl.type())).routerId().toString(); org.onlab.packet.IpAddress routerId = org.onlab.packet.IpAddress.valueOf(rS); long interfaceId = ((UnnumberedLink) yangPathEl.type()).interfaceId(); type = new org.onosproject.tetopology.management.api.link.UnnumberedLink(routerId, interfaceId); longTeNodeId = Long.valueOf(((UnnumberedLink) yangPathEl.type()).routerId().toString()); } else if (yangPathEl.type() instanceof Ipv4Address) { short v4PrefixLength = ((Ipv4Address) yangPathEl.type()).v4PrefixLength(); Ip4Address v4Address = Ip4Address .valueOf(((Ipv4Address) yangPathEl.type()).v4Address().string()); loose = ((Ipv4Address) yangPathEl.type()).v4Loose(); type = new TeIpv4(v4Address, v4PrefixLength); } org.onosproject.tetopology.management.api.link.PathElement patel = new org.onosproject.tetopology.management.api.link.PathElement( yangPathEl.pathElementId(), longTeNodeId, type, loose); pathElements.add(patel); } } underlayPath = new UnderlayAbstractPath(pathElements, loose); List<ElementType> mergingList = Lists.newArrayList(); // empty merging list for now List<ElementType> constrainingElements = Lists.newArrayList(); ElementType to = new TeLinkId(Long.valueOf(((String) cmYang.to().tpRef()))); // is this correct? constrainingElements.add(to); BitSet flags = new BitSet(); // what are the flags in cmYang? List<Long> srlgs = Lists.newArrayList(); if (cmYang.teSrlgs() != null) { for (Srlg srlg : cmYang.teSrlgs().value()) { srlgs.add(srlg.uint32()); } } TePathAttributes teAttributes = new TePathAttributes(cmYang.teDefaultMetric(), cmYang.teDelayMetric(), srlgs); ConnectivityMatrix coreCm = new ConnectivityMatrix(cmYang.id(), from, mergingList, constrainingElements, flags, teAttributes, underlayPath); teCmList.put(cmYang.id(), coreCm); } return teCmList; }
From source file:com.ibm.cics.ca1y.Emit.java
/** * Add name / value properties from the contents of CICS start data. * /* w w w. ja va 2s. c om*/ * @param props * - the properties to add to. * @return true if successful */ private static boolean addRetrieveData(Properties props) { BitSet bs = new BitSet(); bs.set(RetrieveBits.DATA, true); RetrievedDataHolder rdh = new RetrievedDataHolder(); try { Task.getTask().retrieve(bs, rdh); } catch (Exception e) { e.printStackTrace(); return false; } String configuration; try { configuration = new String(rdh.getValue().getData(), LOCAL_CCSID); } catch (Exception e) { logger.warning(messages.getString("InvalidStartData") + " " + LOCAL_CCSID + ":" + e.getMessage()); return false; } if (logger.isLoggable(Level.FINE)) { logger.fine(messages.getString("LoadingPropertiesFromStartData") + ":" + configuration); } return Util.loadProperties(props, configuration); }
From source file:org.onosproject.teyang.utils.topology.NodeConverter.java
private static Map<Long, org.onosproject.tetopology.management.api.node.TunnelTerminationPoint> yang2TeSubsystemTtp( List<TunnelTerminationPoint> ttps, Node yangNode, Networks yangNetworks) { Map<Long, org.onosproject.tetopology.management.api.node.TunnelTerminationPoint> ttpsMap = Maps .newHashMap();//from w ww . j a va 2 s. com for (TunnelTerminationPoint ttpYang : ttps) { SwitchingType switchingLayer = null; // how to find switching type? EncodingType encodingLayer = null; // TODO: find proper encoding type from ttpYang.config().encoding(); BitSet flags = new BitSet(); // how to set flags? List<Long> interLayerLockList = Lists.newArrayList(); if (ttpYang.config() != null) { interLayerLockList.add(ttpYang.config().interLayerLockId()); // interLayerLock in yang is not a list } List<LocalLinkConnectivity> localLinkConnectivityList = Lists.newArrayList(); // FIXME: once new yang model is used, we can make llc ElementType elt = null; List<ElementType> eltList = Lists.newArrayList(); if (ttpYang.config() != null && ttpYang.config().localLinkConnectivities() != null && CollectionUtils .isNotEmpty(ttpYang.config().localLinkConnectivities().localLinkConnectivity())) { for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodetunnelterminationattributes.locallinkconnectivities.LocalLinkConnectivity yangLlc : ttpYang .config().localLinkConnectivities().localLinkConnectivity()) { if (MapUtils.isNotEmpty(yangNode.yangAugmentedInfoMap())) { AugmentedNdNode yangTpNodeAugment = (AugmentedNdNode) yangNode .yangAugmentedInfo(AugmentedNdNode.class); for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology.networks.network.node.augmentedndnode.TerminationPoint tpItem : yangTpNodeAugment .terminationPoint()) { if (tpItem.tpId().uri().string().equals(yangLlc.linkTpRef().toString())) { if (tpItem.yangAugmentedInfoMap() != null && !tpItem.yangAugmentedInfoMap().isEmpty()) { AugmentedNtTerminationPoint yangTpAugment = (AugmentedNtTerminationPoint) tpItem .yangAugmentedInfo(AugmentedNtTerminationPoint.class); if (yangTpAugment.teTpId() != null) { elt = new TeLinkId(Long.valueOf(yangTpAugment.teTpId().toString())); break; } } } } } eltList.add(elt); // tercap.linkTp().toString() //tpId -> tp -> te-tp-id (long) } } TePathAttributes teAttributes = null; // how to find these // attributes from ttpYang? UnderlayAbstractPath underlayPath = null; // how to find underlayAbstractPath from ttpYang? LocalLinkConnectivity llc = new LocalLinkConnectivity(eltList, flags, teAttributes, underlayPath); localLinkConnectivityList.add(llc); float[] availAdaptBandwidth = null; // how to find availableBandwidth? TeTopologyKey teTopologyKey = null; Object networkRefObj = null; NetworkId networkId = null; if (ttpYang != null && ttpYang.supportingTunnelTerminationPoint() != null && !ttpYang.supportingTunnelTerminationPoint().isEmpty() && ttpYang.supportingTunnelTerminationPoint().get(0) != null) { networkRefObj = ttpYang.supportingTunnelTerminationPoint().get(0).networkRef(); } if (networkRefObj != null) { teTopologyKey = LinkConverter.findTopologyId(yangNetworks, networkRefObj); networkId = NetworkId.fromString((String) networkRefObj); } Network teNetworkFound = null; if (yangNetworks.network() != null && !yangNetworks.network().isEmpty() && networkId != null) { for (Network ynetItem : yangNetworks.network()) { if (ynetItem.networkId() != null) { if (ynetItem.networkId().equals(networkId)) { teNetworkFound = ynetItem; break; } } } } TeNodeId teNodeIdSupport = null; if (teNetworkFound != null && ttpYang != null && ttpYang.supportingTunnelTerminationPoint() != null && ttpYang.supportingTunnelTerminationPoint().get(0) != null) { String s = ((String) ttpYang.supportingTunnelTerminationPoint().get(0).nodeRef()); int integ = Integer.valueOf(s); NodeId nodeId = NodeId.fromString(DottedQuad.of(Ip4Address.valueOf(integ).toString()).toString()); teNodeIdSupport = LinkConverter.findTeNodeId(teNetworkFound, nodeId); } long tenIdLong = -1; if (teNodeIdSupport != null) { tenIdLong = Ip4Address.valueOf(teNodeIdSupport.dottedQuad().string()).toInt(); } TeNodeKey teNodeKey = null; if (teTopologyKey != null && tenIdLong != -1) { teNodeKey = new TeNodeKey(teTopologyKey, tenIdLong); } TtpKey supportTtpKey = null; if (teNodeKey != null && ttpYang != null && ttpYang.supportingTunnelTerminationPoint() != null && !ttpYang.supportingTunnelTerminationPoint().isEmpty() && ttpYang.supportingTunnelTerminationPoint().get(0) != null) { supportTtpKey = new TtpKey(teNodeKey, ByteUtils .bytesToLong((byte[]) ttpYang.supportingTunnelTerminationPoint().get(0).tunnelTpRef())); } org.onosproject.tetopology.management.api.node.TunnelTerminationPoint ttpTe = new org.onosproject.tetopology.management.api.node.DefaultTunnelTerminationPoint( ByteUtils.bytesToLong(ttpYang.tunnelTpId()), switchingLayer, encodingLayer, flags, interLayerLockList, localLinkConnectivityList, availAdaptBandwidth, supportTtpKey); ttpsMap.put(ByteUtils.bytesToLong(ttpYang.tunnelTpId()), ttpTe); } return ttpsMap; }
From source file:org.apache.kylin.cube.model.CubeDesc.java
private void initMeasureReferenceToColumnFamily() { if (measures == null || measures.size() == 0) return;//from w w w . jav a 2 s .com Map<String, MeasureDesc> measureLookup = new HashMap<String, MeasureDesc>(); for (MeasureDesc m : measures) measureLookup.put(m.getName(), m); Map<String, Integer> measureIndexLookup = new HashMap<String, Integer>(); for (int i = 0; i < measures.size(); i++) measureIndexLookup.put(measures.get(i).getName(), i); BitSet checkEachMeasureExist = new BitSet(); for (HBaseColumnFamilyDesc cf : getHbaseMapping().getColumnFamily()) { for (HBaseColumnDesc c : cf.getColumns()) { String[] colMeasureRefs = c.getMeasureRefs(); MeasureDesc[] measureDescs = new MeasureDesc[colMeasureRefs.length]; int[] measureIndex = new int[colMeasureRefs.length]; for (int i = 0; i < colMeasureRefs.length; i++) { measureDescs[i] = measureLookup.get(colMeasureRefs[i]); checkState(measureDescs[i] != null, "measure desc at (%s) is null", i); measureIndex[i] = measureIndexLookup.get(colMeasureRefs[i]); checkState(measureIndex[i] >= 0, "measure index at (%s) not positive", i); checkEachMeasureExist.set(measureIndex[i]); } c.setMeasures(measureDescs); c.setMeasureIndex(measureIndex); c.setColumnFamilyName(cf.getName()); } } for (int i = 0; i < measures.size(); i++) { checkState(checkEachMeasureExist.get(i), "measure (%s) does not exist in column familyor measure duplicates", measures.get(i)); } }