use of oop.JOOP46_Collections_Part01.Product in project java-notes by esalkan.
the class HashSetOfProducts method main.
/**
* @param args
*/
public static void main(String[] args) {
Set<Product> prodSet = new TreeSet<>();
// Add product to prodSet via Product Class
prodSet.add(new Product("book", 25.99));
prodSet.add(new Product("book", 19.99));
prodSet.add(new Product("magazine", 7.99));
prodSet.add(new Product("phone", 100));
System.out.println(prodSet.toString());
// print each product by using for each loop
for (Product product : prodSet) {
System.out.println(product.getPrice());
}
// print each product by using forEach method
prodSet.forEach(x -> System.out.println(x.getName()));
// prodSet.forEach(product -> System.out.println(product));
}
use of oop.JOOP46_Collections_Part01.Product in project java-retail by googleapis.
the class RemoveTestResources method deleteAllProducts.
public static void deleteAllProducts() throws IOException {
System.out.println("Deleting products in process, please wait...");
try (ProductServiceClient productServiceClient = ProductServiceClient.create()) {
ListProductsRequest listRequest = ListProductsRequest.newBuilder().setParent(DEFAULT_CATALOG).build();
ListProductsPagedResponse products = productServiceClient.listProducts(listRequest);
int deleteCount = 0;
for (Product product : products.iterateAll()) {
DeleteProductRequest deleteRequest = DeleteProductRequest.newBuilder().setName(product.getName()).build();
try {
productServiceClient.deleteProduct(deleteRequest);
deleteCount++;
} catch (PermissionDeniedException e) {
System.out.println("Ignore PermissionDenied in case the product does not exist " + "at time of deletion.");
}
}
System.out.printf("%s products were deleted from %s%n", deleteCount, DEFAULT_CATALOG);
}
}
use of oop.JOOP46_Collections_Part01.Product in project narchy by automenta.
the class BooleanChallenge method event.
@Override
public void event(Class event, Object[] arguments) {
if (!(arguments[0] instanceof Task))
return;
Task answer = (Task) arguments[0];
if (!answer.isJudgment())
return;
if (answer.isInput()) {
// this is a repetition of something explicitly input
return;
}
// if (!started) {
// if (answer.getTerm().toString().equals(startChallenge)) {
// started = true;
// }
// else {
// return;
// }
// }
// for now, assume the qustion term is answer term
Term qterm = answer.getTerm();
if (answerProvided.contains(qterm)) {
return;
}
if (answer.getConfidence() < confThreshold)
return;
Term t = answer.getTerm();
if (t instanceof Inheritance) {
Term subj = ((Inheritance) t).getSubject();
Term pred = ((Inheritance) t).getPredicate();
if ((subj instanceof SetExt) && (((SetExt) subj).length() == 1))
subj = ((Compound) subj).term[0];
if (subj instanceof Product) {
Product p = (Product) subj;
int[] n = n(p, 3);
if (n != null) {
boolean correct = false;
switch(pred.toString()) {
case "and":
correct = evalAnd(n);
break;
case "or":
correct = evalOr(n);
break;
case "xor":
correct = evalXor(n);
break;
// case "not": correct = evalNot(n); break;
default:
return;
}
float freq = answer.getFrequency();
float conf = answer.getConfidence();
if (freq < freqThresh) {
// invert
correct = !correct;
freq = 1f - freq;
}
if (freq < (1.0 - freqThresh)) {
// not clear 0 or 1
return;
}
addScore(qterm, answer, correct, freq * conf);
if (!correct) {
System.err.println(answer.getExplanation());
if (failOnError)
System.exit(1);
// give correct answer
if (correctFeedback) {
// String c = getTerm(n[0], n[1], pred.toString(), not(n[2])) + ('.');
Term fc = nar.term(getTerm(n[0], n[1], pred.toString(), n[2]));
String c = "(--," + fc + ("). %1.00;" + n2(inputConf) + "%");
nar.input(c);
answerProvided.add(fc);
questionScores.remove(fc);
}
}
}
}
}
}
use of oop.JOOP46_Collections_Part01.Product in project cuba by cuba-platform.
the class DataManagerTransactionalUsageTest method testSecureWithProgrammaticTx.
@Test
public void testSecureWithProgrammaticTx() {
SaleProcessor processor = AppBeans.get("test_SaleProcessor");
Id<OrderLine, UUID> orderLineId = processor.sellSecureWithProgrammaticTx("abc", 10);
Product product1 = dataManager.load(Product.class).query("select p from sales1$Product p where p.name = :name").parameter("name", "abc").one();
assertEquals(90, (int) product1.getQuantity());
Product product2 = dataManager.create(Product.class);
product2.setName("def");
product2.setQuantity(100);
dataManager.commit(product2);
OrderLine orderLine = dataManager.load(orderLineId).view("with-product").one();
orderLine.setProduct(product2);
dataManager.commit(orderLine);
Product changedProduct1 = dataManager.load(Id.of(product1)).one();
assertEquals(100, (int) changedProduct1.getQuantity());
Product changedProduct2 = dataManager.load(Id.of(product2)).one();
assertEquals(90, (int) changedProduct2.getQuantity());
}
use of oop.JOOP46_Collections_Part01.Product in project java-vision by googleapis.
the class ProductInProductSetManagement method listProductsInProductSet.
// [END vision_product_search_add_product_to_product_set]
// [START vision_product_search_list_products_in_product_set]
/**
* List all products in a product set.
*
* @param projectId - Id of the project.
* @param computeRegion - Region name.
* @param productSetId - Id of the product set.
* @throws IOException - on I/O errors.
*/
public static void listProductsInProductSet(String projectId, String computeRegion, String productSetId) throws IOException {
try (ProductSearchClient client = ProductSearchClient.create()) {
// Get the full path of the product set.
String formattedName = ProductSearchClient.formatProductSetName(projectId, computeRegion, productSetId);
// List all the products available in the product set.
for (Product product : client.listProductsInProductSet(formattedName).iterateAll()) {
// Display the product information
System.out.println(String.format("Product name: %s", product.getName()));
System.out.println(String.format("Product id: %s", product.getName().substring(product.getName().lastIndexOf('/') + 1)));
System.out.println(String.format("Product display name: %s", product.getDisplayName()));
System.out.println(String.format("Product description: %s", product.getDescription()));
System.out.println(String.format("Product category: %s", product.getProductCategory()));
System.out.println("Product labels: ");
for (Product.KeyValue element : product.getProductLabelsList()) {
System.out.println(String.format("%s: %s", element.getKey(), element.getValue()));
}
}
}
}
Aggregations