当前位置: 首页>>代码示例>>Java>>正文


Java GenericTypeIndicator类代码示例

本文整理汇总了Java中com.google.firebase.database.GenericTypeIndicator的典型用法代码示例。如果您正苦于以下问题:Java GenericTypeIndicator类的具体用法?Java GenericTypeIndicator怎么用?Java GenericTypeIndicator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GenericTypeIndicator类属于com.google.firebase.database包,在下文中一共展示了GenericTypeIndicator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: convertToCustomClass

import com.google.firebase.database.GenericTypeIndicator; //导入依赖的package包/类
/**
 * Converts a standard library Java representation of JSON data to an object of the class provided
 * through the GenericTypeIndicator
 *
 * @param object The representation of the JSON data
 * @param typeIndicator The indicator providing class of the object to convert to
 * @return The POJO object.
 */
public static <T> T convertToCustomClass(Object object, GenericTypeIndicator<T> typeIndicator) {
  Class<?> clazz = typeIndicator.getClass();
  Type genericTypeIndicatorType = clazz.getGenericSuperclass();
  if (genericTypeIndicatorType instanceof ParameterizedType) {
    ParameterizedType parameterizedType = (ParameterizedType) genericTypeIndicatorType;
    if (!parameterizedType.getRawType().equals(GenericTypeIndicator.class)) {
      throw new DatabaseException(
          "Not a direct subclass of GenericTypeIndicator: " + genericTypeIndicatorType);
    }
    // We are guaranteed to have exactly one type parameter
    Type type = parameterizedType.getActualTypeArguments()[0];
    return deserializeToType(object, type);
  } else {
    throw new DatabaseException(
        "Not a direct subclass of GenericTypeIndicator: " + genericTypeIndicatorType);
  }
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:26,代码来源:CustomClassMapper.java

示例2: testMultipleWriteValuesReconnectRead

import com.google.firebase.database.GenericTypeIndicator; //导入依赖的package包/类
@Test
public void testMultipleWriteValuesReconnectRead()
    throws ExecutionException, TimeoutException, InterruptedException, TestFailure {
  List<DatabaseReference> refs = IntegrationTestUtils.getRandomNode(masterApp, 2);
  final DatabaseReference writer = refs.get(0);
  final DatabaseReference reader = refs.get(1);

  writer.child("a").child("b").child("c").setValueAsync(1);
  writer.child("a").child("d").child("e").setValueAsync(2);
  writer.child("a").child("d").child("f").setValueAsync(3);
  WriteFuture writeFuture = new WriteFuture(writer.child("g"), 4);
  writeFuture.timedGet();

  Map<String, Object> expected = new MapBuilder()
      .put("a",
          new MapBuilder().put("b", new MapBuilder().put("c", 1L).build())
              .put("d", new MapBuilder().put("e", 2L).put("f", 3L).build()).build())
      .put("g", 4L).build();
  ReadFuture readFuture = new ReadFuture(reader);

  GenericTypeIndicator<Map<String, Object>> t = new GenericTypeIndicator<Map<String, Object>>() {
  };
  Map<String, Object> result = readFuture.timedGet().get(0).getSnapshot().getValue(t);
  TestHelpers.assertDeepEquals(expected, result);
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:26,代码来源:DataTestIT.java

示例3: retrieveDeckFromFirebaseDb

import com.google.firebase.database.GenericTypeIndicator; //导入依赖的package包/类
private void retrieveDeckFromFirebaseDb(String key) {
    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference databaseReference = database.getReference(FirebaseDb.DECK_KEY + "/" + key);
    databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            GenericTypeIndicator<Deck> t = new GenericTypeIndicator<Deck>() {
            };

            Deck deck = dataSnapshot.getValue(t);
            if (deck != null) {
                deck.setFirebaseKey(dataSnapshot.getKey()); // firebase reference for tracking following status
                decks.add(deck);
            }
            onDeckLoadedOrFailed();
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            Logger.w(TAG, "loadPost:onCancelled", databaseError.toException());
            onDeckLoadedOrFailed();
        }
    });
}
 
开发者ID:unparalleled,项目名称:kcards,代码行数:25,代码来源:FavoritesDeckListActivity.java

示例4: updateChartReference

import com.google.firebase.database.GenericTypeIndicator; //导入依赖的package包/类
private void updateChartReference(final String mealKey, final PieChart chart) {
    DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference().child("meals").child(mealKey);

    mDatabase.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            GenericTypeIndicator<Map<String, Integer>> t = new GenericTypeIndicator<Map<String, Integer>>() {};
            Map<String, Integer> ratings = dataSnapshot.child("ratings").getValue(t);
            if( ratings == null ) {
                clearChartData(chart);
            }
            else {
                setChartData(chart, calculateRatings(ratings));
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
}
 
开发者ID:kaiomax,项目名称:RUSpotlight,代码行数:23,代码来源:StatisticsFragment.java

示例5: findLastMilestone

import com.google.firebase.database.GenericTypeIndicator; //导入依赖的package包/类
public void findLastMilestone(final OneMilestoneReceivedListener listener){
    final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    if(user!=null) {
        mDatabase.child(Constants.FIREBASE_MILESTONES).child(user.getUid()).child(SessionSingleton.getInstance().currentCar.getid()).limitToLast(1).addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                GenericTypeIndicator<Map<String,Milestone>> indicator = new GenericTypeIndicator<Map<String, Milestone>>() {};
                Map<String, Milestone> map = dataSnapshot.getValue(indicator);
                if (map != null) {
                    final Milestone m = map.get(map.keySet().iterator().next());
                    Log.e("DataSnapshot", m.toString());
                    listener.onMilestoneReceived(m);
                } else {
                    listener.onMilestoneReceived(null);
                }


            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
                listener.onCancelled(databaseError);
            }
        });
    }
}
 
开发者ID:Gaso-UFS,项目名称:gaso,代码行数:27,代码来源:MilestoneDAO.java

示例6: toAgendaSection

import com.google.firebase.database.GenericTypeIndicator; //导入依赖的package包/类
public static AgendaSection toAgendaSection(final DataSnapshot data) {
    final AgendaSection section = new AgendaSection();
    populateSection(data, section);
    Map<String, AgendaItem> items = data.child("items").getValue(new GenericTypeIndicator<Map<String, AgendaItem>>() {});
    if (items == null) {
        items = Collections.emptyMap();
    }

    // Force empty speaker list when null so the client doesn't have to
    // always check null.
    for (final Map.Entry<String, AgendaItem> entry : items.entrySet()) {
        if (entry.getValue().getSpeakerIds() == null) {
            entry.getValue().setSpeakerIds(Collections.<String>emptyList());
        }
    }

    section.setItems(items);
    return section;
}
 
开发者ID:CodingDoug,项目名称:white-label-event-app,代码行数:20,代码来源:FirebaseDatabaseHelpers.java

示例7: testDataChangesOfGenericTypeIndicator

import com.google.firebase.database.GenericTypeIndicator; //导入依赖的package包/类
@Test public void testDataChangesOfGenericTypeIndicator() {
  List<String> values = new ArrayList<>();
  values.add("Foo");
  values.add("Bar");

  GenericTypeIndicator<List<String>> typeIndicator = new GenericTypeIndicator<List<String>>() {
  };

  TestObserver<Optional<List<String>>> sub = TestObserver.create();

  RxFirebaseDatabase.dataChangesOf(mockDatabaseReference, typeIndicator).subscribe(sub);

  verifyAddValueEventListener();
  callValueEventOnDataChange(typeIndicator, values);

  sub.assertNotComplete();

  sub.assertValue(new Predicate<Optional<List<String>>>() {
    @Override public boolean test(Optional<List<String>> listOptional) throws Exception {
      return listOptional.isPresent() && "Foo".equals(listOptional.get().get(0)) && "Bar".equals(
          listOptional.get().get(1));
    }
  });

  sub.dispose();

  callValueEventOnDataChange(typeIndicator, values);

  // Ensure no more values are emitted after unsubscribe
  sub.assertValueCount(1);
}
 
开发者ID:b3er,项目名称:RxFirebase2,代码行数:32,代码来源:RxFirebaseDatabaseTest.java

示例8: testDataOfGenericTypeIndicator

import com.google.firebase.database.GenericTypeIndicator; //导入依赖的package包/类
@Test public void testDataOfGenericTypeIndicator() {
  List<String> values = new ArrayList<>();
  values.add("Foo");
  values.add("Bar");

  GenericTypeIndicator<List<String>> typeIndicator = new GenericTypeIndicator<List<String>>() {
  };

  TestObserver<Optional<List<String>>> sub = TestObserver.create();

  RxFirebaseDatabase.dataOf(mockDatabaseReference, typeIndicator).subscribe(sub);

  verifyAddListenerForSingleValueEvent();
  callValueEventOnDataChange(typeIndicator, values);

  sub.assertComplete();
  sub.assertNoErrors();

  sub.assertValue(new Predicate<Optional<List<String>>>() {
    @Override public boolean test(Optional<List<String>> listOptional) throws Exception {
      return listOptional.isPresent() && "Foo".equals(listOptional.get().get(0)) && "Bar".equals(
          listOptional.get().get(1));
    }
  });

  sub.dispose();

  callValueEventOnDataChange(typeIndicator, values);

  // Ensure no more values are emitted after unsubscribe
  sub.assertValueCount(1);
}
 
开发者ID:b3er,项目名称:RxFirebase2,代码行数:33,代码来源:RxFirebaseDatabaseTest.java

示例9: buscarPeloNome

import com.google.firebase.database.GenericTypeIndicator; //导入依赖的package包/类
/**
 * Este método cria um evento com a primeira agenda que corresponde ao nome no firebase,
 * mesmo que mais de um seja encontrada
 *
 * @param nomeAgenda nome da agenda que se deseja obter
 */
public void buscarPeloNome(String nomeAgenda) {
    getDatabaseReference()
        .child(DATABASE_CHILD)
        .orderByChild("nome")
        .equalTo(nomeAgenda)
        .addListenerForSingleValueEvent(
            new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    Log.w(TAG, "SNAPSHOT: " + dataSnapshot);
                    // Agenda agenda = dataSnapshot.getValue(Agenda.class);
                    GenericTypeIndicator<HashMap<String, Agenda>> t =
                        new GenericTypeIndicator<HashMap<String, Agenda>>() {
                        };
                    HashMap<String, Agenda> agendasEncontradas = dataSnapshot.getValue(t);

                    Iterator it = agendasEncontradas.values().iterator();

                    Agenda agenda = null;
                    if (it.hasNext()) {
                        agenda = (Agenda) it.next();
                        //Salva no objeto agenda o id do banco gerado pelo firebase
                        agenda.setId(agendasEncontradas.keySet().iterator().next());
                        Log.w(TAG, "agenda buscada pelo nome: " + agenda.getId());
                    } else {
                        Log.w(TAG, "agenda não encontrada");
                    }

                    EventBus.getDefault().post(agenda);
                }

                @Override
                public void onCancelled(DatabaseError databaseError) {
                    Log.e(TAG, "ValueListener: onCancelled:", databaseError.toException());
                    EventBus.getDefault().post(new DatabaseEvent<>(databaseError));
                }
            }
        );
}
 
开发者ID:Yuri-M-Dias,项目名称:HealthHelp,代码行数:46,代码来源:AgendaDAO.java

示例10: buscarPelaId

import com.google.firebase.database.GenericTypeIndicator; //导入依赖的package包/类
@Override
    public void buscarPelaId(String id) {
        getDatabaseReference()
            .child(DATABASE_CHILD)
            .orderByChild("id")
            .equalTo(id)
            .addListenerForSingleValueEvent(
                new ValueEventListener() {
                    @Override
                    public void onDataChange(DataSnapshot dataSnapshot) {
                        GenericTypeIndicator<HashMap<String, Usuario>> genericTypeIndicator =
                            new GenericTypeIndicator<HashMap<String, Usuario>>() {
                            };
                        HashMap<String, Usuario> usuarioHashMap = dataSnapshot.
                            getValue(genericTypeIndicator);
                        Usuario usuarioEncontrado = usuarioHashMap.values().iterator().next();
                        Log.w(TAG, "buscaPeloId.OnDataChange: o usuário encontrado foi: " +
                            usuarioEncontrado.getNome());

                        // chama de volta quem pediu o local que foi buscado
//                        getDatabaseCallback().onComplete(usuarioEncontrado);
                    }

                    @Override
                    public void onCancelled(DatabaseError databaseError) {
                        Log.e(TAG, "buscaPelaId: onCancelled:", databaseError.toException());
//                        getDatabaseCallback().onError(databaseError);
                    }
                }
            );
    }
 
开发者ID:Yuri-M-Dias,项目名称:HealthHelp,代码行数:32,代码来源:UsuarioDAO.java

示例11: construirObjetoFirebase

import com.google.firebase.database.GenericTypeIndicator; //导入依赖的package包/类
protected T construirObjetoFirebase(DataSnapshot snapshot) {
    T objetoEncontrado = null;
    GenericTypeIndicator tipoParaConverter = getTipoEntidadeConstrucao();
    if (tipoParaConverter != null) {
        objetoEncontrado = (T) snapshot.getValue(tipoParaConverter);
    } else {
        objetoEncontrado = snapshot.getValue(getTipoEntidade());
    }
    objetoEncontrado.setId(snapshot.getKey());
    return objetoEncontrado;
}
 
开发者ID:Yuri-M-Dias,项目名称:HealthHelp,代码行数:12,代码来源:AbstractDAO.java

示例12: initRecyclerView

import com.google.firebase.database.GenericTypeIndicator; //导入依赖的package包/类
private void initRecyclerView() {

        databaseReference.child("animals").orderByChild("userUid").equalTo(getArguments()
                .getString("userUid")).addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                if (dataSnapshot.getValue() != null) {
                    GenericTypeIndicator<HashMap<String, Animal>> objectGTI =
                            new GenericTypeIndicator<HashMap<String, Animal>>() {
                            };
                    Map<String, Animal> objectHashMap = dataSnapshot.getValue(objectGTI);
                    friends = new ArrayList<>(objectHashMap.values());
                }
                LinearLayoutManager llm = new LinearLayoutManager(getActivity());
                llm.setOrientation(LinearLayoutManager.VERTICAL);
                animalList.setLayoutManager(llm);
                RecyclerView.Adapter adapter = new RecyclerAnimalAdapter(friends);
                animalList.setAdapter(adapter);
                if (friends == null || friends.isEmpty()) {
                    animalListSeparator.setVisibility(View.GONE);
                    animalListWrapper.setVisibility(View.GONE);
                } else {
                    if(getActivity() != null) {
                        firstOption.setText(getActivity().getString(R.string.option) + " 1: " + firstOption.getText());
                        secondOption.setText(getActivity().getString(R.string.option) + " 2: " + secondOption.getText());
                    } else {
                        firstOption.setText("Option 1: " + firstOption.getText());
                        secondOption.setText("Option 2: " + secondOption.getText());
                    }
                }
                databaseReference.removeEventListener(this);
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
                Log.e("databaseError", String.valueOf(databaseError));
            }
        });
    }
 
开发者ID:juanjecilla,项目名称:FindMeAHome,代码行数:40,代码来源:AnimalSelectionDialogFrament.java

示例13: findStationEvaluationById

import com.google.firebase.database.GenericTypeIndicator; //导入依赖的package包/类
public void findStationEvaluationById(String stationId, final OneStationEvaluationReceivedListener listener) {
    mDatabase.child(Constants.FIREBASE_STATIONS_EVALUATIONS).child(stationId).addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            GenericTypeIndicator<HashMap<String,GeneralStationEvaluation>> indicator = new GenericTypeIndicator<HashMap<String, GeneralStationEvaluation>>() {};
            HashMap<String,GeneralStationEvaluation> evaluation = dataSnapshot.getValue(indicator);
            listener.onStationEvaluationReceived(evaluation);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            listener.onCancelled(databaseError);
        }
    });
}
 
开发者ID:Gaso-UFS,项目名称:gaso,代码行数:16,代码来源:StationEvaluationDAO.java

示例14: dataChangesOf

import com.google.firebase.database.GenericTypeIndicator; //导入依赖的package包/类
/**
 * @param ref
 * @param typeIndicator
 * @param <T>
 * @return
 */
@NonNull
@CheckReturnValue
public static <T> Observable<DataValue<T>> dataChangesOf(
        @NonNull DatabaseReference ref, @NonNull GenericTypeIndicator<T> typeIndicator) {
    return dataChanges(ref)
            .compose(new TransformerOfGenericTypeIndicator<T>(typeIndicator));
}
 
开发者ID:yongjhih,项目名称:rxfirebase,代码行数:14,代码来源:RxFirebaseDatabase.java

示例15: dataOf

import com.google.firebase.database.GenericTypeIndicator; //导入依赖的package包/类
/**
 * @param ref
 * @param typeIndicator
 * @param <T>
 * @return
 */
@NonNull
@CheckReturnValue
public static <T> Single<T> dataOf(
        @NonNull DatabaseReference ref, @NonNull GenericTypeIndicator<T> typeIndicator) {
    return data(ref).compose(new SingleTransformerOfGenericTypeIndicator<T>(typeIndicator));
}
 
开发者ID:yongjhih,项目名称:rxfirebase,代码行数:13,代码来源:RxFirebaseDatabase.java


注:本文中的com.google.firebase.database.GenericTypeIndicator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。