From 9425990f532b1152c2d73db96c0f07ef5216a3d1 Mon Sep 17 00:00:00 2001 From: lresende Date: Thu, 12 Nov 2009 00:43:48 +0000 Subject: Moving 2.x contribs git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835178 13f79535-47bb-0310-9956-ffa450edef68 --- .../store/assets/services/ShoppingCartImpl.java | 112 --------------------- 1 file changed, 112 deletions(-) delete mode 100644 java/sca-contrib/tutorials/store/assets/services/ShoppingCartImpl.java (limited to 'java/sca-contrib/tutorials/store/assets/services/ShoppingCartImpl.java') diff --git a/java/sca-contrib/tutorials/store/assets/services/ShoppingCartImpl.java b/java/sca-contrib/tutorials/store/assets/services/ShoppingCartImpl.java deleted file mode 100644 index 698614212d..0000000000 --- a/java/sca-contrib/tutorials/store/assets/services/ShoppingCartImpl.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package services; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.apache.tuscany.sca.data.collection.Entry; -import org.apache.tuscany.sca.data.collection.NotFoundException; -import org.oasisopen.sca.annotation.Init; -import org.oasisopen.sca.annotation.Scope; - -@Scope("COMPOSITE") -public class ShoppingCartImpl implements Cart, Total { - - private Map cart; - - @Init - public void init() { - cart = new HashMap(); - } - - public Entry[] getAll() { - Entry[] entries = new Entry[cart.size()]; - int i = 0; - for (Map.Entry e: cart.entrySet()) { - entries[i++] = new Entry(e.getKey(), e.getValue()); - } - return entries; - } - - public Item get(String key) throws NotFoundException { - Item item = cart.get(key); - if (item == null) { - throw new NotFoundException(key); - } else { - return item; - } - } - - public String post(String key, Item item) { - if (key == null) { - key ="cart-" + UUID.randomUUID().toString(); - } - cart.put(key, item); - return key; - } - - public void put(String key, Item item) throws NotFoundException { - if (!cart.containsKey(key)) { - throw new NotFoundException(key); - } - cart.put(key, item); - } - - public void delete(String key) throws NotFoundException { - if (key == null || key.equals("")) { - cart.clear(); - } else { - Item item = cart.remove(key); - if (item == null) - throw new NotFoundException(key); - } - } - - public Entry[] query(String queryString) { - List> entries = new ArrayList>(); - if (queryString.startsWith("name=")) { - String name = queryString.substring(5); - for (Map.Entry e: cart.entrySet()) { - Item item = e.getValue(); - if (item.getName().equals(name)) { - entries.add(new Entry(e.getKey(), e.getValue())); - } - } - } - return entries.toArray(new Entry[entries.size()]); - } - - public String getTotal() { - double total = 0; - String currencySymbol = ""; - if (!cart.isEmpty()) { - Item item = cart.values().iterator().next(); - currencySymbol = item.getPrice().substring(0, 1); - } - for (Item item : cart.values()) { - total += Double.valueOf(item.getPrice().substring(1)); - } - return currencySymbol + String.valueOf(total); - } -} -- cgit v1.2.3