1 /*
2 * ObjectLab, http://www.objectlab.co.uk/open is supporting JTreeMap.
3 *
4 * Based in London, we are world leaders in the design and development
5 * of bespoke applications for the securities financing markets.
6 *
7 * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a>
8 * ___ _ _ _ _ _
9 * / _ \| |__ (_) ___ ___| |_| | __ _| |__
10 * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \
11 * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) |
12 * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
13 * |__/
14 *
15 * www.ObjectLab.co.uk
16 *
17 * $Id$
18 *
19 * Copyright 2006 the original author or authors.
20 *
21 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
22 * use this file except in compliance with the License. You may obtain a copy of
23 * the License at
24 *
25 * http://www.apache.org/licenses/LICENSE-2.0
26 *
27 * Unless required by applicable law or agreed to in writing, software
28 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
29 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
30 * License for the specific language governing permissions and limitations under
31 * the License.
32 */
33 package net.sf.jtreemap.swing;
34
35 import java.util.ArrayList;
36 import java.util.List;
37
38 /**
39 * Strategy who split the elements in 2 groups of equivalent weight.
40 * <p>
41 * The elements are first sorted by descending weight. Then they are splitted in
42 * 2 groups of equivalent weight.
43 * <p>
44 * The heaviest elements are on the top left of the JTreeMap. The lightest
45 * elements are on the bottom right of the JTreeMap
46 *
47 * @author Laurent Dutheil
48 */
49
50 public class SplitBySortedWeight extends SplitStrategy {
51
52 /**
53 *
54 */
55 private static final long serialVersionUID = 1600419780258843122L;
56
57 @Override
58 public void splitElements(final List<TreeMapNode> v, final List<TreeMapNode> v1, final List<TreeMapNode> v2) {
59 final List<TreeMapNode> vClone = new ArrayList<>(v);
60 final double sumWeight = sumWeight(v);
61
62 sortList(vClone);
63
64 workOutWeight(v1, v2, vClone, sumWeight);
65 }
66 }
67 /*
68 * ObjectLab is supporing JTreeMap
69 *
70 * Based in London, we are world leaders in the design and development
71 * of bespoke applications for the securities financing markets.
72 *
73 * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a>
74 * ___ _ _ _ _ _
75 * / _ \| |__ (_) ___ ___| |_| | __ _| |__
76 * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \
77 * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) |
78 * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
79 * |__/
80 *
81 * www.ObjectLab.co.uk
82 */