/** * Compare the specified object with this entry for equality. * * @param o Object. * @return {@code true} if the given object is also a map entry and the two entries represent the * same mapping. */ @Override public boolean equals(Object o) { if (o == null) { return false; } if (!(o instanceof Pair)) { return false; } else { Pair<?, ?> oP = (Pair<?, ?>) o; return (key == null ? oP.getKey() == null : key.equals(oP.getKey())) && (value == null ? oP.getValue() == null : value.equals(oP.getValue())); } }
public static Provider url2Provider(Pair<Long, URL> pair) { if (pair == null) { return null; } Long id = pair.getKey(); URL url = pair.getValue(); if (url == null) return null; Provider p = new Provider(); p.setId(id); p.setService(url.getServiceKey()); p.setAddress(url.getAddress()); p.setApplication(url.getParameter(Constants.APPLICATION_KEY)); p.setUrl(url.toIdentityString()); p.setParameters(url.toParameterString()); p.setDynamic(url.getParameter("dynamic", true)); p.setEnabled(url.getParameter(Constants.ENABLED_KEY, true)); p.setWeight(url.getParameter(Constants.WEIGHT_KEY, Constants.DEFAULT_WEIGHT)); p.setUsername(url.getParameter("owner")); return p; }
@Override public Long getValue(final Pair<String, String> current_friend) { return DB.getHumanCrudWallLocal(false) .readWallId( new HumanId(current_friend.getValue()), new Obj<String>(current_friend.getKey())) .returnValueBadly(); }
/** * This function will get slice of the input frame block overlapping in overall slice(Range), * slice has requested for. * * @param val * @param range * @param brlen * @param bclen * @param outlist * @throws DMLRuntimeException */ public static void performSlice( Pair<Long, FrameBlock> in, IndexRange ixrange, int brlen, int bclen, ArrayList<Pair<Long, FrameBlock>> outlist) throws DMLRuntimeException { long index = in.getKey(); FrameBlock block = in.getValue(); // Get Block indexes (rows and columns boundaries) long cellIndexTopRow = index; long cellIndexBottomRow = index + block.getNumRows() - 1; long cellIndexLeftCol = 1; long cellIndexRightCol = block.getNumColumns(); // Calculate block boundaries with range of slice to be performed (Global index) long cellIndexOverlapTop = Math.max(cellIndexTopRow, ixrange.rowStart); long cellIndexOverlapBottom = Math.min(cellIndexBottomRow, ixrange.rowEnd); long cellIndexOverlapLeft = Math.max(cellIndexLeftCol, ixrange.colStart); long cellIndexOverlapRight = Math.min(cellIndexRightCol, ixrange.colEnd); // check if block is outside the indexing range if (cellIndexOverlapTop > cellIndexOverlapBottom || cellIndexOverlapLeft > cellIndexOverlapRight) { return; } // Create IndexRange for the slice to be performed on this block. IndexRange tmpRange = new IndexRange( cellIndexOverlapTop - index, cellIndexOverlapBottom - index, cellIndexOverlapLeft - 1, cellIndexOverlapRight - 1); // Get Top Row and Left column cutting point. int rowCut = (int) (ixrange.rowStart - index); // Get indices for result block long resultBlockIndexTop = UtilFunctions.computeBlockIndex(cellIndexOverlapTop, brlen); long resultBlockIndexBottom = UtilFunctions.computeBlockIndex(cellIndexOverlapBottom, brlen); // allocate space for the output value for (long r = resultBlockIndexTop; r <= resultBlockIndexBottom; r++) { List<ValueType> schema = UtilFunctions.getSubSchema(block.getSchema(), tmpRange.colStart, tmpRange.colEnd); long iResultIndex = (r - 1) * brlen + tmpRange.rowStart; Pair<Long, FrameBlock> out = new Pair<Long, FrameBlock>(new Long(iResultIndex + 1), new FrameBlock(schema)); outlist.add(out); } // execute actual slice operation block.sliceOperations(outlist, tmpRange, rowCut); }
/** * Looks up a device type given a User-Agent string * * @param userAgent The User-Agent of the remote SIP requesting device */ public DeviceType lookupDeviceType(String userAgent) { if (null != userAgent) { userAgent = userAgent.toUpperCase(); Iterator<Pair<String, String>> iter = m_mapDeviceTypes.getOrderedIterator(); while (iter.hasNext()) { Pair<String, String> pair = (Pair<String, String>) iter.next(); if (userAgent.contains(pair.getKey())) { return new DeviceType(pair.getValue()); } } } return new DeviceType(); }
public static Consumer url2Consumer(Pair<Long, URL> pair) { if (pair == null) { return null; } Long id = pair.getKey(); URL url = pair.getValue(); if (null == url) return null; Consumer c = new Consumer(); c.setId(id); c.setService(url.getServiceKey()); c.setAddress(url.getHost()); c.setApplication(url.getParameter(Constants.APPLICATION_KEY)); c.setParameters(url.toParameterString()); return c; }
public static Route url2Route(Pair<Long, URL> pair) { if (pair == null) { return null; } Long id = pair.getKey(); URL url = pair.getValue(); if (null == url) return null; Route r = new Route(); r.setId(id); r.setName(url.getParameter("name")); r.setService(url.getServiceKey()); r.setPriority(url.getParameter(Constants.PRIORITY_KEY, 0)); r.setEnabled(url.getParameter(Constants.ENABLED_KEY, true)); r.setForce(url.getParameter(Constants.FORCE_KEY, false)); r.setRule(url.getParameterAndDecoded(Constants.RULE_KEY)); return r; }
/** * Resolves the component name in each of the couplings in the given set to its devs component, * and returns a new list of resolved such couplings. * * @param couplings The set of couplings, each containing an unresolved component name. * @param modelToSimMap A mapping of (names of) components to their simulators. * @param rootSim The root simulator (or coordinator) of the simulator making this call (if any). * @return A new list of couplings, corresponding to the given one, except each coupling contains * the actual destination component, rather than just that component's name. */ protected static List resolveCouplings( Set couplings, Function modelToSimMap, atomicSimulator rootSim) { // for each of the couplings to the source port List resolvedCouplings = new ArrayList(); Iterator i = couplings.iterator(); while (i.hasNext()) { Pair coupling = (Pair) i.next(); // resolve the destination component name to its actual component EntityInterface component = getComponentWithName((String) coupling.getKey(), modelToSimMap, rootSim); // package the destination component with the destination // port-name, and add the result to our list of resolved // couplings resolvedCouplings.add(new Pair(component, coupling.getValue())); } return resolvedCouplings; }
public static com.dubbo.domain.Override url2Override(Pair<Long, URL> pair) { if (pair == null) { return null; } Long id = pair.getKey(); URL url = pair.getValue(); if (null == url) return null; Override o = new Override(); o.setId(id); Map<String, String> parameters = new HashMap<String, String>(url.getParameters()); o.setService(url.getServiceKey()); parameters.remove(Constants.INTERFACE_KEY); parameters.remove(Constants.GROUP_KEY); parameters.remove(Constants.VERSION_KEY); parameters.remove(Constants.APPLICATION_KEY); parameters.remove(Constants.CATEGORY_KEY); parameters.remove(Constants.DYNAMIC_KEY); parameters.remove(Constants.ENABLED_KEY); o.setEnabled(url.getParameter(Constants.ENABLED_KEY, true)); String host = url.getHost(); boolean anyhost = url.getParameter(Constants.ANYHOST_VALUE, false); if (!anyhost || !"0.0.0.0".equals(host)) { o.setAddress(url.getAddress()); } o.setApplication(url.getParameter(Constants.APPLICATION_KEY, url.getUsername())); parameters.remove(Constants.VERSION_KEY); o.setParams(StringUtils.toQueryString(parameters)); return o; }
public URI build() throws MeteoException { StringBuilder sb = new StringBuilder(); sb.append(API_MET_NO_SERVICE_PREFIX) .append(serviceName) .append("/") .append(serviceVersion.toStringVersion()) .append("/"); if (!skipQuestionMarkInUrl) { sb.append("?"); } boolean first = true; for (Pair pair : parameters) { sb.append(first ? "" : "&").append(pair.getKey()); if (pair.getValue() != null) { sb.append("=").append(pair.getValue().toString()); } first = false; } return MeteoNetUtils.createUri(sb.toString()); }
// Generic static method public static <K, V> boolean compare(Pair<K, V> p1, Pair<K, V> p2) { return p1.getKey().equals(p2.getKey()) && p1.getValue().equals(p2.getValue()); }
public Pair(Pair other) { this.key = new String(other.getKey()); this.value = new Integer(other.getValue()); }
@SuppressWarnings("rawtypes") public static String getSnapshot(Communication communication) { Validate.notNull(communication); Map<String, Object> state = new HashMap<String, Object>(); Pair pair = getTotalBytes(communication); state.put((String) pair.getKey(), pair.getValue()); pair = getTotalRecords(communication); state.put((String) pair.getKey(), pair.getValue()); pair = getSpeedRecord(communication); state.put((String) pair.getKey(), pair.getValue()); pair = getSpeedByte(communication); state.put((String) pair.getKey(), pair.getValue()); pair = getStage(communication); state.put((String) pair.getKey(), pair.getValue()); pair = getErrorRecords(communication); state.put((String) pair.getKey(), pair.getValue()); pair = getErrorBytes(communication); state.put((String) pair.getKey(), pair.getValue()); pair = getErrorMessage(communication); state.put((String) pair.getKey(), pair.getValue()); pair = getPercentage(communication); state.put((String) pair.getKey(), pair.getValue()); pair = getWaitReaderTime(communication); state.put((String) pair.getKey(), pair.getValue()); pair = getWaitWriterTime(communication); state.put((String) pair.getKey(), pair.getValue()); return JSON.toJSONString(state); }
/** * @param in * @param ixrange * @param brlen * @param bclen * @param rlen * @param clen * @param outlist * @throws DMLRuntimeException */ public static void performShift( Pair<Long, FrameBlock> in, IndexRange ixrange, int brlenLeft, int clenLeft /*, int bclen*/, long rlen, long clen, ArrayList<Pair<Long, FrameBlock>> outlist) throws DMLRuntimeException { Long ix = in.getKey(); FrameBlock fb = in.getValue(); long start_lhs_globalRowIndex = ixrange.rowStart + (ix - 1); long start_lhs_globalColIndex = ixrange.colStart; long end_lhs_globalRowIndex = start_lhs_globalRowIndex + fb.getNumRows() - 1; long end_lhs_globalColIndex = ixrange.colEnd; long start_lhs_rowIndex = UtilFunctions.computeBlockIndex(start_lhs_globalRowIndex, brlenLeft); long end_lhs_rowIndex = UtilFunctions.computeBlockIndex(end_lhs_globalRowIndex, brlenLeft); for (long leftRowIndex = start_lhs_rowIndex; leftRowIndex <= end_lhs_rowIndex; leftRowIndex++) { // Calculate global index of right hand side block long lhs_rl = Math.max((leftRowIndex - 1) * brlenLeft + 1, start_lhs_globalRowIndex); long lhs_ru = Math.min(leftRowIndex * brlenLeft, end_lhs_globalRowIndex); long lhs_cl = start_lhs_globalColIndex; long lhs_cu = end_lhs_globalColIndex; int lhs_lrl = UtilFunctions.computeCellInBlock(lhs_rl, brlenLeft); int lhs_lru = UtilFunctions.computeCellInBlock(lhs_ru, brlenLeft); int lhs_lcl = (int) lhs_cl - 1; int lhs_lcu = (int) lhs_cu - 1; long rhs_rl = lhs_rl - (ixrange.rowStart - 1) - (ix - 1); long rhs_ru = rhs_rl + (lhs_ru - lhs_rl); long rhs_cl = lhs_cl - ixrange.colStart + 1; long rhs_cu = rhs_cl + (lhs_cu - lhs_cl); // local indices are 0 (zero) based. int rhs_lrl = (int) (UtilFunctions.computeCellInBlock(rhs_rl, fb.getNumRows())); int rhs_lru = (int) (UtilFunctions.computeCellInBlock(rhs_ru, fb.getNumRows())); int rhs_lcl = (int) rhs_cl - 1; int rhs_lcu = (int) rhs_cu - 1; FrameBlock slicedRHSBlk = fb.sliceOperations(rhs_lrl, rhs_lru, rhs_lcl, rhs_lcu, new FrameBlock()); int lbclen = clenLeft; List<ValueType> schemaPartialLeft = Collections.nCopies(lhs_lcl, ValueType.STRING); List<ValueType> schemaRHS = UtilFunctions.getSubSchema(fb.getSchema(), rhs_lcl, rhs_lcl - lhs_lcl + lhs_lcu); List<ValueType> schema = new ArrayList<ValueType>(schemaPartialLeft); schema.addAll(schemaRHS); List<ValueType> schemaPartialRight = Collections.nCopies(lbclen - schema.size(), ValueType.STRING); schema.addAll(schemaPartialRight); FrameBlock resultBlock = new FrameBlock(schema); int iRHSRows = (int) (leftRowIndex <= rlen / brlenLeft ? brlenLeft : rlen - (rlen / brlenLeft) * brlenLeft); resultBlock.ensureAllocatedColumns(iRHSRows); resultBlock = resultBlock.leftIndexingOperations( slicedRHSBlk, lhs_lrl, lhs_lru, lhs_lcl, lhs_lcu, new FrameBlock()); outlist.add(new Pair<Long, FrameBlock>((leftRowIndex - 1) * brlenLeft + 1, resultBlock)); } }
/** * Create an entry representing the same mapping as the specified entry. * * @param entry Entry to copy. */ public Pair(Pair<? extends K, ? extends V> entry) { key = entry.getKey(); value = entry.getValue(); }