List of usage examples for java.util HashMap isEmpty
public boolean isEmpty()
From source file:org.apache.axis2.engine.MessageContextSaveCTest.java
private boolean compareMCTable(OperationContext oc1, OperationContext oc2) { String title = "compareMCTable: "; if ((oc1 != null) && (oc2 != null)) { HashMap mcTable1 = oc1.getMessageContexts(); HashMap mcTable2 = oc2.getMessageContexts(); if ((mcTable1 != null) && (mcTable2 != null)) { if ((!mcTable1.isEmpty()) && (!mcTable2.isEmpty())) { int size1 = mcTable1.size(); int size2 = mcTable2.size(); if (size1 != size2) { log.debug(title + " Return FALSE: table sizes don't match size1[" + size1 + "] != size2 [" + size2 + "] "); return false; }/*from www . j ava2s .c om*/ Iterator it1 = mcTable1.keySet().iterator(); while (it1.hasNext()) { String key1 = (String) it1.next(); MessageContext mc1 = (MessageContext) mcTable1.get(key1); MessageContext mc2 = (MessageContext) mcTable2.get(key1); if ((mc1 != null) && (mc2 != null)) { // check the IDs String id1 = mc1.getMessageID(); String id2 = mc2.getMessageID(); if ((id1 != null) && (id2 != null)) { if (!id1.equals(id2)) { log.debug(title + " Return FALSE: message IDs don't match id1[" + id1 + "] != id2 [" + id2 + "] "); return false; } } else if ((id1 == null) && (id2 == null)) { // can't tell, keep going } else { // mismatch log.debug(title + " Return FALSE: message IDs don't match id1[" + id1 + "] != id2 [" + id2 + "] "); return false; } } else if ((mc1 == null) && (mc2 == null)) { // entries match } else { // mismatch log.debug(title + " Return FALSE: message context objects don't match "); return false; } } log.debug(title + " Return TRUE: message context tables match"); return true; } else if (mcTable1.isEmpty() && mcTable2.isEmpty()) { log.debug(title + " Return TRUE: message context tables are both empty "); return true; } else { log.debug(title + " Return FALSE: message context tables mismatch"); return false; } } else if ((mcTable1 == null) && (mcTable2 == null)) { log.debug(title + " Return TRUE: message context tables are null"); return true; } else { log.debug(title + " Return FALSE: message context tables don't match"); return false; } } else if ((oc1 == null) && (oc2 == null)) { log.debug(title + " Return TRUE: operation context objects are null "); return true; } else { log.debug(title + " Return FALSE: operation context objects don't match "); return false; } }
From source file:org.archive.modules.recrawl.wbm.WbmPersistLoadProcessor.java
protected HashMap<String, Object> getLastCrawl(InputStream is) throws IOException { // read CDX lines, save most recent (at the end) hash. ByteBuffer buffer = ByteBuffer.allocate(32); ByteBuffer tsbuffer = ByteBuffer.allocate(14); int field = 0; int c;//from w w w .ja v a 2 s . c om do { c = is.read(); if (field == 1) { // 14-digits timestamp tsbuffer.clear(); while (Character.isDigit(c) && tsbuffer.remaining() > 0) { tsbuffer.put((byte) c); c = is.read(); } if (c != ' ' || tsbuffer.position() != 14) { tsbuffer.clear(); } // fall through to skip the rest } else if (field == 5) { buffer.clear(); while ((c >= 'A' && c <= 'Z' || c >= '0' && c <= '9') && buffer.remaining() > 0) { buffer.put((byte) c); c = is.read(); } if (c != ' ' || buffer.position() != 32) { buffer.clear(); } // fall through to skip the rest } while (true) { if (c == -1) { break; } else if (c == '\n') { field = 0; break; } else if (c == ' ') { field++; break; } c = is.read(); } } while (c != -1); HashMap<String, Object> info = new HashMap<String, Object>(); if (buffer.remaining() == 0) { info.put(RecrawlAttributeConstants.A_CONTENT_DIGEST, contentDigestScheme + new String(buffer.array())); } if (tsbuffer.remaining() == 0) { try { long ts = DateUtils.parse14DigitDate(new String(tsbuffer.array())).getTime(); // A_TIMESTAMP has been used for sorting history long before A_FETCH_BEGAN_TIME // field was introduced. Now FetchHistoryProcessor fails if A_FETCH_BEGAN_TIME is // not set. We could stop storing A_TIMESTAMP and sort by A_FETCH_BEGAN_TIME. info.put(FetchHistoryHelper.A_TIMESTAMP, ts); info.put(CoreAttributeConstants.A_FETCH_BEGAN_TIME, ts); } catch (ParseException ex) { } } return info.isEmpty() ? null : info; }
From source file:org.apache.ojb.broker.ant.PreparedModel.java
/** * Extracts indirection tables from the given class descriptor, and adds elements * for them. In contrast to normal elements, for indirection tables the element name * matches the table name, and the attribute names match the column names. * /*from www . j ava 2 s. com*/ * @param model The model * @param elements The elements */ private void extractIndirectionTables(DescriptorRepository model, Database schema) { HashMap indirectionTables = new HashMap(); // first we gather all participants for each m:n relationship for (Iterator classDescIt = model.getDescriptorTable().values().iterator(); classDescIt.hasNext();) { ClassDescriptor classDesc = (ClassDescriptor) classDescIt.next(); for (Iterator collDescIt = classDesc.getCollectionDescriptors().iterator(); collDescIt.hasNext();) { CollectionDescriptor collDesc = (CollectionDescriptor) collDescIt.next(); String indirTable = collDesc.getIndirectionTable(); if ((indirTable != null) && (indirTable.length() > 0)) { Set columns = (Set) indirectionTables.get(indirTable); if (columns == null) { columns = new HashSet(); indirectionTables.put(indirTable, columns); } columns.addAll(Arrays.asList(collDesc.getFksToThisClass())); columns.addAll(Arrays.asList(collDesc.getFksToItemClass())); } } } if (indirectionTables.isEmpty()) { // nothing to do return; } for (Iterator it = indirectionTables.keySet().iterator(); it.hasNext();) { String tableName = (String) it.next(); Set columns = (Set) indirectionTables.get(tableName); String elementName = tableName; for (Iterator classDescIt = model.getDescriptorTable().values().iterator(); classDescIt.hasNext();) { ClassDescriptor classDesc = (ClassDescriptor) classDescIt.next(); if (tableName.equals(classDesc.getFullTableName())) { elementName = getElementName(classDesc); FieldDescriptor[] fieldDescs = classDesc.getFieldDescriptions(); if (fieldDescs != null) { for (int idx = 0; idx < fieldDescs.length; idx++) { columns.remove(fieldDescs[idx].getColumnName()); } } } } Table mappedTable = getTableFor(elementName); Map columnsMap = getColumnsFor(elementName); Map requiredAttributes = getRequiredAttributes(elementName); if (mappedTable == null) { mappedTable = schema.findTable(elementName); if (mappedTable == null) { continue; } columnsMap = new TreeMap(); requiredAttributes = new HashMap(); _elementToTable.put(elementName, mappedTable); _elementToColumnMap.put(elementName, columnsMap); _elementToRequiredAttributesMap.put(elementName, requiredAttributes); } for (Iterator columnIt = columns.iterator(); columnIt.hasNext();) { String columnName = (String) columnIt.next(); Column column = mappedTable.findColumn(columnName); if (column != null) { columnsMap.put(columnName, column); requiredAttributes.put(columnName, Boolean.TRUE); } } } }
From source file:com.ibm.bi.dml.hops.ipa.InterProceduralAnalysis.java
/** * //from w w w . jav a 2s .co m * @param dmlp * @throws HopsException */ private void removeConstantBinaryOps(DMLProgram dmlp) throws HopsException { //approach: scan over top-level program (guaranteed to be unconditional), //collect ones=matrix(1,...); remove b(*)ones if not outer operation HashMap<String, Hop> mOnes = new HashMap<String, Hop>(); for (StatementBlock sb : dmlp.getStatementBlocks()) { //pruning updated variables for (String var : sb.variablesUpdated().getVariableNames()) if (mOnes.containsKey(var)) mOnes.remove(var); //replace constant binary ops if (!mOnes.isEmpty()) rRemoveConstantBinaryOp(sb, mOnes); //collect matrices of ones from last-level statement blocks if (!(sb instanceof IfStatementBlock || sb instanceof WhileStatementBlock || sb instanceof ForStatementBlock)) { collectMatrixOfOnes(sb.get_hops(), mOnes); } } }
From source file:com.google.android.apps.gutenberg.provider.SyncAdapter.java
private ContentValues[] parseAttendees(String eventId, JSONArray attendees) throws JSONException { int length = attendees.length(); ContentValues[] array = new ContentValues[length]; HashMap<String, String> imageUrls = new HashMap<>(); for (int i = 0; i < length; ++i) { JSONObject attendee = attendees.getJSONObject(i); array[i] = new ContentValues(); array[i].put(Table.Attendee.EVENT_ID, eventId); array[i].put(Table.Attendee.NAME, attendee.getString("name")); array[i].put(Table.Attendee.ID, attendee.getString("id")); array[i].put(Table.Attendee.EMAIL, attendee.getString("email")); String plusid = attendee.getString("plusid"); if (!TextUtils.isEmpty(plusid)) { array[i].put(Table.Attendee.PLUSID, plusid); imageUrls.put(plusid, "null"); }// w w w . ja v a2 s. c om long checkinTime = attendee.getLong("checkinTime"); if (0 == checkinTime) { array[i].putNull(Table.Attendee.CHECKIN); } else { array[i].put(Table.Attendee.CHECKIN, checkinTime); } array[i].putNull(Table.Attendee.IMAGE_URL); } // Fetch all the Google+ Image URLs at once if necessary if (mApiClient != null && mApiClient.isConnected() && !imageUrls.isEmpty()) { People.LoadPeopleResult result = Plus.PeopleApi.load(mApiClient, imageUrls.keySet()).await(); PersonBuffer personBuffer = result.getPersonBuffer(); if (personBuffer != null) { // Copy URLs into the HashMap for (Person person : personBuffer) { if (person.hasImage()) { imageUrls.put(extractId(person.getUrl()), person.getImage().getUrl()); } } // Fill the missing URLs in the array of ContentValues for (ContentValues values : array) { if (values.containsKey(Table.Attendee.PLUSID)) { String plusId = values.getAsString(Table.Attendee.PLUSID); String imageUrl = imageUrls.get(plusId); if (!TextUtils.isEmpty(imageUrl)) { values.put(Table.Attendee.IMAGE_URL, imageUrl); } } } } } return array; }
From source file:it.gmariotti.cardslib.library.view.CardViewNative.java
/** * Setup All listeners/*from ww w . j ava 2 s .c o m*/ */ @SuppressWarnings("deprecation") @SuppressLint("NewApi") protected void setupListeners() { //Swipe listener if (mCard.isSwipeable()) { this.setOnTouchListener(new SwipeDismissViewTouchListener(this, mCard, new SwipeDismissViewTouchListener.DismissCallbacks() { @Override public boolean canDismiss(Card card) { return card.isSwipeable(); } @Override public void onDismiss(CardViewWrapper cardView, Card card) { final ViewGroup vg = (ViewGroup) (((View) cardView).getParent()); if (vg != null) { vg.removeView((View) cardView); card.onSwipeCard(); } } })); } else { this.setOnTouchListener(null); } //OnClick listeners and partial listener //Reset Partial Listeners resetPartialListeners(); if (mCard.isClickable()) { //Set the onClickListener if (!mCard.isMultiChoiceEnabled()) { if (mCard.getOnClickListener() != null) { this.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mCard.getOnClickListener() != null) mCard.getOnClickListener().onClick(mCard, v); } }); //Prevent multiple events //if (!mCard.isSwipeable() && mCard.getOnSwipeListener() == null) { // this.setClickable(true); //} } else { HashMap<Integer, Card.OnCardClickListener> mMultipleOnClickListner = mCard .getMultipleOnClickListener(); if (mMultipleOnClickListner != null && !mMultipleOnClickListner.isEmpty()) { for (int key : mMultipleOnClickListner.keySet()) { View viewClickable = decodeAreaOnClickListener(key); final Card.OnCardClickListener mListener = mMultipleOnClickListner.get(key); if (viewClickable != null) { //Add listener to this view viewClickable.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //Callback to card listener if (mListener != null) mListener.onClick(mCard, v); } }); //Add Selector to this view if (key > Card.CLICK_LISTENER_ALL_VIEW) { mHelperImpl.setBackground(viewClickable, mHelperImpl.getResourceFromAttrs( getContext(), android.R.attr.selectableItemBackground)); } } } } else { //There aren't listners this.setClickable(false); } } } } else { this.setClickable(false); } //LongClick listener if (mCard.isLongClickable()) { this.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { if (mCard.getOnLongClickListener() != null) return mCard.getOnLongClickListener().onLongClick(mCard, v); return false; } }); } else { this.setLongClickable(false); } }
From source file:com.google.gwt.emultest.java.util.HashMapTest.java
public void testIteration_withCollidingHashCodesAndFullIteration() { List<Object> keys = new ArrayList<>(); HashMap<Object, String> testMap = new HashMap<>(); for (int i = 0; i < 100; i++) { Object key = createObjectWithHashCode((i + 10) / 10); keys.add(key);//from ww w.ja va 2s .c o m testMap.put(key, "" + i); } int expectedSize = keys.size(); for (Iterator<Object> it = testMap.keySet().iterator(); it.hasNext(); expectedSize--) { Object key = it.next(); assertTrue("Unexpected key was returned", keys.contains(key)); keys.remove(key); it.remove(); assertEquals("Map size", expectedSize - 1, testMap.size()); } assertEquals("expected size", 0, expectedSize); assertTrue(testMap.isEmpty()); assertTrue(keys.isEmpty()); }
From source file:org.apache.sysml.hops.ipa.InterProceduralAnalysis.java
private void removeConstantBinaryOps(DMLProgram dmlp) throws HopsException { //approach: scan over top-level program (guaranteed to be unconditional), //collect ones=matrix(1,...); remove b(*)ones if not outer operation HashMap<String, Hop> mOnes = new HashMap<String, Hop>(); for (StatementBlock sb : dmlp.getStatementBlocks()) { //pruning updated variables for (String var : sb.variablesUpdated().getVariableNames()) if (mOnes.containsKey(var)) mOnes.remove(var); //replace constant binary ops if (!mOnes.isEmpty()) rRemoveConstantBinaryOp(sb, mOnes); //collect matrices of ones from last-level statement blocks if (!(sb instanceof IfStatementBlock || sb instanceof WhileStatementBlock || sb instanceof ForStatementBlock)) { collectMatrixOfOnes(sb.get_hops(), mOnes); }/*from w ww.jav a 2s. c om*/ } }
From source file:UnitTest2.java
public static void testAddJar() throws IOException, DScabiException, ExecutionException, InterruptedException { String action = "dao = new Dao(@localhost@, @27017@, @MetaDB@);" + "dao.setTableName(@ComputeMetaDataTable@);" + "jsonQuery = @{ @@Status@@ : @@Available@@, @@ComputePort@@ : @@4568@@ }@;" + "jsonResult = dao.executeQuery(jsonQuery);" + "return jsonResult;"; String action2 = "import test.TestNew;" + "t = new TestNew();" + "dao = new Dao(@localhost@, @27017@, @MetaDB@);" + "dao.setTableName(@ComputeMetaDataTable@);" + "jsonQuery = @{ @@Status@@ : @@Available@@, @@ComputePort@@ : @@4568@@ }@;" + "jsonResult = dao.executeQuery(jsonQuery);" + "return @Result1 : @ + t.compute(null) + @ Result2: @ + jsonResult;"; DMeta meta = new DMeta("localhost", "5000"); long time1 = System.currentTimeMillis(); //String primeresult = cu2.compute(Dson.dummyDson()); //String primeresult = c.executeObject(cu2); DComputeAsync c = new DComputeAsync(meta); DComputeUnit cu2 = new DComputeUnit() { public String compute(Dson jsonInput) { //System.out.println("compute() Testing 2 in remote. I'm from CU class from CNS"); return "Hello from this Compute Unit, CU #" + jsonInput.getCU(); }// ww w . java2 s. c o m }; HashMap<String, String> out1 = new HashMap<String, String>(); HashMap<String, String> out2 = new HashMap<String, String>(); HashMap<String, String> out3 = new HashMap<String, String>(); HashMap<String, String> out4 = new HashMap<String, String>(); //works c.executeObject(cu2).input(Dson.empty()).maxSplit(5000).output(out1); //c.executeObject(cu2).input(Dson.empty()).maxSplit(100000).output(out1); //c.executeObject(cu2).input(Dson.empty()).maxSplit(25).output(out1); //c.executeClass(CU.class).input(Dson.empty()).maxSplit(100).output(out2); //c.executeClass(cu2.getClass()).input(Dson.empty()).maxSplit(2).output(out).perform(); //c.executeCode(action).input(Dson.empty()).maxSplit(7).output(out3); //c.executeObject(cu2).input(Dson.empty()).split(15).output(out1); /* c.executeObject(cu2).input(Dson.empty()).split(2).output(out1); c.executeClass(CU.class).input(Dson.empty()).split(5).output(out2); //c.executeClass(cu2.getClass()).input(Dson.empty()).maxSplit(2).output(out).perform(); c.executeCode(action).input(Dson.empty()).split(7).splitRange(2, 6).output(out3); c.executeClassNameInJar("/home/anees/self/test.jar", "TestNew").split(3).output(out4); c.perform(); c.finish(); */ /* c.addJar("/home/anees/self/test.jar"); c.executeClass(CU.class).input(Dson.empty()).split(5).output(out1); c.perform(); c.finish(); c.addJar("/home/anees/self/test.jar"); c.executeObject(cu2).input(Dson.empty()).split(2).output(out2); c.perform(); c.finish(); c.addJar("/home/anees/self/test.jar"); c.executeCode(action2).input(Dson.empty()).split(4).output(out3); c.perform(); c.finish(); */ c.addJar("/home/anees/self/test.jar"); c.executeJar("/home/anees/self/test.jar", "TestNew").split(3).output(out4); c.perform(); c.finish(); //try {Thread.currentThread().sleep(20000);} //catch (Exception e) { } if (out1.isEmpty()) System.out.println("out1 is empty"); Set<String> st1 = out1.keySet(); for (String s : st1) { log.debug("out1 for s : {} value : {}", s, out1.get(s)); //System.out.println("out1 s : " + s + " value : " + out1.get(s)); } if (out2.isEmpty()) System.out.println("out2 is empty"); Set<String> st2 = out2.keySet(); for (String s : st2) { log.debug("out2 for s : {} value : {}", s, out2.get(s)); } if (out3.isEmpty()) System.out.println("out3 is empty"); Set<String> st3 = out3.keySet(); for (String s : st3) { log.debug("out3 for s : {} value : {}", s, out3.get(s)); } if (out4.isEmpty()) System.out.println("out4 is empty"); Set<String> st4 = out4.keySet(); for (String s : st4) { log.debug("out4 for s : {} value : {}", s, out4.get(s)); } long time2 = System.currentTimeMillis(); //log.debug("prime number check result : {}", primeresult); //log.debug("Last prime number : {}", primeresult); log.debug("Time taken : {}", time2 - time1); System.out.println("Time taken : " + (time2 - time1)); }
From source file:edu.mit.ll.graphulo.pig.backend.GraphuloOneTableStorage.java
@Override protected Tuple getTuple(Key key, Value value) throws IOException { SortedMap<Key, Value> rowKVs = WholeRowIterator.decodeRow(key, value); Tuple tuple = TupleFactory.getInstance().newTuple(columns.size() + 1); final Text cfHolder = new Text(); final Text cqHolder = new Text(); final Text row = key.getRow(); int tupleOffset = 0; tuple.set(tupleOffset, new DataByteArray(Text.decode(row.getBytes(), 0, row.getLength()))); for (Column column : this.columns) { tupleOffset++;/*from ww w. j av a 2 s. com*/ switch (column.getType()) { case LITERAL: cfHolder.set(column.getColumnFamily()); if (null != column.getColumnQualifier()) { cqHolder.set(column.getColumnQualifier()); } else { cqHolder.set(EMPTY_TEXT); } // Get the key where our literal would exist (accounting for // "colf:colq" or "colf:" empty colq) Key literalStartKey = new Key(row, cfHolder, cqHolder); SortedMap<Key, Value> tailMap = rowKVs.tailMap(literalStartKey); // Find the element if (tailMap.isEmpty()) { tuple.set(tupleOffset, EMPTY_DATA_BYTE_ARRAY); } else { Key actualKey = tailMap.firstKey(); // Only place it in the tuple if it matches the user // request, avoid using a value from a // key with the wrong colqual if (0 == literalStartKey.compareTo(actualKey, PartialKey.ROW_COLFAM_COLQUAL)) { tuple.set(tupleOffset, new DataByteArray(tailMap.get(actualKey).get())); } else { // This row doesn't have the column we were looking for tuple.set(tupleOffset, EMPTY_DATA_BYTE_ARRAY); } } break; case COLFAM_PREFIX: cfHolder.set(column.getColumnFamily()); Range colfamPrefixRange = Range.prefix(row, cfHolder); Key colfamPrefixStartKey = new Key(row, cfHolder); SortedMap<Key, Value> cfTailMap = rowKVs.tailMap(colfamPrefixStartKey); // Find the element if (cfTailMap.isEmpty()) { tuple.set(tupleOffset, EMPTY_DATA_BYTE_ARRAY); } else { HashMap<String, DataByteArray> tupleMap = new HashMap<String, DataByteArray>(); // Build up a map for all the entries in this row that match // the colfam prefix for (Entry<Key, Value> entry : cfTailMap.entrySet()) { if (colfamPrefixRange.contains(entry.getKey())) { entry.getKey().getColumnFamily(cfHolder); entry.getKey().getColumnQualifier(cqHolder); DataByteArray val = new DataByteArray(entry.getValue().get()); // Avoid adding an extra ':' when colqual is empty if (0 == cqHolder.getLength()) { tupleMap.put(cfHolder.toString(), val); } else { tupleMap.put(cfHolder.toString() + COLON + cqHolder.toString(), val); } } else { break; } } if (!tupleMap.isEmpty()) { tuple.set(tupleOffset, tupleMap); } } break; case COLQUAL_PREFIX: cfHolder.set(column.getColumnFamily()); cqHolder.set(column.getColumnQualifier()); Range colqualPrefixRange = Range.prefix(row, cfHolder, cqHolder); Key colqualPrefixStartKey = new Key(row, cfHolder, cqHolder); SortedMap<Key, Value> cqTailMap = rowKVs.tailMap(colqualPrefixStartKey); if (cqTailMap.isEmpty()) { tuple.set(tupleOffset, EMPTY_DATA_BYTE_ARRAY); } else { HashMap<String, DataByteArray> tupleMap = new HashMap<String, DataByteArray>(); // Build up a map for all the entries in this row that match // the colqual prefix for (Entry<Key, Value> entry : cqTailMap.entrySet()) { if (colqualPrefixRange.contains(entry.getKey())) { entry.getKey().getColumnFamily(cfHolder); entry.getKey().getColumnQualifier(cqHolder); DataByteArray val = new DataByteArray(entry.getValue().get()); // Avoid the extra ':' on empty colqual if (0 == cqHolder.getLength()) { tupleMap.put(cfHolder.toString(), val); } else { tupleMap.put(cfHolder.toString() + COLON + cqHolder.toString(), val); } } else { break; } } if (!tupleMap.isEmpty()) { tuple.set(tupleOffset, tupleMap); } } break; default: break; } } return tuple; }