Example usage for java.util Set toArray

List of usage examples for java.util Set toArray

Introduction

In this page you can find the example usage for java.util Set toArray.

Prototype

Object[] toArray();

Source Link

Document

Returns an array containing all of the elements in this set.

Usage

From source file:alluxio.cli.fsadmin.report.CapacityCommand.java

/**
 * Prints worker capacity information./*from   ww  w. j  av  a  2  s  . com*/
 *
 * @param workerInfoList the worker info list to get info from
 */
private void printWorkerInfo(List<WorkerInfo> workerInfoList) {
    mIndentationLevel = 0;
    if (mCapacityTierInfoMap.size() == 0) {
        return;
    } else if (mCapacityTierInfoMap.size() == 1) {
        // Do not print Total value when only one tier exists
        printShortWorkerInfo(workerInfoList);
        return;
    }
    Set<String> tiers = mCapacityTierInfoMap.keySet();
    String tiersInfo = String.format(Strings.repeat("%-14s", tiers.size()), tiers.toArray());
    print(String.format("%n" + LONG_INFO_FORMAT, "Worker Name", "Last Heartbeat", "Storage", "Total",
            tiersInfo));

    for (WorkerInfo info : workerInfoList) {
        String workerName = info.getAddress().getHost();

        long usedBytes = info.getUsedBytes();
        long capacityBytes = info.getCapacityBytes();

        String usedPercentageInfo = "";
        if (capacityBytes != 0) {
            int usedPercentage = (int) (100L * usedBytes / capacityBytes);
            usedPercentageInfo = String.format(" (%s%%)", usedPercentage);
        }

        String capacityTierInfo = getWorkerFormattedTierValues(mCapacityTierInfoMap, workerName);
        String usedTierInfo = getWorkerFormattedTierValues(mUsedTierInfoMap, workerName);

        print(String.format(LONG_INFO_FORMAT, workerName, info.getLastContactSec(), "capacity",
                FormatUtils.getSizeFromBytes(capacityBytes), capacityTierInfo));
        print(String.format(LONG_INFO_FORMAT, "", "", "used",
                FormatUtils.getSizeFromBytes(usedBytes) + usedPercentageInfo, usedTierInfo));
    }
}

From source file:files.populate.java

void populate_users(Connection connection, String filename) {
    String fileName = "/Users/yash/Documents/workspace/HW 3/data/yelp_user.json";
    Path path = Paths.get(fileName);
    Scanner scanner = null;//from  w w  w . ja  v a2  s.  c o  m
    try {
        scanner = new Scanner(path);

    } catch (IOException e) {
        e.printStackTrace();
    }

    //read file line by line
    scanner.useDelimiter("\n");
    int i = 0;
    while (scanner.hasNext()) {
        if (i < 500) {
            JSONParser parser = new JSONParser();
            String s = (String) scanner.next();
            JSONObject obj;
            try {
                obj = (JSONObject) parser.parse(s);
                Map votes = (Map) obj.get("votes");
                ArrayList friends;
                friends = (ArrayList) obj.get("friends");
                Map compliments = (Map) obj.get("compliments");
                //                    
                String query = "INSERT INTO YELP_USERS (user_id,yelping_since,name,fans,average_stars,type,review_count,VOTES_FUNNY,VOTES_COOL,VOTES_USEFUL) VALUES('"
                        + obj.get("user_id") + "','" + obj.get("yelping_since") + "','" + obj.get("name") + "',"
                        + obj.get("fans") + "," + obj.get("average_stars") + ",'" + obj.get("type") + "',"
                        + obj.get("review_count") + "," + votes.get("funny") + "," + votes.get("cool") + ","
                        + votes.get("useful") + ")";
                System.out.println(query);
                Statement statement = connection.createStatement();
                statement.executeUpdate(query);
                for (int j = 0; j < friends.size(); ++j) {
                    String q2 = "insert into users_friends values ('" + obj.get("user_id") + "','"
                            + friends.get(j) + "')";
                    System.out.println(q2);
                    statement.executeUpdate(q2);
                }
                Set keys = compliments.keySet();
                Object[] keys1 = keys.toArray();
                for (int j = 0; j < keys1.length; ++j) {
                    //                             String q2 = "insert into users_friends values ("+obj.get("user_id")+","+compliments.get(j)+")";
                    String thiskey = keys1[j].toString();
                    long val = (long) compliments.get(thiskey);
                    String q3 = "insert into users_compliments values ('" + obj.get("user_id") + "','" + thiskey
                            + "'," + val + ")";
                    System.out.println(q3);
                    statement.executeUpdate(q3);
                }
                statement.close();
            } catch (ParseException ex) {
                Logger.getLogger(populate.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(populate.class.getName()).log(Level.SEVERE, null, ex);
            }

            i++;
        } else
            break;
    }

    scanner.close();

}

From source file:edu.pitt.dbmi.ccd.queue.service.AlgorithmSlurmService.java

private void deleteRunSlurmScript(JobQueueInfo jobQueueInfo) {
    Long queueId = jobQueueInfo.getId();
    Set<UserAccount> userAccounts = jobQueueInfo.getUserAccounts();
    UserAccount userAccount = (UserAccount) userAccounts.toArray()[0];
    String username = userAccount.getUsername();

    Path scriptPath = Paths.get(remoteworkspace, username, runSlurmJobScript);
    String scriptDir = scriptPath.toAbsolutePath().toString() + queueId + ".sh";
    if (client.remoteFileExistes(scriptDir)) {
        client.deleteRemoteFile(scriptDir);
    }//from  w ww .  ja  v a2  s. c o  m
}

From source file:fr.certu.chouette.manager.ConnectionLinkManager.java

@Transactional
@Override/*from   w ww.  j ava  2  s.c om*/
public void saveAll(User user, List<ConnectionLink> connectionLinks, boolean propagate, boolean fast)
        throws ChouetteException {
    Set<String> areaIds = new HashSet<String>();
    for (ConnectionLink link : connectionLinks) {
        if (link.getStartOfLink() == null)
            areaIds.add(link.getStartOfLinkId());
        if (link.getEndOfLink() == null)
            areaIds.add(link.getEndOfLinkId());
    }
    if (!areaIds.isEmpty()) {
        areaIds.toArray();
        Filter filter = Filter.getNewInFilter("objectId", areaIds.toArray(new String[0]));
        INeptuneManager<StopArea> areaManager = (INeptuneManager<StopArea>) getManager(StopArea.class);

        List<StopArea> stopareas = areaManager.getAll(user, filter);
        Map<String, StopArea> map = new HashMap<String, StopArea>();
        for (StopArea stopArea : stopareas) {
            map.put(stopArea.getObjectId(), stopArea);
        }
        for (Iterator<ConnectionLink> iterator = connectionLinks.iterator(); iterator.hasNext();) {
            ConnectionLink link = iterator.next();
            if (link.getStartOfLink() == null)
                link.setStartOfLink(map.get(link.getStartOfLinkId()));
            if (link.getEndOfLink() == null)
                link.setEndOfLink(map.get(link.getEndOfLinkId()));
            if (link.getStartOfLink() == null || link.getEndOfLink() == null) {
                String id = null;
                if (link.getStartOfLink() == null)
                    id = link.getStartOfLinkId();
                else
                    id = link.getEndOfLinkId();
                logger.warn("ConnectionLink (objectId = " + link.getObjectId()
                        + " cannot be saved : missing target stopArea " + id);
                iterator.remove();
            }
        }

    }

    super.saveAll(user, connectionLinks, propagate, fast);

    if (propagate) {
        INeptuneManager<Facility> facilityManager = (INeptuneManager<Facility>) getManager(Facility.class);
        List<Facility> facilities = new ArrayList<Facility>();
        for (ConnectionLink connectionLink : connectionLinks) {
            mergeCollection(facilities, connectionLink.getFacilities());
        }

        if (!facilities.isEmpty())
            facilityManager.saveAll(user, facilities, propagate, fast);
    }
}

From source file:com.medigy.service.party.TestAddContactMechanismService.java

public void testAddPostalAddress() throws Exception {
    Country country = new Country();
    country.setCountryName("United States of America");
    country.setIsoThreeLetterCode("USA");
    country.setIsoThreeDigitCode("123");
    country.setIsoTwoLetterCode("US");
    State state = new State("Virginia", "VA");
    country.addState(state);//from www  .  ja v  a2s  . c om
    getSession().save(country);

    final Person p = new Person();
    p.setLastName("Hackett");
    p.setFirstName("Ryan");
    p.addGender(GenderType.Cache.MALE.getEntity());
    p.setBirthDate(new Date(123456));
    getSession().save(p);
    getSession().flush();

    //AddContactMechanismService service =  (AddContactMechanismService) getRegistry().getService(AddContactMechanismService.class);
    final NewPostalAddress address = addContactMechanismService
            .addPostalAddress(new AddPostalAddressParameters() {
                public Serializable getPartyId() {
                    return p.getPartyId();
                }

                public ServiceVersion getServiceVersion() {
                    return null;
                }

                public PostalAddressParameters getPostalAddressParameters() {
                    return new PostalAddressParameters() {
                        public String getStreet1() {
                            return "123 Acme Road";
                        }

                        public String getStreet2() {
                            return "Suite 100";
                        }

                        public String getCity() {
                            return "Fairfax";
                        }

                        public String getState() {
                            return "VA";
                        }

                        public String getProvince() {
                            return null;
                        }

                        public String getPostalCode() {
                            return "22033";
                        }

                        public String getCounty() {
                            return "Fairfax County";
                        }

                        public String getCountry() {
                            return "USA";
                        }

                        public String getPurposeDescription() {
                            return null;
                        }

                        public ServiceVersion getServiceVersion() {
                            return null;
                        }

                        public String getPurposeType() {
                            return ContactMechanismPurposeType.Cache.HOME_ADDRESS.getCode();
                        }

                    };
                }

            });
    assertNull(address.getErrorMessage());

    /*
    Criteria criteria = getSession().createCriteria(PartyContactMechanism.class);
    criteria.createCriteria("party").add(Restrictions.eq("partyId", p.getPartyId()));
    List partyContactMechList = criteria.list();
            
    assertEquals(1, partyContactMechList.size());
    PartyContactMechanism partyContactMechanism = ((PartyContactMechanism)partyContactMechList.toArray()[0]);
    final Party party = partyContactMechanism.getPerson();
    assertEquals(party.getPartyId(), p.getPartyId());
    assertEquals(partyContactMechanism.getContactMechanism().getType(), ContactMechanismType.Cache.POSTAL_ADDRESS.getEntity());
    assertEquals(partyContactMechanism.getPurposes().size(), 1);
    final PartyContactMechanismPurpose purpose = (PartyContactMechanismPurpose) partyContactMechanism.getPurposes().toArray()[0];
    assertEquals(purpose.getType(), ContactMechanismPurposeType.Cache.HOME_ADDRESS.getEntity());
    */
    // verify the contact mchanism data
    final PostalAddress ps = (PostalAddress) getSession().get(PostalAddress.class,
            address.getPostalAddressId());
    assertEquals(ps.getAddress1(), "123 Acme Road");
    assertEquals(ps.getAddress2(), "Suite 100");
    assertEquals(5, ps.getAddressBoundaries().size());
    assertEquals(ps.getCity().getCityName(), "Fairfax");
    assertEquals(ps.getState().getStateAbbreviation(), "VA");
    assertEquals(ps.getPostalCode().getCodeValue(), "22033");
    assertEquals(ps.getCounty().getCountyName(), "Fairfax County");
    assertEquals(ps.getCountry().getIsoThreeLetterCode(), "USA");

    final Set<PartyContactMechanism> pcmList = ps.getPartyContactMechanisms();
    assertEquals(1, pcmList.size());
    final PartyContactMechanism partyContactMechanism = (PartyContactMechanism) pcmList.toArray()[0];
    final Party party = partyContactMechanism.getParty();
    assertEquals(party.getPartyId(), p.getPartyId());
    assertEquals(partyContactMechanism.getContactMechanism().getType(),
            ContactMechanismType.Cache.POSTAL_ADDRESS.getEntity());
    assertEquals(partyContactMechanism.getPurposes().size(), 1);
    final PartyContactMechanismPurpose purpose = (PartyContactMechanismPurpose) partyContactMechanism
            .getPurposes().toArray()[0];
    assertEquals(purpose.getType(), ContactMechanismPurposeType.Cache.HOME_ADDRESS.getEntity());
}

From source file:com.chinamobile.bcbsp.io.db.TableInputFormatBase.java

/**
 * Calculates the splits that will serve as input for the map tasks. The
 * number of splits matches the number of regions in a table.
 * //www  . j  a v  a 2 s . co m
 * @param job
 *        The current job BSPJob.
 * @return The list of input splits.
 * @throws IOException
 *         When creating the list of splits fails.
 * @see org.apache.hadoop.mapreduce.InputFormat#getSplits
 *      (org.apache.hadoop.mapreduce.JobContext)
 */
// Changed by Zhicheng Liu
// 2013.4.16
// Reason: The code changes because of the new version of HBase 1.94.x
@Override
public List<InputSplit> getSplits(BSPJob job) throws IOException {
    if (table == null) {
        throw new IOException("No table was provided.");
    }
    Set<byte[]> set = table.getTableDescriptor().getFamiliesKeys();
    if (set.size() == 0) {
        throw new IOException("Expecting at least one record.");
    }
    ResultScanner sc = table.getScanner((byte[]) set.toArray()[0]);
    Pair<byte[][], byte[][]> keys = table.getStartEndKeys();
    List<InputSplit> splits = new ArrayList<InputSplit>(keys.getFirst().length);
    String regionLocation = null;
    String tmpLocation = null;
    byte[] startRow = null;
    byte[] endRow = null;
    for (Result r : sc) {
        // tmpLocation = table.getRegionLocation(new
        // String(r.getRow())).getHostName();
        tmpLocation = table.getRegionLocation(new String(r.getRow())).getRegionInfo().getRegionNameAsString();
        if (startRow == null) {
            startRow = r.getRow();
            regionLocation = tmpLocation;
        }
        if (tmpLocation.equals(regionLocation)) {
            endRow = r.getRow();
        } else {
            InputSplit split = new TableSplit(table.getTableName(), startRow, endRow, regionLocation);
            splits.add(split);
            startRow = r.getRow();
            regionLocation = tmpLocation;
            endRow = r.getRow();
        }
    }
    InputSplit split = new TableSplit(table.getTableName(), startRow, endRow, regionLocation);
    splits.add(split);
    return splits;
}

From source file:it.unibo.alchemist.language.protelis.datatype.ArrayTupleImpl.java

@Override
public Tuple union(final Tuple t) {
    final Set<Object> l = new HashSet<>(Arrays.asList(a));
    for (final Object o : t) {
        l.add(o);/*from   w  w w. j  a v a 2  s.  c  om*/
    }
    return Tuples.create(l.toArray());
}

From source file:it.unibo.alchemist.language.protelis.datatype.ArrayTupleImpl.java

@Override
public Tuple subtract(final Tuple t) {
    final Set<Object> l = new HashSet<>(Arrays.asList(a));
    for (final Object o : t) {
        l.remove(o);/*from w  w w  .  j a v  a 2  s . c  om*/
    }
    return Tuples.create(l.toArray());
}

From source file:com.wesley.urban_cuts.client.urbancuts.barber.Report.java

private void populate_combo_boxes() {

    // populate barber combo box
    List<Payment> allPayments = paymentCrudService.findAll();
    ArrayList<String> barbers = new ArrayList<>();

    for (int i = 0; i < paymentCrudService.count(); i++) {
        barbers.add(allPayments.get(i).getBarber_name());
    }/*from   w  w w. ja v  a 2s .  com*/
    barbers.toArray();
    Set<String> barb = (Set<String>) new LinkedHashSet<>(barbers);

    jComboBox1.setModel(new DefaultComboBoxModel(barb.toArray()));

    // populate month combo box
    months = new ArrayList<>();
    months.add("Jan");
    months.add("Feb");
    months.add("Mar");
    months.add("Apr");
    months.add("May");
    months.add("Jun");
    months.add("Jul");
    months.add("Aug");
    months.add("Sept");
    months.add("Oct");
    months.add("Nov");
    months.add("Dec");

    jComboBox2.setModel(new DefaultComboBoxModel(months.toArray()));
}