Example usage for java.util SortedMap put

List of usage examples for java.util SortedMap put

Introduction

In this page you can find the example usage for java.util SortedMap put.

Prototype

V put(K key, V value);

Source Link

Document

Associates the specified value with the specified key in this map (optional operation).

Usage

From source file:net.sourceforge.msscodefactory.cfcore.v2_0.CFGenKbXMsgRspnHandler.CFGenKbXMsgRspnDefClassRecHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {//www . j a va 2 s .  c om
        // Common XML Attributes
        String attrId = null;
        String attrRevision = null;
        // DefClass Attributes
        String attrName = null;
        String attrBaseId = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("DefClass");

        CFGenKbXMsgRspnHandler xmsgRspnHandler = (CFGenKbXMsgRspnHandler) getParser();
        if (xmsgRspnHandler == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser()");
        }

        ICFGenKbSchemaObj schemaObj = xmsgRspnHandler.getSchemaObj();
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser().getSchemaObj()");
        }

        // Extract Attributes
        numAttrs = attrs.getLength();
        for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
            attrLocalName = attrs.getLocalName(idxAttr);
            if (attrLocalName.equals("Id")) {
                if (attrId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Revision")) {
                if (attrRevision != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrRevision = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Name")) {
                if (attrName != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrName = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("BaseId")) {
                if (attrBaseId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrBaseId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("schemaLocation")) {
                // ignored
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values
        if ((attrId == null) || (attrId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Id");
        }
        if (attrName == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "Name");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = xmsgRspnHandler.getCurContext();

        // Convert string attributes to native Java types

        short natId = Short.parseShort(attrId);

        String natName = attrName;

        Short natBaseId;
        if ((attrBaseId == null) || (attrBaseId.length() <= 0)) {
            natBaseId = null;
        } else {
            natBaseId = new Short(Short.parseShort(attrBaseId));
        }

        int natRevision = Integer.parseInt(attrRevision);
        // Get the parent context
        CFLibXmlCoreContext parentContext = curContext.getPrevContext();
        // Instantiate a buffer for the parsed information
        ICFGenKbDefClassObj obj = schemaObj.getDefClassTableObj().newInstance();
        CFGenKbDefClassBuff dataBuff = obj.getDefClassBuff();
        dataBuff.setRequiredId(natId);
        dataBuff.setRequiredName(natName);
        dataBuff.setOptionalBaseId(natBaseId);
        dataBuff.setRequiredRevision(natRevision);
        obj.copyBuffToPKey();
        SortedMap<CFGenKbDefClassPKey, ICFGenKbDefClassObj> sortedMap = (SortedMap<CFGenKbDefClassPKey, ICFGenKbDefClassObj>) xmsgRspnHandler
                .getSortedMapOfObjects();
        ICFGenKbDefClassObj realized = (ICFGenKbDefClassObj) obj.realize();
        xmsgRspnHandler.setLastObjectProcessed(realized);
        if (sortedMap != null) {
            sortedMap.put(realized.getPKey(), realized);
        }
    } catch (RuntimeException e) {
        throw new RuntimeException("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    } catch (Error e) {
        throw new Error("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    }
}

From source file:de.blizzy.documentr.web.page.PageControllerTest.java

@Test
public void cherryPick() throws IOException {
    when(permissionEvaluator.hasPagePermission(authenticatedAuthentication, PROJECT, "targetBranch", PAGE_PATH, //$NON-NLS-1$
            Permission.EDIT_PAGE)).thenReturn(true);

    when(cherryPicker.getCommitsList(PROJECT, BRANCH, PAGE_PATH, "version2", "version4")) //$NON-NLS-1$ //$NON-NLS-2$
            .thenReturn(Lists.newArrayList("version3", "version4")); //$NON-NLS-1$ //$NON-NLS-2$

    @SuppressWarnings("nls")
    List<CommitCherryPickResult> branchResults = Lists.newArrayList(
            new CommitCherryPickResult(new PageVersion("version3", "user", new Date()),
                    CommitCherryPickResult.Status.OK),
            new CommitCherryPickResult(new PageVersion("version3", "user", new Date()),
                    CommitCherryPickResult.Status.OK));
    SortedMap<String, List<CommitCherryPickResult>> results = Maps.newTreeMap();
    results.put("targetBranch", branchResults); //$NON-NLS-1$
    when(cherryPicker.cherryPick(PROJECT, BRANCH, PAGE_PATH, Lists.newArrayList("version3", "version4"), //$NON-NLS-1$ //$NON-NLS-2$
            Sets.newHashSet("targetBranch"), Collections.<CommitCherryPickConflictResolve>emptySet(), false, //$NON-NLS-1$
            USER, LOCALE)).thenReturn(results);

    String view = pageController.cherryPick(PROJECT, BRANCH, PAGE_PATH, "version2", "version4", //$NON-NLS-1$ //$NON-NLS-2$
            Sets.newHashSet("targetBranch"), false, webRequest, model, authenticatedAuthentication, LOCALE); //$NON-NLS-1$
    assertEquals("/page/" + PROJECT + "/" + BRANCH + "/" + PAGE_PATH_URL, removeViewPrefix(view)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    assertRedirect(view);//from w w  w.  ja v a  2s.c  om
}

From source file:net.sourceforge.msscodefactory.cfgcash.v2_0.CFGCashXMsgRspnHandler.CFGCashXMsgRspnAuditActionRecHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {//from   ww  w. j a  va 2  s  .  c o m
        // Common XML Attributes
        String attrId = null;
        String attrRevision = null;
        // AuditAction Attributes
        String attrAuditActionId = null;
        String attrDescription = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("AuditAction");

        CFGCashXMsgRspnHandler xmsgRspnHandler = (CFGCashXMsgRspnHandler) getParser();
        if (xmsgRspnHandler == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser()");
        }

        ICFGCashSchemaObj schemaObj = xmsgRspnHandler.getSchemaObj();
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser().getSchemaObj()");
        }

        // Extract Attributes
        numAttrs = attrs.getLength();
        for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
            attrLocalName = attrs.getLocalName(idxAttr);
            if (attrLocalName.equals("Id")) {
                if (attrId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Revision")) {
                if (attrRevision != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrRevision = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("AuditActionId")) {
                if (attrAuditActionId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrAuditActionId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Description")) {
                if (attrDescription != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrDescription = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("schemaLocation")) {
                // ignored
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values
        if ((attrAuditActionId == null) || (attrAuditActionId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "AuditActionId");
        }
        if (attrDescription == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "Description");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = xmsgRspnHandler.getCurContext();

        // Convert string attributes to native Java types

        short natAuditActionId = Short.parseShort(attrAuditActionId);

        String natDescription = attrDescription;

        int natRevision = Integer.parseInt(attrRevision);
        // Get the parent context
        CFLibXmlCoreContext parentContext = curContext.getPrevContext();
        // Instantiate a buffer for the parsed information
        ICFGCashAuditActionObj obj = schemaObj.getAuditActionTableObj().newInstance();
        CFGCashAuditActionBuff dataBuff = obj.getAuditActionBuff();
        dataBuff.setRequiredAuditActionId(natAuditActionId);
        dataBuff.setRequiredDescription(natDescription);
        dataBuff.setRequiredRevision(natRevision);
        obj.copyBuffToPKey();
        SortedMap<CFGCashAuditActionPKey, ICFGCashAuditActionObj> sortedMap = (SortedMap<CFGCashAuditActionPKey, ICFGCashAuditActionObj>) xmsgRspnHandler
                .getSortedMapOfObjects();
        ICFGCashAuditActionObj realized = (ICFGCashAuditActionObj) obj.realize();
        xmsgRspnHandler.setLastObjectProcessed(realized);
        if (sortedMap != null) {
            sortedMap.put(realized.getPKey(), realized);
        }
    } catch (RuntimeException e) {
        throw new RuntimeException("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    } catch (Error e) {
        throw new Error("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    }
}

From source file:de.blizzy.documentr.web.page.PageControllerTest.java

@Test
public void cherryPickWithConflicts() throws IOException {
    when(permissionEvaluator.hasPagePermission(authenticatedAuthentication, PROJECT, "targetBranch", PAGE_PATH, //$NON-NLS-1$
            Permission.EDIT_PAGE)).thenReturn(true);

    when(cherryPicker.getCommitsList(PROJECT, BRANCH, PAGE_PATH, "version2", "version4")) //$NON-NLS-1$ //$NON-NLS-2$
            .thenReturn(Lists.newArrayList("version3", "version4")); //$NON-NLS-1$ //$NON-NLS-2$

    @SuppressWarnings("nls")
    List<CommitCherryPickResult> branchResults = Lists.newArrayList(
            new CommitCherryPickResult(new PageVersion("version3", "user", new Date()),
                    CommitCherryPickResult.Status.OK),
            new CommitCherryPickResult(new PageVersion("version3", "user", new Date()), "conflictText"));
    SortedMap<String, List<CommitCherryPickResult>> results = Maps.newTreeMap();
    results.put("targetBranch", branchResults); //$NON-NLS-1$
    when(cherryPicker.cherryPick(PROJECT, BRANCH, PAGE_PATH, Lists.newArrayList("version3", "version4"), //$NON-NLS-1$ //$NON-NLS-2$
            Sets.newHashSet("targetBranch"), Collections.<CommitCherryPickConflictResolve>emptySet(), false, //$NON-NLS-1$
            USER, LOCALE)).thenReturn(results);

    String view = pageController.cherryPick(PROJECT, BRANCH, PAGE_PATH, "version2", "version4", //$NON-NLS-1$ //$NON-NLS-2$
            Sets.newHashSet("targetBranch"), false, webRequest, model, authenticatedAuthentication, LOCALE); //$NON-NLS-1$
    assertEquals("/project/branch/page/cherryPick", view); //$NON-NLS-1$

    verify(model).addAttribute("cherryPickResults", results); //$NON-NLS-1$
    verify(model).addAttribute("version1", "version2"); //$NON-NLS-1$ //$NON-NLS-2$
    verify(model).addAttribute("version2", "version4"); //$NON-NLS-1$ //$NON-NLS-2$
    verify(model).addAttribute("resolves", Collections.emptySet()); //$NON-NLS-1$
}

From source file:net.proest.librepilot.web.handler.ObjectHandler.java

public void handleGet(String target, Request baseRequest, HttpServletRequest request,
        HttpServletResponse response) throws IOException, ServletException {
    PrintWriter out = response.getWriter();

    List<String> targetObjects = Arrays.asList(target.split("/"));

    SortedMap<String, UAVTalkXMLObject> objects = new TreeMap<>();

    for (UAVTalkXMLObject xmlObj : mFcDevice.getObjectTree().getXmlObjects().values()) {
        if (targetObjects.size() == 0 || targetObjects.contains(xmlObj.getName())) {
            if (mShowSettings && xmlObj.isSettings() || mShowState && !xmlObj.isSettings()) {
                mFcDevice.requestObject(xmlObj.getName());
                objects.put(xmlObj.getName(), xmlObj);
            }/*from ww  w.ja  va  2 s .  com*/
        }
    }

    SortedMap<String, UAVTalkObjectSerializer> uavObjects = new TreeMap<>();

    for (UAVTalkXMLObject xmlObj : objects.values()) {
        UAVTalkObjectSerializer os = new UAVTalkObjectSerializer();
        if (targetObjects.size() == 0 || targetObjects.contains(xmlObj.getName())) {
            UAVTalkObject obj = mFcDevice.getObjectTree().getObjectFromName(xmlObj.getName());
            for (int i = 0; i < obj.getInstances().values().size(); i++) {
                UAVTalkInstanceSerializer is = new UAVTalkInstanceSerializer();
                for (UAVTalkXMLObject.UAVTalkXMLObjectField xmlField : xmlObj.getFields().values()) {
                    UAVTalkFieldSerializer fs = new UAVTalkFieldSerializer();
                    boolean hasElements = true;
                    Object res = null;
                    for (String element : xmlField.getElements()) {
                        try {
                            res = mFcDevice.getObjectTree().getData(xmlObj.getName(), i, xmlField.getName(),
                                    element);
                            if (element == null || xmlField.getElements().size() == 1
                                    && (element.equals("") || element.equals("0"))) {
                                hasElements = false;
                                fs.setElements(null);
                                fs.setValue(res);
                            } else {
                                fs.getElements().put(element, res);
                                fs.setValue(null);
                            }
                        } catch (UAVTalkMissingObjectException e) {
                            e.printStackTrace();
                        }
                    }
                    if (hasElements) {
                        is.getFields().put(xmlField.getName(), fs);
                    } else {
                        is.getFields().put(xmlField.getName(), res);
                    }
                }
                os.getInstances().put(i, is);
            }
        }
        uavObjects.put(xmlObj.getName(), os);
    }

    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    String callback = request.getParameter("callback");
    if (callback != null) {
        response.setContentType("application/javascript");
        out.println(callback + "(");
    } else {
        response.setContentType("application/json");
    }

    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.INDENT_OUTPUT);

    out.println(mapper.writeValueAsString(uavObjects));

    if (callback != null) {
        out.print(")");
    }

    out.println("");
}

From source file:de.blizzy.documentr.web.page.PageControllerTest.java

@Test
public void cherryPickWithConflictsAndResolveTexts() throws IOException {
    when(permissionEvaluator.hasPagePermission(authenticatedAuthentication, PROJECT, "targetBranch", PAGE_PATH, //$NON-NLS-1$
            Permission.EDIT_PAGE)).thenReturn(true);

    when(cherryPicker.getCommitsList(PROJECT, BRANCH, PAGE_PATH, "version2", "version4")) //$NON-NLS-1$ //$NON-NLS-2$
            .thenReturn(Lists.newArrayList("version3", "version4")); //$NON-NLS-1$ //$NON-NLS-2$

    @SuppressWarnings("nls")
    Set<CommitCherryPickConflictResolve> resolves = Sets
            .newHashSet(new CommitCherryPickConflictResolve("targetBranch", "version3", "resolveText"));
    @SuppressWarnings("nls")
    List<CommitCherryPickResult> branchResults = Lists.newArrayList(
            new CommitCherryPickResult(new PageVersion("version3", "user", new Date()),
                    CommitCherryPickResult.Status.OK),
            new CommitCherryPickResult(new PageVersion("version3", "user", new Date()),
                    CommitCherryPickResult.Status.OK));
    SortedMap<String, List<CommitCherryPickResult>> results = Maps.newTreeMap();
    results.put("targetBranch", branchResults); //$NON-NLS-1$
    when(cherryPicker.cherryPick(PROJECT, BRANCH, PAGE_PATH, Lists.newArrayList("version3", "version4"), //$NON-NLS-1$ //$NON-NLS-2$
            Sets.newHashSet("targetBranch"), resolves, false, USER, LOCALE)) //$NON-NLS-1$
                    .thenReturn(results);

    Map<String, String[]> params = Maps.newHashMap();
    params.put("resolveText_targetBranch/version3", new String[] { "resolveText" }); //$NON-NLS-1$ //$NON-NLS-2$
    when(webRequest.getParameterMap()).thenReturn(params);

    String view = pageController.cherryPick(PROJECT, BRANCH, PAGE_PATH, "version2", "version4", //$NON-NLS-1$ //$NON-NLS-2$
            Sets.newHashSet("targetBranch"), false, webRequest, model, authenticatedAuthentication, LOCALE); //$NON-NLS-1$
    assertEquals("/page/" + PROJECT + "/" + BRANCH + "/" + PAGE_PATH_URL, removeViewPrefix(view)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    assertRedirect(view);//from w  w w  . j ava2s  . c  o  m
}

From source file:cn.loveapple.client.android.database.impl.TemperatureDaoImpl.java

/**
 * {@inheritDoc}//from   w  ww .j  a v a  2 s  . c  o m
 */
@Override
public SortedMap<String, TemperatureEntity> findTemperatureMap(String datePoint) {
    Calendar current = Calendar.getInstance();
    Calendar start = Calendar.getInstance();
    if (StringUtils.isNotEmpty(datePoint)) {
        current.setTime(DateUtil.paseDate(datePoint, DateUtil.DATE_PTTERN_YYYYMMDD));
    }
    start.set(current.get(Calendar.YEAR), current.get(Calendar.MONTH) - LIMIT_MONTH,
            current.get(Calendar.DAY_OF_MONTH));

    List<TemperatureEntity> tempList = findByTerm(DateUtil.toDateString(start.getTime()),
            DateUtil.toDateString(current.getTime()));

    SortedMap<String, TemperatureEntity> result = new TreeMap<String, TemperatureEntity>();

    if (CollectionUtils.isEmpty(tempList)) {
        return result;
    }

    // ???
    SortedSet<String> dateSet = createDateKey(tempList.get(0).getDate());
    for (TemperatureEntity temp : tempList) {
        dateSet.remove(temp.getDate());
        result.put(temp.getDate(), temp);
    }
    for (String date : dateSet) {
        TemperatureEntity temperature = new TemperatureEntity();
        temperature.setDate(date);
        result.put(date, temperature);
    }

    return result;
}

From source file:net.sourceforge.msscodefactory.cfcore.v2_0.CFGenKbXMsgRspnHandler.CFGenKbXMsgRspnToolRecHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {// w  w w  .j av a 2 s . co m
        // Common XML Attributes
        String attrId = null;
        String attrRevision = null;
        // Tool Attributes
        String attrName = null;
        String attrReplacesId = null;
        String attrIsSupported = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("Tool");

        CFGenKbXMsgRspnHandler xmsgRspnHandler = (CFGenKbXMsgRspnHandler) getParser();
        if (xmsgRspnHandler == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser()");
        }

        ICFGenKbSchemaObj schemaObj = xmsgRspnHandler.getSchemaObj();
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser().getSchemaObj()");
        }

        // Extract Attributes
        numAttrs = attrs.getLength();
        for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
            attrLocalName = attrs.getLocalName(idxAttr);
            if (attrLocalName.equals("Id")) {
                if (attrId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Revision")) {
                if (attrRevision != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrRevision = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Name")) {
                if (attrName != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrName = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ReplacesId")) {
                if (attrReplacesId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrReplacesId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("IsSupported")) {
                if (attrIsSupported != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrIsSupported = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("schemaLocation")) {
                // ignored
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values
        if ((attrId == null) || (attrId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Id");
        }
        if (attrName == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "Name");
        }
        if ((attrIsSupported == null) || (attrIsSupported.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "IsSupported");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = xmsgRspnHandler.getCurContext();

        // Convert string attributes to native Java types

        short natId = Short.parseShort(attrId);

        String natName = attrName;

        Short natReplacesId;
        if ((attrReplacesId == null) || (attrReplacesId.length() <= 0)) {
            natReplacesId = null;
        } else {
            natReplacesId = new Short(Short.parseShort(attrReplacesId));
        }

        boolean natIsSupported;
        if (attrIsSupported.equals("true") || attrIsSupported.equals("yes") || attrIsSupported.equals("1")) {
            natIsSupported = true;
        } else if (attrIsSupported.equals("false") || attrIsSupported.equals("no")
                || attrIsSupported.equals("0")) {
            natIsSupported = false;
        } else {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Unexpected IsSupported value, must be one of true, false, yes, no, 1, or 0, not \""
                            + attrIsSupported + "\"");
        }

        int natRevision = Integer.parseInt(attrRevision);
        // Get the parent context
        CFLibXmlCoreContext parentContext = curContext.getPrevContext();
        // Instantiate a buffer for the parsed information
        ICFGenKbToolObj obj = schemaObj.getToolTableObj().newInstance();
        CFGenKbToolBuff dataBuff = obj.getToolBuff();
        dataBuff.setRequiredId(natId);
        dataBuff.setRequiredName(natName);
        dataBuff.setOptionalReplacesId(natReplacesId);
        dataBuff.setRequiredIsSupported(natIsSupported);
        dataBuff.setRequiredRevision(natRevision);
        obj.copyBuffToPKey();
        SortedMap<CFGenKbToolPKey, ICFGenKbToolObj> sortedMap = (SortedMap<CFGenKbToolPKey, ICFGenKbToolObj>) xmsgRspnHandler
                .getSortedMapOfObjects();
        ICFGenKbToolObj realized = (ICFGenKbToolObj) obj.realize();
        xmsgRspnHandler.setLastObjectProcessed(realized);
        if (sortedMap != null) {
            sortedMap.put(realized.getPKey(), realized);
        }
    } catch (RuntimeException e) {
        throw new RuntimeException("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    } catch (Error e) {
        throw new Error("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    }
}

From source file:es.uvigo.ei.sing.gc.model.entities.ExpertResult.java

private synchronized void initClassificationPerformance() {
    if (this.performance == null && this.samples != null && !this.samples.isEmpty()) {
        final Set<Object> classes = new HashSet<Object>();
        Boolean multi = null;/* www  . jav  a  2s  .  c  o m*/
        for (SampleClassification sample : this.samples) {
            if (multi == null) {
                multi = sample.isMultiStep();
            } else if (multi != sample.isMultiStep()) {
                throw new IllegalStateException("Different sample types");
            }

            classes.add(sample.getRealClass());
        }

        final Object[] classArray = classes.toArray(new Object[classes.size()]);
        if (multi) {
            final SortedMap<Integer, List<SampleClassification>> sampleMap = new TreeMap<Integer, List<SampleClassification>>();

            for (SampleClassification sample : this.samples) {
                if (!sampleMap.containsKey(sample.getStep())) {
                    sampleMap.put(sample.getStep(), new LinkedList<SampleClassification>());
                }

                sampleMap.get(sample.getStep()).add(sample);
            }

            for (Map.Entry<Integer, List<SampleClassification>> entry : sampleMap.entrySet()) {
                if (this.performance == null) {
                    this.performance = new DefaultMultiStepClassificationPerformance(
                            ExpertResult.createClassificationPerformance(
                                    Integer.toString(this.getId()) + "-Step " + entry.getKey(), classArray,
                                    entry.getValue()));
                } else {
                    this.performance = this.performance.merge(ExpertResult.createClassificationPerformance(
                            Integer.toString(this.getId()) + "-Step " + entry.getKey(), classArray,
                            entry.getValue()));
                }
            }
        } else {
            this.performance = ExpertResult.createClassificationPerformance(Integer.toString(this.getId()),
                    classArray, samples);
        }
    }
}

From source file:com.lingeringsocket.mobflare.RpcCoordinator.java

List<String> listFlares(Location location) throws Exception {
    String uri = serverUri + "/list?latitude=" + location.getLatitude() + "&longitude="
            + location.getLongitude() + "&radius=" + Prefs.getSearchRadius(context);
    HttpGet httpGet = new HttpGet(uri);
    try {//from w  w w.  j  a va  2  s.c om
        HttpResponse httpResponse = execute(httpGet);
        String json = readInputStream(httpResponse.getEntity().getContent());
        JSONTokener tokener = new JSONTokener(json);
        JSONArray jsonArray = new JSONArray(tokener);
        // sort flares by distance; fake a multimap just to deal
        // with the pathological case of equal distances,
        // which actually comes up during testing on
        // an emulator
        SortedMap<Double, List<String>> sortedMap = new TreeMap<Double, List<String>>();
        for (int i = 0; i < jsonArray.length(); ++i) {
            JSONObject jsonObj = jsonArray.getJSONObject(i);
            String name = jsonObj.getString("name");
            double distance = jsonObj.getDouble("km");
            List<String> list = sortedMap.get(distance);
            if (list == null) {
                list = new ArrayList<String>();
                sortedMap.put(distance, list);
            }
            list.add(name);
        }
        List<String> flareList = new ArrayList<String>();
        for (List<String> list : sortedMap.values()) {
            flareList.addAll(list);
        }
        return flareList;
    } catch (Exception ex) {
        Log.e(LOGTAG, "HTTP GET failed", ex);
        throw ex;
    }
}