def setActiveChannel(self, channel):
     self.channel = channel
     # convert from List to Array
     items = self.channel.getItems().toArray()
     # sort news items
     Arrays.sort(items, ItemComparator(1))
     self.items = items
     self.fireTableDataChanged()
Esempio n. 2
0
 def setActiveChannel(self, channel):
     self.channel = channel
     # convert from List to Array
     items = self.channel.getItems().toArray()
     # sort news items
     Arrays.sort(items, ItemComparator(1))
     self.items = items
     self.fireTableDataChanged()
Esempio n. 3
0
 def __queryNewestRefTime(self):
     from com.raytheon.uf.viz.core.catalog import CatalogQuery
     from java.util import Arrays
     from com.raytheon.uf.common.time import DataTime                 
     results = CatalogQuery.performQuery('dataTime.refTime', self._buildConstraints(None))
     Arrays.sort(results)
     if len(results) == 0:
         if self.site:
             raise NoDataException.NoDataException("No data available for site " + self.site)
         else:
             raise NoDataException.NoDataException("No data available")
     dt = DataTime(results[len(results)-1])        
     return dt.getRefTime().getTime() / 1000
from array import array as A
from java.util import Arrays as AS

array_1 = A('i')
print(array_1)
for k in range(10):
    array_1.append(-k)
print(array_1)
AS.parallelSort(array_1)
for k in range(11, 20):
    array_1.append(-k)
print(array_1)
AS.sort(array_1)
print(array_1)
Esempio n. 5
0
def run(title):
    gd = GenericDialog("Record Window")
    gd.addMessage("Maximum number of frames to record.\nZero means infinite, interrupt with ESC key.")
    gd.addNumericField("Max. frames:", 50, 0)
    gd.addNumericField("Milisecond interval:", 300, 0)
    gd.addSlider("Start in (seconds):", 0, 20, 5)
    frames = []
    titles = []
    for f in Frame.getFrames():
        if f.isEnabled() and f.isVisible():
            frames.append(f)
            titles.append(f.getTitle())
    gd.addChoice("Window:", titles, titles[0])
    gd.addCheckbox("To file", False)
    gd.showDialog()
    if gd.wasCanceled():
        return
    n_frames = int(gd.getNextNumber())
    interval = gd.getNextNumber() / 1000.0  # in seconds
    frame = frames[gd.getNextChoiceIndex()]
    delay = int(gd.getNextNumber())
    tofile = gd.getNextBoolean()

    dir = None
    if tofile:
        dc = DirectoryChooser("Directory to store image frames")
        dir = dc.getDirectory()
        if dir is None:
            return  # dialog canceled

    snaps = []
    borders = None
    executors = Executors.newFixedThreadPool(1)
    try:
        while delay > 0:
            IJ.showStatus("Starting in " + str(delay) + "s.")
            time.sleep(1)  # one second
            delay -= 1

        IJ.showStatus("Capturing frame borders...")
        bounds = frame.getBounds()
        robot = Robot()
        frame.toFront()
        time.sleep(0.5)  # half a second
        borders = robot.createScreenCapture(bounds)

        IJ.showStatus("Recording " + frame.getTitle())

        # Set box to the inside borders of the frame
        insets = frame.getInsets()
        box = bounds.clone()
        box.x = insets.left
        box.y = insets.top
        box.width -= insets.left + insets.right
        box.height -= insets.top + insets.bottom

        start = System.currentTimeMillis() / 1000.0  # in seconds
        last = start
        intervals = []
        real_interval = 0
        i = 1
        fus = None
        if tofile:
            fus = []

            # 0 n_frames means continuous acquisition
        while 0 == n_frames or (len(snaps) < n_frames and last - start < n_frames * interval):
            now = System.currentTimeMillis() / 1000.0  # in seconds
            real_interval = now - last
            if real_interval >= interval:
                last = now
                img = snapshot(frame, box)
                if tofile:
                    fus.append(executors.submit(Saver(i, dir, bounds, borders, img, insets)))  # will flush img
                    i += 1
                else:
                    snaps.append(img)
                intervals.append(real_interval)
            else:
                time.sleep(interval / 5)
                # interrupt capturing:
            if IJ.escapePressed():
                IJ.showStatus("Recording user-interrupted")
                break

                # debug:
                # print "insets:", insets
                # print "bounds:", bounds
                # print "box:", box
                # print "snap dimensions:", snaps[0].getWidth(), snaps[0].getHeight()

                # Create stack
        stack = None
        if tofile:
            for fu in snaps:
                fu.get()  # wait on all
            stack = VirtualStack(bounds.width, bounds.height, None, dir)
            files = File(dir).list(TifFilter())
            Arrays.sort(files)
            for f in files:
                stack.addSlice(f)
        else:
            stack = ImageStack(bounds.width, bounds.height, None)
            t = 0
            for snap, real_interval in zip(snaps, intervals):
                bi = BufferedImage(bounds.width, bounds.height, BufferedImage.TYPE_INT_RGB)
                g = bi.createGraphics()
                g.drawImage(borders, 0, 0, None)
                g.drawImage(snap, insets.left, insets.top, None)
                stack.addSlice(str(IJ.d2s(t, 3)), ImagePlus("", bi).getProcessor())
                t += real_interval
                snap.flush()
                bi.flush()

        borders.flush()

        ImagePlus(frame.getTitle() + " recording", stack).show()
        IJ.showStatus("Done recording " + frame.getTitle())
    except Exception, e:
        print "Some error ocurred:"
        print e.printStackTrace()
        IJ.showStatus("")
        if borders is not None:
            borders.flush()
        for snap in snaps:
            snap.flush()
Esempio n. 6
0
package algorithm_toolbox.week3;//package algorithm_toolbox.week3.week4.week3;


import java.util.Arrays;
import java.util.Scanner;

public class DotProduct {
    private static long maxDotProduct(int[] a, int[] b) {
        //write your code here
        long result = 0;
        Arrays.sort(a);

        Arrays.sort(b);
        for (int i = 0; i < a.length; i++) {
            result += a[i] * b[i];
        }
        return result;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        int[] b = new int[n];
        for (int i = 0; i < n; i++) {
            b[i] = scanner.nextInt();
        }
        System.out.println(maxDotProduct(a, b));
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
import java.util.List;

public class Solution {
    public List<List<Integer>> combinationSum(int[] candidates, int target) {

        List<List<Integer>> res = new ArrayList<>();
        if (len == 0) {
            return res;
        }

        // 排序剪枝
        Arrays.sort(candidates);
        Deque<Integer> path = new ArrayDeque<>();
        dfs(candidates, target, 0, path, res);
        return res;
    }

    private void dfs(int[] candidates, int target, int begin, Deque<Integer> path, List<List<Inter>> res) {
        // 由于进入更深层回溯时,小于0的部分被剪枝,因此递归终止条件值只判断等于0的情况
        if (target == 0) {
            res.add(new ArrayList<>(path));
            return;
        }

        for (int i = begin; i < candidates.length; i++) {
            if (target - candidates[i] < 0) {
                break;
from java.util import Comparator as C
from array import array as A
from java.util import Arrays as AS


class asc(C):
    def compare(val1, val2):
        if (val1 > val2):
            return -1
        elif (val1 < val2):
            return 1
        else:
            return 0


array_1 = A('i')
for x in range(10):
    array_1.append(x)
print(array_1)
print(AS.sort(array_1, asc()))
Esempio n. 9
0
def run(title):
    gd = GenericDialog('Record Window')
    gd.addMessage(
        "Maximum number of frames to record.\nZero means infinite, interrupt with ESC key."
    )
    gd.addNumericField('Max. frames:', 50, 0)
    gd.addNumericField('Milisecond interval:', 300, 0)
    gd.addSlider('Start in (seconds):', 0, 20, 5)
    frames = []
    titles = []
    for f in Frame.getFrames():
        if f.isEnabled() and f.isVisible():
            frames.append(f)
            titles.append(f.getTitle())
    gd.addChoice('Window:', titles, titles[0])
    gd.addCheckbox("To file", False)
    gd.showDialog()
    if gd.wasCanceled():
        return
    n_frames = int(gd.getNextNumber())
    interval = gd.getNextNumber() / 1000.0  # in seconds
    frame = frames[gd.getNextChoiceIndex()]
    delay = int(gd.getNextNumber())
    tofile = gd.getNextBoolean()

    dir = None
    if tofile:
        dc = DirectoryChooser("Directory to store image frames")
        dir = dc.getDirectory()
        if dir is None:
            return  # dialog canceled

    snaps = []
    borders = None
    executors = Executors.newFixedThreadPool(1)
    try:
        while delay > 0:
            IJ.showStatus('Starting in ' + str(delay) + 's.')
            time.sleep(1)  # one second
            delay -= 1

        IJ.showStatus('Capturing frame borders...')
        bounds = frame.getBounds()
        robot = Robot()
        frame.toFront()
        time.sleep(0.5)  # half a second
        borders = robot.createScreenCapture(bounds)

        IJ.showStatus("Recording " + frame.getTitle())

        # Set box to the inside borders of the frame
        insets = frame.getInsets()
        box = bounds.clone()
        box.x = insets.left
        box.y = insets.top
        box.width -= insets.left + insets.right
        box.height -= insets.top + insets.bottom

        start = System.currentTimeMillis() / 1000.0  # in seconds
        last = start
        intervals = []
        real_interval = 0
        i = 1
        fus = None
        if tofile:
            fus = []

        # 0 n_frames means continuous acquisition
        while 0 == n_frames or (len(snaps) < n_frames
                                and last - start < n_frames * interval):
            now = System.currentTimeMillis() / 1000.0  # in seconds
            real_interval = now - last
            if real_interval >= interval:
                last = now
                img = snapshot(frame, box)
                if tofile:
                    fus.append(
                        executors.submit(
                            Saver(i, dir, bounds, borders, img,
                                  insets)))  # will flush img
                    i += 1
                else:
                    snaps.append(img)
                intervals.append(real_interval)
            else:
                time.sleep(interval / 5)
            # interrupt capturing:
            if IJ.escapePressed():
                IJ.showStatus("Recording user-interrupted")
                break

        # debug:
        #print "insets:", insets
        #print "bounds:", bounds
        #print "box:", box
        #print "snap dimensions:", snaps[0].getWidth(), snaps[0].getHeight()

        # Create stack
        stack = None
        if tofile:
            for fu in snaps:
                fu.get()  # wait on all
            stack = VirtualStack(bounds.width, bounds.height, None, dir)
            files = File(dir).list(TifFilter())
            Arrays.sort(files)
            for f in files:
                stack.addSlice(f)
        else:
            stack = ImageStack(bounds.width, bounds.height, None)
            t = 0
            for snap, real_interval in zip(snaps, intervals):
                bi = BufferedImage(bounds.width, bounds.height,
                                   BufferedImage.TYPE_INT_RGB)
                g = bi.createGraphics()
                g.drawImage(borders, 0, 0, None)
                g.drawImage(snap, insets.left, insets.top, None)
                stack.addSlice(str(IJ.d2s(t, 3)),
                               ImagePlus('', bi).getProcessor())
                t += real_interval
                snap.flush()
                bi.flush()

        borders.flush()

        ImagePlus(frame.getTitle() + " recording", stack).show()
        IJ.showStatus('Done recording ' + frame.getTitle())
    except Exception, e:
        print "Some error ocurred:"
        print e.printStackTrace()
        IJ.showStatus('')
        if borders is not None: borders.flush()
        for snap in snaps:
            snap.flush()
Esempio n. 10
0
import java.util.Scanner;
import java.util.Arrays;

public class Array_1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("NHap so phan tu cua mang: ");
        int n = sc.nextInt();
        int[] a = new int[n];

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a,1,n);
        for (int i = 0;i < n;i++) {
            System.out.print(a[i] + " ");
        }
    }
}

     # Unit tests the <tt>Interval1D</tt> data type.
     #/
    def main(String[] args):
        Interval1D[] intervals = new Interval1D[4]
        intervals[0] = new Interval1D(15.0, 33.0)
        intervals[1] = new Interval1D(45.0, 60.0)
        intervals[2] = new Interval1D(20.0, 70.0)
        intervals[3] = new Interval1D(46.0, 55.0)

        prt.write("Unsorted")
        for (int i = 0; i < len(intervals); i += 1)
            prt.write(intervals[i])
        prt.write()
        
        prt.write("Sort by left endpoint")
        Arrays.sort(intervals, Interval1D.LEFT_ENDPOINT_ORDER)
        for (int i = 0; i < len(intervals); i += 1)
            prt.write(intervals[i])
        prt.write()

        prt.write("Sort by right endpoint")
        Arrays.sort(intervals, Interval1D.RIGHT_ENDPOINT_ORDER)
        for (int i = 0; i < len(intervals); i += 1)
            prt.write(intervals[i])
        prt.write()

        prt.write("Sort by length")
        Arrays.sort(intervals, Interval1D.LENGTH_ORDER)
        for (int i = 0; i < len(intervals); i += 1)
            prt.write(intervals[i])
        prt.write()
Esempio n. 12
0
import java.util.Arrays;
import java.util.HashSet;
class Solution {
    public int coinChange(int[] coins, int amount) {
        if (amount == 0){return 0;}
        Set tocheck = new HashSet();
        tocheck.add(amount);
        int count = 0;
        Arrays.sort(coins);
        while (! tocheck.isEmpty()){
            count += 1;
            Set temp = new HashSet();
            for (Iterator it = tocheck.iterator();it.hasNext();){
                int x = (int)it.next();
                for (int j=0; j<coins.length; j++){
                    int coin = coins[j];
                    if (x == coin){
                        return count;
                    }
                    if (x > coin){
                        temp.add(x-coin);
                    }
                    if (x < coin){
                        break;
                    }
                }
            }
                tocheck = temp;
        
        }
        return -1;
Esempio n. 13
0
import java.util.Arrays;
import java.util.Collections;

class GFG
{   
    // Function to return k'th smallest 
    // element in a given array
    public static int kthSmallest(Integer [] arr, 
                                         int k) 
   {
        Arrays.sort(arr);
        return arr[k-1];
    } 
    
    public static void main(String[] args) 
    {
        Integer arr[] = new Integer[]{11, 2, 4, 6, 18};
        int k = 1;
        System.out.print( "K'th smallest element is "+
                            kthSmallest(arr, k) );     
    }
}