Example usage for java.util TreeMap values

List of usage examples for java.util TreeMap values

Introduction

In this page you can find the example usage for java.util TreeMap values.

Prototype

public Collection<V> values() 

Source Link

Document

Returns a Collection view of the values contained in this map.

Usage

From source file:org.openmicroscopy.shoola.agents.measurement.view.MeasurementViewerComponent.java

/** 
  * Implemented as specified by the {@link MeasurementViewer} interface.
  * @see MeasurementViewer#setMagnifiedPlane(int, int, double)
  *//*w  w w.  j av  a 2s . c o m*/
public void setMagnifiedPlane(int defaultZ, int defaultT, double magnification) {
    int z = model.getDefaultZ();
    int t = model.getDefaultT();
    double f = model.getMagnification();
    if (z == defaultZ && t == defaultT) {
        if (f != magnification) {
            model.setMagnification(magnification);
            view.onMagnificationChanged();
        }
        if (!model.isBigImage())
            return;
    }
    model.setPlane(defaultZ, defaultT);
    Drawing drawing = model.getDrawing();
    drawing.removeDrawingListener(controller);
    drawing.clear();
    ShapeList list = null;
    try {
        list = model.getShapeList();
    } catch (Exception e) {
        view.handleROIException(e, MeasurementViewerUI.RETRIEVE_MSG);
    }
    view.setStatus(MeasurementViewerUI.DEFAULT_MSG);
    if (list != null) {
        TreeMap map = list.getList();
        Iterator i = map.values().iterator();
        ROIShape shape;
        ROIFigure fig;
        while (i.hasNext()) {
            shape = (ROIShape) i.next();
            if (shape != null) {
                fig = shape.getFigure();
                drawing.add(fig);
                if (fig.canAnnotate())
                    fig.addFigureListener(controller);
            }
        }
    }
    //Reset the result.
    view.displayAnalysisResults();
    model.getDrawingView().setDrawing(drawing);
    drawing.addDrawingListener(controller);
    if (f != magnification)
        model.setMagnification(magnification);
}

From source file:net.dv8tion.jda.handle.EntityBuilder.java

public Message createMessage(JSONObject jsonObject) {
    String id = jsonObject.getString("id");
    String content = jsonObject.getString("content");
    MessageImpl message = new MessageImpl(id, api)
            .setAuthor(api.getUserMap().get(jsonObject.getJSONObject("author").getString("id")))
            .setContent(content).setTime(OffsetDateTime.parse(jsonObject.getString("timestamp")))
            .setMentionsEveryone(jsonObject.getBoolean("mention_everyone")).setTTS(jsonObject.getBoolean("tts"))
            .setPinned(jsonObject.getBoolean("pinned"));

    List<Message.Attachment> attachments = new LinkedList<>();
    JSONArray jsonAttachments = jsonObject.getJSONArray("attachments");
    for (int i = 0; i < jsonAttachments.length(); i++) {
        JSONObject jsonAttachment = jsonAttachments.getJSONObject(i);
        attachments.add(new Message.Attachment(jsonAttachment.getString("id"), jsonAttachment.getString("url"),
                jsonAttachment.getString("proxy_url"), jsonAttachment.getString("filename"),
                jsonAttachment.getInt("size"),
                jsonAttachment.has("height") ? jsonAttachment.getInt("height") : 0,
                jsonAttachment.has("width") ? jsonAttachment.getInt("width") : 0, api));
    }/*from ww w .j a  va  2s  . c  o  m*/
    message.setAttachments(attachments);

    List<MessageEmbed> embeds = new LinkedList<>();
    JSONArray jsonEmbeds = jsonObject.getJSONArray("embeds");
    for (int i = 0; i < jsonEmbeds.length(); i++) {
        embeds.add(createMessageEmbed(jsonEmbeds.getJSONObject(i)));
    }
    message.setEmbeds(embeds);

    Matcher matcher = emotePatter.matcher(content);
    List<Emote> emoteList = new LinkedList<>();
    while (matcher.find())
        emoteList.add(
                api.getEmoteById(matcher.group(2)) == null ? new EmoteImpl(matcher.group(1), matcher.group(2))
                        : api.getEmoteById(matcher.group(2)));
    message.setEmotes(emoteList);

    if (!jsonObject.isNull("edited_timestamp"))
        message.setEditedTime(OffsetDateTime.parse(jsonObject.getString("edited_timestamp")));

    String channelId = jsonObject.getString("channel_id");
    TextChannel textChannel = api.getChannelMap().get(channelId);
    if (textChannel != null) {
        message.setChannelId(textChannel.getId());
        message.setIsPrivate(false);
        TreeMap<Integer, User> mentionedUsers = new TreeMap<>();
        JSONArray mentions = jsonObject.getJSONArray("mentions");
        for (int i = 0; i < mentions.length(); i++) {
            JSONObject mention = mentions.getJSONObject(i);
            User u = api.getUserMap().get(mention.getString("id"));
            if (u != null) {
                //We do this to properly order the mentions. The array given by discord is out of order sometimes.
                int index = content.indexOf("<@" + mention.getString("id") + ">");
                mentionedUsers.put(index, u);
            }
        }
        message.setMentionedUsers(new LinkedList<User>(mentionedUsers.values()));

        TreeMap<Integer, Role> mentionedRoles = new TreeMap<>();
        JSONArray roleMentions = jsonObject.getJSONArray("mention_roles");
        for (int i = 0; i < roleMentions.length(); i++) {
            String roleId = roleMentions.getString(i);
            Role r = textChannel.getGuild().getRoleById(roleId);
            if (r != null) {
                int index = content.indexOf("<@&" + roleId + ">");
                mentionedRoles.put(index, r);
            }
        }
        message.setMentionedRoles(new LinkedList<Role>(mentionedRoles.values()));

        List<TextChannel> mentionedChannels = new LinkedList<>();
        Map<String, TextChannel> chanMap = ((GuildImpl) textChannel.getGuild()).getTextChannelsMap();
        matcher = channelMentionPattern.matcher(content);
        while (matcher.find()) {
            TextChannel channel = chanMap.get(matcher.group(1));
            if (channel != null && !mentionedChannels.contains(channel)) {
                mentionedChannels.add(channel);
            }
        }
        message.setMentionedChannels(mentionedChannels);
    } else {
        message.setIsPrivate(true);
        PrivateChannel privateChannel = api.getPmChannelMap().get(channelId);
        if (privateChannel != null) {
            message.setChannelId(privateChannel.getId());
        } else {
            throw new IllegalArgumentException("Could not find Private/Text Channel of id " + channelId);
        }
    }

    return message;
}

From source file:org.ncic.bioinfo.sparkseq.algorithms.utils.reports.GATKReportTable.java

private List<Object[]> getOrderedRows() {

    switch (sortingWay) {
    case SORT_BY_COLUMN:
        Collections.sort(underlyingData, new Comparator<Object[]>() {
            //INVARIANT the two arrays are of the same length and corresponding elements are of the same type
            @Override/*w w  w  .  j  a  v  a 2 s. c o  m*/
            public int compare(Object[] objectArr1, Object[] objectArr2) {
                final int EQUAL = 0;
                int result = EQUAL;
                int l = objectArr1.length;
                for (int x = 0; x < l; x++) {
                    if (objectArr1[x] instanceof Integer) {
                        result = ((Integer) objectArr1[x]).compareTo((Integer) objectArr2[x]);
                    } else if (objectArr1[x] instanceof Double) {
                        result = ((Double) objectArr1[x]).compareTo((Double) objectArr2[x]);
                    } else { // default uses String comparison
                        result = objectArr1[x].toString().compareTo(objectArr2[x].toString());
                    }
                    if (result != EQUAL) {
                        return result;
                    }
                }
                return result;
            }
        });
        return underlyingData;
    case SORT_BY_ROW:
        final TreeMap<Object, Integer> sortedMap;
        try {
            sortedMap = new TreeMap<Object, Integer>(rowIdToIndex);
        } catch (ClassCastException e) {
            return underlyingData;
        }

        final List<Object[]> orderedData = new ArrayList<Object[]>(underlyingData.size());
        for (final int rowKey : sortedMap.values())
            orderedData.add(underlyingData.get(rowKey));

        return orderedData;
    default:
        return underlyingData;
    }
}

From source file:com.amalto.workbench.utils.XSDAnnotationsStructure.java

public void removeSchematron(String pattern) {
    TreeMap<String, String> infos = getSchematrons();
    for (Entry<String, String> entry : infos.entrySet()) {
        if (pattern.equals(entry.getValue())) {
            infos.remove(entry.getKey());
            break;
        }//from w  ww  .j  a  v  a 2s .  c  o m
    }
    setSchematrons(infos.values());
}

From source file:com.amalto.workbench.utils.XSDAnnotationsStructure.java

public void removeWorkflow(String pattern) {
    TreeMap<String, String> infos = getSchematrons();
    for (Entry<String, String> entry : infos.entrySet()) {
        if (pattern.equals(entry.getValue())) {
            infos.remove(entry.getKey());
            break;
        }//from   w  ww . j a v  a2s . c o  m
    }
    setSchematrons(infos.values());
}

From source file:org.voltdb.utils.CatalogUtil.java

/**
 * Given a set of catalog items, return a sorted list of them, sorted by
 * the value of a specified field. The field is specified by name. If the
 * field doesn't exist, trip an assertion. This is primarily used to sort
 * a table's columns or a procedure's parameters.
 *
 * @param <T> The type of item to sort.
 * @param items The set of catalog items.
 * @param sortFieldName The name of the field to sort on.
 * @return A list of catalog items, sorted on the specified field.
 *///  ww w.  jav  a  2  s.co  m
public static <T extends CatalogType> List<T> getSortedCatalogItems(CatalogMap<T> items, String sortFieldName) {
    assert (items != null);
    assert (sortFieldName != null);

    // build a treemap based on the field value
    TreeMap<Object, T> map = new TreeMap<Object, T>();
    boolean hasField = false;
    for (T item : items) {
        // check the first time through for the field
        if (hasField == false) {
            hasField = ArrayUtils.contains(item.getFields(), sortFieldName);
        }
        assert (hasField == true);

        map.put(item.getField(sortFieldName), item);
    }

    // create a sorted list from the map
    ArrayList<T> retval = new ArrayList<T>();
    for (T item : map.values()) {
        retval.add(item);
    }

    return retval;
}

From source file:com.mirth.connect.client.ui.components.MirthTable.java

public void restoreColumnPreferences() {
    try {/*  w w  w .  ja v  a2 s.  co m*/
        if (StringUtils.isNotEmpty(prefix)) {
            TableColumnModelExt columnModel = (TableColumnModelExt) getColumnModel();
            TreeMap<Integer, Integer> columnOrder = new TreeMap<Integer, Integer>();

            int columnIndex = 0;
            for (TableColumn column : columnModel.getColumns(true)) {
                String columnName = (String) column.getIdentifier();
                Integer viewIndex = columnOrderMap.get(columnName);
                TableColumnExt columnExt = getColumnExt(columnName);

                boolean visible = false;
                if (viewIndex == null) {
                    visible = defaultVisibleColumns == null || defaultVisibleColumns.contains(columnName);
                } else {
                    visible = viewIndex > -1;
                }

                columnExt.setVisible(visible);
                if (viewIndex != null && viewIndex > -1) {
                    columnOrder.put(viewIndex, columnIndex);
                }

                columnIndex++;
            }

            int viewIndex = 0;
            for (int index : columnOrder.values()) {
                columnModel.moveColumn(convertColumnIndexToView(index), viewIndex++);
            }

            if (sortKeys != null && !sortKeys.isEmpty()) {
                getRowSorter().setSortKeys(sortKeys);
            }
        }
    } catch (Exception e) {
        restoreDefaultColumnPreferences();
    }
}

From source file:nz.net.orcon.kanban.automation.AutomationEngine.java

private void executeTaskRules(Map<String, Rule> rules, Card card) throws Exception {
    Collection<CardTask> tasks = cardController.getTasks(card.getBoard(), card.getPhase(),
            card.getId().toString());// w  w  w  .  j a v  a 2s.  c  o m
    TreeMap<Integer, Rule> rulesToExecute = new TreeMap<Integer, Rule>();

    for (CardTask task : tasks) {
        if (!task.getComplete()) {
            Rule rule = rules.get(task.getTaskid());
            if (rule.getAutomationConditions() == null) {
                rulesToExecute.put(rule.getIndex(), rule);
            } else {
                if (conditionsMet(card, rule, rule.getAutomationConditions(), null, null)) {
                    rulesToExecute.put(rule.getIndex(), rule);
                }
            }
        }
    }

    for (Rule rule : rulesToExecute.values()) {
        LOG.info("Executing task rule " + rule.getId() + " for card :" + card.getPath());
        executeActions(card, rule);
        cardController.completeTask(card.getBoard(), card.getPhase(), card.getId().toString(), rule.getId());
    }
}

From source file:net.sourceforge.processdash.ev.ui.EVReport.java

private static List<EVTaskDataWriter> getTaskDataWriters() {
    if (taskDataWriters == null) {
        List<EVTaskDataWriter> result = new ArrayList();
        result.add(new TreeViewTaskDataWriter());
        result.add(new FlatViewTaskDataWriter());

        TreeMap<String, EVTaskDataWriter> customWriters = new TreeMap();
        for (Object extObj : ExtensionManager.getExecutableExtensions("ev-task-writer", null)) {
            if (extObj instanceof EVTaskDataWriter) {
                EVTaskDataWriter custom = (EVTaskDataWriter) extObj;
                customWriters.put(custom.getID(), custom);
            }//w  ww.j ava  2s.co  m
        }
        result.addAll(customWriters.values());

        taskDataWriters = Collections.unmodifiableList(result);
    }
    return taskDataWriters;
}

From source file:com.alibaba.wasp.fserver.TestEntityGroup.java

/**
 * Splits twice and verifies getting from each of the split entityGroups.
 * /*from   w ww . j a v  a  2s .c o m*/
 * @throws Exception
 */
@Test
public void testBasicSplit() throws Exception {
    byte[] tableName = Bytes.toBytes("testtable");
    List<Field> fileds = Arrays.asList(field1, field2, field3);

    Configuration hc = TEST_UTIL.getConfiguration(); // initSplit();
    // Setting up entityGroup
    String method = "testBasicSplit";
    this.entityGroup = initEntityGroup(tableName, method, hc, fileds);

    try {
        entityGroup.internalCommitTransaction();

        byte[] sp = Bytes.toBytes("hijklmn");
        entityGroup.forceSplit(sp);
        byte[] splitRow = entityGroup.checkSplit();
        Assert.assertNotNull(splitRow);
        LOG.info("SplitRow: " + Bytes.toString(splitRow));
        EntityGroup[] entityGroups = splitEntityGroup(entityGroup, splitRow);
        try {
            // Need to open the entityGroups.
            // TODO: Add an 'open' to EntityGroup... don't do open by constructing
            // instance.
            for (int i = 0; i < entityGroups.length; i++) {
                openClosedEntityGroup(entityGroups[i]);
                // entityGroups[i] = openClosedEntityGroup(entityGroups[i]);
            }
            // Assert can get rows out of new entityGroups. Should be able to get
            // first
            // row from first entityGroup and the midkey from second entityGroup.
            // assertGet(entityGroups[0], field3, Bytes.toBytes(START_KEY));
            // assertGet(entityGroups[1], field3, splitRow);
            // Test I can get scanner and that it starts at right place.
            // assertScan(entityGroups[0], field3, Bytes.toBytes(START_KEY));
            // assertScan(entityGroups[1], field3, splitRow);
            // Now prove can't split entityGroups that have references.
            for (int i = 0; i < entityGroups.length; i++) {
                // Add so much data to this entityGroup, we create a store file that
                // is >
                // than one of our unsplitable references. it will.
                for (int j = 0; j < 2; j++) {
                    // addContent(entityGroups[i], field3);
                }
                // addContent(entityGroups[i], field2);
                // addContent(entityGroups[i], field1);
                entityGroups[i].internalCommitTransaction();
            }

            byte[][] midkeys = new byte[entityGroups.length][];

            for (int i = 0; i < entityGroups.length; i++) {
                midkeys[i] = entityGroups[i].checkSplit();
                System.out.println(" tianzhaotianzhao 3 " + entityGroups[i]);
            }

            TreeMap<String, EntityGroup> sortedMap = new TreeMap<String, EntityGroup>();
            // Split these two daughter entityGroups so then I'll have 4
            // entityGroups. Will
            // split because added data above.
            for (int i = 0; i < entityGroups.length; i++) {
                EntityGroup[] rs = null;
                if (midkeys[i] != null) {
                    rs = splitEntityGroup(entityGroups[i], midkeys[i]);
                    for (int j = 0; j < rs.length; j++) {
                        sortedMap.put(Bytes.toString(rs[j].getEntityGroupName()), openClosedEntityGroup(rs[j]));
                    }
                }
            }
            LOG.info("Made 4 entityGroups");
            // The splits should have been even. Test I can get some arbitrary row
            // out of each.
            int interval = (LAST_CHAR - FIRST_CHAR) / 3;
            byte[] b = Bytes.toBytes(START_KEY);
            for (EntityGroup r : sortedMap.values()) {
                b[0] += interval;
            }
        } finally {
            for (int i = 0; i < entityGroups.length; i++) {
                try {
                    entityGroups[i].close();
                } catch (IOException e) {
                    // Ignore.
                }
            }
        }
    } finally {
        EntityGroup.closeEntityGroup(this.entityGroup);
        this.entityGroup = null;
    }
}